Search this API

y.view
Class HotSpotMode

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

public class HotSpotMode
extends ViewMode

Handles hotspot drags. Causes selected nodes to change their size when the user drags one of the hotspots visible around such a node.

The mode is activated when the mouse is moved over a hotspot. It changes the mouse cursor according to the hotspot. In this state the HotSpotMode is *inactive*. When the left mouse button is pressed it goes into *active* mode.

This mode provides two modifiers to influence the resizing. The first one (isModifierPressed(java.awt.event.MouseEvent)) determines whether resizing shall keep the aspect ratio of the selected node(s). The second modifier (isKeepNodeCenterModifierPressed(java.awt.event.MouseEvent)) determines whether the selected node(s) shall keep their center locations when being resized. Both can be used in conjunction.

Client code may overwrite method accept(Graph2D, y.base.Node) to adjust the logic for determining the nodes to change.

 

Field Summary
static byte BLOCK_UPON_MINIMUM_SIZE
          Resize policy specifier.
static byte DISCRETE_BLOCK_POLICY
          Resize policy specifier.
static byte FIXED_AUTOBOUNDS_INSETS
          Group bounds policy specifier.
static byte FIXED_MINIMUM_GROUP_BOUNDS
          Group bounds policy specifier.
static byte FLIP_SIDES_UPON_MINIMUM_SIZE
          Resize policy specifier.
static java.lang.String NODE_CENTER_RESIZING_MODIFIER_MASK_PROPERTY
          Property name constant used for PropertyChangeEvent.getPropertyName().
static byte SEMI_BLOCK_UPON_MINIMUM_SIZE
          Resize policy specifier.
 
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
HotSpotMode()
          Instantiates a new HotSpotMode.
HotSpotMode(ViewContainer vc)
          Instantiates a new HotSpotMode for a given ViewContainer.
 
Method Summary
protected  boolean accept(Graph2D graph, Node node)
          Determines whether or not the size of the specified node should be changed by this mode.
 void activate(boolean b)
          Invoked when the Mode is activated/deactivated from the ViewControl or via the setChild() and reactivateParent operations This behaves like a bound property using ViewMode.ACTIVE_PROPERTY as the property name.
protected  void adjustPortOffsets(Graph2D graph, Node node, double wOld, double hOld, double wNew, double hNew)
          Callback method that adjusts the ports of a NodeRealizer after that NodeRealizer's bounds have been changed.
 void cancelEditing()
          This can be used to cleanly exit an edit that is currently in progress.
protected  void cancelNodeResize()
          Calling this method cancels node resizing properly.
protected  HotSpotSnapContext createSnapContext()
          Creates the MoveSnapContext that will be used by this instance to snap the mouse coordinates.
 int getCancelKeyCode()
          Returns the virtual key code that identifies key events that cancels node resizing.
static java.awt.Cursor getCursor(byte hotSpotType)
          Returns a suitable cursor for the given hotSpotType.
 int getDisableSnappingModifier()
          Gets the modifier mask that can be used to determine whether the user disables snapping via the snap context temporarily.
 byte getGroupBoundsPolicy()
          Returns the group bounds policy used when resizing the child nodes of a group.
 int getKeepNodeCenterModifierMask()
          Returns the modifier mask that is used to determine whether or not the node center should be kept when resizing nodes.
 byte getResizePolicy()
          Returns the resize policy employed when dragging at a hotspot of a node.
 HotSpotSnapContext getSnapContext()
          Gets the HotSpotSnapContext instance that can be used by this instance to perform mouse snapping during the move operation if snapping is enabled.
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.
protected  boolean isKeepNodeCenterModifierPressed(java.awt.event.MouseEvent me)
          Determines whether or not the keepNodeCenter modifier mask is set for the specified mouse event.
protected  boolean isModifierPressed(java.awt.event.MouseEvent me)
          This method determines whether at the creation time of the given MouseEvent the modifier key was pressed.
