Search this API

y.view
Class OrthogonalMoveBendsMode

java.lang.Object
  extended by y.view.ViewMode
      extended by y.view.OrthogonalMoveBendsMode
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener, javax.swing.event.MouseInputListener

public class OrthogonalMoveBendsMode
extends ViewMode

A specialized ViewMode that moves or creates bends in such a way that an edge's path is always orthogonal.

This mode should be used as a child mode of a ViewMode that is delegated to whenever the user begins a drag on an edge. In particular, this also includes dragging an edge segment, which results in the edge segment being moved such that the orthogonal edge path is maintained.
Note that this does not apply to the first and last edge segments.

To create additional bends/edge segments while preserving an orthogonal edge path, a modifier key has to be pressed while clicking on or dragging an edge segment. This is the default behavior for the first and last edge segments. It can be suppressed by setting the autoBendsInsertionEnabled property to false.
See methods ViewMode.isModifierPressed(java.awt.event.MouseEvent) and ViewMode.setModifierMask(int).
The default is MouseEvent.SHIFT_MASK.

If the owning edge of the bends is deleted while editing this mode reactivates its parent view mode. If the graph changes which is displayed by the view for which this view mode is created, then cancelEditing() is called if this mode is editing.

 

Field Summary
 
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
OrthogonalMoveBendsMode()
           
 
Method Summary
 void cancelEditing()
          If this mode is currently editing, the editing is completed for the current mouse position and the parent view mode is reactivated.
protected  MoveSnapContext createSnapContext()
          Creates the MoveSnapContext that will be used by this instance to snap the mouse coordinates.
protected  void dragFinished(Bend bend, double x, double y)
          Callback method that is called once the dragging has been finished.
 int getDisableSnappingModifier()
          Gets the modifier mask that can be used to determine whether the user disables snapping via the snap context temporarily.
protected  EdgeRealizer getRealizer()
          Gets the realizer whose bends are being dragged.
 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  Bend initDrag(y.view.OrthogonalMoveBendsMode.MinMax minMax, EdgeRealizer realizer, Bend hitBend, java.util.Collection movingSegmentInfos)
          Initializes the dragging for a given realizer and hit bend.
protected  void initDrag(y.view.OrthogonalMoveBendsMode.MinMax minMax, EdgeRealizer realizer, double x, double y, java.util.Collection movingSegmentInfos)
          Initializes a drag for a given realizer and location.
 boolean isAutoBendInsertionEnabled()
          Determines whether bends should be inserted automatically if the first or last segment is dragged by the user.
 boolean isBendSelectionEnabled()
          Whether the bend that is being moved is automatically selected.
 boolean isClearingBendSelection()
          Determines whether the bend selection of the bends that are not influenced by the move operation should be cleared by this mode whenever a segment is moved.
 boolean isClearingNodeSelection()
          Determines whether the node selection should be cleared by this mode whenever a segment is moved.
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 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)
          Called when the mouse was dragged with the left button down.
 void mousePressedLeft(double x, double y)
          Called when the left mouse button was pressed.
 void mouseReleasedLeft(double x, double y)
          Called when the left mouse button was released.
 void mouseReleasedRight(double x, double y)
          Called when the right mouse button was released
static boolean normalizeBends(EdgeRealizer er)
          Utility method that adjusts the bends of the given realizer so that they form an orthogonal path.
 void reactivateParent()
          The parent of this ViewMode is reactivated and this ViewMode is deactivated.
static int removeDuplicateBends(EdgeRealizer er, int pointCount)
          Utility method that removes duplicate bends from an EdgeRealizer Note that this method won't execute if EdgeRealizer.getMinBendCount() yields non-zero values or if the realizer is not bound to an edge of a graph.
protected  void removeDuplicates(EdgeRealizer realizer)
          Removes duplicate and collinear bends from the given realizer.
 void setAutoBendInsertionEnabled(boolean autoBendInsertionEnabled)
          Determines whether bends should be inserted automatically if the first or last segment is dragged by the user.
 void setBendSelectionEnabled(boolean bendSelectionEnabled)
          Determines whether the bend that is being moved is automatically selected.
 void setClearingBendSelection(boolean clearingBendSelection)
          Determines whether the bend selection of the bends that are not influenced by the move operation should be cleared by this mode whenever a segment is moved.
 void setClearingNodeSelection(boolean clearingNodeSelection)
          Determines whether the node selection should be cleared by this mode whenever a segment is moved.
 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 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
activate, 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, mouseDraggedRight, mouseEntered, mouseExited, mouseMoved, mouseMoved, mousePressed, mousePressedMiddle, mousePressedRight, mouseReleased, mouseReleased, mouseReleasedMiddle, mouseShiftPressedLeft, mouseShiftPressedMiddle, mouseShiftPressedRight, mouseShiftReleasedLeft, 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
 

