org.graffiti.plugin.view
Class AbstractGrid

java.lang.Object
  extended by org.graffiti.plugin.view.AbstractGrid
All Implemented Interfaces:
Grid
Direct Known Subclasses:
NoGrid

public abstract class AbstractGrid
extends Object
implements Grid

This class provides default implementations for the Grid interface. Standard behaviors like the get and set methods for Grid object properties (origin, snap tolerance, bend snap) are defined here. The developer need only subclass this abstract class and define the getShapes(Rectangle2D) and snap(Point2D, double) methods. All parameters are given in logical (i.e. attribute system) coordinates. To define a parameter for a concrete grid, declare a public field in the implementing class and annotate it with GridParameter.

Version:
$Revision$ $Date$
Author:
Andreas Gleißner
See Also:
GridAttribute

Field Summary
protected  Point2D origin
          Origin of the grid.
 
Fields inherited from interface org.graffiti.plugin.view.Grid
DESCRIPTION_PATTERN, NAME_PATTERN
 
Constructor Summary
protected AbstractGrid()
          Constructs an AbstractGrid.
 
Method Summary
 Point2D getOrigin()
          Returns the origin of the grid.
abstract  List<Shape> getShapes(Rectangle2D area)
          Returns a list of shapes to present the grid in the specified area.
 double getSnapTolerance()
          Returns the snap tolerance of the grid.
 boolean isBendSnap()
          Returns if the snap behavior of the grid is enabled for bends.
 void setBendSnap(boolean isBendSnap)
          Sets if the snap behavior of the grid is enabled for bends.
 void setOrigin(Point2D origin)
          Sets the origin of the grid.
 void setSnapTolerance(double snapTolerance)
          Sets the snap tolerance of the grid.
protected abstract  Point2D snap(Point2D point, double tolerance)
          Returns the new position of a node or bend that was previously located at the specified point and snap in the grid.
 Point2D snapBend(Point2D point)
          Returns the new position of a bend that was previously located at the specified point and snap in the grid.
 Point2D snapNode(Point2D point)
          Returns the new position of a node that was previously located at the specified point and snaps in the grid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

origin

protected Point2D origin
Origin of the grid.

Constructor Detail

AbstractGrid

protected AbstractGrid()
Constructs an AbstractGrid.

Method Detail

setOrigin

public final void setOrigin(Point2D origin)
Sets the origin of the grid.

Specified by:
setOrigin in interface Grid
Parameters:
origin - the origin of the grid.

getOrigin

public final Point2D getOrigin()
Returns the origin of the grid.

Specified by:
getOrigin in interface Grid
Returns:
the origin of the grid.

setSnapTolerance

public final void setSnapTolerance(double snapTolerance)
Sets the snap tolerance of the grid.

Specified by:
setSnapTolerance in interface Grid
Parameters:
snapTolerance - the snap tolerance of the grid. Negative values denote a disabled snap behavior.

getSnapTolerance

public final double getSnapTolerance()
Returns the snap tolerance of the grid.

Specified by:
getSnapTolerance in interface Grid
Returns:
the snap tolerance of the grid. Negative values denote a disabled snap behavior.

setBendSnap

public final void setBendSnap(boolean isBendSnap)
Sets if the snap behavior of the grid is enabled for bends.

Specified by:
setBendSnap in interface Grid
Parameters:
isBendSnap - denotes if the snap behavior of the grid is enabled for bends.

isBendSnap

public final boolean isBendSnap()
Returns if the snap behavior of the grid is enabled for bends.

Specified by:
isBendSnap in interface Grid
Returns:
if the snap behavior of the grid is enabled for bends.

snapNode

public final Point2D snapNode(Point2D point)
Returns the new position of a node that was previously located at the specified point and snaps in the grid.

Specified by:
snapNode in interface Grid
Parameters:
point - the previous position of the node.
Returns:
the new position of the node.

snapBend

public final Point2D snapBend(Point2D point)
Returns the new position of a bend that was previously located at the specified point and snap in the grid.

Specified by:
snapBend in interface Grid
Parameters:
point - the previous position of the bend.
Returns:
the new position of the bend.

getShapes

public abstract List<Shape> getShapes(Rectangle2D area)
Returns a list of shapes to present the grid in the specified area.

Specified by:
getShapes in interface Grid
Parameters:
area - the area.
Returns:
a list of shapes to present the grid in the specified area.

snap

protected abstract Point2D snap(Point2D point,
                                double tolerance)
Returns the new position of a node or bend that was previously located at the specified point and snap in the grid.

Parameters:
point - the previous position of the node or bend.
Returns:
the new position of the node or bend.


Generated at 2012-05-30 11:00:36 PM CEST