protected  boolean isOrthogonalRouting(Edge edge)
          Determines whether the given edge instance should be routed orthogonally.
 boolean isRemovingInnerBends()
          Determines whether this instance should remove bends of edges adjacent to nodes that are contained in these nodes that have been resized during the resize operation after the move is finished.
 boolean isSnappingEnabled()
          Whether this mode should use the getSnapContext() to HotSpotSnapContext.adjustMouseCoordinates(y.geom.YPoint, byte, boolean, boolean) adjust the mouse coordinates so that the resized items snap to the precalculated SnapLines.
 void mouseDraggedLeft(double x, double y)
          Changes node sizes.
 void mousePressedLeft(double x, double y)
          Initiates changing node sizes.
 void mouseReleased(java.awt.event.MouseEvent ev)
          Perform additional cleanup.
 void mouseReleasedLeft(double x, double y)
          Terminates changing node sizes.
 void reactivateParent()
          The parent of this ViewMode is reactivated and this ViewMode is deactivated.
 void setCancelKeyCode(int cancelKeyCode)
          Sets the virtual key code that identifies key events that cancels node resizing.
 void setDisableSnappingModifier(int disableSnappingModifier)
          Sets the modifier mask that can be used to determine whether the user disables snapping via the snap context temporarily.
 void setGroupBoundsPolicy(byte groupBoundsPolicy)
          Sets the group bounds policy used when resizing the child nodes of a group.
 void setKeepNodeCenterModifierMask(int modifierMask)
          Sets the modifier mask that is used to determine whether or not the node center should be kept when resizing nodes.
 void setRemovingInnerBends(boolean removingInnerBends)
          Determines whether this instance should remove bends of edges adjacent to nodes that are contained in these nodes that have been resized during the resize operation after the move is finished.
 void setResizePolicy(byte policy)
          Sets the resize policy employed when dragging one of the hotspots of a selected node.
 void setSnapContext(HotSpotSnapContext snapContext)
          Sets a different HotSpotSnapContext to use for this instance.
 void setSnappingEnabled(boolean snappingEnabled)
          Whether this mode should use the getSnapContext() to HotSpotSnapContext.adjustMouseCoordinates(y.geom.YPoint, byte, boolean, boolean) adjust the mouse coordinates so that the resized items snap to the precalculated SnapLines.
protected  void updateNodeRealizerBounds(NodeRealizer vr, double x, double y, double w, double h)
          This method will be invoked by this view mode when the current bounds of a node need to be updated.
 
Methods inherited from class y.view.ViewMode
addPropertyChangeListener, addPropertyChangeListener, deactivateChild, firePropertyChange, firePropertyChange, firePropertyChange, getChild, getGraph2D, getGridX, getGridY, getHitInfo, getHitInfo, getLastClickEvent, getLastDragEvent, getLastHitInfo, getLastMoveEvent, getLastPressEvent, getLastReleaseEvent, getModifierMask, getName, getParent, init, isActive, isEditing, isGrabFocusEnabled, isGridMode, mouseClicked, mouseClicked, mouseDragged, mouseDraggedMiddle, mouseDraggedRight, mouseEntered, mouseExited, mouseMoved, mouseMoved, mousePressed, mousePressedMiddle, mousePressedRight, mouseReleased, mouseReleasedMiddle, mouseReleasedRight, mouseShiftPressedLeft, mouseShiftPressedMiddle, mouseShiftPressedRight, mouseShiftReleasedLeft, 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
 

Field Detail

FIXED_AUTOBOUNDS_INSETS

public static final byte FIXED_AUTOBOUNDS_INSETS
Group bounds policy specifier. When resizing a node that belongs to a group whose realizer implements AutoBoundsFeature, the group node's autoBoundsInsets will stay fixed. It's overall bounds can grow or shrink.

See Also:
Constant Field Values

FIXED_MINIMUM_GROUP_BOUNDS

public static final byte FIXED_MINIMUM_GROUP_BOUNDS
Group bounds policy specifier. When resizing a node that belongs to a group whose realizer implements AutoBoundsFeature, the group node's bounds can grow but not shrink. Before a group node starts to grow its autoBoundsInset will be reduced, first.

See Also:
Constant Field Values

NODE_CENTER_RESIZING_MODIFIER_MASK_PROPERTY

public static final java.lang.String NODE_CENTER_RESIZING_MODIFIER_MASK_PROPERTY
Property name constant used for PropertyChangeEvent.getPropertyName(). This property is used if setKeepNodeCenterModifierMask(int) is called.

See Also:
Constant Field Values

