Search this API

y.view
Class AbstractSnapContext

java.lang.Object
  extended by y.view.AbstractSnapContext
Direct Known Subclasses:
HotSpotSnapContext, LabelSnapContext, MoveSnapContext

public class AbstractSnapContext
extends java.lang.Object

The common base class of MoveSnapContext and HotSpotSnapContext that stores the context and manages the snapping related data for ViewMode implementations and the like.

See Also:
SnapResult
 

Constructor Summary
AbstractSnapContext(Graph2DView view)
          Instantiates a new instance for the given Graph2DView.
 
Method Summary
 void addSnapLine(SnapLine snapLine)
          Adds a snap line that will be used by this context in addition to the automatically generated ones.
 void addSnapResult(SnapResult result)
          Adds a SnapResult to this instance that will be honored during calls to processSnapResults(java.util.List,y.geom.YPoint)
 void cleanUp()
          Called after the snapping operation is done to clean up internal data structures.
 void clearAdditionalSnapLines()
          Clears the set of additional SnapLines.
 void clearAdditionalSnapResults()
          Clears additionally added snap results that have been previously added to this instance via addSnapResult(SnapResult)
protected  void collectFixedNodes(java.util.Collection nodesToBeChanged, java.util.Collection fixedNodes)
          Collects all nodes in the current view's graph into the provided collection that will have their bounds fixed during the upcoming operation.
protected  java.util.List getAdditionalSnapLines()
          Yields the list of additional SnapLines.
 Drawable getDrawable()
          The Drawable that will be placed into the view.
 YPoint getInitialCoordinates()
          Gets the initial mouse coordinates at the beginning of the operation that uses this context.
 double getSnapDistance()
          Gets the global snap distance, which is the maximum distance between the current mouse coordinates and the coordinates to which the mouse will snap.
 java.awt.Color getSnapLineColor()
          Gets the color to use for the rendering of the snap lines.
 Graph2DView getView()
          Gets the view associated with this context.
protected  void initialize()
          Base method for the initialization of this context.
protected  boolean intersectsView(EdgeRealizer realizer, YPoint p1, YPoint p2)
          Convenience method that determines whether a segment that is indicated by the two given endpoints and belongs to the path of the provided edge realizer is deemed visible in the current view.
protected  boolean intersectsView(NodeRealizer realizer)
          Convenience method that determines whether the given realizer intersect the current view.
 boolean isRenderingSnapLines()
          Indicates whether this instance will be rendering the snap lines.
protected  YPoint processSnapResults(java.util.List snapResults, YPoint mouseCoordinates)
          Main method of this class that processes a list of SnapResult given the current set of mouse coordinates.
 void removeSnapResult(SnapResult result)
          Removes a result that has previously been added to this instance via addSnapResult(SnapResult)
 void resetResults()
          Alternative method to processSnapResults(java.util.List, y.geom.YPoint) if no snapping should be performed.
 void setInitialCoordinates(YPoint initialCoordinates)
          Sets the initial mouse coordinates at the beginning of the operation that uses this context.
 void setRenderingSnapLines(boolean renderingSnapLines)
          Determines whether this instance will be rendering the snap lines.
 void setSnapDistance(double snapDistance)
          Sets the global snap distance, which is the maximum distance between the current mouse coordinates and the coordinates to which the mouse will snap.
 void setSnapLineColor(java.awt.Color snapLineColor)
          Sets the color to use for the rendering of the snap lines.
 void setView(Graph2DView view)
          Sets the view instance this context will be working on.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSnapContext

public AbstractSnapContext(Graph2DView view)
Instantiates a new instance for the given Graph2DView.

Parameters:
view - the view, which can be null, in which case it has to be set at a later point in time using setView(Graph2DView)
See Also:
initialize(), cleanUp()
Method Detail

getSnapLineColor

public java.awt.Color getSnapLineColor()
Gets the color to use for the rendering of the snap lines.

Returns:
the color - the default is Color.LIGHT_GRAY

setSnapLineColor

public void setSnapLineColor(java.awt.Color snapLineColor)
Sets the color to use for the rendering of the snap lines.

Parameters:
snapLineColor - the new color to use - the default is Color.LIGHT_GRAY

isRenderingSnapLines

public boolean isRenderingSnapLines()
Indicates whether this instance will be rendering the snap lines. During processSnapResults(java.util.List,y.geom.YPoint) this instance will collect all SnapResult instances that are currently snapped and will display their drawable if this flag is set to true.


setRenderingSnapLines

public void setRenderingSnapLines(boolean renderingSnapLines)
Determines whether this instance will be rendering the snap lines. During processSnapResults(java.util.List,y.geom.YPoint) this instance will collect all SnapResult instances that are currently snapped and will display their drawable if this flag is set to true.


addSnapResult

