y.view
Class CreateEdgeMode

java.lang.Object
  extended by y.view.ViewMode
      extended by y.view.CreateEdgeMode
All Implemented Interfaces:
MouseListener, MouseMotionListener, EventListener, MouseInputListener
Direct Known Subclasses:
HierarchyCreateEdgeMode

public class CreateEdgeMode
extends ViewMode

This view mode is responsible for creating edges.

An edge is created with this mode in the following way:

The default edge realizer of the Graph2D will be assigned to the newly created edge.

This mode provides several options, e.g.:

This mode provides some hook methods that are meant to be overridden in order to influence its behavior.

 

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
CreateEdgeMode()
          Instantiates a new CreateEdgeMode.
CreateEdgeMode(ViewContainer view)
          Instantiates a new CreateEdgeMode for a given ViewContainer
 
Method Summary
protected  boolean acceptBend(Node start, Node hitNode, double x, double y)
          Whether or not to accept the creation of a bend.
protected  boolean acceptSourceNode(Node source, double x, double y)
          This method gets called right before someone wants to start creating an edge at location (x,y) starting from node source.
protected  boolean acceptTargetNode(Node target, double x, double y)
          This method gets called right before someone wants to complete creating an edge at location (x,y) by connecting to node target.
protected  void addBend(EdgeRealizer realizer, double x, double y)
          Invoked when the bend creation mouse gesture occured and bend creation is allowed.
 void allowBendCreation(boolean b)
          Allows or disallows bend creation.
 void allowSelfloopCreation(boolean b)
          Allows or disallows selfloop creation.
protected  void cancelEdgeCreation()
          Calling this method cancels edge creation properly.
 void cancelEditing()
          This can be used to cleanly exit an edit that is currently in progress.
protected  EdgeRealizer createDummyEdgeRealizer()
          Factory method, which creates the dummy EdgeRealizer which is used during the edge creation process.
protected  NodeRealizer createDummySourceNodeRealizer(NodeRealizer currentRealizer)
          Creates a dummy node for the target node of the dummy edge By default, this method returns currentRealizer.createCopy();
protected  NodeRealizer createDummyTargetNodeRealizer(double x, double y)
          Creates a dummy node for the other end of the edge.
protected  Edge createEdge(Graph2D graph, Node startNode, Node targetNode, EdgeRealizer realizer)
          Callback method that is responsible for the actual creation of the edge.
protected  Node determineHitNode(Graph2D graph, double x, double y)
          Callback used during the dragging to determine the target hit node
 boolean doAllowBendCreation()
          Returns true iff the creation of bends should be allowed.
 boolean doAllowSelfloopCreation()
          Returns true iff the creation of selfloops should be allowed.
protected  void edgeCreated(Edge edge)
          This method gets called after a new edge was completely created by this mode.
protected  void edgeMoved(double x, double y)
          This method gets called whenever the dummy endpoint of the to be created edge has changed it's location.
 int getCancelKeyCode()
          Sets the virtual key code as defined in KeyEvent which cancels the edge creation.
protected  EdgeRealizer getDummyEdgeRealizer()
          Returns the dummy EdgeRealizer which is currently in use.
protected  NodeRealizer getDummySourceNodeRealizer()
          Returns the currently used dummy node realizer for the source node of the dummy edge.
protected  NodeRealizer getDummyTargetNodeRealizer()
          Returns the currently used dummy node realizer for the target node of the dummy edge.
protected  YPoint getSourcePortOffset(boolean modifierPressed, Node sourceNode, double dx, double dy)
          Invoked when the edge is about to be created.
