Search this API

y.view
Class CreateEdgeMode

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

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.

 
Your browser does not support SVG content.

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 acceptSourceNodePort(Node node, NodePort port, double x, double y)
          This method gets called right before someone wants to start creating an edge at location (x,y) starting from the specified node port of the specified node.
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  boolean acceptTargetNodePort(Node node, NodePort port, double x, double y)
          This method gets called right before someone wants to complete creating an edge at location (x,y) by connecting to the specified node port of the specified node.
protected  void addBend(EdgeRealizer realizer, double x, double y)
          Invoked when the bend creation mouse gesture occurred and bend creation is allowed.
 void allowBendCreation(boolean b)
          Allows or disallows bend creation.
 void allowSelfloopCreation(boolean b)
          Allows or disallows self-loop 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  HitInfo createLabelHitInfo(double x, double y)
          Performs a hit test for a group node label at the specified location.
protected  MoveSnapContext createSnapContext()
          Creates the MoveSnapContext that will be used by this instance to snap the mouse coordinates.
protected  HitInfo createTargetNodeHitInfo(double x, double y)
          Performs a hit test for a target node at the specified location.
protected  Node determineHitNode(Graph2D graph, double x, double y)
          Callback used during the dragging to determine the target hit node
 boolean doAllowBendCreation()
          Returns true if the creation of bends should be allowed.
 boolean doAllowSelfloopCreation()
          Returns true if the creation of self-loops should be allowed.
protected  void drawTargetNodeIndicator(java.awt.Graphics2D gfx, NodeRealizer nodeRealizer)
          Callback method that actually renders the target node indicator.
protected  void drawTargetPortIndicator(java.awt.Graphics2D gfx, NodePort port)
          Callback method that actually renders the target port indicator.
protected  void edgeCreated(Edge edge)
          Serves as a hook for performing actions right after a new edge has been created by this CreateEdgeMode.
protected  void edgeMoved(double x, double y)
          This method gets called whenever the dummy end point 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.
 int getDisableSnappingModifier()
          Gets the modifier mask that can be used to determine whether the user disables snapping via the snap context and getSnapToOrthogonalSegmentsDistance() or isSnappingOrthogonalSegments() temporarily.
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.
 int getGroupBorderWidth()
          returns the width the active group node border.
 MoveSnapContext getSnapContext()
          Gets the MoveSnapContext instance that can be used by this instance to perform mouse snapping during the edge creation operation if isSnappingOrthogonalSegments() snapping is enabled}.
 double getSnapToOrthogonalSegmentsDistance()
          Gets the maximal distance in the view coordinate system this mode will try to snap segments to so that they become orthogonally oriented.
protected  Node getSourceNode(double x, double y)
          Determines the source node for a new edge.
protected  NodePort getSourceNodePort(Node sourceNode, double x, double y)
          Returns a suitable source NodePort instance for an edge starting at the specified coordinates of the specified source node.
protected  YPoint getSourcePortOffset(boolean modifierPressed, Node sourceNode, double dx, double dy)
          Invoked when the edge is about to be created.
protected  Node getTargetNode(double x, double y)
          Determines the target node for a new edge.
protected  java.awt.geom.Rectangle2D getTargetNodeIndicatorBounds(NodeRealizer nodeRealizer)
          Yields the bounds of the target node indicator Drawable.
protected  NodePort getTargetNodePort(Node targetNode, double x, double y)
          Returns a suitable target NodePort instance for an edge ending at the specified coordinates of the specified target node.
protected  YPoint getTargetPortOffset(boolean modifierPressed, Node targetNode, double dx, double dy)
          Invoked when the edge has been created.
protected  YPoint getTargetPortOffset(Edge newEdge, boolean modifierPressed, Node targetNode, double dx, double dy, boolean didSnap, double snappedX, double snappedY)
          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 isConnectOnGroupNodeLabelEnabled()
          Returns whether or not a bend will be created when the mouse is released on the first label of a group node.
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 isEarlyEdgeCancelingEnabled()
          Determines whether the edge creation should be canceled if the user released the mouse inside the source node before even leaving it once.
