org.opensourcephysics.display
Class Grid

java.lang.Object
  extended by org.opensourcephysics.display.Grid
All Implemented Interfaces:
Drawable
Direct Known Subclasses:
CellLatticeOSX, SiteLattice

public class Grid
extends java.lang.Object
implements Drawable

Grid draws a rectangular grid on a data panel.

Version:
1.0
Author:
Wolfgang Christian

Field Summary
protected  java.awt.Color color
           
protected  double dx
           
protected  double dy
           
protected  java.awt.geom.GeneralPath generalPath
           
protected  int nx
           
protected  int ny
           
protected  boolean visible
           
protected  double xmax
           
protected  double xmin
           
protected  double ymax
           
protected  double ymin
           
 
Constructor Summary
Grid(int n)
          Constructs a square grid of the given size with a spacing of 1.
Grid(int nx, int ny)
          Constructs an (nx,ny) grid an x spacing of 1 and a y spacing of 1.
Grid(int _nx, int _ny, double xmin, double xmax, double ymin, double ymax)
          Constructs a grid with the given number of x and y points and the given range.
 
Method Summary
 void draw(DrawingPanel panel, java.awt.Graphics g)
          Draws a representation of an object in a drawing panel.
 int[] getCellPoint(double x, double y)
          Gets the cell column and row index for the specified location
 java.awt.geom.Point2D.Double getClosestGridPoint(double x, double y)
          Gets the grid point closest to the specified location
 java.awt.Color getColor()
          Gets the drawing color.
 double getDx()
          Gets the x separation between x gid lines.
 double getDy()
          Gets the y separation between x gid lines.
 double getXMax()
          Gets the maximum value of x.
 double getXMin()
          Gets the minimum value of x.
 double getYMax()
          Gets the maximum value of y.
 double getYMin()
          Gets the minimum value of y.
 boolean isVisible()
          Checks if the grid is visible.
 void setColor(java.awt.Color _color)
          Sets the drawing color.
 void setMinMax(double _xmin, double _xmax, double _ymin, double _ymax)
          Assigns a scale to the grid in world units.
 void setVisible(boolean isVisible)
          Sets the visible flag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nx

protected int nx

ny

protected int ny

xmin

protected double xmin

xmax

protected double xmax

ymin

protected double ymin

ymax

protected double ymax

dx

protected double dx

dy

protected double dy

color

protected java.awt.Color color

generalPath

protected java.awt.geom.GeneralPath generalPath

visible

protected boolean visible
Constructor Detail

Grid

public Grid(int n)
Constructs a square grid of the given size with a spacing of 1.

Parameters:
n - number of cells on a side

Grid

public Grid(int nx,
            int ny)
Constructs an (nx,ny) grid an x spacing of 1 and a y spacing of 1.

Parameters:
nx - the number of grid lines in the x direction
ny - the number of grid lines in the y direction

Grid

public Grid(int _nx,
            int _ny,
            double xmin,
            double xmax,
            double ymin,
            double ymax)
Constructs a grid with the given number of x and y points and the given range.

Parameters:
_nx - the number of grid lines in the x direction
_ny - the number of grid lines in the y direction
xmin -
xmax -
ymin -
ymax -
Method Detail

setVisible

public void setVisible(boolean isVisible)
Sets the visible flag. Drawing will be disabled if visible is false.

Parameters:
isVisible -

isVisible

public boolean isVisible()
Checks if the grid is visible.

Returns:
true if visible; false otherwise

setColor

public void setColor(java.awt.Color _color)
Sets the drawing color.

Parameters:
_color -

getColor

public java.awt.Color getColor()
Gets the drawing color.

Returns:
the color

getDx

public double getDx()
Gets the x separation between x gid lines.

Returns:
dx

getXMin

public double getXMin()
Gets the minimum value of x.

Returns:
xmin

getXMax

public double getXMax()
Gets the maximum value of x.

Returns:
xamx

getYMin

public double getYMin()
Gets the minimum value of y.

Returns:
ymin

getYMax

public double getYMax()
Gets the maximum value of y.

Returns:
ymax

getDy

public double getDy()
Gets the y separation between x gid lines.

Returns:
dy

setMinMax

public void setMinMax(double _xmin,
                      double _xmax,
                      double _ymin,
                      double _ymax)
Assigns a scale to the grid in world units.

Parameters:
_xmin -
_xmax -
_ymin -
_ymax -

draw

public void draw(DrawingPanel panel,
                 java.awt.Graphics g)
Description copied from interface: Drawable
Draws a representation of an object in a drawing panel.

Specified by:
draw in interface Drawable

getCellPoint

public int[] getCellPoint(double x,
                          double y)
Gets the cell column and row index for the specified location


getClosestGridPoint

public java.awt.geom.Point2D.Double getClosestGridPoint(double x,
                                                        double y)
Gets the grid point closest to the specified location