gui
Class Grid

java.lang.Object
  extended by gui.Grid

public class Grid
extends java.lang.Object

A grid object stores the current state of the grid.


Field Summary
static double GRID_WIDTH
          the default spacing of the grid
private  boolean snapToGrid
          specifies if objects should snap to the grid
private  double spacing
          the distance between different grid lines
private  boolean visible
          specifies if the grid is visible
 
Constructor Summary
Grid(double spacing)
          Constructs a grid with the specified spacing.
 
Method Summary
 java.awt.geom.Point2D getGridCoordinate(double x, double y)
          Calculates the nearest grid point for the given coordinate.
 boolean getSnapToGrid()
          Returns true if objects should snap to the grid.
 double getSpacing()
          Gets the distance between grid lines.
 boolean isVisible()
          Gets the visibility of the grid.
 void setSnapToGrid(boolean snap)
          Sets if objects should snap to the grid.
 void setVisible(boolean visible)
          Sets the visibility of the grid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GRID_WIDTH

public static double GRID_WIDTH
the default spacing of the grid


visible

private boolean visible
specifies if the grid is visible


snapToGrid

private boolean snapToGrid
specifies if objects should snap to the grid


spacing

private double spacing
the distance between different grid lines

Constructor Detail

Grid

public Grid(double spacing)
Constructs a grid with the specified spacing.

Parameters:
spacing - - the spacing between grid line.
Method Detail

setSnapToGrid

public void setSnapToGrid(boolean snap)
Sets if objects should snap to the grid.


getSnapToGrid

public boolean getSnapToGrid()
Returns true if objects should snap to the grid.


setVisible

public void setVisible(boolean visible)
Sets the visibility of the grid.


isVisible

public boolean isVisible()
Gets the visibility of the grid.


getSpacing

public double getSpacing()
Gets the distance between grid lines.


getGridCoordinate

public java.awt.geom.Point2D getGridCoordinate(double x,
                                               double y)
Calculates the nearest grid point for the given coordinate.

Parameters:
x - - the x value of a coordinate
y - - the y value of a coordinate
Returns:
- the location of the nearest grid point