protected  boolean isFirstSegmentVertical(int mouseDx, int mouseDy, Node startNode)
          Determines whether the first segment should be a vertical segment in the case of orthogonal edge creation.
 boolean isFuzzyTargetPortDetermination()
          Determines whether this mode should use fuzzy logic to determine the location of the target port.
 boolean isIndicatingTargetNode()
          Whether this instance indicates the target node (or node port) of the edge creation operation using a Drawable.
 boolean isNodePortAware()
          Returns true if this CreateEdgeMode instance supports connecting edges to NodePorts and false otherwise.
 boolean isOrthogonalEdgeCreation()
          Determines whether this mode creates orthogonally routed edges.
 boolean isRemovingInnerBends()
          Determines whether this instance should remove bends of the newly created edges that are contained in nodes after the edge creation operation is finished.
 boolean isSnappingOrthogonalSegments()
          Determines whether this instance should snap the location of orthogonal edge segments against other orthogonal snap lines created by the getSnapContext().
 boolean isUsingNodeCenterSnapping()
          Determines whether for non orthogonal edge creation, moving a segment should snap the end point at the location of the centers of nodes in the graph.
 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 setConnectOnGroupNodeLabelEnabled(boolean enabled)
          Whether or not to connect an edge to a group node when the mouse is released on its first label.
 void setDisableSnappingModifier(int disableSnappingModifier)
          Sets the modifier mask that can be used to determine whether the user disables snapping via the snap context and getSnapToOrthogonalSegmentsDistance() or isSnappingOrthogonalSegments() temporarily.
 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 setFuzzyTargetPortDetermination(boolean fuzzyTargetPortDetermination)
          Determines whether this mode should use fuzzy logic to determine the location of the target port.
 void setGroupBorderWidth(int groupBorderWidth)
          Sets the width of the active group node border.
 void setIndicatingTargetNode(boolean indicatingTargetNode)
          Determines whether this instance indicates the target node (or node port) of the edge creation operation using a Drawable.
 void setNodePortAware(boolean nodePortAware)
          Specifies whether or not this CreateEdgeMode instance supports connecting edges to NodePorts.
 void setOrthogonalEdgeCreation(boolean orthogonalEdgeCreation)
          Determines whether this mode should create orthogonally routed edges, only.
 void setRemovingInnerBends(boolean removingInnerBends)
          Determines whether this instance should remove bends of the newly created edges that are contained in nodes after the edge creation operation is finished.
 void setSnapContext(MoveSnapContext snapContext)
          Sets a different MoveSnapContext to use for this instance.
 void setSnappingOrthogonalSegments(boolean snappingOrthogonalSegments)
          Determines whether this instance should snap the location of orthogonal edge segments against other orthogonal snap lines created by the getSnapContext().
 void setSnapToOrthogonalSegmentsDistance(double snapToOrthogonalSegmentsDistance)
          Sets the maximal distance in the view coordinate system this mode will try to snap segments to so that they become orthogonally oriented.
 void setUsingNodeCenterSnapping(boolean usingNodeCenterSnapping)
          Determines whether for non orthogonal edge creation, moving a segment should snap the end point at the location of the centers of nodes in the graph.
protected  void sourceNodeDeclined(Node source, double x, double y)
          This method gets called in case method acceptSourceNode(Node, double, double) returns false.
protected  void sourceNodePortDeclined(Node node, NodePort port, double x, double y)
          This method gets called in case method acceptSourceNodePort(y.base.Node, NodePort, 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.
protected  void targetNodePortDeclined(Node node, NodePort port, double x, double y)
          This method gets called in case method acceptTargetNodePort(y.base.Node, NodePort, double, double) returns false.
 
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, 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

getSnapContext

public MoveSnapContext getSnapContext()
Gets the MoveSnapContext instance that can be used by this instance to perform mouse snapping during the edge creation operation if isSnappingOrthogonalSegments() 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 setSnappingOrthogonalSegments(boolean) is called to enable snapping, this instance will not be used.

Parameters:
snapContext - The new context to use.

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.

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)

isFuzzyTargetPortDetermination

public boolean isFuzzyTargetPortDetermination()
Determines whether this mode should use fuzzy logic to determine the location of the target port. If this feature is enabled and the last created edge segment is orthogonally oriented, this mode will inspect the number of parallel edge segments that leave the node at the same side and if that number is greater than zero, the current location of the mouse will be used as the location of the target port. Otherwise the default target port location (usually the center of the node) will be used. By default this feature is disabled.


setFuzzyTargetPortDetermination

