y.view
Class MovePortMode

java.lang.Object
  extended by y.view.ViewMode
      extended by y.view.MovePortMode
All Implemented Interfaces:
MouseListener, MouseMotionListener, EventListener, MouseInputListener

public class MovePortMode
extends ViewMode

A view mode that allows interactive reassignment of edge ports.

A Port of a selected edge can be moved to another position by pressing the left mouse button on it and then dragging the port around. While dragging port candidate boxes will appear. These boxes mark the positions that are available for the port. The set of available port positions depends on the return value of the node realizer method NodeRealizer.getPortCandidates(double). The mode terminates it's action when the mouse is released again. The port will then automatically snap to the closest available port position. If the portSnappingEnabled property is set to false, holding the shift modifier while releasing the mouse button assigns the exact current position as the new port position. Optionally this mode can be configured to change an edge's source or target node by dragging the corresponding port to another node.

 
Your browser does not support SVG content.

Field Summary
protected  YList candidates
          The list of Port Candidates, consisting of YPoint instances.
protected  Port port
          The port that is being currently being moved.
 
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
MovePortMode()
          Instantiates a new MovePortMode
MovePortMode(ViewContainer vc)
          Instantiates a new MovePortMode for a given ViewContainer
 
Method Summary
 void cancelEditing()
          This can be used to cleanly exit an edit that is currently in progress.
protected  EdgeRealizer createDummyEdgeRealizer(EdgeRealizer edgeRealizer)
          Creates a dummy EdgeRealizer for the dummy edge that is used during changeEdge operations.
protected  NodeRealizer createDummySourceNodeRealizer(NodeRealizer nodeRealizer)
          Creates a dummy NodeRealizer for the source node of the dummy edge By default, this method returns This will only be used if setChangeEdgeEnabled(boolean) is set to true.
protected  NodeRealizer createDummyTargetNodeRealizer(double x, double y)
          Creates a dummy node for the other end of the edge.
protected  HitInfo createHitNodeHitInfo(double x, double y)
           
protected  void drawPortCandidate(Graphics2D gfx, YPoint p, Node v, Edge e)
          Draws a single port candidate.
protected  void drawPortCandidate(Graphics2D gfx, YPoint p, Node v, Edge e, boolean isSnapActive, boolean isSnapCandidate)
          Draws a single port candidate.
 Cursor getDefaultCursor()
          Returns the cursor to be used when the mouse is not over a draggable port point.
protected  HitInfo getHitInfo(double x, double y)
          Returns the first hit port, only.
protected  Node getHitNode(double x, double y)
          Returns the possible new node for the currently moved port.
 Cursor getMovePortCursor()
          Returns the cursor to be used when the mouse is over a draggable port point.
protected  YList getPortCandidates(Node v, Edge e, double gridSpacing)
          Returns a list of YPoint objects each of which represents an allowed port location for the given edge at the given node.
 boolean isChangeEdgeEnabled()
          Determines whether this mode allows the changing of edges so that they connect to different source and target nodes.
protected  boolean isOrthogonalRouting(Edge edge)
          Determines whether the given edge instance should be routed orthogonally.
 boolean isPortSnappingEnabled()
          Returns whether this mode should snap the port to one of the predefined port positions, even if the shift modifier is pressed.
 void mouseDraggedLeft(double x, double y)
          Moves the port.
 void mousePressedLeft(double x, double y)
          Initiates reassignment of a hit port.
 void mouseReleasedLeft(double x, double y)
          Terminates the reassignment of a port.
 void mouseShiftReleasedLeft(double x, double y)
          Terminates the reassignment of a port.
 void setChangeEdgeEnabled(boolean changeEdgeEnabled)
          Determines whether this mode allows the changing of edges so that they connect to different source and target nodes.
 void setPortSnappingEnabled(boolean portSnappingEnabled)
          Sets whether this mode should snap the port to one of the predefined port positions, even if the modifier is pressed.
protected  void updatePortPosition(double x, double y)
           
 
Methods inherited from class y.view.ViewMode
activate, addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, getChild, getGraph2D, getGridX, getGridY, 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, 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
 

Field Detail

port

protected Port port
The port that is being currently being moved.


candidates

protected YList candidates
The list of Port Candidates, consisting of YPoint instances.

Constructor Detail

MovePortMode

public MovePortMode(ViewContainer vc)
Instantiates a new MovePortMode for a given ViewContainer


MovePortMode

public MovePortMode()
Instantiates a new MovePortMode

Method Detail

isChangeEdgeEnabled

public boolean isChangeEdgeEnabled()
Determines whether this mode allows the changing of edges so that they connect to different source and target nodes. The default is false.

Returns:
whether to allow changing of edges
See Also:
Graph.changeEdge(y.base.Edge, y.base.Node, y.base.Node)

setChangeEdgeEnabled

public void setChangeEdgeEnabled(boolean changeEdgeEnabled)
Determines whether this mode allows the changing of edges so that they connect to different source and target nodes. The default is false.

Parameters:
changeEdgeEnabled - whether to allow changing of edges
See Also:
Graph.changeEdge(y.base.Edge, y.base.Node, y.base.Node)

