com.javadocking.drag
Class DefaultDragListener

java.lang.Object
  extended by com.javadocking.drag.DefaultDragListener
All Implemented Interfaces:
DragListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener, javax.swing.event.MouseInputListener

public class DefaultDragListener
extends java.lang.Object
implements DragListener

This drag listener contains a Dragger. The real dragging functionality is done by this dragger. This class only analyzes the mouse events and decides if dragging should be started, continued, stopped, or canceled.

Dragging is started when a mouse button is pressed and a specific modifier (CTRL, ALT, SHIFT or META) is down.

To have a specific mouse button for starting dragging, this button should be specified with the method setStartButtonMask(int), e.g. if you want to use the middle mouse button for dragging: setStartButtonMask(java.awt.event.InputEvent.BUTTON2_MASK)
The default mouse button for starting dragging is the left mouse button.

To have a specific modifier for starting dragging, this modifier should be specified with the method setStartModifierMask(int), e.g. if you want to use the CTRL modifier for dragging: setStartModifierMask(java.awt.event.InputEvent.CTRL_DOWN_MASK)
If no specific modifier should be down, give NO_MASK as parameter. The default modifier for starting dragging is NO_MASK.

Dragging is canceled when a specific mouse button is pressed. To have a specific mouse button for canceling dragging, this button should be specified with the method setCancelButtonMask(int), e.g. if you want to use the right mouse button for canceling dragging: setCancelButtonMask(java.awt.event.InputEvent.BUTTON3_MASK)
The default mouse button for canceling dragging is the right mouse button.

Dragging can also be canceled when releasing the mouse button while a modifier (CTRL, ALT, SHIFT or META) is pressed. To have a specific modifier for canceling dragging, this modifier should be specified with the method setCancelModifierMask(int), f.e. if you want to use the ALT modifier for canceling dragging: setCancelModifierMask(java.awt.event.InputEvent.ALT_DOWN_MASK)
There is no default modifier for canceling dragging.

Author:
Heidi Rakels.

Field Summary
static int NO_MASK
           
 
Constructor Summary
DefaultDragListener(Dock dock)
          Constructs a drag mouse listener for the given dock.
DefaultDragListener(Dockable dockable)
          Constructs a drag mouse listener for the given dockable.
 
Method Summary
protected  boolean canCancelDragging(java.awt.event.MouseEvent mouseEvent)
          Determines if dragging should be canceled for the given mouse event.
protected  boolean canShowPopup(java.awt.event.MouseEvent mouseEvent)
          Determines if for this mouse event the popup of the dockable should be shown.
protected  boolean canStartDragging(java.awt.event.MouseEvent mouseEvent)
          Determines if dragging should be started for the given mouse event.
 int getCancelButtonMask()
          Gets the mouse button that should be pressed for canceling dragging.
 int getCancelModifierMask()
          Gets the modifier that should be down for canceling dragging when the button is released.
 int getStartButtonMask()
          Gets the mouse button that should be pressed for starting dragging.
 int getStartModifierMask()
          Gets the modifier that should be pressed for starting dragging.
 void mouseClicked(java.awt.event.MouseEvent mouseEvent)
           
 void mouseDragged(java.awt.event.MouseEvent mouseEvent)
           
 void mouseEntered(java.awt.event.MouseEvent mouseEvent)
           
 void mouseExited(java.awt.event.MouseEvent mouseEvent)
           
 void mouseMoved(java.awt.event.MouseEvent mouseEvent)
           
 void mousePressed(java.awt.event.MouseEvent mouseEvent)
           
 void mouseReleased(java.awt.event.MouseEvent mouseEvent)
           
 void setCancelButtonMask(int cancelButtonMask)
          Sets the mouse button that should be pressed for canceling dragging.
 void setCancelModifierMask(int cancelModifierMask)
          Sets the modifier that should be down for canceling dragging when the button is released.
 void setStartButtonMask(int startButtonMask)
          Sets the mouse button that should be pressed for starting dragging.
 void setStartModifierMask(int startModifierMask)
          Sets the modifier that should be pressed for starting dragging.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_MASK