Constructor Detail

OrthogonalMoveBendsMode

public OrthogonalMoveBendsMode()
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 their 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 their 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.


isClearingBendSelection

public boolean isClearingBendSelection()
Determines whether the bend selection of the bends that are not influenced by the move operation should be cleared by this mode whenever a segment is moved. The default is true:


setClearingBendSelection

public void setClearingBendSelection(boolean clearingBendSelection)
Determines whether the bend selection of the bends that are not influenced by the move operation should be cleared by this mode whenever a segment is moved. The default is true:


isClearingNodeSelection

public boolean isClearingNodeSelection()
Determines whether the node selection should be cleared by this mode whenever a segment is moved. The default is true:


setClearingNodeSelection

public void setClearingNodeSelection(boolean clearingNodeSelection)
Determines whether the node selection should be cleared by this mode whenever a segment is moved. The default is true:


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.

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 enabled.


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 enabled.


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.

isAutoBendInsertionEnabled

public boolean isAutoBendInsertionEnabled()
Determines whether bends should be inserted automatically if the first or last segment is dragged by the user. The default is true.

Returns:
Whether to automatically create bends for the first and last segments.

setAutoBendInsertionEnabled

public void setAutoBendInsertionEnabled(boolean autoBendInsertionEnabled)
Determines whether bends should be inserted automatically if the first or last segment is dragged by the user. The default is true.

Parameters:
autoBendInsertionEnabled - Whether to automatically create bends for the first and last segments.

isBendSelectionEnabled

public boolean isBendSelectionEnabled()
Whether the bend that is being moved is automatically selected. By default, the bend is automatically selected.

Returns:
whether to select the bend

setBendSelectionEnabled

public void setBendSelectionEnabled(boolean bendSelectionEnabled)
Determines whether the bend that is being moved is automatically selected. By default, the bend is automatically selected.

Parameters:
bendSelectionEnabled - whether to select the bend

mousePressedLeft

public void mousePressedLeft(double x,
                             double y)
Description copied from class: ViewMode
Called when the left mouse button was pressed.

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.

cancelEditing

public void cancelEditing()
If this mode is currently editing, the editing is completed for the current mouse position and the parent view mode is reactivated.

Overrides:
cancelEditing in class ViewMode

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

getRealizer

protected EdgeRealizer getRealizer()
Gets the realizer whose bends are being dragged.

Returns:
the realizer instance

initDrag

protected Bend initDrag(y.view.OrthogonalMoveBendsMode.MinMax minMax,
                        EdgeRealizer realizer,
                        Bend hitBend,
                        java.util.Collection movingSegmentInfos)
Initializes the dragging for a given realizer and hit bend.

Returns:
the bend to actually drag.

initDrag

protected void initDrag(y.view.OrthogonalMoveBendsMode.MinMax minMax,
                        EdgeRealizer realizer,
                        double x,
                        double y,
                        java.util.Collection movingSegmentInfos)
Initializes a drag for a given realizer and location.

Parameters:
realizer - the realizer to create a bend for
x - the location of the mouse press
y - the location of the mouse press

mouseDraggedLeft

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

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.

mouseReleasedLeft

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

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.

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.

normalizeBends

public static boolean normalizeBends(EdgeRealizer er)
Utility method that adjusts the bends of the given realizer so that they form an orthogonal path. This is done by moving, inserting, and possibly removing bends from the realizer. For self loops that are adjacent to the same port location there is a special treatment where the last remaining bend (if there is one) is duplicated and orthogonalized. Otherwise the edge segment would become completely invisible. Note that this method won't execute if EdgeRealizer.getMinBendCount() yields non-zero values or if the realizer is not bound to an edge of a graph.

Parameters:
er - the realizer to adjust.
Returns:
whether odd segments are vertical

removeDuplicateBends

public static int removeDuplicateBends(EdgeRealizer er,
                                       int pointCount)
Utility method that removes duplicate bends from an EdgeRealizer Note that this method won't execute if EdgeRealizer.getMinBendCount() yields non-zero values or if the realizer is not bound to an edge of a graph.

Parameters:
er - the realizer to remove duplicate bends from.
pointCount - the number of points, bendCount + 2
Returns:
the number of points remaining, bendCount + 2

dragFinished

protected void dragFinished(Bend bend,
                            double x,
                            double y)
Callback method that is called once the dragging has been finished.

Parameters:
bend - the bend that has been moved
x - the new location
y - the new location

removeDuplicates

protected void removeDuplicates(EdgeRealizer realizer)
Removes duplicate and collinear bends from the given realizer. Note that this method won't execute if EdgeRealizer.getMinBendCount() yields non-zero values or if the realizer is not bound to an edge of a graph.

Parameters:
realizer - the realizer from which duplicate bends should be removed.

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