Search this API

y.view
Class MoveLabelMode

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

public class MoveLabelMode
extends ViewMode

This view mode allows interactive reassignment of label positions.

A label can be moved to another position by pressing with the left mouse button on it and then by dragging the label around. While dragging label candidate boxes will appear. These boxes mark the positions that are available for the label. the set of available label positions depend on the LabelModel that is associated which the label. The move terminates it's action when the mouse is released again. The label will then automatically snap to the closest available label position.

 

Nested Class Summary
static class MoveLabelMode.MoveLabelEvent
          An event that indicates that a label has been moved to a new location.
static interface MoveLabelMode.MoveLabelHelper
          Handles mouse pressed, dragged, and released events to provide label specific interactive behavior for moving labels.
static interface MoveLabelMode.MoveLabelHelperProvider
          This interface is implemented by label model's that need to provide specific interactive behavior (such as snapping) for moving labels.
 
Field Summary
static byte CANDIDATES_TYPE_ALL
          Specifier which defines that all label candidates will be displayed.
static byte CANDIDATES_TYPE_BEST
          Specifier which defines that only the best label candidate will be displayed.
static byte CANDIDATES_TYPE_NONE
          Specifier which defines that no label candidates will be displayed.
 
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
MoveLabelMode()
          Instantiates a new MoveLabelMode.
MoveLabelMode(ViewContainer view)
          Instantiates a new MoveLabelMode for the given ViewContainer.
 
Method Summary
 void cancelEditing()
          This can be used to cleanly exit an edit that is currently in progress.
protected  java.lang.Object createModelParameter(EdgeLabelModel model, OrientedRectangle box, EdgeRealizer er, java.awt.event.MouseEvent e)
          Creates a new label model parameter for the specified label model.
protected  java.lang.Object createModelParameter(NodeLabelModel model, OrientedRectangle box, NodeRealizer nr, java.awt.event.MouseEvent e)
          Creates a new label model parameter for the specified label model.
protected  MoveLabelMode.MoveLabelHelper createMoveLabelHelper(YLabel label)
          Creates an appropriate MoveLabelHelper for the specified label.
protected  LabelSnapContext createSnapContext()
          Creates the LabelSnapContext that will be used by this instance to snap the mouse coordinates.
protected  LabelCandidate findBestCandidate(OrientedRectangle labelBounds, YList candidates)
          Determines the best label candidate for the specified label geometry.
protected  byte getCandidatesType(EdgeLabelModel model)
          Determines which candidate positions will be displayed for different EdgeLabelModels.
protected  byte getCandidatesType(NodeLabelModel model)
          Determines which candidate positions will be displayed for different NodeLabelModels.
 int getDisableSnappingModifier()
          Gets the modifier mask that can be used to determine whether the user disables snapping via the snap context temporarily.
 LabelSnapContext getSnapContext()
          Gets the LabelSnapContext 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.
 boolean isSelectOwnerOnMoveEnabled()
          Determines whether or not the owner element of the label that will be moved is automatically selected by this view mode.
 boolean isSnappingEnabled()
          Determines whether or not this mode should use the snap context to adjust mouse coordinates so that moved labels snap to pre-calculated snap lines.
 void mouseDraggedLeft(double x, double y)
          Moves the label.
 void mouseDraggedRight(double x, double y)
          Called when the mouse was dragged with the right button down.
 void mousePressedLeft(double x, double y)
          Initiates the movement of a hit label.
 void mouseReleasedLeft(double x, double y)
          Terminates the movement of a label.
 void mouseReleasedRight(double x, double y)
          Called when the right mouse button was released
protected  void selectionMovedAction(double dx, double dy, double x, double y)
          Performs an action after the selection was moved.
 void setDisableSnappingModifier(int disableSnappingModifier)
          Sets the modifier mask that can be used to determine whether the user disables snapping via the snap context temporarily.
protected  void setSelected(Graph2D graph, Edge edge, boolean flag)
          Sets the specified selection state for the specified edge.
protected  void setSelected(Graph2D graph, Node node, boolean flag)
          Sets the specified selection state for the specified node.
 void setSelectOwnerOnMoveEnabled(boolean enabled)
          Specifies whether or not the owner element of the label that will be moved is automatically selected by this view mode.
 void setSnapContext(LabelSnapContext snapContext)
          Sets a different LabelSnapContext to use for this instance.
 void setSnappingEnabled(boolean snappingEnabled)
          Specifies whether or not this mode should use the snap context to adjust mouse coordinates so that the moved labels snap to the pre-calculated snap lines.
protected  void updateSelectionState(Graph2D graph, Edge edge)
          Updates the selection state of the specified edge.
