Search this API

y.view
Class SnapResult

java.lang.Object
  extended by y.view.SnapResult
All Implemented Interfaces:
java.lang.Comparable

public abstract class SnapResult
extends java.lang.Object
implements java.lang.Comparable

This is the abstract base class used by AbstractSnapContext and the subclasses to model the result of the mouse being snapped to a certain coordinate. It carries a weight and can be used to obtain a Drawable that will be included in the view if the result is actually snapped after all other results with higher weight have been snapped.

 

Field Summary
static byte NOT_SNAPPED
          Constant for use in snap(y.geom.YPoint, java.awt.geom.Point2D.Double, byte) and isSnapped(y.geom.YPoint, y.geom.YPoint, byte) that indicates that the coordinate has not been snapped to its x or y values.
static SnapResult NULL_RESULT
          A null-object implementation of the SnapResult abstract class.
static byte SNAPPED_X
          Constant for use in snap(y.geom.YPoint, java.awt.geom.Point2D.Double, byte) and isSnapped(y.geom.YPoint, y.geom.YPoint, byte) that indicates that the coordinate has been snapped to its x value.
static byte SNAPPED_XY
          Constant for use in snap(y.geom.YPoint, java.awt.geom.Point2D.Double, byte) and isSnapped(y.geom.YPoint, y.geom.YPoint, byte) that indicates that the coordinate has been snapped to its x and y values.
static byte SNAPPED_Y
          Constant for use in snap(y.geom.YPoint, java.awt.geom.Point2D.Double, byte) and isSnapped(y.geom.YPoint, y.geom.YPoint, byte) that indicates that the coordinate has been snapped to its y value.
 
Constructor Summary
protected SnapResult(double weight)
          Constructor that takes a weight and an empty drawable.
protected SnapResult(double weight, Drawable drawable)
          Constructor that takes a weight and a drawable.
protected SnapResult(double weight, Drawable drawable, java.lang.Object tag)
          Constructor that takes a weight and a drawable and a tag.
 
Method Summary
 int compareTo(java.lang.Object o)
          Implements the Comparable interface using getWeight()
static SnapResult createOrthogonalSnapResult(double weight, Drawable drawable, boolean adjustX, double snappedValue)
          Convenience factory method that creates a simple snap result that snaps to a given x or y coordinates orthogonally.
static SnapResult createOrthogonalSnapResult(double weight, Drawable drawable, boolean adjustX, double snappedValue, java.lang.Object tag)
          Convenience factory method that creates a simple snap result that snaps to a given x or y coordinates orthogonally.
 Drawable getDrawable(AbstractSnapContext snapContext, YPoint mouseCoordinates)
          Creates a drawable that indicates the snapping of this instance.
 java.lang.Object getTag()
          The tag associated with this result.
 double getWeight()
          Yields the weight of this result, the higher the weight, the more important it is.
abstract  boolean isSnapped(YPoint unsnappedMouseCoordinates, YPoint mouseCoordinates, byte finalSnappingState)
          Checks whether this instance is still snapped given the final mouse coordinates.
protected  void setTag(java.lang.Object tag)
          Sets the tag to return in getTag()
abstract  byte snap(YPoint unsnappedCoordinates, java.awt.geom.Point2D.Double mouseCoordinates, byte snapState)
          Core method that performs the actual snapping.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SNAPPED_X

public static final byte SNAPPED_X
Constant for use in snap(y.geom.YPoint, java.awt.geom.Point2D.Double, byte) and isSnapped(y.geom.YPoint, y.geom.YPoint, byte) that indicates that the coordinate has been snapped to its x value. The methods can take a bitwise combination of this field and SNAPPED_Y, SNAPPED_XY, and NOT_SNAPPED.

See Also:
Constant Field Values

SNAPPED_Y

public static final byte SNAPPED_Y
Constant for use in snap(y.geom.YPoint, java.awt.geom.Point2D.Double, byte) and isSnapped(y.geom.YPoint, y.geom.YPoint, byte) that indicates that the coordinate has been snapped to its y value. The methods can take a bitwise combination of this field and SNAPPED_X, SNAPPED_XY, and NOT_SNAPPED.

See Also:
Constant Field Values

SNAPPED_XY

public static final byte SNAPPED_XY
Constant for use in snap(y.geom.YPoint, java.awt.geom.Point2D.Double, byte) and isSnapped(y.geom.YPoint, y.geom.YPoint, byte) that indicates that the coordinate has been snapped to its x and y values. This is a bitwise combination of SNAPPED_X, and SNAPPED_Y.

See Also:
Constant Field Values

NOT_SNAPPED

