Package net.sf.jaxodraw.gui.grid
Class JaxoDefaultGrid
java.lang.Object
net.sf.jaxodraw.gui.grid.JaxoDefaultGrid
- All Implemented Interfaces:
Transparency
,Cloneable
,JaxoGrid
,JaxoPaintableGrid
Paints a grid on the canvas.
- Since:
- 2.0
-
Field Summary
Fields inherited from interface net.sf.jaxodraw.gui.grid.JaxoPaintableGrid
STYLE_CROSS, STYLE_DOT, STYLE_LINE, STYLE_LINE_HONEYCOMB, TYPE_HEXAGONAL, TYPE_RECTANGULAR
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
-
Constructor Summary
ConstructorsConstructorDescriptionJaxoDefaultGrid
(int gsize, int gtype) Constructor.JaxoDefaultGrid
(int gsize, int gtype, int gridStyle, Color color) Constructor: Sets the dimension to the current screen size and take the other argument values.JaxoDefaultGrid
(int gsize, int gtype, int gridStyle, Color color, Dimension canvasDim) Constructor: Sets the dimension, type and value from the arguments.JaxoDefaultGrid
(int gsize, int gtype, Dimension canvasDim) Constructor: Sets the dimension, type and value from the arguments. -
Method Summary
Modifier and TypeMethodDescriptionvoid
ChangeEvents will be fired everytime the actual image of the grid changes (not on canvasSize changes).clone()
Standard clone with all properties at the same values.void
Copies all properties from the argument.protected void
Notifies all listeners of a state change.final Color
Background of the grid (filling the whole canvas).Size of the grid canvas.final Color
Color of the grid.final int
Returns the current size of the grid.final int
Grid style (STYLE_XYZ constant).final int
Returns the type of the grid.final int
Base on the 'transparent' property and the 'background' and 'gridColor' properties, assuming SRC_OVER rule.boolean
Determine if this grid gets painted.boolean
Determines if 'p' is on the grid.boolean
Check if points are currently snapped to the grid.static final JaxoDefaultGrid
A new grid with the values from the preferences.final void
paint
(Graphics2D g) Paints the grid.void
Removes a change listener.void
setBackground
(Color value) Sets the grid background color.void
setCanvasSize
(Dimension value) Sets the size of the grid canvas.void
setGridColor
(Color value) Sets the color of the grid points.final void
setGridSize
(int value) Sets the size of the grid to the given value.void
setGridStyle
(int value) Set style, and repaint.final void
setGridType
(int value) Sets the type of the grid (TYPE_XYZ).void
setPainted
(boolean painted) Determine if this grid gets painted.void
setSnapping
(boolean snapping) Switch on/off the snapping of this grid.final Point
Closest point to 'p' on the grid.final void
Change 'p' to the closest point on the grid.
-
Constructor Details
-
JaxoDefaultGrid
public JaxoDefaultGrid(int gsize, int gtype) Constructor.- Parameters:
gsize
- The grid size to be set.gtype
- The grid type to be set.
-
JaxoDefaultGrid
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 setcolor
- The grid color to be set
-
JaxoDefaultGrid
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
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 Details
-
clone
Standard clone with all properties at the same values.- Overrides:
clone
in classObject
- Returns:
- A clone of this grid.
- Throws:
CloneNotSupportedException
- If the object's class does not support the Cloneable interface.
-
copyFrom
Copies all properties from the argument.- Parameters:
g
- The grid to take the properties from.
-
addChangeListener
ChangeEvents will be fired everytime the actual image of the grid changes (not on canvasSize changes).- Specified by:
addChangeListener
in interfaceJaxoPaintableGrid
- Parameters:
l
- The listener to add.
-
removeChangeListener
Removes a change listener.- Specified by:
removeChangeListener
in interfaceJaxoPaintableGrid
- Parameters:
l
- The listener to remove.
-
fireStateChanged
protected void fireStateChanged()Notifies all listeners of a state change. -
isSnapped
Determines if 'p' is on the grid. This is equivalent top.equals(snappedPoint(p))
. -
snappedPoint
Closest point to 'p' on the grid.- Specified by:
snappedPoint
in interfaceJaxoGrid
- Parameters:
p
- The point to snap.- Returns:
- The closest grid point.
-
snapPoint
Change 'p' to the closest point on the grid. -
getTransparency
public final int getTransparency()Base on the 'transparent' property and the 'background' and 'gridColor' properties, assuming SRC_OVER rule.- Specified by:
getTransparency
in interfaceTransparency
- Returns:
- The transparency.
-
paint
Paints the grid.- Specified by:
paint
in interfaceJaxoPaintableGrid
- Parameters:
g
- The graphics context to paint the grid.
-
getCanvasSize
Size of the grid canvas. This is the size of the area on which the grid will be painted.- Specified by:
getCanvasSize
in interfaceJaxoPaintableGrid
- Returns:
- The size of the grid canvas.
-
setCanvasSize
Sets the size of the grid canvas. This is the size of the area on which the grid will be painted.- Specified by:
setCanvasSize
in interfaceJaxoPaintableGrid
- Parameters:
value
- The size to set.
-
setGridSize
public final void setGridSize(int value) Sets the size of the grid to the given value. This is the distance between two grid points. For a hexagonal grid, the grid size is always forced to be even.- Specified by:
setGridSize
in interfaceJaxoPaintableGrid
- Parameters:
value
- The grid size to be set.
-
getGridSize
public final int getGridSize()Returns the current size of the grid. This is the distance between two grid points.- Specified by:
getGridSize
in interfaceJaxoPaintableGrid
- Returns:
- The grid size.
-
setGridType
public final void setGridType(int value) Sets the type of the grid (TYPE_XYZ).- Specified by:
setGridType
in interfaceJaxoPaintableGrid
- Parameters:
value
- The gridtype to be set.
-
getGridType
public final int getGridType()Returns the type of the grid.- Specified by:
getGridType
in interfaceJaxoPaintableGrid
- Returns:
- The gridtype (TYPE_XYZ).
-
getGridColor
Color of the grid.- Specified by:
getGridColor
in interfaceJaxoPaintableGrid
- Returns:
- The color of the grid.
-
setGridColor
Sets the color of the grid points.- Specified by:
setGridColor
in interfaceJaxoPaintableGrid
- Parameters:
value
- The color to set.
-
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
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.- Specified by:
getGridStyle
in interfaceJaxoPaintableGrid
- Returns:
- The grid style.
-
setGridStyle
public void setGridStyle(int value) Set style, and repaint.- Specified by:
setGridStyle
in interfaceJaxoPaintableGrid
- Parameters:
value
- The style to set.
-
newDefaultGrid
A new grid with the values from the preferences.- Returns:
- A new grid.
-
isPainted
public boolean isPainted()Determine if this grid gets painted. By default, a grid is painted.- Specified by:
isPainted
in interfaceJaxoPaintableGrid
- Returns:
- true if the grid is switched on, false otherwise.
-
setPainted
public void setPainted(boolean painted) Determine if this grid gets painted.- Specified by:
setPainted
in interfaceJaxoPaintableGrid
- Parameters:
painted
- true if this grid should get painted, false otherwise.
-
isSnapping
public boolean isSnapping()Check if points are currently snapped to the grid. By default snapping is off.- Specified by:
isSnapping
in interfaceJaxoPaintableGrid
- Returns:
- true if this grid snaps points, false otherwise.
-
setSnapping
public void setSnapping(boolean snapping) Switch on/off the snapping of this grid.- Specified by:
setSnapping
in interfaceJaxoPaintableGrid
- Parameters:
snapping
- true if this grid should snap points, false otherwise.
-