Class Grid

  • All Implemented Interfaces:
    java.io.Serializable

    public class Grid
    extends Drawable
    A Grid object draws a graph paper-like grid on a Canvas. The pixel width and height between adjacent grid lines is specified as a parameter to the constructer, or through the access methods "setXSP(double)" and "setYSP(double)". Note that the spacing will be scaled to between PIX_MIN and PIX_MAX (20 and 80, respectively, by default). The color of the grid lines can be set, and defaults to (220, 220, 220).

    This class was written by Gabriel Weinstock (with some modifications by David Eck).

    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      Grid()
      Create a Grid object with x and y spacing 1.0.
      Grid​(double xspace, double yspace)
      Create a Grid object with spacing specified.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void draw​(java.awt.Graphics g, boolean coordsch)
      Draws the grid if an update is required.
      java.awt.Color getColor()
      Access method which returns the Color of the grid lines.
      double getXSP()
      Access method to return the x spacing used between grid lines.
      double getYSP()
      Access method to return the y spacing used between grid lines
      void setColor​(java.awt.Color c)
      Method to set the Color used to draw grid lines.
      void setXSP​(double x)
      Method to set the x spacing between grid lines.
      void setYSP​(double y)
      Method to set the y spacing between grid lines.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Grid

        public Grid()
        Create a Grid object with x and y spacing 1.0. This does not mean that the actual spacing between grid lines will be 1. It will be some reasonable fraction or multiply of 1, with the value chosen to give a reasonable spacing between the grid lines.
      • Grid

        public Grid​(double xspace,
                    double yspace)
        Create a Grid object with spacing specified.
    • Method Detail

      • getColor

        public java.awt.Color getColor()
        Access method which returns the Color of the grid lines.
      • setColor

        public void setColor​(java.awt.Color c)
        Method to set the Color used to draw grid lines.
      • getXSP

        public double getXSP()
        Access method to return the x spacing used between grid lines.
      • getYSP

        public double getYSP()
        Access method to return the y spacing used between grid lines
      • setXSP

        public void setXSP​(double x)
        Method to set the x spacing between grid lines. This does not mean that the actual spacing between grid lines will be x. It will be some reasonable fraction or multiply of s, with the value chosen to give a reasonable spacing between the grid lines.
      • setYSP

        public void setYSP​(double y)
        Method to set the y spacing between grid lines. This does not mean that the actual spacing between grid lines will be y. It will be some reasonable fraction or multiply of s, with the value chosen to give a reasonable spacing between the grid lines.
      • draw

        public void draw​(java.awt.Graphics g,
                         boolean coordsch)
        Draws the grid if an update is required. This is not usually called directly.
        Specified by:
        draw in class Drawable
        Parameters:
        g - the Graphics context
        coordsch - boolean describing whether coordinates have changed