public static final int NO_MASK
See Also:
Constant Field Values
Constructor Detail

DefaultDragListener

public DefaultDragListener(Dock dock)
Constructs a drag mouse listener for the given dock.

Parameters:
dock - The drag listener listens to drag events for this dock.
Throws:
java.lang.IllegalArgumentException - If the dock is null.

DefaultDragListener

public DefaultDragListener(Dockable dockable)
Constructs a drag mouse listener for the given dockable.

Parameters:
dockable - The drag listener listens to drag events for this dockable.
Throws:
java.lang.IllegalArgumentException - If the dockable is null.
Method Detail

mousePressed

public void mousePressed(java.awt.event.MouseEvent mouseEvent)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent mouseEvent)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent mouseEvent)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent mouseEvent)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent mouseEvent)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent mouseEvent)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent mouseEvent)
Specified by:
mouseExited in interface java.awt.event.MouseListener

getCancelButtonMask

public int getCancelButtonMask()
Gets the mouse button that should be pressed for canceling dragging.

Returns:
The mouse button that should be pressed for canceling dragging. When no mouse button has to be pressed, NO_MASK is returned. The default value is the right mouse button java.awt.event.InputEvent.BUTTON3_MASK.

setCancelButtonMask

public void setCancelButtonMask(int cancelButtonMask)
Sets the mouse button that should be pressed for canceling dragging.

Parameters:
cancelButtonMask - The mouse button that should be pressed for canceling dragging. When no mouse button has to be pressed, this should be NO_MASK.

getCancelModifierMask

public int getCancelModifierMask()
Gets the modifier that should be down for canceling dragging when the button is released.

Returns:
The modifier that should be down for canceling dragging when the button is released. When no modifier has to be down, NO_MASK is returned. The default value is NO_MASK.

setCancelModifierMask

public void setCancelModifierMask(int cancelModifierMask)
Sets the modifier that should be down for canceling dragging when the button is released.

Parameters:
cancelModifierMask - The modifier that should be down for canceling dragging when the button is released. When no modifier has to be down, this should be NO_MASK.

getStartButtonMask

public int getStartButtonMask()
Gets the mouse button that should be pressed for starting dragging.

Returns:
The mouse button that should be pressed for starting dragging. When no specific mouse button has to be pressed, NO_MASK is returned. The default value is the left mouse button java.awt.event.InputEvent.BUTTON1_MASK.

setStartButtonMask

public void setStartButtonMask(int startButtonMask)
Sets the mouse button that should be pressed for starting dragging.

Parameters:
startButtonMask - The mouse button that should be pressed for starting dragging. When no specific mouse button has to be pressed, this should be NO_MASK.

getStartModifierMask

public int getStartModifierMask()
Gets the modifier that should be pressed for starting dragging.

Returns:
The modifier that should be pressed for starting dragging. When no modifier has to be pressed, NO_MASK is returned. The default value is NO_MASK.

setStartModifierMask

public void setStartModifierMask(int startModifierMask)
Sets the modifier that should be pressed for starting dragging.

Parameters:
startModifierMask - The modifier that should be pressed for starting dragging. When no modifier has to be pressed, this should be NO_MASK.

canStartDragging

protected boolean canStartDragging(java.awt.event.MouseEvent mouseEvent)
Determines if dragging should be started for the given mouse event. Dragging can be started if the start button defined by getStartButtonMask() is pressed and if one of the modifiers defined by getStartModifierMask() is down.

Returns:
True if dragging should be started, false otherwise.

canCancelDragging

protected boolean canCancelDragging(java.awt.event.MouseEvent mouseEvent)
Determines if dragging should be canceled for the given mouse event. Dragging should be canceled if the cancel button defined by getCancelButtonMask() is pressed and if one of the modifiers defined by getCancelModifierMask() is down.

Returns:
True if dragging should be started, false otherwise.

canShowPopup

protected boolean canShowPopup(java.awt.event.MouseEvent mouseEvent)
Determines if for this mouse event the popup of the dockable should be shown.

Returns:
True if dragging should be started, false otherwise.