y.view
Class OrthogonalMoveBendsMode

java.lang.Object
  extended by y.view.ViewMode
      extended by y.view.OrthogonalMoveBendsMode
All Implemented Interfaces:
MouseListener, MouseMotionListener, EventListener, 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.

 

Nested Class Summary
static class OrthogonalMoveBendsMode.MinMax
          Utility class that holds a valid coordinate range and properly crops coordinates.
 
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
protected  void dragFinished(Bend bend, double x, double y)
          Callback method that is called once the dragging has been finished.
protected  Bend getBend()
          Yields the main bend that is currently being dragged.
protected  OrthogonalMoveBendsMode.MinMax getMinMax()
          Returns the data structure that describes the current valid range for the bend.
protected  OrthogonalMoveBendsMode.MinMax getMinMax(EdgeRealizer realizer, Bend bend, int index)
          Creates the data structure that describes the valid range of the movement for a given bend.
protected  EdgeRealizer getRealizer()
          Gets the realizer whose bends are being dragged.
 double getSnapEpsilon()
          Gets the value to use that determines the distance to snap a moving segment to an adjacent segment.
protected  Bend initDrag(EdgeRealizer realizer, Bend hitBend)
          Initializes the dragging for a given realizer and hit bend.
protected  Bend initDrag(EdgeRealizer realizer, double x, double y)
          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.
 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.
static boolean normalizeBends(EdgeRealizer er)
          Utility method that adjusts the bends of the given realizer so that they form an orthogonal path.
protected  void relocateBend(EdgeRealizer realizer, Bend bend, double x, double y)
          Actually moves a bend to the given location.
static int removeDuplicateBends(EdgeRealizer er, int pointCount)
          Utility method that removes duplicate bends from an EdgeRealizer
protected  void removeDuplicates(EdgeRealizer realizer)
          Removes duplicate and colinear 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 setSnapEpsilon(double snapEpsilon)
          Sets the value to use that determines the distance to snap a moving segment to an adjacent segment.
protected  void snapPoint(Point2D.Double point)
          Implements the snapping logic.
 
Methods inherited from class y.view.ViewMode
activate, addPropertyChangeListener, addPropertyChangeListener, cancelEditing, firePropertyChange, firePropertyChange, firePropertyChange, getChild, getGraph2D, getGridX, getGridY, getHitInfo, getHitInfo, getLastHitInfo, getModifierMask, getName, getParent, init, isActive, isEditing, isGrabFocusEnabled, isGridMode, isModifierPressed, mouseClicked, mouseClicked, mouseDragged, mouseDraggedMiddle, mouseDraggedRight, mouseEntered, mouseExited, mouseMoved, mouseMoved, mousePressed, mousePressedMiddle, mousePressedRight, mouseReleased, mouseReleased, mouseReleasedMiddle, mouseReleasedRight, mouseShiftPressedLeft, mouseShiftPressedMiddle, mouseShiftPressedRight, mouseShiftReleasedLeft, mouseShiftReleasedMiddle, mouseShiftReleasedRight, reactivateParent, 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

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

getSnapEpsilon

public double getSnapEpsilon()
Gets the value to use that determines the distance to snap a moving segment to an adjacent segment. A value of 0.0 effectively disables snapping. The default is 5.0.

Returns:
the distance to snap a segment during a drag.

setSnapEpsilon

public void setSnapEpsilon(double snapEpsilon)
Sets the value to use that determines the distance to snap a moving segment to an adjacent segment. A value of 0.0d effectively disables snapping. The default is 5.0.

Parameters:
snapEpsilon - the distance to snap a segment during a drag.

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.

getBend

protected Bend getBend()
Yields the main bend that is currently being dragged.

Returns:
the bend that is being dragged.

getRealizer

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

Returns:
the realizer instance

getMinMax

protected OrthogonalMoveBendsMode.MinMax getMinMax()
Returns the data structure that describes the current valid range for the bend.

Returns:
the data structure that crops mouse coordinates to valid coordinates.

getMinMax

protected OrthogonalMoveBendsMode.MinMax getMinMax(EdgeRealizer realizer,
                                                   Bend bend,
                                                   int index)
Creates the data structure that describes the valid range of the movement for a given bend.

Parameters:
realizer - The realizer that owns the bend.
bend - the bend
index - the index of the bend in the realizer's list.
Returns:
the object that describes the valid range.

initDrag

protected Bend initDrag(EdgeRealizer realizer,
                        Bend hitBend)
Initializes the dragging for a given realizer and hit bend.

Returns:
the bend to actually drag.

initDrag

protected Bend initDrag(EdgeRealizer realizer,
                        double x,
                        double y)
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
Returns:
the bend to drag.

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.

relocateBend

protected void relocateBend(EdgeRealizer realizer,
                            Bend bend,
                            double x,
                            double y)
Actually moves a bend to the given location. This implementation uses the OrthogonalMoveBendsMode.MinMax.adjust(java.awt.geom.Point2D) method to calculate the new location and automatically adjusts the neighboring bends to keep the edge orthogonal.

Parameters:
realizer - The realizer the bend belongs to.
bend - the bend to move
x - the new location
y - the new location

snapPoint

protected void snapPoint(Point2D.Double point)
Implements the snapping logic.

Parameters:
point - The point that will be snapped if it needs to be snapped.

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.

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.

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

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 colinear bends from the given realizer.

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

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