public static final byte NOT_SNAPPED
Constant for use in snap(y.geom.YPoint, java.awt.geom.Point2D.Double, byte) and isSnapped(y.geom.YPoint, y.geom.YPoint, byte) that indicates that the coordinate has not been snapped to its x or y values.

See Also:
Constant Field Values

NULL_RESULT

public static final SnapResult NULL_RESULT
A null-object implementation of the SnapResult abstract class.

Constructor Detail

SnapResult

protected SnapResult(double weight)
Constructor that takes a weight and an empty drawable.

Parameters:
weight - the weight to yield in getWeight()

SnapResult

protected SnapResult(double weight,
                     Drawable drawable)
Constructor that takes a weight and a drawable.

Parameters:
weight - the weight to yield in getWeight()
drawable - the drawable to return in getDrawable(AbstractSnapContext,y.geom.YPoint)

SnapResult

protected SnapResult(double weight,
                     Drawable drawable,
                     java.lang.Object tag)
Constructor that takes a weight and a drawable and a tag. Only one snap result of each set of results that use the same tag will be drawn.

Parameters:
weight - the weight to yield in getWeight()
drawable - the drawable to return in getDrawable(AbstractSnapContext,y.geom.YPoint)
tag - the tag to associate with this result.
Method Detail

getTag

public java.lang.Object getTag()
The tag associated with this result. If more than one result uses the same tag (not null), only the one with the highest weight will be rendered.

Returns:
the tag or null

setTag

protected void setTag(java.lang.Object tag)
Sets the tag to return in getTag()

Parameters:
tag - the tag to use which may be null.

getWeight

public double getWeight()
Yields the weight of this result, the higher the weight, the more important it is.

Returns:
the weight of this result.

snap

public abstract byte snap(YPoint unsnappedCoordinates,
                          java.awt.geom.Point2D.Double mouseCoordinates,
                          byte snapState)
Core method that performs the actual snapping.

Parameters:
unsnappedCoordinates - The coordinates prior to the snapping.
mouseCoordinates - The currently snapped coordinates, the result needs to be placed in here.
snapState - The current snap state, which is a combination of SNAPPED_X,SNAPPED_Y,SNAPPED_XY, or NOT_SNAPPED.
Returns:
the new snap state which is one of SNAPPED_X,SNAPPED_Y,SNAPPED_XY, or NOT_SNAPPED.

isSnapped

public abstract boolean isSnapped(YPoint unsnappedMouseCoordinates,
                                  YPoint mouseCoordinates,
                                  byte finalSnappingState)
Checks whether this instance is still snapped given the final mouse coordinates.

Parameters:
unsnappedMouseCoordinates - the unsnapped coordinates
mouseCoordinates - the resulting mouse coordinates
finalSnappingState - the final snapping state.
Returns:
whether the coordinates are still snapped for this instance.

compareTo

public int compareTo(java.lang.Object o)
Implements the Comparable interface using getWeight()

Specified by:
compareTo in interface java.lang.Comparable

getDrawable

public Drawable getDrawable(AbstractSnapContext snapContext,
                            YPoint mouseCoordinates)
Creates a drawable that indicates the snapping of this instance.

Parameters:
snapContext - The context in which this result is being used.
mouseCoordinates - The final snapped mouse coordinates.
Returns:
The drawable to use, may not be null.
See Also:
NULL_RESULT, AbstractSnapContext.getInitialCoordinates()

createOrthogonalSnapResult

public static SnapResult createOrthogonalSnapResult(double weight,
                                                    Drawable drawable,
                                                    boolean adjustX,
                                                    double snappedValue)
Convenience factory method that creates a simple snap result that snaps to a given x or y coordinates orthogonally.

Parameters:
weight - The weight of the result.
drawable - The drawable to use, may be null.
adjustX - Whether to adjust the x coordinate.
snappedValue - The value to set the coordinate to.
Returns:
A result for use in AbstractSnapContext.processSnapResults(java.util.List,y.geom.YPoint)

createOrthogonalSnapResult

public static SnapResult createOrthogonalSnapResult(double weight,
                                                    Drawable drawable,
                                                    boolean adjustX,
                                                    double snappedValue,
                                                    java.lang.Object tag)
Convenience factory method that creates a simple snap result that snaps to a given x or y coordinates orthogonally.

Parameters:
weight - The weight of the result.
drawable - The drawable to use, may be null.
adjustX - Whether to adjust the x coordinate.
snappedValue - The value to set the coordinate to.
tag - the tag to use for the result.
Returns:
A result for use in AbstractSnapContext.processSnapResults(java.util.List,y.geom.YPoint)

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