net.sf.jaxodraw.gui.grid
Class JaxoDefaultGrid

java.lang.Object
  extended by net.sf.jaxodraw.gui.grid.JaxoDefaultGrid
All Implemented Interfaces:
java.awt.Transparency, java.lang.Cloneable, JaxoGrid

public class JaxoDefaultGrid
extends java.lang.Object
implements JaxoGrid, java.awt.Transparency, java.lang.Cloneable

Paints a grid on the canvas.

Since:
2.0

Field Summary
static int STYLE_CROSS
          Cross style.
static int STYLE_DOT
          Dot style.
static int STYLE_LINE
          Line style.
static int STYLE_LINE_HONEYCOMB
          Honeycomb style.
static int TYPE_HEXAGONAL
          Hexagonal type.
static int TYPE_RECTANGULAR
          Rectangular type.
 
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
 
Constructor Summary
JaxoDefaultGrid(int gsize, int gtype)
          Constructor.
JaxoDefaultGrid(int gsize, int gtype, java.awt.Dimension canvasDim)
          Constructor: Sets the dimension, type and value from the arguments.
JaxoDefaultGrid(int gsize, int gtype, int gridStyle, java.awt.Color color)
          Constructor: Sets the dimension to the current screen size and take the other argument values.
JaxoDefaultGrid(int gsize, int gtype, int gridStyle, java.awt.Color color, java.awt.Dimension canvasDim)
          Constructor: Sets the dimension, type and value from the arguments.
 
Method Summary
 void addChangeListener(javax.swing.event.ChangeListener l)
          ChangeEvents will be fired everytime the actual image of the grid changes (not on canvasSize changes).
 java.lang.Object clone()
          Standard clone with all properties at the same values.
 void copyFrom(JaxoDefaultGrid g)
          Copies all properties from the argument.
protected  void fireStateChanged()
          Notifies all listeners of a state change.
 java.awt.Color getBackground()
          Background of the grid (filling the whole canvas).
 java.awt.Dimension getCanvasSize()
          Size of the grid canvas.
 java.awt.Color getGridColor()
          Color of the grid points.
 int getGridSize()
          Returns the current size of the grid.
 int getGridStyle()
          Grid style (STYLE_XYZ constant).
 int getGridType()
          Returns the type of the grid.
 int getTransparency()
          Base on the 'transparent' property and the 'background' and 'gridColor' properties, assuming SRC_OVER rule.
 boolean isSnapped(java.awt.Point p)
          Determines if 'p' is on the grid.
static JaxoDefaultGrid newDefaultGrid()
          A new grid with the values from the preferences.
 void paint(java.awt.Graphics2D g)
          Paints the grid.
 void removeChangeListener(javax.swing.event.ChangeListener l)
          Removes a change listener.
 void setBackground(java.awt.Color value)
          Sets the grid background color.
 void setCanvasSize(java.awt.Dimension value)
          Sets the size of the grid canvas.
 void setGridColor(java.awt.Color value)
          Sets the color of the grid points.
 void setGridSize(int value)
          Sets the size of the grid to the given value.
 void setGridStyle(int value)
          Set style, and repaint.
 void setGridType(int value)
          Sets the type of the grid (TYPE_XYZ).
 java.awt.Point snappedPoint(java.awt.Point p)
          Closest point to 'p' on the grid.
 void snapPoint(java.awt.Point p)
          Change 'p' to the closest point on the grid.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_RECTANGULAR

public static final int TYPE_RECTANGULAR
Rectangular type.

See Also:
Constant Field Values

TYPE_HEXAGONAL

public static final int TYPE_HEXAGONAL
Hexagonal type.

See Also:
Constant Field Values

STYLE_DOT

public static final int STYLE_DOT
Dot style.

See Also:
Constant Field Values

STYLE_CROSS

public static final int STYLE_CROSS
Cross style.

See Also:
Constant Field Values

STYLE_LINE

public static final int STYLE_LINE
Line style.

See Also:
Constant Field Values

STYLE_LINE_HONEYCOMB

public static final int STYLE_LINE_HONEYCOMB
Honeycomb style.

See Also:
Constant Field Values
Constructor Detail

JaxoDefaultGrid

public JaxoDefaultGrid(int gsize,
                       int gtype)
Constructor.

Parameters:
gsize - The grid size to be set.
gtype - The grid type to be set.

JaxoDefaultGrid

public JaxoDefaultGrid(int gsize,
                       int gtype,
                       int gridStyle,
                       java.awt.Color color)
Constructor: Sets the dimension to the current screen size and take the other argument values.

Parameters:
gsize - The grid size to be set.
gtype - The grid type to be set.
gridStyle - The grid style to be set
color - The grid color to be set