public void addSnapResult(SnapResult result)
Adds a SnapResult to this instance that will be honored during calls to processSnapResults(java.util.List,y.geom.YPoint)

Parameters:
result - The result to add to the processing.
See Also:
clearAdditionalSnapResults()

removeSnapResult

public void removeSnapResult(SnapResult result)
Removes a result that has previously been added to this instance via addSnapResult(SnapResult)

Parameters:
result - the result to remove from this instance.
See Also:
clearAdditionalSnapResults()

clearAdditionalSnapResults

public void clearAdditionalSnapResults()
Clears additionally added snap results that have been previously added to this instance via addSnapResult(SnapResult)


processSnapResults

protected YPoint processSnapResults(java.util.List snapResults,
                                    YPoint mouseCoordinates)
Main method of this class that processes a list of SnapResult given the current set of mouse coordinates. This method will sort the results according to their weight and for set of results that share the same non-null tag, the one with the greatest weight will be chosen for rendering. This method will yield the final mouse coordinate for which the most important SnapResult instances have snapped.

Parameters:
snapResults - A list of SnapResult instances that will be processed by this method
mouseCoordinates - The coordinates to snap
Returns:
The snapped coordinates.
See Also:
resetResults()

getView

public Graph2DView getView()
Gets the view associated with this context. This view will display the snap result Drawables.

Returns:
The view.

getDrawable

public Drawable getDrawable()
The Drawable that will be placed into the view. This drawable will be updated after calls to processSnapResults(java.util.List, y.geom.YPoint) and resetResults().

Returns:
The compound drawable of all snap result.

setView

public void setView(Graph2DView view)
Sets the view instance this context will be working on. This view will be used to display the drawable.

Parameters:
view - the new view, which may be null.

intersectsView

protected boolean intersectsView(NodeRealizer realizer)
Convenience method that determines whether the given realizer intersect the current view.

Parameters:
realizer - The realizer to check.
Returns:
Whether the realizer should be included in the current operation based on its visibility in the view.

intersectsView

protected boolean intersectsView(EdgeRealizer realizer,
                                 YPoint p1,
                                 YPoint p2)
Convenience method that determines whether a segment that is indicated by the two given endpoints and belongs to the path of the provided edge realizer is deemed visible in the current view.

Parameters:
realizer - The realizer to check.
p1 - The first point of the segment.
p2 - The second point of the segment.
Returns:
Whether the segment should be included in the current operation based on its visibility in the view.

collectFixedNodes

protected void collectFixedNodes(java.util.Collection nodesToBeChanged,
                                 java.util.Collection fixedNodes)
Collects all nodes in the current view's graph into the provided collection that will have their bounds fixed during the upcoming operation. This method will use the hierarchy manager to determine which nodes will actually be changed due to one of their children being changed. For this the isAdjustingToChild(y.base.Node) method will be used as a callback to determine whether bounds changes of a child will possibly influence the bounds of a given parent node.

Parameters:
nodesToBeChanged - The collection of nodes that will change their bounds during the upcoming operation.
fixedNodes - The collection to which the fixed nodes will be added by this method.

getSnapDistance

public double getSnapDistance()
Gets the global snap distance, which is the maximum distance between the current mouse coordinates and the coordinates to which the mouse will snap. The distance is interpreted in view coordinates. The default is 5.0d

Returns:
The snap distance.

setSnapDistance

public void setSnapDistance(double snapDistance)
Sets the global snap distance, which is the maximum distance between the current mouse coordinates and the coordinates to which the mouse will snap. The distance is interpreted in view coordinates. The default is 5.0d

Parameters:
snapDistance - The new snap distance.

cleanUp

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


initialize

protected void initialize()
Base method for the initialization of this context. Before calling this method, a view has to be set on this instance.

See Also:
cleanUp()

resetResults

public void resetResults()
Alternative method to processSnapResults(java.util.List, y.geom.YPoint) if no snapping should be performed. This will temporarily disable snapping and clear the drawable to not draw snap lines.


clearAdditionalSnapLines

public void clearAdditionalSnapLines()
Clears the set of additional SnapLines.

See Also:
addSnapLine(SnapLine)

addSnapLine

public void addSnapLine(SnapLine snapLine)
Adds a snap line that will be used by this context in addition to the automatically generated ones.

See Also:
clearAdditionalSnapLines()

getAdditionalSnapLines

protected java.util.List getAdditionalSnapLines()
Yields the list of additional SnapLines. The list of the SnapLine instances.


setInitialCoordinates

public void setInitialCoordinates(YPoint initialCoordinates)
Sets the initial mouse coordinates at the beginning of the operation that uses this context.

Parameters:
initialCoordinates - The world coordinates of the mouse at the beginning of the operation.

getInitialCoordinates

public YPoint getInitialCoordinates()
Gets the initial mouse coordinates at the beginning of the operation that uses this context.


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