protected  YPoint getTargetPortOffset(boolean modifierPressed, Node targetNode, double dx, double dy)
          Invoked when the edge has been created.
 void init()
          This method is called in a child mode when it gets installed in another mode.
 boolean isEarlyEdgeCancelingEnabled()
          Determines whether the edge creation should be canceled if the user released the mouse inside the source node before even leaving it once.
 boolean isOrthogonalEdgeCreation()
          Determines whether this mode creates orthogonally routed edges.
 void mouseDraggedLeft(double x, double y)
          Moves the dummy end of the edge while the actual target node is unknown.
 void mouseMoved(double x, double y)
          Moves the dummy end of the edge while the actual target node is unknown.
 void mousePressedLeft(double x, double y)
          Initiates the creation of an edge.
 void mouseReleasedLeft(double x, double y)
          If a node was hit at the given coordinates, that node will be used as target node for the newly created edge.
 void mouseReleasedRight(double x, double y)
          Removes a bend if possible. otherwise cancels edge creation.
 void mouseShiftPressedLeft(double x, double y)
          Initiates the creation of an edge.
 void mouseShiftReleasedLeft(double x, double y)
          If a node was hit at the given coordinates, that node will be used as target node for the newly created edge.
 void reactivateParent()
          The parent of this ViewMode is reactivated and this ViewMode is deactivated.
protected  void removeBend(EdgeRealizer edgeRealizer, int index)
          Callback used by mouseReleasedRight(double, double) that actually removes the given bend from the edge.
 void setCancelKeyCode(int cancelKeyCode)
          Sets the virtual key code as defined in KeyEvent which cancels the edge creation.
 void setEarlyEdgeCancelingEnabled(boolean earlyEdgeCancelingEnabled)
          Determines whether the edge creation should be canceled if the user released the mouse inside the source node before even leaving it once.
 void setOrthogonalEdgeCreation(boolean orthogonalEdgeCreation)
          Determines whether this mode should create orthogonally routed edges, only.
protected  void sourceNodeDeclined(Node target, double x, double y)
          This method gets called in case method acceptSourceNode(Node, double, double) returns false.
protected  void targetNodeDeclined(Node target, double x, double y)
          This method gets called in case method acceptTargetNode(Node, double, double) returns false.
 
Methods inherited from class y.view.ViewMode
activate, addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, getChild, getGraph2D, getGridX, getGridY, getHitInfo, getHitInfo, getLastHitInfo, getModifierMask, getName, getParent, isActive, isEditing, isGrabFocusEnabled, isGridMode, isModifierPressed, mouseClicked, mouseClicked, mouseDragged, mouseDraggedMiddle, mouseDraggedRight, mouseEntered, mouseExited, mouseMoved, mousePressed, mousePressedMiddle, mousePressedRight, mouseReleased, 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
 

Constructor Detail

CreateEdgeMode

public CreateEdgeMode(ViewContainer view)
Instantiates a new CreateEdgeMode for a given ViewContainer


CreateEdgeMode

public CreateEdgeMode()
Instantiates a new CreateEdgeMode.

Method Detail

init

public void init()
Description copied from class: ViewMode
This method is called in a child mode when it gets installed in another mode.

Overrides:
init in class ViewMode
See Also:
ViewMode.setChild(ViewMode,MouseEvent,MouseEvent)

allowBendCreation

public void allowBendCreation(boolean b)
Allows or disallows bend creation. By default bend creation is allowed.


doAllowBendCreation

public boolean doAllowBendCreation()
Returns true iff the creation of bends should be allowed. This mode will act according to the return value of this method.


allowSelfloopCreation

public void allowSelfloopCreation(boolean b)
Allows or disallows selfloop creation. By default selfloopcreation is allowed.


doAllowSelfloopCreation

public boolean doAllowSelfloopCreation()
Returns true iff the creation of selfloops should be allowed. This mode will act according to the return value of this method.


mousePressedLeft

public void mousePressedLeft(double x,
                             double y)
Initiates the creation of an edge.

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.

mouseShiftPressedLeft

public void mouseShiftPressedLeft(double x,
                                  double y)
Initiates the creation of an edge. By pressing shift a source port for that edge at the given location will be assigned.

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.

getSourcePortOffset

protected YPoint getSourcePortOffset(boolean modifierPressed,
                                     Node sourceNode,
                                     double dx,
                                     double dy)
Invoked when the edge is about to be created. This method can be used to adjust the source port offset. This implementation returns YPoint.ORIGIN if the modifier is false, otherwise the ViewMode.getGridX(double) and ViewMode.getGridY(double) methods are used to snap to the next availabe grid point.

Parameters:
modifierPressed - indicates if the user wants to have an alternative port assignment
sourceNode - the node which will be the source of the newly created edge
dx - the x offset were the click occured on the node
dy - the y offset were the click occured on the node
Returns:
the offset should be assigned to the newly created source port.

