Search this API

y.view
Class MoveSelectionMode

java.lang.Object
  extended by y.view.ViewMode
      extended by y.view.MoveSelectionMode
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener, javax.swing.event.MouseInputListener
Direct Known Subclasses:
PortAssignmentMoveSelectionMode

public class MoveSelectionMode
extends ViewMode

This view mode is responsible for moving selected parts of the displayed graph. On a left press this mode starts to move selected graph elements around. While the mouse is being dragged the selected parts will be moved around. If the mouse gets released the operation will end and all registered views will receive an update event.

This mode automatically adds the contents of selected group nodes to the list of objects that need to be moved. Also, it automatically moves all children of a selected group node. This way the view mode naturally extends the selection in the presence of node groups.

Additionally, this view mode allows to add or remove nodes to and from a group. To add a selected node to a group, the node has to be dragged with the mouse to the target group node, then while pressing the modifier key the left mouse button needs to be released. To remove a selected node from a group the modifier key needs to be held down while pressing the left mouse button to initiate the move selection action.

 

Field Summary
static byte FIXED_AUTOBOUNDS_INSETS
          Group bounds policy specifier.
static byte FIXED_MINIMUM_GROUP_BOUNDS
          Group bounds policy specifier.
 
Fields inherited from class y.view.ViewMode
ACTIVE_PROPERTY, ACTIVE_VIEW_PROPERTY, CHILD_MODE_PROPERTY, EDITING_PROPERTY, GRAB_FOCUS_ENABLED_PROPERTY, lastClickEvent, lastDragEvent, lastMoveEvent, lastPressEvent, lastReleaseEvent, MODIFIER_MASK_PROPERTY, NAME_PROPERTY, originalX, originalY, PARENT_MODE_PROPERTY, view
 
Constructor Summary
MoveSelectionMode()
          Initializes a new MoveSelectionMode.
MoveSelectionMode(ViewContainer view)
          Initializes a new MoveSelectionMode for a given ViewContainer
 
Method Summary
 void activate(boolean b)
          Invoked when the Mode is activated/deactivated from the ViewControl or via the setChild() and reactivateParent operations This behaves like a bound property using ViewMode.ACTIVE_PROPERTY as the property name.
 void cancelEditing()
          This can be used to cleanly exit an edit that is currently in progress.
protected  HitInfo createDropTargetHitInfo(double x, double y)
          Performs a hit test for a target group node at the specified drop target location.
protected  MoveSnapContext createSnapContext()
          Creates the MoveSnapContext that will be used by this instance to snap the mouse coordinates.
protected  void drawTargetNodeIndicator(java.awt.Graphics2D gfx, NodeRealizer nodeRealizer)
          Callback method that actually renders the target group node indicator.
protected  void findAdditionalElements(NodeList nodesToBeMoved, BendList bendsToBeMoved)
          Determines nodes and bends that are moved in addition to the ones returned by getNodesToBeMoved() and getBendsToBeMoved().
protected  void findAdditionalElements(NodeList nodesToBeMoved, NodeList ancestorNodes, BendList bendsToBeMoved)
          Determines nodes and bends that are moved in addition to the ones returned by getNodesToBeMoved() and getBendsToBeMoved().
protected  BendList getBendsToBeMoved()
          Returns the bends that should be moved by this view mode.
 int getDisableSnappingModifier()
          Gets the modifier mask that can be used to determine whether the user disables snapping via the snap context temporarily.
 byte getGroupBoundsPolicy()
          Returns the group bounds policy used when moving the child nodes of a group.
protected  java.lang.Object getGroupingDropTarget(double x, double y)
          Determines the Node or Graph that will be used for the given coordinates for a reparenting move operation.
protected  HierarchyManager getHierarchyManager()
          Returns the HierarchyManager associated with the graph displayed in the underlying Graph2DView.
protected  NodeList getNodesToBeMoved()
          Returns the nodes that should be moved by this view mode.
 MoveSnapContext getSnapContext()
          Gets the MoveSnapContext instance that can be used by this instance to perform mouse snapping during the move operation if snapping is enabled.
protected  java.awt.geom.Rectangle2D getTargetNodeIndicatorBounds(NodeRealizer nodeRealizer)
          Yields the bounds of the target group node indicator Drawable.