SEMI_BLOCK_UPON_MINIMUM_SIZE

public static final byte SEMI_BLOCK_UPON_MINIMUM_SIZE
Resize policy specifier. Unless a node has not yet reached minimum size, each drag gesture will cause the node to change its size. With this policy the mouse location can easily get out of sync with the active hotspot of a node. The minimum size is determined by a SizeConstraintProvider if provided using method NodeRealizer.getSizeConstraintProvider(). If no SizeConstraintProvider is provided the minimum size is 1,1 for normal nodes or determined by the minimum group bounds for open group nodes.

See Also:
setResizePolicy(byte), Constant Field Values

BLOCK_UPON_MINIMUM_SIZE

public static final byte BLOCK_UPON_MINIMUM_SIZE
Resize policy specifier. Resizes the nodes until a minimum size is reached. Resizing will be blocked whenever the mouse location is out of sync with the hotspot location. The minimum size is determined by a SizeConstraintProvider if provided using method NodeRealizer.getSizeConstraintProvider(). If no SizeConstraintProvider is provided the minimum size is 1,1 for normal nodes or determined by the minimum group bounds for open group nodes.

See Also:
setResizePolicy(byte), Constant Field Values

FLIP_SIDES_UPON_MINIMUM_SIZE

public static final byte FLIP_SIDES_UPON_MINIMUM_SIZE
Resize policy specifier. When the minimum size of a node is reached, the sides of the nodes will be exchanged so that the size of the node grows again.

See Also:
setResizePolicy(byte), Constant Field Values

DISCRETE_BLOCK_POLICY

public static final byte DISCRETE_BLOCK_POLICY
Resize policy specifier. Each node can be resized up to its minimal/maximal bounds. This policy supports keeping the aspect ratio (isModifierPressed(java.awt.event.MouseEvent)) as well as keeping the center locations (isKeepNodeCenterModifierPressed(java.awt.event.MouseEvent)) of selected nodes.

See Also:
setResizePolicy(byte), Constant Field Values
Constructor Detail

HotSpotMode

public HotSpotMode(ViewContainer vc)
Instantiates a new HotSpotMode for a given ViewContainer.

Parameters:
vc - the ViewContainer to which the mode will be bound.

HotSpotMode

public HotSpotMode()
Instantiates a new HotSpotMode.

Method Detail

getDisableSnappingModifier

public int getDisableSnappingModifier()
Gets the modifier mask that can be used to determine whether the user disables snapping via the snap context temporarily. By default this is set to 0 so there is no modifier that will allow the user to take full control over the resizing 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 temporarily. By default this is set to 0 so there is no modifier that will allow the user to take full control over the resizing 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()

getSnapContext

public HotSpotSnapContext getSnapContext()
Gets the HotSpotSnapContext instance that can be used by this instance to perform mouse snapping during the move operation if snapping is enabled.

Returns:
The context instance to use.
See Also:
setSnapContext(HotSpotSnapContext)

setSnapContext

public void setSnapContext(HotSpotSnapContext snapContext)
Sets a different HotSpotSnapContext to use for this instance. Note that unless setSnappingEnabled(boolean) is called to enable snapping, this instance will not be used.

Parameters:
snapContext - The new context to use.

isSnappingEnabled

public boolean isSnappingEnabled()
Whether this mode should use the getSnapContext() to HotSpotSnapContext.adjustMouseCoordinates(y.geom.YPoint, byte, boolean, boolean) adjust the mouse coordinates so that the resized items snap to the precalculated SnapLines.

By default this is disabled.

Returns:
true if snapping is enabled; false otherwise.

setSnappingEnabled

public void setSnappingEnabled(boolean snappingEnabled)
Whether this mode should use the getSnapContext() to HotSpotSnapContext.adjustMouseCoordinates(y.geom.YPoint, byte, boolean, boolean) adjust the mouse coordinates so that the resized items snap to the precalculated SnapLines.

By default this is disabled.

Parameters:
snappingEnabled - if true snapping will be enabled; if false snapping will be disabled.

createSnapContext

protected HotSpotSnapContext createSnapContext()
Creates the MoveSnapContext that will be used by this instance to snap the mouse coordinates.

Returns:
a preconfigured instance of MoveSnapContext.