createDummyEdgeRealizer

protected EdgeRealizer createDummyEdgeRealizer()
Factory method, which creates the dummy EdgeRealizer which is used during the edge creation process. By default, this method returns getGraph2D().getDefaultEdgeRealizer().createCopy();


getDummyEdgeRealizer

protected EdgeRealizer getDummyEdgeRealizer()
Returns the dummy EdgeRealizer which is currently in use.

Throws:
IllegalStateException - if the edge has not yet been created

createDummySourceNodeRealizer

protected NodeRealizer createDummySourceNodeRealizer(NodeRealizer currentRealizer)
Creates a dummy node for the target node of the dummy edge By default, this method returns currentRealizer.createCopy();


createDummyTargetNodeRealizer

protected NodeRealizer createDummyTargetNodeRealizer(double x,
                                                     double y)
Creates a dummy node for the other end of the edge. 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

getDummyTargetNodeRealizer

protected NodeRealizer getDummyTargetNodeRealizer()
Returns the currently used dummy node realizer for the target node of the dummy edge.

Throws:
IllegalStateException - if the edge has not yet been created
Returns:
the realizer

getDummySourceNodeRealizer

protected NodeRealizer getDummySourceNodeRealizer()
Returns the currently used dummy node realizer for the source node of the dummy edge.

Throws:
IllegalStateException - if the edge has not yet been created
Returns:
the realizer

mouseReleasedRight

public void mouseReleasedRight(double x,
                               double y)
Removes a bend if possible. otherwise cancels edge creation.

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.

removeBend

protected void removeBend(EdgeRealizer edgeRealizer,
                          int index)
Callback used by mouseReleasedRight(double, double) that actually removes the given bend from the edge.

Parameters:
edgeRealizer - the dummy realizer that is used for displaying the edge during the creation.
index - the index of the bend to remove.

mouseShiftReleasedLeft

public void mouseShiftReleasedLeft(double x,
                                   double y)
If a node was hit at the given coordinates, that node will be used as target node for the newly created edge. By pressing shift a target port at the given coordinate will be assigned to the edge.

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)
If a node was hit at the given coordinates, that node will be used as target node for the newly created edge.

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.

addBend

protected void addBend(EdgeRealizer realizer,
                       double x,
                       double y)
Invoked when the bend creation mouse gesture occured and bend creation is allowed.

Parameters:
realizer - The realizer for the edge that is being created.
x - The x coordinate where the mouse gesture occured.
y - The y coordinate where the mouse gesture occured.

getTargetPortOffset

protected YPoint getTargetPortOffset(boolean modifierPressed,
                                     Node targetNode,
                                     double dx,
                                     double dy)
Invoked when the edge has been created. This method can be used to adjust the target port offset. This implementation returns YPoint.ORIGIN if the modifier is false, otherwise the ViewMode.getGridX(double) and ViewMode.getGridY(double) methods are used to snap to the next availabe grid point.

Parameters:
modifierPressed - indicates if the user wants to have an alternative port assignment
targetNode - the node which is the target of the newly created edge
dx - the x offset where the click occured on the node
dy - the y offset where the click occured on the node
Returns:
the offset that should be assigned to the newly created target port.

createEdge

protected Edge createEdge(Graph2D graph,
                          Node startNode,
                          Node targetNode,
                          EdgeRealizer realizer)
Callback method that is responsible for the actual creation of the edge. This implementation returns graph.createEdge(startNode, targetNode, realizer)

Parameters:
graph - the graph to create the edge in
startNode - the start node of the edge
targetNode - the target node of the edge
realizer - the realizer to use (may be replaced or altered by subclass implementations)
Returns:
the newly created Edge or null if no edge should be created

acceptBend

protected boolean acceptBend(Node start,
                             Node hitNode,
                             double x,
                             double y)
Whether or not to accept the creation of a bend.

Parameters:
start - the node from where edge creation started
hitNode - the node that was hit at the given location
x - the x-coordinate of the current location
y - the y-coordinate of the current location

mouseDraggedLeft

public void mouseDraggedLeft(double x,
                             double y)
