y.view
Class MovePortMode

java.lang.Object
  |
  +--y.view.ViewMode
        |
        +--y.view.MovePortMode
All Implemented Interfaces:
EventListener, MouseInputListener, MouseListener, MouseMotionListener

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 with the left mouse button on it and then by dragging the port around. While dragging ports 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 getPortCandidates. 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.


Field Summary
protected  YList candidates
           
 
Fields inherited from class y.view.ViewMode
lastClickEvent, lastDragEvent, lastPressEvent, lastReleaseEvent, originalX, originalY, view
 
Constructor Summary
MovePortMode()
          Instantiates a new MovePortMode
MovePortMode(ViewContainer vc)
          Instantiates a new MovePortMode for a given ViewContainer
 
Method Summary
protected  void drawPortCandidate(Graphics2D gfx, YPoint p, Node v, Edge e)
          Draws a single port candidate.
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 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 setPortSnappingEnabled(boolean portSnappingEnabled)
          Sets whether this mode should snap the port to one of the predefined port positions, even if the shift modifier is pressed.
 
Methods inherited from class y.view.ViewMode
activate, getGraph2D, getGridX, getGridY, getHitInfo, getHitInfo, getLastHitInfo, getName, init, isGrabFocusEnabled, isGridMode, mouseClicked, mouseClicked, mouseDragged, mouseDraggedMiddle, mouseDraggedRight, mouseEntered, mouseExited, mouseMoved, mouseMoved, mousePressed, mousePressedMiddle, mousePressedRight, mouseReleased, mouseReleased, mouseReleasedMiddle, mouseReleasedRight, mouseShiftPressedLeft, mouseShiftPressedMiddle, mouseShiftPressedRight, mouseShiftReleasedMiddle, mouseShiftReleasedRight, reactivateParent, setActiveView, setChild, setChild, setGrabFocusEnabled, setGridMode, setLastHitInfo, setName, setParent, translateX, translateY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

candidates

protected YList candidates
Constructor Detail

MovePortMode

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


MovePortMode

public MovePortMode()
Instantiates a new MovePortMode

Method Detail

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.

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 noderealizer method NodeRealizer.getPortCandidates(double). Subsclasses may override thisd method to change the behaviour 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.

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 MovePortMode.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 a port candidate by overriding this method.

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

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 shift modifier is pressed. Default is true.


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

2003