public void setFuzzyTargetPortDetermination(boolean fuzzyTargetPortDetermination)
Determines whether this mode should use fuzzy logic to determine the location of the target port. If this feature is enabled and the last created edge segment is orthogonally oriented, this mode will inspect the number of parallel edge segments that leave the node at the same side and if that number is greater than zero, the current location of the mouse will be used as the location of the target port. Otherwise the default target port location (usually the center of the node) will be used. By default this feature is disabled.


isNodePortAware

public boolean isNodePortAware()
Returns true if this CreateEdgeMode instance supports connecting edges to NodePorts and false otherwise.

Returns:
true if this instance supports connecting edges to NodePorts and false otherwise.
See Also:
setNodePortAware(boolean)

setNodePortAware

public void setNodePortAware(boolean nodePortAware)
Specifies whether or not this CreateEdgeMode instance supports connecting edges to NodePorts.

Parameters:
nodePortAware - true if connecting edges to NodePort has to be supported and false otherwise.
See Also:
isNodePortAware()

isIndicatingTargetNode

public boolean isIndicatingTargetNode()
Whether this instance indicates the target node (or node port) of the edge creation operation using a Drawable. The default is false.

See Also:
drawTargetNodeIndicator(java.awt.Graphics2D, NodeRealizer), drawTargetPortIndicator(java.awt.Graphics2D, NodePort)

setIndicatingTargetNode

public void setIndicatingTargetNode(boolean indicatingTargetNode)
Determines whether this instance indicates the target node (or node port) of the edge creation operation using a Drawable. The default is false.

See Also:
drawTargetNodeIndicator(java.awt.Graphics2D, NodeRealizer), drawTargetPortIndicator(java.awt.Graphics2D, NodePort)

isRemovingInnerBends

public boolean isRemovingInnerBends()
Determines whether this instance should remove bends of the newly created edges that are contained in nodes after the edge creation operation is finished. If enabled this will remove all bends inside adjacent node and instead place the corresponding port at the location of the last bend that lay inside the node. This is especially useful for orthogonal edge creation By default this feature is turned off.


setRemovingInnerBends

public void setRemovingInnerBends(boolean removingInnerBends)
Determines whether this instance should remove bends of the newly created edges that are contained in nodes after the edge creation operation is finished. If enabled this will remove all bends inside adjacent node and instead place the corresponding port at the location of the last bend that lay inside the node. This is especially useful for orthogonal edge creation By default this feature is turned off.


isSnappingOrthogonalSegments

public boolean isSnappingOrthogonalSegments()
Determines whether this instance should snap the location of orthogonal edge segments against other orthogonal snap lines created by the getSnapContext(). By default this feature is turned off.


setSnappingOrthogonalSegments

public void setSnappingOrthogonalSegments(boolean snappingOrthogonalSegments)
Determines whether this instance should snap the location of orthogonal edge segments against other orthogonal snap lines created by the getSnapContext(). By default this feature is turned off.


getSnapToOrthogonalSegmentsDistance

public double getSnapToOrthogonalSegmentsDistance()
Gets the maximal distance in the view coordinate system this mode will try to snap segments to so that they become orthogonally oriented. The default is 0.0d which effectively turns off the snapping.


setSnapToOrthogonalSegmentsDistance

public void setSnapToOrthogonalSegmentsDistance(double snapToOrthogonalSegmentsDistance)
Sets the maximal distance in the view coordinate system this mode will try to snap segments to so that they become orthogonally oriented. The default is 0.0d which effectively turns off the snapping.


isUsingNodeCenterSnapping

public boolean isUsingNodeCenterSnapping()
Determines whether for non orthogonal edge creation, moving a segment should snap the end point at the location of the centers of nodes in the graph. This allows for easy creation of orthogonal last segments when the target ports lie at the center of the nodes. The default value is false.


setUsingNodeCenterSnapping

public void setUsingNodeCenterSnapping(boolean usingNodeCenterSnapping)
Determines whether for non orthogonal edge creation, moving a segment should snap the end point at the location of the centers of nodes in the graph. This allows for easy creation of orthogonal last segments when the target ports lie at the center of the nodes. The default value is false.


allowBendCreation

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


doAllowBendCreation

public boolean doAllowBendCreation()
Returns true if 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 self-loop creation. By default self-loop creation is allowed.


doAllowSelfloopCreation

public boolean doAllowSelfloopCreation()
Returns true if the creation of self-loops 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.

getSourceNode

protected Node getSourceNode(double x,
                             double y)
Determines the source node for a new edge.