protected  boolean isDisableSnappingModifierPressed(java.awt.event.MouseEvent e)
          Callback used by this mode to determine whether the modifier to disable snapping has been currently pressed.
 boolean isGroupReassignmentEnabled()
          Returns whether or not reassignment of nodes to other groups is enabled.
 boolean isIndicatingTargetGroup()
          Whether this instance indicates the target group node for a group reassignment operation using a Drawable.
protected  boolean isOrthogonalRouting(Edge edge)
          Determines whether the given edge instance should be routed orthogonally.
 boolean isRemovingInnerBends()
          Determines whether this instance should remove bends of edges adjacent to nodes that are contained in nodes that have been moved during the move operation after the move is finished.
 boolean isSnappingEnabled()
          Whether this mode should use the getSnapContext() to MoveSnapContext.adjustMouseCoordinates(y.geom.YPoint) adjust the mouse coordinates so that the moved items snap to the precalculated SnapLines.
 void mouseDraggedLeft(double x, double y)
          Moves the selected graph elements around.
 void mouseDraggedRight(double x, double y)
          Called when the mouse was dragged with the right button down.
 void mousePressedLeft(double x, double y)
          Initiates the movement of the selected graph elements.
 void mouseReleased(java.awt.event.MouseEvent ev)
          A mouse button get released
 void mouseReleasedLeft(double x, double y)
          Terminates the movements of the selected graph elements.
 void mouseReleasedRight(double x, double y)
          Called when the right mouse button was released
 void mouseShiftPressedLeft(double x, double y)
          Initiates the movement of the selected graph elements.
 void mouseShiftReleasedLeft(double x, double y)
          Terminates the movements of the selected graph elements.
 void reactivateParent()
          The parent of this ViewMode is reactivated and this ViewMode is deactivated.
protected  void selectionMovedAction(double dx, double dy, double x, double y)
          Performs an action after the selection was moved.
protected  void selectionMoveStarted(double x, double y)
          Performs an action when the selection is about to be moved.
protected  void selectionOnMove(double dx, double dy, double x, double y)
          Performs an action when the selection is moving.
 void setDisableSnappingModifier(int disableSnappingModifier)
          Sets the modifier mask that can be used to determine whether the user disables snapping via the snap context temporarily.
 void setGroupBoundsPolicy(byte groupBoundsPolicy)
          Sets the group bounds policy used when moving the child nodes of a group.
 void setGroupReassignmentEnabled(boolean enabled)
          Sets whether or not a reassignment of nodes to other groups can be triggered by a mouse/keyboard gesture.
 void setIndicatingTargetGroup(boolean indicatingTargetGroup)
          Determines whether this instance indicates the target group node for a group reassignment operation using a Drawable.
 void setRemovingInnerBends(boolean removingInnerBends)
          Determines whether this instance should remove bends of edges adjacent to nodes that are contained in nodes that have been moved during the move operation after the move is finished.
 void setSnapContext(MoveSnapContext snapContext)
          Sets a different MoveSnapContext to use for this instance.
 void setSnappingEnabled(boolean snappingEnabled)
          Whether this mode should use the getSnapContext() to MoveSnapContext.adjustMouseCoordinates(y.geom.YPoint) adjust the mouse coordinates so that the moved items snap to the precalculated SnapLines.
 
Methods inherited from class y.view.ViewMode
addPropertyChangeListener, addPropertyChangeListener, deactivateChild, firePropertyChange, firePropertyChange, firePropertyChange, getChild, getGraph2D, getGridX, getGridY, getHitInfo, getHitInfo, getLastClickEvent, getLastDragEvent, getLastHitInfo, getLastMoveEvent, getLastPressEvent, getLastReleaseEvent, getModifierMask, getName, getParent, init, isActive, isEditing, isGrabFocusEnabled, isGridMode, isModifierPressed, mouseClicked, mouseClicked, mouseDragged, mouseDraggedMiddle, mouseEntered, mouseExited, mouseMoved, mouseMoved, mousePressed, mousePressedMiddle, mousePressedRight, mouseReleased, mouseReleasedMiddle, mouseShiftPressedMiddle, mouseShiftPressedRight, mouseShiftReleasedMiddle, mouseShiftReleasedRight, removePropertyChangeListener, removePropertyChangeListener, setActiveView, setChild, setChild, setEditing, setGrabFocusEnabled, setGridMode, setLastHitInfo, setModifierMask, setName, setParent, translateX, translateY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIXED_AUTOBOUNDS_INSETS