protected  void updateSelectionState(Graph2D graph, Node node)
          Updates the selection state of the specified node.
 
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, init, isActive, isEditing, isGrabFocusEnabled, isGridMode, isModifierPressed, mouseClicked, mouseClicked, mouseDragged, mouseDraggedMiddle, mouseEntered, mouseExited, mouseMoved, mouseMoved, mousePressed, mousePressedMiddle, mousePressedRight, mouseReleased, mouseReleased, mouseReleasedMiddle, mouseShiftPressedLeft, mouseShiftPressedMiddle, mouseShiftPressedRight, mouseShiftReleasedLeft, mouseShiftReleasedMiddle, mouseShiftReleasedRight, reactivateParent, removePropertyChangeListener, removePropertyChangeListener, setActiveView, setChild, setChild, setEditing, setGrabFocusEnabled, setGridMode, setLastHitInfo, setModifierMask, setName, setParent, translateX, translateY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CANDIDATES_TYPE_ALL

public static final byte CANDIDATES_TYPE_ALL
Specifier which defines that all label candidates will be displayed.

See Also:
Constant Field Values

CANDIDATES_TYPE_BEST

public static final byte CANDIDATES_TYPE_BEST
Specifier which defines that only the best label candidate will be displayed.

See Also:
Constant Field Values

CANDIDATES_TYPE_NONE

public static final byte CANDIDATES_TYPE_NONE
Specifier which defines that no label candidates will be displayed.

See Also:
Constant Field Values
Constructor Detail

MoveLabelMode

public MoveLabelMode(ViewContainer view)
Instantiates a new MoveLabelMode for the given ViewContainer.

Parameters:
view - the ViewContainer to whose current view this mode is bound.

MoveLabelMode

public MoveLabelMode()
Instantiates a new MoveLabelMode.

Method Detail

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 InputEvent.CTRL_MASK so that pressing the CTRL modifier will allow the user to take full control over the movement without the aid of snap lines.

Parameters:
disableSnappingModifier - the modifier mask that determines which modifier keys will disable snapping.

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 InputEvent.CTRL_MASK so that pressing the CTRL modifier will allow the user to take full control over the movement without the aid of snap lines.

Returns:
the modifier mask that determines which modifier keys will disable snapping.

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(), isSnappingEnabled()

getSnapContext

public LabelSnapContext getSnapContext()
Gets the LabelSnapContext 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:
createSnapContext(), setSnapContext(LabelSnapContext), isSnappingEnabled(), setSnappingEnabled(boolean)

setSnapContext

public void setSnapContext(LabelSnapContext snapContext)
Sets a different LabelSnapContext 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.
See Also:
getSnapContext(), isSnappingEnabled(), setSnappingEnabled(boolean)

isSnappingEnabled

public boolean isSnappingEnabled()
Determines whether or not this mode should use the snap context to adjust mouse coordinates so that moved labels snap to pre-calculated snap lines.

By default this feature is enabled.

Returns:
true if snapping is enabled and false otherwise.
See Also:
setSnappingEnabled(boolean), getSnapContext(), setSnapContext(LabelSnapContext)

setSnappingEnabled

public void setSnappingEnabled(boolean snappingEnabled)
Specifies whether or not this mode should use the snap context to adjust mouse coordinates so that the moved labels snap to the pre-calculated snap lines.

By default this feature is enabled.

Parameters:
snappingEnabled - if true snapping is enabled.
See Also:
isSnappingEnabled(), getSnapContext(), setSnapContext(LabelSnapContext)

createSnapContext

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

Returns:
a configured instance of LabelSnapContext.
See Also:
getSnapContext()

isSelectOwnerOnMoveEnabled

public boolean isSelectOwnerOnMoveEnabled()
Determines whether or not the owner element of the label that will be moved is automatically selected by this view mode.

Defaults to true.

Returns:
true if the owner element of the label that will be moved is automatically selected; false otherwise.
See Also:
setSelectOwnerOnMoveEnabled(boolean), updateSelectionState(Graph2D, y.base.Edge), updateSelectionState(Graph2D, y.base.Node)

setSelectOwnerOnMoveEnabled

public void setSelectOwnerOnMoveEnabled(boolean enabled)
Specifies whether or not the owner element of the label that will be moved is automatically selected by this view mode.

Defaults to true.

Parameters:
enabled - if true the owner element of the label that will be moved is automatically selected.
See Also:
isSelectOwnerOnMoveEnabled(), updateSelectionState(Graph2D, y.base.Edge), updateSelectionState(Graph2D, y.base.Node)

mousePressedLeft

public void mousePressedLeft(double x,
                             double y)
Initiates the movement of a hit label.

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.

createMoveLabelHelper

protected MoveLabelMode.MoveLabelHelper createMoveLabelHelper(YLabel label)
Creates an appropriate MoveLabelHelper for the specified label. Move helpers handle mouse pressed, dragged, and released events to provide label (or label model) specific interactive behavior.

The default implementation checks whether or not the specified label's label model is a MoveLabelHelperProvider and calls the provider's createMoveLabelHelper method.

Called from mousePressedLeft.

