com.horstmann.violet.framework
Class Grid

java.lang.Object
  extended by com.horstmann.violet.framework.Grid

public class Grid
extends java.lang.Object

A grid to which points and rectangles can be "snapped". The snapping operation moves a point to the nearest grid point.


Constructor Summary
Grid()
          Constructs a grid with no grid points.
 
Method Summary
 void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D bounds)
          Draws this grid inside a rectangle.
 void setGrid(double x, double y)
          Sets the grid point distances in x- and y-direction
 void snap(java.awt.geom.Point2D p)
          Snaps a point to the nearest grid point
 void snap(java.awt.geom.Rectangle2D r)
          Snaps a rectangle to the nearest grid points
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Grid

public Grid()
Constructs a grid with no grid points.

Method Detail

setGrid

public void setGrid(double x,
                    double y)
Sets the grid point distances in x- and y-direction

Parameters:
x - the grid point distance in x-direction
y - the grid point distance in y-direction

draw

public void draw(java.awt.Graphics2D g2,
                 java.awt.geom.Rectangle2D bounds)
Draws this grid inside a rectangle.

Parameters:
g2 - the graphics context
bounds - the bounding rectangle

snap

public void snap(java.awt.geom.Point2D p)
Snaps a point to the nearest grid point

Parameters:
p - the point to snap. After the call, the coordinates of p are changed so that p falls on the grid.

snap

public void snap(java.awt.geom.Rectangle2D r)
Snaps a rectangle to the nearest grid points

Parameters:
r - the rectangle to snap. After the call, the coordinates of r are changed so that all of its corners falls on the grid.