getHitInfo

protected HitInfo getHitInfo(double x,
                             double y)
Returns the first hit port, only.

Overrides:
getHitInfo in class ViewMode
Returns:
A HitInfo object that holds the first graph element that was hit at the given world coordinate.

mousePressedLeft

public void mousePressedLeft(double x,
                             double y)
Initiates reassignment of a hit port.

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.

createDummyEdgeRealizer

protected EdgeRealizer createDummyEdgeRealizer(EdgeRealizer edgeRealizer)
Creates a dummy EdgeRealizer for the dummy edge that is used during changeEdge operations. This will only be used if setChangeEdgeEnabled(boolean) is set to true. By default, this method returns edgeRealizer.createCopy();


createDummySourceNodeRealizer

protected NodeRealizer createDummySourceNodeRealizer(NodeRealizer nodeRealizer)
Creates a dummy NodeRealizer for the source node of the dummy edge By default, this method returns This will only be used if setChangeEdgeEnabled(boolean) is set to true. nodeRealizer.createCopy();


createDummyTargetNodeRealizer

protected NodeRealizer createDummyTargetNodeRealizer(double x,
                                                     double y)
Creates a dummy node for the other end of the edge. This will only be used if setChangeEdgeEnabled(boolean) is set to true. This implementation returns a zero width/ zero height ShapeNodeRealizer

Parameters:
x - the initial x coordinate
y - the initial y coordinate
Returns:
the created dummy target realizer

getPortCandidates

protected YList getPortCandidates(Node v,
                                  Edge e,
                                  double gridSpacing)
Returns a list of YPoint objects each of which represents an allowed port location for the given edge at the given node. The port coordinates are given in absolute world (graph) coordinates. The default implementation calls the given node's node realizer method NodeRealizer.getPortCandidates(double). Subclasses may override this method to change the behavior of this method.

Parameters:
v - the node that yields the port candidates
e - the edge that requests the port candidates
gridSpacing - the current gridSpacing.
Returns:
a list of YPoint objects that represent absolute port coordinates.

mouseDraggedLeft

public void mouseDraggedLeft(double x,
                             double y)
Moves the port.

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.

getHitNode

protected Node getHitNode(double x,
                          double y)
Returns the possible new node for the currently moved port. This implementation returns the original node first, and if the original node is not hit, the node returned by createHitNodeHitInfo(x, y).getHitNode() is returned.

Parameters:
x - the x world coordinate
y - the y world coordinate
Returns:
the new candidate to use as a replacement or null

createHitNodeHitInfo

protected HitInfo createHitNodeHitInfo(double x,
                                       double y)

updatePortPosition

protected void updatePortPosition(double x,
                                  double y)

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)

mouseShiftReleasedLeft

public void mouseShiftReleasedLeft(double x,
                                   double y)
Terminates the reassignment of a port. The port will be assigned to the exact current position. If portSnappingEnabled is true mouseReleasedLeft(double, double) gets invoked instead.

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 reassignment of a port. The port will automatically snap to the closest available port position.

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.

drawPortCandidate

protected void drawPortCandidate(Graphics2D gfx,
                                 YPoint p,
                                 Node v,
                                 Edge e)
Draws a single port candidate. Subclasses can change the look of a port candidate by overriding this method. By default this method delegates to method drawPortCandidate(java.awt.Graphics2D, y.geom.YPoint, y.base.Node, y.base.Edge, boolean, boolean).

Parameters:
gfx - the active graphics context
p - the absolute port location
v - the node that yields the port
e - the edge that requests the port

drawPortCandidate

protected void drawPortCandidate(Graphics2D gfx,
                                 YPoint p,
                                 Node v,
                                 Edge e,
                                 boolean isSnapActive,
                                 boolean isSnapCandidate)
Draws a single port candidate. Subclasses can change the look of a port candidate by overriding this method. Additional parameters give contextual information that will allow to draw single port candidates differently, depending on context.

Parameters:
gfx - the active graphics context
p - the absolute port location
v - the node that yields the port
e - the edge that requests the port
isSnapActive - whether or not port snapping is currently active
isSnapCandidate - whether or not the given port candidate is the candidate that will be snapped to.

isPortSnappingEnabled

public boolean isPortSnappingEnabled()
Returns whether this mode should snap the port to one of the predefined port positions, even if the shift modifier is pressed.


setPortSnappingEnabled

public void setPortSnappingEnabled(boolean portSnappingEnabled)
Sets whether this mode should snap the port to one of the predefined port positions, even if the modifier is pressed. Default is true.


cancelEditing

public void cancelEditing()
                   throws 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:
UnsupportedOperationException - if the editing cannot be canceled for any reason.

getMovePortCursor

public Cursor getMovePortCursor()
Returns the cursor to be used when the mouse is over a draggable port point.

Returns:
by default Cursor.MOVE_CURSOR is returned.

getDefaultCursor

public Cursor getDefaultCursor()
Returns the cursor to be used when the mouse is not over a draggable port point.

Returns:
by default Cursor.DEFAULT_CURSOR is returned.

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