JaxoDefaultGrid

public JaxoDefaultGrid(int gsize,
                       int gtype,
                       java.awt.Dimension canvasDim)
Constructor: Sets the dimension, type and value from the arguments.

Parameters:
gsize - The grid size to be set.
gtype - The grid type to be set.
canvasDim - The canvasSize.

JaxoDefaultGrid

public JaxoDefaultGrid(int gsize,
                       int gtype,
                       int gridStyle,
                       java.awt.Color color,
                       java.awt.Dimension canvasDim)
Constructor: Sets the dimension, type and value from the arguments.

Parameters:
gsize - The grid size to be set.
gtype - The grid type to be set.
gridStyle - The grid style to be set.
color - The grid color to be set.
canvasDim - The current canvas size.
Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Standard clone with all properties at the same values.

Overrides:
clone in class java.lang.Object
Returns:
A clone of this grid.
Throws:
java.lang.CloneNotSupportedException - If the object's class does not support the Cloneable interface.

copyFrom

public void copyFrom(JaxoDefaultGrid g)
Copies all properties from the argument.

Parameters:
g - The grid to take the properties from.

addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener l)
ChangeEvents will be fired everytime the actual image of the grid changes (not on canvasSize changes).

Parameters:
l - The listener to add.

removeChangeListener

public void removeChangeListener(javax.swing.event.ChangeListener l)
Removes a change listener.

Parameters:
l - The listener to remove.

fireStateChanged

protected void fireStateChanged()
Notifies all listeners of a state change.


isSnapped

public boolean isSnapped(java.awt.Point p)
Determines if 'p' is on the grid. This is equivalent to p.equals(snappedPoint(p)).

Specified by:
isSnapped in interface JaxoGrid
Parameters:
p - The point to snap.
Returns:
True if p is on the grid.

snappedPoint

public final java.awt.Point snappedPoint(java.awt.Point p)
Closest point to 'p' on the grid.

Specified by:
snappedPoint in interface JaxoGrid
Parameters:
p - The point to snap.
Returns:
The closest grid point.

snapPoint

public final void snapPoint(java.awt.Point p)
Change 'p' to the closest point on the grid.

Specified by:
snapPoint in interface JaxoGrid
Parameters:
p - The point to snap.

getTransparency

public final int getTransparency()
Base on the 'transparent' property and the 'background' and 'gridColor' properties, assuming SRC_OVER rule.

Specified by:
getTransparency in interface java.awt.Transparency
Returns:
The transparency.

paint

public final void paint(java.awt.Graphics2D g)
Paints the grid.

Parameters:
g - The graphics context to paint the grid.

getCanvasSize

public java.awt.Dimension getCanvasSize()
Size of the grid canvas.

Returns:
The size of the grid canvas.

setCanvasSize

public void setCanvasSize(java.awt.Dimension value)
Sets the size of the grid canvas.

Parameters:
value - The size to set.

setGridSize

public final void setGridSize(int value)
Sets the size of the grid to the given value. For a hexagonal grid, the grid size is always forced to be even.

Parameters:
value - The gridSize to be set.

getGridSize

public final int getGridSize()
Returns the current size of the grid.

Returns:
The grid size.

setGridType

public final void setGridType(int value)
Sets the type of the grid (TYPE_XYZ).

Parameters:
value - The gridtype to be set.

getGridType

public final int getGridType()
Returns the type of the grid.

Returns:
The gridtype (TYPE_XYZ).

getGridColor

public final java.awt.Color getGridColor()
Color of the grid points.

Returns:
The color of the grid points.

setGridColor

public void setGridColor(java.awt.Color value)
Sets the color of the grid points.

Parameters:
value - The color to set.

getBackground

public final java.awt.Color getBackground()
Background of the grid (filling the whole canvas). May be null, indicating no background painting, and is ignored in 'transparent' mode. The default is White (the default mode is transparent, so it does not matter).

Returns:
The background color.

setBackground

public void setBackground(java.awt.Color value)
Sets the grid background color.

Parameters:
value - The color to set.

getGridStyle

public final int getGridStyle()
Grid style (STYLE_XYZ constant). The default is STYLE_DOT.

Returns:
The grid style.

setGridStyle

public void setGridStyle(int value)
Set style, and repaint.

Parameters:
value - The style to set.

newDefaultGrid

public static final JaxoDefaultGrid newDefaultGrid()
A new grid with the values from the preferences.

Returns:
A new grid.


Licensed under GPL. For more information, see http://jaxodraw.sourceforge.net/license.html or the LICENSE file in the jaxodraw distribution.