Parameters:
x - the x-coordinate of the mouse event that initiated edge creation.
y - the y-coordinate of the mouse event that initiated edge creation.
Returns:
the source node for a new edge or null if no edge should or can be created.

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 available 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 occurred on the node
dy - the y offset were the click occurred on the node
Returns:
the offset should be assigned to the newly created source port.

getSourceNodePort

protected NodePort getSourceNodePort(Node sourceNode,
                                     double x,
                                     double y)
Returns a suitable source NodePort instance for an edge starting at the specified coordinates of the specified source node. This method is invoked when the new edge is about to be created.

The default implementation returns the NodePort instance associated to the specified node that has the least distance to the specified coordinates among all of the specified node's associated NodePort instances.

Parameters:
sourceNode - the node whose ports are queried.
x - the absolute x-coordinate of the desired start location.
y - the absolute y-coordinate of the desired start location.
Returns:
a NodePort instance associated to the specified node or null if there is no associated NodePort instance.

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:
java.lang.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.

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

getDummySourceNodeRealizer

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

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

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.

getDisableSnappingModifier

public int getDisableSnappingModifier()
Gets the modifier mask that can be used to determine whether the user disables snapping via the snap context and getSnapToOrthogonalSegmentsDistance() or isSnappingOrthogonalSegments() 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 edge creation 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 and getSnapToOrthogonalSegmentsDistance() or isSnappingOrthogonalSegments() 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 edge creation 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()

createTargetNodeHitInfo

protected HitInfo createTargetNodeHitInfo(double x,
                                          double y)
Performs a hit test for a target node at the specified location.


getTargetNode

protected Node getTargetNode(double x,
                             double y)
Determines the target node for a new edge.

Parameters:
x - the x-coordinate of the mouse event that initiated edge creation.
y - the y-coordinate of the mouse event that initiated edge creation.
Returns:
the source node for a new edge or null if no edge should or can be created.

addBend

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

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

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 available 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 occurred on the node
dy - the y offset where the click occurred on the node
Returns:
the offset that should be assigned to the newly created target port.

getTargetNodePort

protected NodePort getTargetNodePort(Node targetNode,
                                     double x,
                                     double y)
Returns a suitable target NodePort instance for an edge ending at the specified coordinates of the specified target node. This method is invoked when the new edge has been created.

The default implementation returns the NodePort instance associated to the specified node that has the least distance to the specified coordinates among all of the specified node's associated NodePort instances.

Parameters:
targetNode - the node whose ports are queried.
x - the absolute x-coordinate of the desired end location.
y - the absolute y-coordinate of the desired end location.
Returns:
a NodePort instance associated to the specified node or null if there is no associated NodePort instance.

getTargetPortOffset

protected YPoint getTargetPortOffset(Edge newEdge,
                                     boolean modifierPressed,
                                     Node targetNode,
                                     double dx,
                                     double dy,
                                     boolean didSnap,
                                     double snappedX,
                                     double snappedY)
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 available 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 occurred on the node
dy - the y offset where the click occurred 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. This method will accept bends if there is no node hit under the given coordinate. Also accepted are bends if their coordinate lies within the inner region of a group node. A coordinate that lies on the border of the group node will not be accepted. Optionally, a coordinate inside the label of a group node will also not be accepted.

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.

isFirstSegmentVertical

protected boolean isFirstSegmentVertical(int mouseDx,
                                         int mouseDy,
                                         Node startNode)
Determines whether the first segment should be a vertical segment in the case of orthogonal edge creation. This method will count the orthogonal edges that leave the node in the same direction and if it is the first edge in that direction, it will be anchored to the center of the node.

Parameters:
mouseDx - The delta coordinates the mouse has been moved since the edge creation started.
mouseDy - The delta coordinates the mouse has been moved since the edge creation started.
startNode - The node at which the creation started.
Returns:
Whether the first segment should be vertical.

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 hit-testing
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.

setGroupBorderWidth

public void setGroupBorderWidth(int groupBorderWidth)
Sets the width of the active group node border. By default the border width is set to 10.

See Also:
acceptBend(y.base.Node, y.base.Node, double, double)

getGroupBorderWidth

public int getGroupBorderWidth()
returns the width the active group node border.

See Also:
setGroupBorderWidth(int)

isConnectOnGroupNodeLabelEnabled

public boolean isConnectOnGroupNodeLabelEnabled()
Returns whether or not a bend will be created when the mouse is released on the first label of a group node.


