bibliothek.gui.dock.control.relocator
Class DefaultDockRelocator

java.lang.Object
  extended by bibliothek.gui.dock.control.relocator.AbstractDockRelocator
      extended by bibliothek.gui.dock.control.relocator.DefaultDockRelocator
All Implemented Interfaces:
DockRelocator

public class DefaultDockRelocator
extends AbstractDockRelocator

Default implementation of a handler that performs the drag & drop operations for a DockController.

Author:
Benjamin Sigg

Field Summary
static String EXTENSION_PARAM
          Name of a parameter of an ExtensionName pointing to this
static Path INSERTER_EXTENSION
          Path of an ExtensionName that adds new Inserters
static Path MERGE_EXTENSION
          Path of an ExtensionName that adds new Mergers
 
Constructor Summary
DefaultDockRelocator(DockController controller, ControllerSetupCollection setup)
          Creates a new manager.
 
Method Summary
 void cancel()
          Cancels the current drag and drop operation (if there is any).
protected  boolean canMerge(StationDropOperation operation, DockStation parent, Dockable selection)
          Checks whether the current Merger can merge parent with child.
 DirectRemoteRelocator createDirectRemote(Dockable dockable)
          Creates a device with which drag&drop operations concerning dockable can be initiated and executed.
 DirectRemoteRelocator createDirectRemote(Dockable dockable, boolean forceDrag)
          Creates a device with which drag&drop operations concerning dockable can be initiated and executed.
 RemoteRelocator createRemote(Dockable dockable)
          Creates a device with which drag&drop operations concerning dockable can be initiated and executed.
 RemoteRelocator createRemote(Dockable dockable, boolean forceDrag)
          Creates a device with which drag&drop operations concerning dockable can be initiated and executed.
protected  RemoteRelocator.Reaction dragMouseDragged(int x, int y, int modifiers, DockTitle title, Dockable dockable, boolean always, boolean forceDrag)
          Handles a mouse-pressed event.
protected  RemoteRelocator.Reaction dragMouseDragged(int x, int y, int modifiers, DockTitle title, Dockable dockable, boolean always, boolean forceDrag, boolean showMovingImage)
          Handles a mouse-pressed event.
protected  void dragMouseDragged(MouseEvent e, DockTitle title, Dockable dockable)
          Invoked while the user drags a title or Dockable.
protected  RemoteRelocator.Reaction dragMousePressed(int x, int y, int dx, int dy, int modifiers, Dockable dockable, boolean forceDrag)
          Handles a mouse-pressed event.
protected  void dragMousePressed(MouseEvent e, DockTitle title, Dockable dockable)
          Invoked by the listeners of a title to start a drag and drop operation.
protected  RemoteRelocator.Reaction dragMouseReleased(int x, int y, int modifiers, Dockable dockable)
          Handles a mouse-released event.
protected  void dragMouseReleased(MouseEvent e, DockTitle title, Dockable dockable)
          Invoked while the user drags a title or Dockable and releases a mouse button.
protected  boolean executeOperation(Dockable dockable, RelocateOperation operation)
          Executes the drag and drop event operation.
 boolean hasTarget()
          Tells whether the current drag and drop operation has a target, i.e.
protected  boolean isCancelLocation(int x, int y, Dockable moved)
          Checks whether the mouse is at a location that cancels a drag and drop operation.
protected  boolean isCancelLocation(int x, int y, DockElementRepresentative item)
          Checks whether the mouse is at a location that cancels a drag and drop operation.
 boolean isOnMove()
          Tells whether the user has currently grabbed a dockable and moves the dockable around.
 boolean isOnPut()
          Tells whether this relocator currently puts a Dockable.
protected  boolean isStationValid(DockStation station)
          Only stations passing this test are considered during drag and drop operation as new parent.
protected  List<DockStation> listStationsOrdered(int x, int y, Dockable moved)
          Makes a list of all stations which are visible and contain the point x/y.
protected  RelocateOperation preparePut(int mouseX, int mouseY, int titleX, int titleY, Dockable dockable)
          Searches a station which can become the parent of dockable if the mouse is released at mouseX/mouseY.
 
Methods inherited from class bibliothek.gui.dock.control.relocator.AbstractDockRelocator
addMode, addVetoableDockRelocatorListener, checkModes, disableAllModes, fireCanceled, fireDragged, fireDragging, fireDropped, fireDropping, fireGrabbed, fireGrabbing, fireSearched, getController, getDragDistance, getInserter, getMerger, isDragOnlyTitel, removeMode, removeVetoableDockRelocatorListener, setDragDistance, setDragOnlyTitel, setInserter, setMerger, vetoableListeners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MERGE_EXTENSION

public static final Path MERGE_EXTENSION
Path of an ExtensionName that adds new Mergers


INSERTER_EXTENSION

public static final Path INSERTER_EXTENSION
Path of an ExtensionName that adds new Inserters


EXTENSION_PARAM

public static final String EXTENSION_PARAM
Name of a parameter of an ExtensionName pointing to this

See Also:
Constant Field Values
Constructor Detail

DefaultDockRelocator

public DefaultDockRelocator(DockController controller,
                            ControllerSetupCollection setup)
Creates a new manager.

Parameters:
controller - the controller whose dockables are moved
setup - observable informing this object when controller is set up.
Method Detail

isOnMove

public boolean isOnMove()
Description copied from interface: DockRelocator
Tells whether the user has currently grabbed a dockable and moves the dockable around.

Returns:
true if a Dockable is currently dragged

isOnPut

public boolean isOnPut()
Description copied from interface: DockRelocator
Tells whether this relocator currently puts a Dockable. A Dockable is put as soon as the user releases the mouse.

Returns:
true if a Dockable is moved

hasTarget

public boolean hasTarget()
Description copied from interface: DockRelocator
Tells whether the current drag and drop operation has a target, i.e. if the operation would be a success if it would end now.

Returns:
whether the current operation has a target, false if there is no operation running

createDirectRemote

public DirectRemoteRelocator createDirectRemote(Dockable dockable)
Description copied from interface: DockRelocator
Creates a device with which drag&drop operations concerning dockable can be initiated and executed.

Parameters:
dockable - the dockable which might be moved
Returns:
the new remote

createDirectRemote

public DirectRemoteRelocator createDirectRemote(Dockable dockable,
                                                boolean forceDrag)
Description copied from interface: DockRelocator
Creates a device with which drag&drop operations concerning dockable can be initiated and executed.

Parameters:
dockable - the dockable which might be moved
forceDrag - if this flag is set to true, then dragging will always start even if one of the usual conditions is not met. I.e. dragging will start even if dockable does not have a parent of even if the parent does not allow dragging. This flag should be used with caution.
Returns:
the new remote

createRemote

public RemoteRelocator createRemote(Dockable dockable)
Description copied from interface: DockRelocator
Creates a device with which drag&drop operations concerning dockable can be initiated and executed.

Parameters:
dockable - the dockable which might be moved
Returns:
the new remote

createRemote

public RemoteRelocator createRemote(Dockable dockable,
                                    boolean forceDrag)
Description copied from interface: DockRelocator
Creates a device with which drag&drop operations concerning dockable can be initiated and executed.

Parameters:
dockable - the dockable which might be moved
forceDrag - if this flag is set to true, then dragging will always start even if one of the usual conditions is not met. I.e. dragging will start even if dockable does not have a parent of even if the parent does not allow dragging. This flag should be used with caution.
Returns:
the new remote

executeOperation

protected boolean executeOperation(Dockable dockable,
                                   RelocateOperation operation)
Executes the drag and drop event operation.

Parameters:
dockable - a Dockable which is moved
operation - the operation to execute
Returns:
true if the operation was a success, false if the operation was canceled

preparePut

protected RelocateOperation preparePut(int mouseX,
                                       int mouseY,
                                       int titleX,
                                       int titleY,
                                       Dockable dockable)
Searches a station which can become the parent of dockable if the mouse is released at mouseX/mouseY.

Parameters:
mouseX - x-coordinate of the mouse on the screen
mouseY - y-coordinate of the mouse on the screen
titleX - x-coordinate of the dragged title or mouseX
titleY - y-coordinate of the dragged title or mouseY
dockable - a Dockable which is dragged
Returns:
the new parent of dockable or null

canMerge

protected boolean canMerge(StationDropOperation operation,
                           DockStation parent,
                           Dockable selection)
Checks whether the current Merger can merge parent with child.

Parameters:
operation - the operation that would be exected
parent - the new parent for the children of child
selection - the element whose children are to be removed
Returns:
true if a merge is possible

listStationsOrdered

protected List<DockStation> listStationsOrdered(int x,
                                                int y,
                                                Dockable moved)
Makes a list of all stations which are visible and contain the point x/y. The stations are ordered by their visibility.

Parameters:
x - x-coordinate on the screen
y - y-coordinate on the screen
moved - a Dockable which is dragged. If this is a station, then no child of the station will be in the resulting list.
Returns:
a list of stations

isCancelLocation

protected boolean isCancelLocation(int x,
                                   int y,
                                   Dockable moved)
Checks whether the mouse is at a location that cancels a drag and drop operation. This method just calls isCancelLocation(int, int, DockElementRepresentative) with all the DockElementRepresentative that can be found for moved.

Parameters:
x - x-coordinate on the screen
y - y-coordinate on the screen
moved - the item that was moved around
Returns:
true if the current location can never result in a valid drop operation

isCancelLocation

protected boolean isCancelLocation(int x,
                                   int y,
                                   DockElementRepresentative item)
