com.alee.extended.window
Class ComponentMoveAdapter

java.lang.Object
  extended by java.awt.event.MouseAdapter
      extended by com.alee.extended.window.ComponentMoveAdapter
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.util.EventListener

public class ComponentMoveAdapter
extends java.awt.event.MouseAdapter

This listener allows you to simplify window/component move action. Simply install this listener onto any component to make it move the window when dragged. You can specify moved window/component or simply let the listener detect it.

Author:
Mikle Garin

Field Summary
protected  java.awt.Component dragged
          Currently dragged component.
protected  boolean dragging
          Whether component is being dragged or not.
protected  java.awt.Rectangle initialBounds
          Dragged component initial bounds.
protected  java.awt.Point initialPoint
          Drag start point.
protected  java.awt.Component toDrag
          Component that should be dragged.
 
Constructor Summary
ComponentMoveAdapter()
          Constructs new component move adapter that alows source component parent window dragging.
ComponentMoveAdapter(java.awt.Component toDrag)
          Constructs new component move adapter that allows specified component dragging.
 
Method Summary
protected  java.awt.Component getDraggedComponent(java.awt.event.MouseEvent e)
          Returns actual dragged component.
protected  java.awt.Rectangle getDragStartBounds(java.awt.event.MouseEvent e)
          Returns bounds within which component will act as a gripper.
static void install(java.awt.Component component)
          Installs window move adapter to the specified window component.
static void install(java.awt.Component component, java.awt.Component toDrag)
          Installs component move adapter to the specified component.
 void mouseDragged(java.awt.event.MouseEvent e)
          
 void mousePressed(java.awt.event.MouseEvent e)
          
 void mouseReleased(java.awt.event.MouseEvent e)
          
 
Methods inherited from class java.awt.event.MouseAdapter
mouseClicked, mouseEntered, mouseExited, mouseMoved, mouseWheelMoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

toDrag

protected java.awt.Component toDrag
Component that should be dragged. If set to null mouse events source component parent window will be dragged instead.


dragging

protected boolean dragging
Whether component is being dragged or not.


dragged

protected java.awt.Component dragged
Currently dragged component.


initialPoint

protected java.awt.Point initialPoint
Drag start point.


initialBounds

protected java.awt.Rectangle initialBounds
Dragged component initial bounds.

Constructor Detail

ComponentMoveAdapter

public ComponentMoveAdapter()
Constructs new component move adapter that alows source component parent window dragging.


ComponentMoveAdapter

public ComponentMoveAdapter(java.awt.Component toDrag)
Constructs new component move adapter that allows specified component dragging.

Parameters:
toDrag - component to drag
Method Detail

install

public static void install(java.awt.Component component)
Installs window move adapter to the specified window component.

Parameters:
component - window component that will act as gripper

install

public static void install(java.awt.Component component,
                           java.awt.Component toDrag)
Installs component move adapter to the specified component.

Parameters:
component - component that will act as gripper
toDrag - component to be moved by the gripper component

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)

Specified by:
mousePressed in interface java.awt.event.MouseListener
Overrides:
mousePressed in class java.awt.event.MouseAdapter

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Overrides:
mouseDragged in class java.awt.event.MouseAdapter

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Overrides:
mouseReleased in class java.awt.event.MouseAdapter

getDraggedComponent

protected java.awt.Component getDraggedComponent(java.awt.event.MouseEvent e)
Returns actual dragged component.

Parameters:
e - occured mouse event
Returns:
actual dragged component

getDragStartBounds

protected java.awt.Rectangle getDragStartBounds(java.awt.event.MouseEvent e)
Returns bounds within which component will act as a gripper.

Parameters:
e - occured mouse event
Returns:
bounds within which component will act as a gripper