public static final byte FIXED_AUTOBOUNDS_INSETS
Group bounds policy specifier. When moving nodes that belong to a group whose realizer implements AutoBoundsFeature, the group node's autoBoundsInsets will stay fixed. It's overall bounds can grow or shrink.

See Also:
Constant Field Values

FIXED_MINIMUM_GROUP_BOUNDS

public static final byte FIXED_MINIMUM_GROUP_BOUNDS
Group bounds policy specifier. When moving nodes that belong to a group whose realizer implements AutoBoundsFeature, the group node's bounds can grow but not shrink. Before a group node starts to grow its autoBoundsInset will be reduced, first.

See Also:
Constant Field Values
Constructor Detail

MoveSelectionMode

public MoveSelectionMode(ViewContainer view)
Initializes a new MoveSelectionMode for a given ViewContainer


MoveSelectionMode

public MoveSelectionMode()
Initializes a new MoveSelectionMode.

Method Detail

isRemovingInnerBends

public boolean isRemovingInnerBends()
Determines whether this instance should remove bends of edges adjacent to nodes that are contained in nodes that have been moved during the move operation after the move is finished. If enabled this will remove all bends inside adjacent node and instead place the corresponding port at the location of the last bend that lay inside the node. By default this feature is turned off.


setRemovingInnerBends

public void setRemovingInnerBends(boolean removingInnerBends)
Determines whether this instance should remove bends of edges adjacent to nodes that are contained in nodes that have been moved during the move operation after the move is finished. If enabled this will remove all bends inside adjacent node and instead place the corresponding port at the location of the last bend that lay inside the node. By default this feature is turned off.


activate

public void activate(boolean b)
Description copied from class: ViewMode
Invoked when the Mode is activated/deactivated from the ViewControl or via the setChild() and reactivateParent operations This behaves like a bound property using ViewMode.ACTIVE_PROPERTY as the property name.

Overrides:
activate in class ViewMode
Parameters:
b - set true when mode was activated false otherwise

getDisableSnappingModifier

public int getDisableSnappingModifier()
Gets the modifier mask that can be used to determine whether the user disables snapping via the snap context temporarily. By default this is set to InputEvent.CTRL_MASK so that pressing the CTRL modifier will allow the user to take full control over the movement without the aid of snap lines.


setDisableSnappingModifier

public void setDisableSnappingModifier(int disableSnappingModifier)
Sets the modifier mask that can be used to determine whether the user disables snapping via the snap context temporarily. By default this is set to InputEvent.CTRL_MASK so that pressing the CTRL modifier will allow the user to take full control over the movement without the aid of snap lines.


isDisableSnappingModifierPressed

protected boolean isDisableSnappingModifierPressed(java.awt.event.MouseEvent e)
Callback used by this mode to determine whether the modifier to disable snapping has been currently pressed. This implementation uses the getDisableSnappingModifier() to determine whether the modifier is currently applied.

Parameters:
e - The last mouse event.
Returns:
Whether the modifier is active, i.e. whether snapping should be disabled temporarily.
See Also:
getSnapContext(), getDisableSnappingModifier()

getSnapContext

public MoveSnapContext getSnapContext()
Gets the MoveSnapContext instance that can be used by this instance to perform mouse snapping during the move operation if snapping is enabled.

Returns:
The context instance to use.
See Also:
setSnapContext(MoveSnapContext)

setSnapContext

public void setSnapContext(MoveSnapContext snapContext)
Sets a different MoveSnapContext to use for this instance. Note that unless setSnappingEnabled(boolean) is called to enable snapping, this instance will not be used.

Parameters:
snapContext - The new context to use.

createSnapContext

protected MoveSnapContext createSnapContext()
Creates the MoveSnapContext that will be used by this instance to snap the mouse coordinates.

Returns:
a preconfigured instance of MoveSnapContext.

isSnappingEnabled

public boolean isSnappingEnabled()
Whether this mode should use the getSnapContext() to MoveSnapContext.adjustMouseCoordinates(y.geom.YPoint) adjust the mouse coordinates so that the moved items snap to the precalculated SnapLines. By default this is disabled.


setSnappingEnabled

public void setSnappingEnabled(boolean snappingEnabled)
Whether this mode should use the getSnapContext() to MoveSnapContext.adjustMouseCoordinates(y.geom.YPoint) adjust the mouse coordinates so that the moved items snap to the precalculated SnapLines. By default this is disabled.