setConnectOnGroupNodeLabelEnabled

public void setConnectOnGroupNodeLabelEnabled(boolean enabled)
Whether or not to connect an edge to a group node when the mouse is released on its first label. By default this feature is enabled.

See Also:
acceptBend(y.base.Node, y.base.Node, double, double)

createLabelHitInfo

protected HitInfo createLabelHitInfo(double x,
                                     double y)
Performs a hit test for a group node label at the specified location.


getTargetNodeIndicatorBounds

protected java.awt.geom.Rectangle2D getTargetNodeIndicatorBounds(NodeRealizer nodeRealizer)
Yields the bounds of the target node indicator Drawable. This method is used as a callback by the actual drawable implementation so that it can be overridden, here, easily.

Parameters:
nodeRealizer - The realizer to highlight.
Returns:
The bounds of the drawable.

drawTargetNodeIndicator

protected void drawTargetNodeIndicator(java.awt.Graphics2D gfx,
                                       NodeRealizer nodeRealizer)
Callback method that actually renders the target node indicator. This callback is used by the actual drawable implementation.

Parameters:
gfx - The graphics to render into.
nodeRealizer - The realizer to highlight.

drawTargetPortIndicator

protected void drawTargetPortIndicator(java.awt.Graphics2D gfx,
                                       NodePort port)
Callback method that actually renders the target port indicator. This callback is used by the actual drawable implementation instead of drawTargetNodeIndicator(java.awt.Graphics2D, NodeRealizer) if this mode supports connecting edges to node ports.

Parameters:
gfx - the graphics to render into.
port - the node port to highlight.
See Also:
drawTargetNodeIndicator(java.awt.Graphics2D, NodeRealizer)

edgeMoved

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

Parameters:
x - the x-coordinate of the end point
y - the y-coordinate of the end point

edgeCreated

protected void edgeCreated(Edge edge)
Serves as a hook for performing actions right after a new edge has been created by this CreateEdgeMode.

The default implementation binds the specified edge to the source and target NodePorts returned by methods getSourceNodePort and getTargetNodePort, if this CreateEdgeMode is node port aware.

Parameters:
edge - the newly created Edge instance.

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.


sourceNodeDeclined

protected void sourceNodeDeclined(Node source,
                                  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 simply calls reactivateParent() and therefor CreateEdgeMode is being left, when the node is not accepted as source node.


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.


sourceNodePortDeclined

protected void sourceNodePortDeclined(Node node,
                                      NodePort port,
                                      double x,
                                      double y)
This method gets called in case method acceptSourceNodePort(y.base.Node, NodePort, double, double) returns false. This method is meant as a hook to perform some post source declination code.

By default this method simply calls reactivateParent() and CreateEdgeMode is being left, when the node port is not accepted as source port.

Parameters:
node - the desired source node for edge creation.
port - the desired source port for edge creation. May be null.
x - the x-coordinate of the desired start location.
y - the y-coordinate of the desired start location.

acceptSourceNodePort

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

By default this method returns true.

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

Parameters:
node - the desired source node for edge creation.
port - the desired source port for edge creation. May be null.
x - the x-coordinate of the desired start location.
y - the y-coordinate of the desired start location.
Returns:
true.

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.


targetNodePortDeclined

protected void targetNodePortDeclined(Node node,
                                      NodePort port,
                                      double x,
                                      double y)
This method gets called in case method acceptTargetNodePort(y.base.Node, NodePort, double, double) returns false. This method is meant as a hook to perform some post target declination code.

By default this method does nothing.

Parameters:
node - the desired target node for edge creation.
port - the desired target port for edge creation. May be null.
x - the x-coordinate of the desired end location.
y - the y-coordinate of the desired end location.

acceptTargetNodePort

protected boolean acceptTargetNodePort(Node node,
                                       NodePort port,
                                       double x,
                                       double y)
This method gets called right before someone wants to complete creating an edge at location (x,y) by connecting to the specified node port of the specified node. The return value of this method determines whether or not the creation of an edge to that node port 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 port.

Parameters:
node - the desired target node for edge creation.
port - the desired target port for edge creation. May be null.
x - the x-coordinate of the desired end location.
y - the y-coordinate of the desired end location.
Returns:
true.

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 java.lang.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:
java.lang.UnsupportedOperationException - if the editing cannot be canceled for any reason.

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