Class GridLayer

All Implemented Interfaces:
FreeformFigure, IFigure

public class GridLayer extends FreeformLayer
This is a layer that displays the grid. The default grid color is light gray. To change the grid color, set the foreground color for this layer.
Since:
3.0
  • Field Details

    • gridX

      protected int gridX
      Field indicating the horizontal grid spacing
    • gridY

      protected int gridY
      Field for the vertical grid spacing
    • origin

      protected Point origin
      Field indicating what the grid origin is. This is used simply to determine the offset from 0,0.
  • Constructor Details

    • GridLayer

      public GridLayer()
      Constructor Sets the default grid color: ColorConstants.lightGray
  • Method Details

    • getPreferredSize

      public Dimension getPreferredSize(int wHint, int hHint)
      Overridden to indicate no preferred size. The grid layer should not affect the size of the layered pane in which it is placed.
      Specified by:
      getPreferredSize in interface IFigure
      Overrides:
      getPreferredSize in class Figure
      See Also:
    • paintFigure

      protected void paintFigure(Graphics graphics)
      Overrides:
      paintFigure in class Figure
      See Also:
    • paintGrid

      protected void paintGrid(Graphics g)
      Paints the grid. Sub-classes can override to customize the grid's look. If this layer is being used with SnapToGrid, this method will only be invoked when the visibility property is set to true.
      Parameters:
      g - The Graphics object to be used to do the painting
      See Also:
    • setOrigin

      public void setOrigin(Point p)
      Sets the origin of the grid. The origin is used only to determine the offset from 0,0.
      Parameters:
      p - the origin
    • setSpacing

      public void setSpacing(Dimension spacing)
      Sets the horizontal and vertical spacing of the grid. A grid spacing of 0 will be replaced with the default spacing. A negative spacing will cause no grid lines to be drawn for that dimension.
      Parameters:
      spacing - A Dimension representing the horizontal (width) and vertical (height) gaps