Class Grid

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

public class Grid extends Object implements Drawable
Grid draws a rectangular grid on a data panel.
Version:
1.0
Author:
Wolfgang Christian
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Color
     
    protected double
     
    protected double
     
    protected GeneralPath
     
    protected int
     
    protected int
     
    protected boolean
     
    protected double
     
    protected double
     
    protected double
     
    protected double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    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

    Modifier and Type
    Method
    Description
    void
    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
    getClosestGridPoint(double x, double y)
    Gets the grid point closest to the specified location
    Gets the drawing color.
    double
    Gets the x separation between x gid lines.
    double
    Gets the y separation between x gid lines.
    double
    Gets the maximum value of x.
    double
    Gets the minimum value of x.
    double
    Gets the maximum value of y.
    double
    Gets the minimum value of y.
    boolean
    Checks if the grid is visible.
    void
    setColor(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

    Methods inherited from interface org.opensourcephysics.display.Drawable

    isInteractive
  • Field Details

    • 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 Color color
    • generalPath

      protected GeneralPath generalPath
    • visible

      protected boolean visible
  • Constructor Details

    • 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 Details

    • 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(Color _color)
      Sets the drawing color.
      Parameters:
      _color -
    • getColor

      public 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, 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 Point2D.Double getClosestGridPoint(double x, double y)
      Gets the grid point closest to the specified location