Class GridLayer

  • All Implemented Interfaces:
    CanvasComponent, VisibleComponent

    public class GridLayer
    extends CanvasLayer
    implements VisibleComponent
    A grid layer displays a rectangular grid. It can be made to display grid lines, grid vertices, or both. For grid lines, the stroke and the paint can be specified; for grid vertices, the shape drawn at the vertex and the paint can be specified. Reasonable default are also supplied.
    Version:
    $Id$
    Author:
    Michael Shilman, John Reekie
    • Constructor Detail

      • GridLayer

        public GridLayer()
        Create a new GridLayer with a default one-pixel grid stroke and a light grey grid color.
      • GridLayer

        public GridLayer​(java.awt.Stroke s,
                         java.awt.Paint p)
        Create a new GridLayer with the given grid stroke and paint
      • GridLayer

        public GridLayer​(java.awt.Shape s,
                         java.awt.Paint p)
        Create a new GridLayer with the given vertex shape and paint. Grid lines will not be displayed.
    • Method Detail

      • getGridStroke

        public java.awt.Stroke getGridStroke()
        Get the grid line stroke.
      • getGridPaint

        public java.awt.Paint getGridPaint()
        Get the grid line paint.
      • getVertexShape

        public java.awt.Shape getVertexShape()
        Get the vertex point shape.
      • getVertexPaint

        public java.awt.Paint getVertexPaint()
        Get the vertex point paint.
      • isVisible

        public boolean isVisible()
        Test the visibility flag of this layer. Note that this flag does not indicate whether the layer is actually visible on the screen, as its pane or one if its ancestors may not be visible.
        Specified by:
        isVisible in interface VisibleComponent
        Returns:
        true if the object is visible.
      • paint

        public void paint​(java.awt.Graphics2D g)
        Paint this layer onto a 2D graphics object. If the layer is not visible, return immediately. Otherwise paint the grid lines if they have a non-null paint, and paint the grid vertices if they have a non-null paint.

        FIXME: Vertexes are not yet supported.

        Specified by:
        paint in interface VisibleComponent
        Parameters:
        g - The 2D graphics object that this object it to be painted upon.
      • paint

        public void paint​(java.awt.Graphics2D g,
                          java.awt.geom.Rectangle2D region)
        Paint this layer onto a 2D graphics object, within the given region. If the layer is not visible, return immediately. Otherwise paint the grid lines if they have a non-null paint, and paint the grid vertices if they have a non-null paint.
        Specified by:
        paint in interface VisibleComponent
        Parameters:
        g - The 2D graphics object that this object it to be painted upon.
        region - The region.
      • setGridStroke

        public void setGridStroke​(java.awt.Stroke s)
        Set the grid line stroke.
      • setGridPaint

        public void setGridPaint​(java.awt.Paint p)
        Set the grid line paint. If this is set to null, grid lines will not be displayed.
      • setVertexShape

        public void setVertexShape​(java.awt.Shape s)
        Set the vertex point shape. The default is a circle with radius equal to 10% of the smallest grid size in either dimension.
      • setVertexPaint

        public void setVertexPaint​(java.awt.Paint p)
        Set the vertex point paint. If this is set to null, vertices will not be displayed.
      • setVisible

        public void setVisible​(boolean flag)
        Set the visibility flag of this layer. If the flag is false, then the layer will not be drawn on the screen.
        Specified by:
        setVisible in interface VisibleComponent
        Parameters:
        flag - True if this object is to be visible.