Moves the dummy end of the edge while the actual target node is unknown.

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.

determineHitNode

protected Node determineHitNode(Graph2D graph,
                                double x,
                                double y)
Callback used during the dragging to determine the target hit node

Parameters:
graph - the graph that can be used for hittesting
x - the x position of the mouse (not yet snapped to grid coordinates)
y - the y position of the mouse (not yet snapped to grid coordinates)
Returns:
the node that will be used as the target

mouseMoved

public void mouseMoved(double x,
                       double y)
Moves the dummy end of the edge while the actual target node is unknown.

Overrides:
mouseMoved 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

isOrthogonalEdgeCreation

public boolean isOrthogonalEdgeCreation()
Determines whether this mode creates orthogonally routed edges. If enabled this mode will insert bends into the edge so that each segment is either horizontally or vertically routed. The default is false.

Returns:
whether to orthogonal edge creation is enabled

setOrthogonalEdgeCreation

public void setOrthogonalEdgeCreation(boolean orthogonalEdgeCreation)
Determines whether this mode should create orthogonally routed edges, only. If enabled this mode will insert bends into the edge so that each segment is either horizontally or vertically routed. The default is false.

Parameters:
orthogonalEdgeCreation - whether to enable orthogonal edge creation.

isEarlyEdgeCancelingEnabled

public boolean isEarlyEdgeCancelingEnabled()
Determines whether the edge creation should be canceled if the user released the mouse inside the source node before even leaving it once. The default is true.

Returns:
whether creation will be canceled early.

setEarlyEdgeCancelingEnabled

public void setEarlyEdgeCancelingEnabled(boolean earlyEdgeCancelingEnabled)
Determines whether the edge creation should be canceled if the user released the mouse inside the source node before even leaving it once. The default is true.

Parameters:
earlyEdgeCancelingEnabled - whether creation should be canceled early.

edgeMoved

protected void edgeMoved(double x,
                         double y)
This method gets called whenever the dummy endpoint of the to be created edge has changed it's location. By default this method does nothing.

Parameters:
x - the x-coordinate of the endpoint
y - the y-coordinate of the endpoint

edgeCreated

protected void edgeCreated(Edge edge)
This method gets called after a new edge was completely created by this mode. It serves as a hook to perform some actions after this event has happened. By default this method does nothing.


cancelEdgeCreation

protected void cancelEdgeCreation()
Calling this method cancels edge creation properly. After doing some cleanup it reactivates the parent if present. This method is meant to be called from within the targetNodeDeclined method in order to cancel edge creation properly.


acceptSourceNode

protected boolean acceptSourceNode(Node source,
                                   double x,
                                   double y)
This method gets called right before someone wants to start creating an edge at location (x,y) starting from node source. The return value of this method determines whether or not creating an edge from that node will actually be initiated.

By default this method returns true.

Subclasses may want to override this feature to forbid edge creation starting from certain nodes.


targetNodeDeclined

protected void targetNodeDeclined(Node target,
                                  double x,
                                  double y)
This method gets called in case method acceptTargetNode(Node, double, double) returns false. This method is meant as a hook to perform some post target declination code.

By default this method does nothing.


acceptTargetNode

protected boolean acceptTargetNode(Node target,
                                   double x,
                                   double y)
This method gets called right before someone wants to complete creating an edge at location (x,y) by connecting to node target. The return value of this method determines whether or not the creation of an edge to that node will be performed.

By default this method returns true.

Subclasses may want to override this feature to forbid connecting an edge to a certain node.


sourceNodeDeclined

protected void sourceNodeDeclined(Node target,
                                  double x,
                                  double y)
This method gets called in case method acceptSourceNode(Node, double, double) returns false. This method is meant as a hook to perform some post source declination code.

By default this method does nothing.


getCancelKeyCode

public int getCancelKeyCode()
Sets the virtual key code as defined in KeyEvent which cancels the edge creation. Negative values disable this feature. Default is KeyEvent.VK_ESCAPE.


setCancelKeyCode

public void setCancelKeyCode(int cancelKeyCode)
Sets the virtual key code as defined in KeyEvent which cancels the edge creation. Negative values disable this feature.


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 "cancelling" 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 cancelled for any reason.

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