isRemovingInnerBends

public boolean isRemovingInnerBends()
Determines whether this instance should remove bends of edges adjacent to nodes that are contained in these nodes that have been resized during the resize operation after the move 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.

By default this feature is turned off.

Returns:
true if inner bends of edges connecting to resized nodes are automatically removed; false otherwise.

setRemovingInnerBends

public void setRemovingInnerBends(boolean removingInnerBends)
Determines whether this instance should remove bends of edges adjacent to nodes that are contained in these nodes that have been resized during the resize operation after the move 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.

By default this feature is turned off.

Parameters:
removingInnerBends - if true inner bends of edges connecting to resized nodes are automatically removed.

setResizePolicy

public void setResizePolicy(byte policy)
Sets the resize policy employed when dragging one of the hotspots of a selected node.
Note: Only the DISCRETE_BLOCK_POLICY-policy supports the modifiers isModifierPressed(java.awt.event.MouseEvent) and isKeepNodeCenterModifierPressed(java.awt.event.MouseEvent).

Parameters:
policy - One of SEMI_BLOCK_UPON_MINIMUM_SIZE, BLOCK_UPON_MINIMUM_SIZE, FLIP_SIDES_UPON_MINIMUM_SIZE, or DISCRETE_BLOCK_POLICY.
By default, DISCRETE_BLOCK_POLICY is set.

getResizePolicy

public byte getResizePolicy()
Returns the resize policy employed when dragging at a hotspot of a node.

Returns:
the currently set resize policy
See Also:
setResizePolicy(byte)

mousePressedLeft

public void mousePressedLeft(double x,
                             double y)
Initiates changing node sizes. By default, the size of all selected nodes is changed. Client code may overwrite method accept(Graph2D, y.base.Node) to adjust the logic for determining the nodes to change.

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.
See Also:
accept(Graph2D, y.base.Node)

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent ev)
Perform additional cleanup.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Overrides:
mouseReleased in class ViewMode

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)

mouseDraggedLeft

public void mouseDraggedLeft(double x,
                             double y)
Changes node sizes. By default, the size of all selected nodes is changed. Client code may overwrite method accept(Graph2D, y.base.Node) to adjust the logic for determining the nodes to change.

Calls updateNodeRealizerBounds(NodeRealizer, double, double, double, double) and adjustPortOffsets(Graph2D, y.base.Node, double, double, double, double) for each node that is being resized.

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.
See Also:
accept(Graph2D, y.base.Node)

isModifierPressed

protected boolean isModifierPressed(java.awt.event.MouseEvent me)
Description copied from class: ViewMode
This method determines whether at the creation time of the given MouseEvent the modifier key was pressed. This implementation checks whether any of the bits in the modifierMask property of this class are set in the MouseEvents modifiers property. Subclasses may override this method to provide a more sophisticated implementation.

Overrides:
isModifierPressed in class ViewMode
See Also:
ViewMode.setModifierMask(int), ViewMode.getModifierMask()

isKeepNodeCenterModifierPressed

protected boolean isKeepNodeCenterModifierPressed(java.awt.event.MouseEvent me)
Determines whether or not the keepNodeCenter modifier mask is set for the specified mouse event. Subclasses may override this method to provide a more sophisticated implementation.

Parameters:
me - the MouseEvent to check.
Returns:
true if the modifier mask for keeping the node center on node resize is set; false otherwise.
See Also:
setKeepNodeCenterModifierMask(int), getKeepNodeCenterModifierMask()

setKeepNodeCenterModifierMask

public void setKeepNodeCenterModifierMask(int modifierMask)
Sets the modifier mask that is used to determine whether or not the node center should be kept when resizing nodes. A modifier is assumed to be set if (mouseEvent.getModifier() & modifierMask) != 0. Valid values are the static fields in the MouseEvent class.

Parameters:
modifierMask - the new modifier mask that will be used to determine whether or not the node center should be kept when resizing nodes.
See Also:
getKeepNodeCenterModifierMask(), isKeepNodeCenterModifierPressed(java.awt.event.MouseEvent)

getKeepNodeCenterModifierMask

public int getKeepNodeCenterModifierMask()
Returns the modifier mask that is used to determine whether or not the node center should be kept when resizing nodes. A modifier is assumed to be set if (mouseEvent.getModifier() & modifierMask) != 0.

