|
Search this API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object y.view.ViewMode y.view.MoveLabelMode
public class MoveLabelMode
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 EdgeLabelModel s. |
protected byte |
getCandidatesType(NodeLabelModel model)
Determines which candidate positions will be displayed for different NodeLabelModel s. |
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 java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final byte CANDIDATES_TYPE_ALL
public static final byte CANDIDATES_TYPE_BEST
public static final byte CANDIDATES_TYPE_NONE
Constructor Detail |
---|
public MoveLabelMode(ViewContainer view)
MoveLabelMode
for the given
ViewContainer
.
view
- the ViewContainer
to whose current view this mode
is bound.public MoveLabelMode()
MoveLabelMode
.
Method Detail |
---|
public void setDisableSnappingModifier(int disableSnappingModifier)
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.
disableSnappingModifier
- the modifier mask that determines
which modifier keys will disable snapping.public int getDisableSnappingModifier()
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.
protected boolean isDisableSnappingModifierPressed(java.awt.event.MouseEvent e)
modifier to disable
snapping
has been currently pressed. This implementation uses the getDisableSnappingModifier()
to
determine whether the modifier is currently applied.
e
- The last mouse event.
getSnapContext()
,
getDisableSnappingModifier()
,
isSnappingEnabled()
public LabelSnapContext getSnapContext()
LabelSnapContext
instance that can be used by this instance to perform mouse snapping
during the move operation if snapping is enabled
.
createSnapContext()
,
setSnapContext(LabelSnapContext)
,
isSnappingEnabled()
,
setSnappingEnabled(boolean)
public void setSnapContext(LabelSnapContext snapContext)
LabelSnapContext
to use for this instance.
Note that unless setSnappingEnabled(boolean)
is called to enable
snapping, this instance will not be used.
snapContext
- The new context to use.getSnapContext()
,
isSnappingEnabled()
,
setSnappingEnabled(boolean)
public boolean isSnappingEnabled()
snap context
to
adjust
mouse coordinates
so that moved labels snap to pre-calculated
snap lines
.
By default this feature is enabled.
true
if snapping is enabled and false
otherwise.setSnappingEnabled(boolean)
,
getSnapContext()
,
setSnapContext(LabelSnapContext)
public void setSnappingEnabled(boolean snappingEnabled)
snap context
to
adjust
mouse coordinates
so that the moved labels snap to the pre-calculated
snap lines
.
By default this feature is enabled.
snappingEnabled
- if true
snapping is enabled.isSnappingEnabled()
,
getSnapContext()
,
setSnapContext(LabelSnapContext)
protected LabelSnapContext createSnapContext()
LabelSnapContext
that will be used by this instance to snap the mouse coordinates.
LabelSnapContext
.getSnapContext()
public boolean isSelectOwnerOnMoveEnabled()
Defaults to true
.
true
if the owner element of the label that will be
moved is automatically selected; false
otherwise.setSelectOwnerOnMoveEnabled(boolean)
,
updateSelectionState(Graph2D, y.base.Edge)
,
updateSelectionState(Graph2D, y.base.Node)
public void setSelectOwnerOnMoveEnabled(boolean enabled)
Defaults to true
.
enabled
- if true
the owner element of the label that
will be moved is automatically selected.isSelectOwnerOnMoveEnabled()
,
updateSelectionState(Graph2D, y.base.Edge)
,
updateSelectionState(Graph2D, y.base.Node)
public void mousePressedLeft(double x, double y)
mousePressedLeft
in class ViewMode
x
- the x-coordinate of the mouse event in world coordinates.y
- the y-coordinate of the mouse event in world coordinates.protected MoveLabelMode.MoveLabelHelper createMoveLabelHelper(YLabel label)
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
.
label
- the label instance for which a move helper should be created.
MoveLabelHelper
instance or null
if the specified label does not support movement helpers.mousePressedLeft(double, double)
,
MoveLabelMode.MoveLabelHelperProvider
,
MoveLabelMode.MoveLabelHelperProvider.createMoveLabelHelper()
protected void updateSelectionState(Graph2D graph, Node node)
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
.
graph
- the graph the specified node resides in.node
- the node associated to the label that will be moved.protected void updateSelectionState(Graph2D graph, Edge edge)
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
.
graph
- the graph the specified edge resides in.edge
- the edge associated to the label that will be moved.protected void setSelected(Graph2D graph, Edge edge, boolean flag)
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.protected void setSelected(Graph2D graph, Node node, boolean flag)
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.public void mouseReleasedRight(double x, double y)
ViewMode
mouseReleasedRight
in class ViewMode
x
- the x-coordinate of the mouse event in world coordinates.y
- the y-coordinate of the mouse event in world coordinates.public void mouseReleasedLeft(double x, double y)
mouseReleasedLeft
in class ViewMode
x
- the x-coordinate of the mouse event in world coordinates.y
- the y-coordinate of the mouse event in world coordinates.public void mouseDraggedRight(double x, double y)
ViewMode
mouseDraggedRight
in class ViewMode
x
- the x-coordinate of the mouse event in world coordinates.y
- the y-coordinate of the mouse event in world coordinates.public void mouseDraggedLeft(double x, double y)
mouseDraggedLeft
in class ViewMode
x
- the x-coordinate of the mouse event in world coordinates.y
- the y-coordinate of the mouse event in world coordinates.protected LabelCandidate findBestCandidate(OrientedRectangle labelBounds, YList candidates)
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
.
null
if no candidate could be found.protected void selectionMovedAction(double dx, double dy, double x, double y)
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.public void cancelEditing() throws java.lang.UnsupportedOperationException
ViewMode
setEditing(false)
if
ViewMode.isEditing()
returns true
cancelEditing
in class ViewMode
java.lang.UnsupportedOperationException
- if the editing cannot be canceled
for any reason.protected byte getCandidatesType(NodeLabelModel model)
NodeLabelModel
s.
model
- The current label model
CANDIDATES_TYPE_ALL
, CANDIDATES_TYPE_BEST
,
or CANDIDATES_TYPE_NONE
protected byte getCandidatesType(EdgeLabelModel model)
EdgeLabelModel
s.
model
- The current label model
CANDIDATES_TYPE_ALL
, CANDIDATES_TYPE_BEST
,
or CANDIDATES_TYPE_NONE
protected java.lang.Object createModelParameter(NodeLabelModel model, OrientedRectangle box, NodeRealizer nr, java.awt.event.MouseEvent e)
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.
protected java.lang.Object createModelParameter(EdgeLabelModel model, OrientedRectangle box, EdgeRealizer er, java.awt.event.MouseEvent e)
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.
|
© Copyright 2000-2022, yWorks GmbH. All rights reserved. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |