Search this API

y.view
Class LabelSnapContext

java.lang.Object
  extended by y.view.AbstractSnapContext
      extended by y.view.LabelSnapContext

public class LabelSnapContext
extends AbstractSnapContext

The context that is used by MoveLabelMode to manage snapping for labels during a label move operation.

 

Constructor Summary
LabelSnapContext()
          Creates a new snap context instance with no initial view.
LabelSnapContext(Graph2DView view)
          Creates a new snap context instance for the given Graph2DView.
 
Method Summary
 YPoint adjustMouseCoordinates(java.util.List snapResults, YPoint currentLocation)
          Invoked to perform snapping for the specified snap results and mouse coordinates after initializeEdgeLabelMove(y.geom.YPoint, EdgeLabel) or initializeNodeLabelMove(y.geom.YPoint, NodeLabel) has been and before cleanUp() is called.
 YPoint adjustMouseCoordinates(YPoint currentLocation)
          Invoked to perform snapping for the specified mouse coordinates after initializeEdgeLabelMove(y.geom.YPoint, EdgeLabel) or initializeNodeLabelMove(y.geom.YPoint, NodeLabel) has been and before cleanUp() is called.
 void cleanUp()
          Called after the snapping operation is done to clean up internal data structures.
 double getEdgeLabelSnapDistance()
          Retrieves the distance where the edge label snaps in position.
 double getNodeLabelSnapDistance()
          Retrieves the distance where the node label snaps in position.
 void initializeEdgeLabelMove(YPoint initialCoordinates, EdgeLabel label)
          Initializes this context object for an edge label move operation.
 void initializeNodeLabelMove(YPoint initialCoordinates, NodeLabel label)
          Initializes this context object for a node label move operation.
 void setEdgeLabelSnapDistance(double distance)
          Sets the distance where the edge label snaps in position.
 void setNodeLabelSnapDistance(double distance)
          Sets the distance where the node label snaps in position.
 
Methods inherited from class y.view.AbstractSnapContext
addSnapLine, addSnapResult, clearAdditionalSnapLines, clearAdditionalSnapResults, collectFixedNodes, getAdditionalSnapLines, getDrawable, getInitialCoordinates, getSnapDistance, getSnapLineColor, getView, initialize, intersectsView, intersectsView, isRenderingSnapLines, processSnapResults, removeSnapResult, resetResults, setInitialCoordinates, setRenderingSnapLines, setSnapDistance, setSnapLineColor, setView
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LabelSnapContext

public LabelSnapContext()
Creates a new snap context instance with no initial view. The view needs to be set before this snap context can be initialized for label movement.

See Also:
initializeEdgeLabelMove(y.geom.YPoint, EdgeLabel), initializeNodeLabelMove(y.geom.YPoint, NodeLabel)

LabelSnapContext

public LabelSnapContext(Graph2DView view)
Creates a new snap context instance for the given Graph2DView.

Parameters:
view - the view in which to perform snapping.
Method Detail

cleanUp

public void cleanUp()
Description copied from class: AbstractSnapContext
Called after the snapping operation is done to clean up internal data structures. This should be paired with calls to AbstractSnapContext.initialize(). Note that subclasses provide more specialized initialization and cleanup methods.

Overrides:
cleanUp in class AbstractSnapContext

initializeEdgeLabelMove

public void initializeEdgeLabelMove(YPoint initialCoordinates,
                                    EdgeLabel label)
Initializes this context object for an edge label move operation. The specified label must be associated to an edge in a graph, i.e. the label's getRealizer method as well as the returned realizer's getSourceRealizer and getTargetRealizer methods may not return null.

Parameters:
initialCoordinates - The initial mouse coordinates.
label - The edge label. Must be associated to an edge in a graph.
See Also:
EdgeLabel.getRealizer(), EdgeRealizer.getSourceRealizer(), EdgeRealizer.getTargetRealizer()

initializeNodeLabelMove

public void initializeNodeLabelMove(YPoint initialCoordinates,
                                    NodeLabel label)
Initializes this context object for a node label move operation. The specified label must be associated to a node in a graph, i.e. the label's getRealizer method must not return null.

Parameters:
initialCoordinates - The initial mouse coordinates.
label - The node label. Must be associated to a node in a graph.
See Also:
NodeLabel.getRealizer()

adjustMouseCoordinates

public YPoint adjustMouseCoordinates(YPoint currentLocation)
Invoked to perform snapping for the specified mouse coordinates after initializeEdgeLabelMove(y.geom.YPoint, EdgeLabel) or initializeNodeLabelMove(y.geom.YPoint, NodeLabel) has been and before cleanUp() is called.

This method should be called for each update in the mouse coordinates to determine the new coordinates. If snapping is temporarily disabled, AbstractSnapContext.resetResults() should be called instead.

The default implementation supports snapping for node labels that use SmartNodeLabelModel or FreeNodeLabelModel and calls adjustMouseCoordinates(java.util.List, y.geom.YPoint) with suitable snap results for the above mentioned models.

Parameters:
currentLocation - the mouse coordinates in the world (graph) coordinate system before snapping.
Returns:
the world coordinates after snapping.

adjustMouseCoordinates

public YPoint adjustMouseCoordinates(java.util.List snapResults,
                                     YPoint currentLocation)
Invoked to perform snapping for the specified snap results and mouse coordinates after initializeEdgeLabelMove(y.geom.YPoint, EdgeLabel) or initializeNodeLabelMove(y.geom.YPoint, NodeLabel) has been and before cleanUp() is called.

This method should be called for each update in the mouse coordinates to determine the new coordinates. If snapping is temporarily disabled, AbstractSnapContext.resetResults() should be called instead.

Parameters:
snapResults - the snap results that handle the actual snapping.
currentLocation - the mouse coordinates in the world (graph) coordinate system before snapping.
Returns:
the world coordinates after snapping.

getNodeLabelSnapDistance

public double getNodeLabelSnapDistance()
Retrieves the distance where the node label snaps in position.

Returns:
the snap distance
See Also:
getNodeLabelSnapDistance()

setNodeLabelSnapDistance

public void setNodeLabelSnapDistance(double distance)
Sets the distance where the node label snaps in position.

Parameters:
distance - the snap distance
See Also:
getNodeLabelSnapDistance()

getEdgeLabelSnapDistance

public double getEdgeLabelSnapDistance()
Retrieves the distance where the edge label snaps in position.

Returns:
the snap distance
See Also:
getEdgeLabelSnapDistance()

setEdgeLabelSnapDistance

public void setEdgeLabelSnapDistance(double distance)
Sets the distance where the edge label snaps in position.

Parameters:
distance - the snap distance
See Also:
getEdgeLabelSnapDistance()

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