Checks whether the mouse is at a location that cancels a drag and drop operation. The default implementation of this method always returns false.

Parameters:
x - x-coordinate on the screen
y - y-coordinate on the screen
item - the item that was moved around
Returns:
true if the current location can never result in a valid drop operation

isStationValid

@ClientOnly
protected boolean isStationValid(DockStation station)
Only stations passing this test are considered during drag and drop operation as new parent. Subclasses may override this method.

Parameters:
station - the station to check
Returns:
true if station should be considered as new parent

dragMousePressed

protected void dragMousePressed(MouseEvent e,
                                DockTitle title,
                                Dockable dockable)
Invoked by the listeners of a title to start a drag and drop operation.

Parameters:
e - the initializing event
title - the grabbed title, can be null if dockable is not null
dockable - the grabbed Dockable, can be null if title is not null

dragMousePressed

protected RemoteRelocator.Reaction dragMousePressed(int x,
                                                    int y,
                                                    int dx,
                                                    int dy,
                                                    int modifiers,
                                                    Dockable dockable,
                                                    boolean forceDrag)
Handles a mouse-pressed event.

Parameters:
x - the x-coordinate of the mouse
y - the y-coordinate of the mouse
dx - the x-coordinate of the mouse on its component
dy - the y-coordinate of the mouse on its component
modifiers - the state of the mouse, see InputEvent.getModifiersEx()
dockable - the dockable which is moved around
forceDrag - if this flag is set to true, then dragging will always start even if one of the usual conditions is not met. I.e. dragging will start even if dockable does not have a parent of even if the parent does not allow dragging. This flag should be used with caution.
Returns:
how this relocator reacts on the event

dragMouseDragged

protected void dragMouseDragged(MouseEvent e,
                                DockTitle title,
                                Dockable dockable)
Invoked while the user drags a title or Dockable.

Parameters:
e - the initializing event
title - the grabbed title, can be null if dockable is not null
dockable - the grabbed Dockable, can be null if title is not null

dragMouseDragged

protected RemoteRelocator.Reaction dragMouseDragged(int x,
                                                    int y,
                                                    int modifiers,
                                                    DockTitle title,
                                                    Dockable dockable,
                                                    boolean always,
                                                    boolean forceDrag)
Handles a mouse-pressed event.

Parameters:
x - the x-coordinate of the mouse
y - the y-coordinate of the mouse
modifiers - the state of the mouse, see InputEvent.getModifiersEx()
title - the title which might be grabbed by the mouse
dockable - the dockable which is moved around
always - true if the drag event should be executed and restrictions to this relocator ignored.
forceDrag - if this flag is set to true, then dragging will always start even if one of the usual conditions is not met. I.e. dragging will start even if dockable does not have a parent of even if the parent does not allow dragging. This flag should be used with caution.
Returns:
how this relocator reacts on the event

dragMouseDragged

protected RemoteRelocator.Reaction dragMouseDragged(int x,
                                                    int y,
                                                    int modifiers,
                                                    DockTitle title,
                                                    Dockable dockable,
                                                    boolean always,
                                                    boolean forceDrag,
                                                    boolean showMovingImage)
Handles a mouse-pressed event.

Parameters:
x - the x-coordinate of the mouse
y - the y-coordinate of the mouse
modifiers - the state of the mouse, see InputEvent.getModifiersEx()
title - the title which might be grabbed by the mouse
dockable - the dockable which is moved around
always - true if the drag event should be executed and restrictions to this relocator ignored.
forceDrag - if this flag is set to true, then dragging will always start even if one of the usual conditions is not met. I.e. dragging will start even if dockable does not have a parent of even if the parent does not allow dragging. This flag should be used with caution.
showMovingImage - whether to show a MovingImage
Returns:
how this relocator reacts on the event

dragMouseReleased

protected void dragMouseReleased(MouseEvent e,
                                 DockTitle title,
                                 Dockable dockable)
Invoked while the user drags a title or Dockable and releases a mouse button.

Parameters:
e - the initializing event
title - the grabbed title, can be null if dockable is not null
dockable - the grabbed Dockable, can be null if title is not null

dragMouseReleased

protected RemoteRelocator.Reaction dragMouseReleased(int x,
                                                     int y,
                                                     int modifiers,
                                                     Dockable dockable)
Handles a mouse-released event.

Parameters:
x - the x-coordinate of the mouse
y - the y-coordinate of the mouse
modifiers - the state of the mouse, see InputEvent.getModifiersEx()
dockable - the dockable which is moved around
Returns:
how this relocator reacts on the event

cancel

public void cancel()
Description copied from interface: DockRelocator
Cancels the current drag and drop operation (if there is any). All evidence of a DnD operation is to be removed immediatelly. Listeners will receive a canceled-event.