JHotDraw 7.0.9

org.jhotdraw.draw
Class GridConstrainer

java.lang.Object
  extended by org.jhotdraw.draw.GridConstrainer
All Implemented Interfaces:
Constrainer

public class GridConstrainer
extends java.lang.Object
implements Constrainer

Constrains a point such that it falls on a grid.

Version:
2.1.1 2006-07-05 Fixed drawing bug.
2.1 2006-07-03 Method isVisible added.
2.0 2006-01-14 Changed to support double precision coordinates.
1.0 2004-03-17 Created.
Author:
Werner Randelshofer

Constructor Summary
GridConstrainer(double width, double height)
          Creates a new instance.
 
Method Summary
 java.awt.geom.Point2D.Double constrainPoint(java.awt.geom.Point2D.Double p)
          Constrains the given point.
 java.awt.geom.Point2D.Double constrainPoint(java.awt.geom.Point2D.Double p, Direction dir)
          Constrains the given point towards the specified direction.
 void draw(java.awt.Graphics2D g, DrawingView view)
          Draws the constrainer grid for the specified drawing view.
 double getHeight()
           
 double getWidth()
           
 boolean isVisible()
          Returns true if the Constrainer grid is visible.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GridConstrainer

public GridConstrainer(double width,
                       double height)
Creates a new instance.

Parameters:
width - The width of a grid cell.
height - The height of a grid cell.
Method Detail

getWidth

public double getWidth()

getHeight

public double getHeight()

constrainPoint

public java.awt.geom.Point2D.Double constrainPoint(java.awt.geom.Point2D.Double p)
Description copied from interface: Constrainer
Constrains the given point. This method changes the point which is passed as a parameter.

Specified by:
constrainPoint in interface Constrainer
Parameters:
p - A point on the drawing.
Returns:
The closest constrained point.

constrainPoint

public java.awt.geom.Point2D.Double constrainPoint(java.awt.geom.Point2D.Double p,
                                                   Direction dir)
Description copied from interface: Constrainer
Constrains the given point towards the specified direction. This method changes the point which is passed as a parameter.

Specified by:
constrainPoint in interface Constrainer
Parameters:
p - A point on the drawing.
dir - A direction.
Returns:
The closest constrained point in the specified direction.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

isVisible

public boolean isVisible()
Description copied from interface: Constrainer
Returns true if the Constrainer grid is visible.

Specified by:
isVisible in interface Constrainer

draw

public void draw(java.awt.Graphics2D g,
                 DrawingView view)
Description copied from interface: Constrainer
Draws the constrainer grid for the specified drawing view.

Specified by:
draw in interface Constrainer

Copyright 1996-2007 (c) JHotDraw.org.
Some rights reserved.