mouseShiftPressedLeft

public void mouseShiftPressedLeft(double x,
                                  double y)
Initiates the movement of the selected graph elements.

Overrides:
mouseShiftPressedLeft in class ViewMode
Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mousePressedLeft

public void mousePressedLeft(double x,
                             double y)
Initiates the movement of the selected graph elements.

Overrides:
mousePressedLeft in class ViewMode
Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseShiftReleasedLeft

public void mouseShiftReleasedLeft(double x,
                                   double y)
Terminates the movements of the selected graph elements.

Overrides:
mouseShiftReleasedLeft in class ViewMode
Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseReleasedLeft

public void mouseReleasedLeft(double x,
                              double y)
Terminates the movements of the selected graph elements.

Overrides:
mouseReleasedLeft in class ViewMode
Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

reactivateParent

public void reactivateParent()
Description copied from class: ViewMode
The parent of this ViewMode is reactivated and this ViewMode is deactivated.

Overrides:
reactivateParent in class ViewMode

mouseDraggedLeft

public void mouseDraggedLeft(double x,
                             double y)
Moves the selected graph elements around.

Overrides:
mouseDraggedLeft in class ViewMode
Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

selectionMoveStarted

protected void selectionMoveStarted(double x,
                                    double y)
Performs an action when the selection is about to be moved. By default this method does nothing. Subclasses may want to override this.


selectionOnMove

protected void selectionOnMove(double dx,
                               double dy,
                               double x,
                               double y)
Performs an action when the selection is moving. Adjusts the group node sizes according to the set group bounds policy. Subclasses may want to override this.

Parameters:
dx - the difference between the given x-coordinate and the x-coordinate of the last mouse event handled by this mode.
dy - the difference between the given y-coordinate and the y-coordinate of the last mouse event handled by this mode.
x - the x-coordinate of the triggering mouse event in the world coordinate system.
y - the y-coordinate of the triggering mouse event in the world coordinate system.

selectionMovedAction

protected void selectionMovedAction(double dx,
                                    double dy,
                                    double x,
                                    double y)
Performs an action after the selection was moved. This method performs the necessary actions for reparenting the moved nodes and updating the bounds of the group nodes correspondingly. Subclasses may want to override this.


getNodesToBeMoved

protected NodeList getNodesToBeMoved()
Returns the nodes that should be moved by this view mode. By default the selected nodes of the graph will be returned.


getBendsToBeMoved

protected BendList getBendsToBeMoved()
Returns the bends that should be moved by this view mode. By default the selected bends of the graph will be returned.


findAdditionalElements

protected void findAdditionalElements(NodeList nodesToBeMoved,
                                      BendList bendsToBeMoved)
Determines nodes and bends that are moved in addition to the ones returned by getNodesToBeMoved() and getBendsToBeMoved().

The default implementation does nothing.

This method is called for flat graphs (i.e. graphs with no associated HierarchyManager instance) only.

Parameters:
nodesToBeMoved - input/output parameter. Contains the nodes returned by getNodesToBeMoved(). Add all additional nodes to this list as well.
bendsToBeMoved - input/output parameter. Contains the bends returned by getBendsToBeMoved(). Add all additional bends to this list as well.
See Also:
findAdditionalElements(y.base.NodeList, y.base.NodeList, BendList)

findAdditionalElements

protected void findAdditionalElements(NodeList nodesToBeMoved,
                                      NodeList ancestorNodes,
                                      BendList bendsToBeMoved)
Determines nodes and bends that are moved in addition to the ones returned by getNodesToBeMoved() and getBendsToBeMoved().

In the default implementation, the additional nodes are descendant nodes of group nodes in the specified nodesToBeMoved list that do not belong to said list themselves. Additional bends collected by this method are bends of edges connecting the aforementioned additional nodes that do not already belong to the specified bendsToBeMoved list themselves.

This method is called for nested graphs (i.e. graphs with an associated HierarchyManager instance) only.