The default is MouseEvent.CTRL_MASK.

Returns:
the current modifier mask that is used to determine whether or not the node center should be kept when resizing nodes.
See Also:
setKeepNodeCenterModifierMask(int), isKeepNodeCenterModifierPressed(java.awt.event.MouseEvent)

adjustPortOffsets

protected void adjustPortOffsets(Graph2D graph,
                                 Node node,
                                 double wOld,
                                 double hOld,
                                 double wNew,
                                 double hNew)
Callback method that adjusts the ports of a NodeRealizer after that NodeRealizer's bounds have been changed.

Parameters:
graph - the graph that contains the node
node - the node whose ports shall be adjusted
wOld - the old width
hOld - the old height
wNew - the new width
hNew - the new height

updateNodeRealizerBounds

protected void updateNodeRealizerBounds(NodeRealizer vr,
                                        double x,
                                        double y,
                                        double w,
                                        double h)
This method will be invoked by this view mode when the current bounds of a node need to be updated.

Parameters:
vr - the realizer of the node whose bounds should change.
x - the desired x-coordinate of the node bounds.
y - the desired y-coordinate of the node bounds.
w - the desired width of the node.
h - the desired height of the node.

mouseReleasedLeft

public void mouseReleasedLeft(double x,
                              double y)
Terminates changing node sizes. By default, the size of all selected nodes is changed. Client code may overwrite method accept(Graph2D, y.base.Node) to adjust the logic for determining the nodes to change.

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.
See Also:
accept(Graph2D, y.base.Node)

activate

public void activate(boolean b)
Description copied from class: ViewMode
Invoked when the Mode is activated/deactivated from the ViewControl or via the setChild() and reactivateParent operations This behaves like a bound property using ViewMode.ACTIVE_PROPERTY as the property name.

Overrides:
activate in class ViewMode
Parameters:
b - set true when mode was activated false otherwise

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

cancelNodeResize

protected void cancelNodeResize()
Calling this method cancels node resizing properly. After doing some cleanup it reactivates the parent if present.


getCursor

public static java.awt.Cursor getCursor(byte hotSpotType)
Returns a suitable cursor for the given hotSpotType. The cursor indicates the kind of resize action that is being performed.

Parameters:
hotSpotType - one of
Returns:
a cursor for the specified hot spot type.

getCancelKeyCode

public int getCancelKeyCode()
Returns the virtual key code that identifies key events that cancels node resizing. Negative values disable this feature.

Default is KeyEvent.VK_ESCAPE.

Returns:
a virtual key code as defined in KeyEvent.
See Also:
setCancelKeyCode(int)

setCancelKeyCode

public void setCancelKeyCode(int cancelKeyCode)
Sets the virtual key code that identifies key events that cancels node resizing. Negative values disable this feature.

Default is KeyEvent.VK_ESCAPE.

Parameters:
cancelKeyCode - a virtual key code as defined in KeyEvent.
See Also:
getCancelKeyCode()

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.

getGroupBoundsPolicy

public byte getGroupBoundsPolicy()
Returns the group bounds policy used when resizing the child nodes of a group.

By default, FIXED_AUTOBOUNDS_INSETS is set.

Returns:
one of FIXED_AUTOBOUNDS_INSETS and FIXED_MINIMUM_GROUP_BOUNDS.
See Also:
setGroupBoundsPolicy(byte)

setGroupBoundsPolicy

public void setGroupBoundsPolicy(byte groupBoundsPolicy)
Sets the group bounds policy used when resizing the child nodes of a group.

By default, FIXED_AUTOBOUNDS_INSETS is set.

Parameters:
groupBoundsPolicy - one of FIXED_AUTOBOUNDS_INSETS and FIXED_MINIMUM_GROUP_BOUNDS.
See Also:
getGroupBoundsPolicy()

accept

protected boolean accept(Graph2D graph,
                         Node node)
Determines whether or not the size of the specified node should be changed by this mode.

The default implementation accepts selected nodes. Client code may overwrite this method to adjust the logic for accepting nodes.

Parameters:
graph - the graph that contains the node.
node - the node that is checked.
Returns:
true if the size of the specified node should be changed and false otherwise.

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