diva.canvas.toolbox
Class GridLayer

java.lang.Object
  extended by diva.canvas.CanvasLayer
      extended by diva.canvas.toolbox.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: GridLayer.java 38798 2005-07-08 20:00:01Z cxh $
Author:
Michael Shilman, John Reekie

Field Summary
private  java.awt.Paint _gridPaint
           
private  java.awt.Stroke _gridStroke
           
private  java.awt.geom.Point2D _origin
           
private  java.awt.geom.Point2D _size
           
private  java.awt.Paint _vertexPaint
           
private  java.awt.Shape _vertexShape
           
private  boolean _visible
           
 
Constructor Summary
GridLayer()
          Create a new GridLayer with a default one-pixel grid stroke and a light grey grid color.
GridLayer(java.awt.Shape s, java.awt.Paint p)
          Create a new GridLayer with the given vertex shape and paint.
GridLayer(java.awt.Stroke s, java.awt.Paint p)
          Create a new GridLayer with the given grid stroke and paint
 
Method Summary
 java.awt.Paint getGridPaint()
          Get the grid line paint.
 java.awt.Stroke getGridStroke()
          Get the grid line stroke.
 java.awt.Paint getVertexPaint()
          Get the vertex point paint.
 java.awt.Shape getVertexShape()
          Get the vertex point shape.
 boolean isVisible()
          Test the visibility flag of this layer.
 void paint(java.awt.Graphics2D g)
          Paint this layer onto a 2D graphics object.
 void paint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D region)
          Paint this layer onto a 2D graphics object, within the given region.
 void setGridPaint(java.awt.Paint p)
          Set the grid line paint.
 void setGridStroke(java.awt.Stroke s)
          Set the grid line stroke.
 void setVertexPaint(java.awt.Paint p)
          Set the vertex point paint.
 void setVertexShape(java.awt.Shape s)
          Set the vertex point shape.
 void setVisible(boolean flag)
          Set the visibility flag of this layer.
 
Methods inherited from class diva.canvas.CanvasLayer
getCanvasPane, getLayerBounds, getParent, getToolTipText, getTransformContext, repaint, repaint, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface diva.canvas.CanvasComponent
getParent, getTransformContext, repaint, repaint
 

Field Detail

_gridPaint

private java.awt.Paint _gridPaint

_gridStroke

private java.awt.Stroke _gridStroke

_origin

private java.awt.geom.Point2D _origin

_size

private java.awt.geom.Point2D _size

_vertexPaint

private java.awt.Paint _vertexPaint

_vertexShape

private java.awt.Shape _vertexShape

_visible

private boolean _visible
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

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

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

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