Parameters:
nodesToBeMoved - input/output parameter. Contains the nodes returned by getNodesToBeMoved(). Add all additional nodes to this list as well.
ancestorNodes - output parameter. Add all ancestor group nodes of the specified nodesToBeMoved (including the additional nodes
bendsToBeMoved - input/output parameter. Contains the bends returned by getBendsToBeMoved(). Add all additional bends to this list as well.
See Also:
findAdditionalElements(y.base.NodeList, BendList)

isOrthogonalRouting

protected boolean isOrthogonalRouting(Edge edge)
Determines whether the given edge instance should be routed orthogonally. This implementation uses the DataProvider bound to the current graph via the EditMode.ORTHOGONAL_ROUTING_DPKEY data provider key to determine whether the given edge should be routed orthogonally.

Parameters:
edge - the edge to decide
Returns:
true if the edge should be routed orthogonally.
See Also:
EditMode.isOrthogonalRouting(y.base.Edge)

cancelEditing

public void cancelEditing()
                   throws java.lang.UnsupportedOperationException
Description copied from class: ViewMode
This can be used to cleanly exit an edit that is currently in progress.
The implementation and interpretation of "canceling" is left to subclasses. This implementation does nothing but calls setEditing(false) if ViewMode.isEditing() returns true

Overrides:
cancelEditing in class ViewMode
Throws:
java.lang.UnsupportedOperationException - if the editing cannot be canceled for any reason.

getGroupingDropTarget

protected java.lang.Object getGroupingDropTarget(double x,
                                                 double y)
Determines the Node or Graph that will be used for the given coordinates for a reparenting move operation.


createDropTargetHitInfo

protected HitInfo createDropTargetHitInfo(double x,
                                          double y)
Performs a hit test for a target group node at the specified drop target location.


getHierarchyManager

protected HierarchyManager getHierarchyManager()
Returns the HierarchyManager associated with the graph displayed in the underlying Graph2DView.


getGroupBoundsPolicy

public byte getGroupBoundsPolicy()
Returns the group bounds policy used when moving the child nodes of a group.

Returns:
Returns one of FIXED_AUTOBOUNDS_INSETS and FIXED_MINIMUM_GROUP_BOUNDS.

setGroupBoundsPolicy

public void setGroupBoundsPolicy(byte groupBoundsPolicy)
Sets the group bounds policy used when moving the child nodes of a group. By default, FIXED_AUTOBOUNDS_INSETS is set.

Parameters:
groupBoundsPolicy - one of FIXED_AUTOBOUNDS_INSETS and FIXED_MINIMUM_GROUP_BOUNDS.

isGroupReassignmentEnabled

public boolean isGroupReassignmentEnabled()
Returns whether or not reassignment of nodes to other groups is enabled.

See Also:
setGroupReassignmentEnabled(boolean)

setGroupReassignmentEnabled

public void setGroupReassignmentEnabled(boolean enabled)
Sets whether or not a reassignment of nodes to other groups can be triggered by a mouse/keyboard gesture. By default this feature is enabled.


isIndicatingTargetGroup

public boolean isIndicatingTargetGroup()
Whether this instance indicates the target group node for a group reassignment operation using a Drawable. The default is false.


setIndicatingTargetGroup

public void setIndicatingTargetGroup(boolean indicatingTargetGroup)
Determines whether this instance indicates the target group node for a group reassignment operation using a Drawable. The default is false.


drawTargetNodeIndicator

protected void drawTargetNodeIndicator(java.awt.Graphics2D gfx,
                                       NodeRealizer nodeRealizer)
Callback method that actually renders the target group node indicator. This callback is used by the actual drawable implementation.

Parameters:
gfx - The graphics to render into.
nodeRealizer - The realizer to highlight.

getTargetNodeIndicatorBounds

protected java.awt.geom.Rectangle2D getTargetNodeIndicatorBounds(NodeRealizer nodeRealizer)
Yields the bounds of the target group node indicator Drawable. This method is used as a callback by the actual drawable implementation so that it can be overridden, here, easily.

Parameters:
nodeRealizer - The realizer to highlight.
Returns:
The bounds of the drawable.

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent ev)
Description copied from class: ViewMode
A mouse button get released

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

mouseReleasedRight

public void mouseReleasedRight(double x,
                               double y)
Description copied from class: ViewMode
Called when the right mouse button was released

Overrides:
mouseReleasedRight in class ViewMode
Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseDraggedRight

public void mouseDraggedRight(double x,
                              double y)
Description copied from class: ViewMode
Called when the mouse was dragged with the right button down.

Overrides:
mouseDraggedRight in class ViewMode
Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

© Copyright 2000-2021,
yWorks GmbH.
All rights reserved.