Parameters:
label - the label instance for which a move helper should be created.
Returns:
a MoveLabelHelper instance or null if the specified label does not support movement helpers.
See Also:
mousePressedLeft(double, double), MoveLabelMode.MoveLabelHelperProvider, MoveLabelMode.MoveLabelHelperProvider.createMoveLabelHelper()

updateSelectionState

protected void updateSelectionState(Graph2D graph,
                                    Node node)
Updates the selection state of the specified node. Called from mousePressedLeft(double, double) when label movement is initialized.

The default implementation will set the specified node's selection state to true if selecting label owners is enabled.

Parameters:
graph - the graph the specified node resides in.
node - the node associated to the label that will be moved.

updateSelectionState

protected void updateSelectionState(Graph2D graph,
                                    Edge edge)
Updates the selection state of the specified edge. Called from mousePressedLeft(double, double) when label movement is initialized.

The default implementation will set the specified edge's selection state to true if selecting label owners is enabled.

Parameters:
graph - the graph the specified edge resides in.
edge - the edge associated to the label that will be moved.

setSelected

protected void setSelected(Graph2D graph,
                           Edge edge,
                           boolean flag)
Sets the specified selection state for the specified edge. Subclasses may override this method to add notifications for edge selection state changes.

Parameters:
graph - the graph the specified edge resides in.
edge - the edge whose selection state has to be changed.
flag - the new selection state for the specified edge.

setSelected

protected void setSelected(Graph2D graph,
                           Node node,
                           boolean flag)
Sets the specified selection state for the specified node. Subclasses may override this method to add notifications for node selection state changes.

Parameters:
graph - the graph the specified node resides in.
node - the node whose selection state has to be changed.
flag - the new selection state for the specified node.

mouseReleasedRight

public void mouseReleasedRight(double x,
                               double y)
Description copied from class: ViewMode
Called when the right mouse button was released

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.

mouseReleasedLeft

public void mouseReleasedLeft(double x,
                              double y)
Terminates the movement of a label. The label will snap from its current position to the closest available candidate box.

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.

mouseDraggedRight

public void mouseDraggedRight(double x,
                              double y)
Description copied from class: ViewMode
Called when the mouse was dragged with the right button down.

Overrides:
mouseDraggedRight 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.

mouseDraggedLeft

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

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.

findBestCandidate

protected LabelCandidate findBestCandidate(OrientedRectangle labelBounds,
                                           YList candidates)
Determines the best label candidate for the specified label geometry. The default implementation returns the label candidate for which the distance between the candidate's center and the specified rectangle's center is minimized.

Parameters:
labelBounds - the label geometry to match to a suitable label candidate.
candidates - the available label candidates. The specified list will hold instances of class LabelCandidate. May be null.
Returns:
the best label candidate for the specified label geometry or null if no candidate could be found.

selectionMovedAction

protected void selectionMovedAction(double dx,
                                    double dy,
                                    double x,
                                    double y)
Performs an action after the selection was moved. By default this method does nothing. Subclasses may want to override this.

Parameters:
dx - the distance moved in x-direction.
dy - the distance moved in y-direction.
x - the x-coordinate to which the selection was moved.
y - the y-coordinate to which the selection was moved.

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.

getCandidatesType

protected byte getCandidatesType(NodeLabelModel model)
Determines which candidate positions will be displayed for different NodeLabelModels.

Parameters:
model - The current label model
Returns:
either CANDIDATES_TYPE_ALL, CANDIDATES_TYPE_BEST, or CANDIDATES_TYPE_NONE

getCandidatesType

protected byte getCandidatesType(EdgeLabelModel model)
Determines which candidate positions will be displayed for different EdgeLabelModels.

Parameters:
model - The current label model
Returns:
either CANDIDATES_TYPE_ALL, CANDIDATES_TYPE_BEST, or CANDIDATES_TYPE_NONE

createModelParameter

protected java.lang.Object createModelParameter(NodeLabelModel model,
                                                OrientedRectangle box,
                                                NodeRealizer nr,
                                                java.awt.event.MouseEvent e)
Creates a new label model parameter for the specified label model.

Parameters:
model - the model for which the parameter has to be valid.
box - the location, size, and orientation that has to be encoded in the parameter.
nr - the owner of the label for which the parameter is created.
e - the mouse event that triggered the parameter creation. Usually a drag or a release event.
Returns:
a new model parameter.

createModelParameter

protected java.lang.Object createModelParameter(EdgeLabelModel model,
                                                OrientedRectangle box,
                                                EdgeRealizer er,
                                                java.awt.event.MouseEvent e)
Creates a new label model parameter for the specified label model.

Parameters:
model - the model for which the parameter has to be valid.
box - the location, size, and orientation that has to be encoded in the parameter.
er - the owner of the label for which the parameter is created.
e - the mouse event that triggered the parameter creation. Usually a drag or a release event.
Returns:
a new model parameter.

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