http://www.jpicedt.org

jpicedt.graphic.grid
Class Grid

java.lang.Object
  extended by jpicedt.graphic.grid.Grid

public class Grid
extends java.lang.Object

A grid for PECanvas, defined in model-coordinate (natural unit = 1mm)

Since:
PicEdt 1.0 ; completely refactored jpicedt 1.3.2
Author:
Sylvain Reynal

Field Summary
static java.awt.Color colorDEFAULT
          default colour used to paint grid lines
static java.lang.String DASH
          paint grid lines using dashed lines
static double gridStepDEFAULT
           
static boolean isVisibleDEFAULT
          default for visible state
static java.lang.String KEY_GRID_COLOR
          key used to fetch the grid colour from the Properties object
static java.lang.String KEY_GRID_STEP
          key used to fetch the grid step from the Properties object
static java.lang.String KEY_LINE_STYLE
          key used to fetch the line style from the Properties object
static java.lang.String KEY_SNAP_ON
          key used to fetch the snap state from the Properties object
static java.lang.String KEY_SNAP_STEP
          key used to fetch the snap step from the Properties object
static java.lang.String KEY_VISIBLE
          key used to fetch the visible state from the Properties object
static java.lang.String lineStyleDEFAULT
          default style used to paint grid lines
static java.lang.String[] PREDEFINED_GRID_STEP_STRINGS
           
static double[] PREDEFINED_GRID_STEPS
           
static java.lang.String[] PREDEFINED_SNAP_STEP_STRINGS
           
static double[] PREDEFINED_SNAP_STEPS
           
static java.lang.String[] PREDEFINED_STYLES
           
static boolean snapOnDEFAULT
          is snapping active ?
static double snapStepDEFAULT
          default snap step
static java.lang.String SOLID
          paint grid lines using solid lines
 
Constructor Summary
Grid()
          Construct a new Grid with default values
Grid(boolean isVisible, boolean isSnapOn, double snapStep, double gridStep, java.awt.Color gridColor, java.lang.String lineStyle)
          Construct a new Grid
Grid(java.util.Properties preferences)
          Construct a new Grid from the given Properties, using the following key/value pairs : - key = KEY_VISIBLE, value = true/false - key = KEY_SNAP_ON, value = true/false - key = KEY_SNAP_STEP, value = a double - key = KEY_GRID_COLOR, value = integer (RGB) representation of the colour - key = KEY_LINE_STYLE, value = one of the predefined string (SOLID or DASH)
 
Method Summary
 java.awt.Color getColor()
           
 double getGridStep()
           
static int getGridStepIndex(double gridStep)
          Utilities to retrieve an index from a given gridStep in PREDEFINED_SNAP_STEPS
 java.lang.String getLineStyle()
           
 double getSnapStep()
           
static int getSnapStepIndex(double snapStep)
          Utilities to retrieve an index from a given snapStep in PREDEFINED_SNAP_STEPS
 boolean isSnapOn()
           
 boolean isVisible()
           
 PicPoint nearestNeighbour(PicPoint srcPt, PicPoint dstPt)
          Compute the nearest-neighbour of the given src point on this grid, using the current snap-step value, and store the result in dst.
 void paint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D clip, double scale)
          paint this grid using a grid-step of "gridstep" mm to compute line-spacing.
The graphic context is in user-coordinate, i.e.
 void setColor(java.awt.Color gridColor)
          set the colour used to paint the grid
 void setGridStep(double gridStep)
          sets the grid (display)-step to the given value
 void setLineStyle(java.lang.String lineStyle)
          set the style used to paint grid lines
 void setSnapOn(boolean state)
          sets whether snap is active or not
 void setSnapStep(double snapStep)
          sets the snap-step to the given value
 void setVisible(boolean state)
          set whether this grid is visible or not
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PREDEFINED_SNAP_STEP_STRINGS

public static final java.lang.String[] PREDEFINED_SNAP_STEP_STRINGS

PREDEFINED_SNAP_STEPS

public static final double[] PREDEFINED_SNAP_STEPS

PREDEFINED_GRID_STEP_STRINGS

public static final java.lang.String[] PREDEFINED_GRID_STEP_STRINGS

PREDEFINED_GRID_STEPS

public static final double[] PREDEFINED_GRID_STEPS

KEY_VISIBLE

public static final java.lang.String KEY_VISIBLE
key used to fetch the visible state from the Properties object

See Also:
Constant Field Values

isVisibleDEFAULT

public static final boolean isVisibleDEFAULT
default for visible state

See Also:
Constant Field Values

KEY_GRID_STEP

public static final java.lang.String KEY_GRID_STEP
key used to fetch the grid step from the Properties object

See Also:
Constant Field Values

gridStepDEFAULT

public static final double gridStepDEFAULT
See Also:
Constant Field Values

KEY_GRID_COLOR

public static final java.lang.String KEY_GRID_COLOR
key used to fetch the grid colour from the Properties object

See Also:
Constant Field Values

colorDEFAULT

public static final java.awt.Color colorDEFAULT
default colour used to paint grid lines


KEY_LINE_STYLE

public static final java.lang.String KEY_LINE_STYLE
key used to fetch the line style from the Properties object

See Also:
Constant Field Values

SOLID

public static final java.lang.String SOLID
paint grid lines using solid lines

See Also:
Constant Field Values

DASH

public static final java.lang.String DASH
paint grid lines using dashed lines

See Also:
Constant Field Values

lineStyleDEFAULT

public static final java.lang.String lineStyleDEFAULT
default style used to paint grid lines

See Also:
Constant Field Values

PREDEFINED_STYLES

public static final java.lang.String[] PREDEFINED_STYLES

KEY_SNAP_ON

public static final java.lang.String KEY_SNAP_ON
key used to fetch the snap state from the Properties object

See Also:
Constant Field Values

snapOnDEFAULT

public static final boolean snapOnDEFAULT
is snapping active ?

See Also:
Constant Field Values

KEY_SNAP_STEP

public static final java.lang.String KEY_SNAP_STEP
key used to fetch the snap step from the Properties object

See Also:
Constant Field Values

snapStepDEFAULT

public static final double snapStepDEFAULT
default snap step

See Also:
Constant Field Values
Constructor Detail

Grid

public Grid()
Construct a new Grid with default values


Grid

public Grid(boolean isVisible,
            boolean isSnapOn,
            double snapStep,
            double gridStep,
            java.awt.Color gridColor,
            java.lang.String lineStyle)
Construct a new Grid

Parameters:
isVisible - whether the grid has to be displayed or not
isSnapOn - whether the snap behaviour is active or not
snapStep - step used to compute the nearest-neighbour of a click point
gridStep - distance b/w grid lines in mm
gridColor - the grid colour
lineStyle - SOLID or DASH (tells what style to apply to grid lines)

Grid

public Grid(java.util.Properties preferences)
Construct a new Grid from the given Properties, using the following key/value pairs : - key = KEY_VISIBLE, value = true/false - key = KEY_SNAP_ON, value = true/false - key = KEY_SNAP_STEP, value = a double - key = KEY_GRID_COLOR, value = integer (RGB) representation of the colour - key = KEY_LINE_STYLE, value = one of the predefined string (SOLID or DASH)

Parameters:
isVisible - whether the grid has to be displayed or not
isSnapOn - whether the snap behaviour is active or not
snapStep - step used to compute the nearest-neighbour of a click point
gridColor - the grid colour
lineStyle - SOLID or DASH (tells what style to apply to grid lines)
Method Detail

setColor

public void setColor(java.awt.Color gridColor)
set the colour used to paint the grid


getColor

public java.awt.Color getColor()
Returns:
the colour used to paint the grid

setLineStyle

public void setLineStyle(java.lang.String lineStyle)
set the style used to paint grid lines

Parameters:
SOLID - or DASH

getLineStyle

public java.lang.String getLineStyle()
Returns:
the style used to paint grid lines

setVisible

public void setVisible(boolean state)
set whether this grid is visible or not


isVisible

public boolean isVisible()
Returns:
whether this grid is visible or not

setSnapOn

public void setSnapOn(boolean state)
sets whether snap is active or not


isSnapOn

public boolean isSnapOn()
Returns:
whether snap is active or not

getSnapStep

public double getSnapStep()
Returns:
the snap step

setSnapStep

public void setSnapStep(double snapStep)
sets the snap-step to the given value


getGridStep

public double getGridStep()
Returns:
the grid step

setGridStep

public void setGridStep(double gridStep)
sets the grid (display)-step to the given value


paint

public void paint(java.awt.Graphics2D g,
                  java.awt.geom.Rectangle2D clip,
                  double scale)
paint this grid using a grid-step of "gridstep" mm to compute line-spacing.
The graphic context is in user-coordinate, i.e. in model-coordinates (left to right, bottom to top, mm)

Parameters:
sclae - the current scale factor, used to scale down line thickness so that lines are displayed with a constant thickness, whatever AffineTransform is currently set to the graphic context.

nearestNeighbour

public PicPoint nearestNeighbour(PicPoint srcPt,
                                 PicPoint dstPt)
Compute the nearest-neighbour of the given src point on this grid, using the current snap-step value, and store the result in dst.
If snap is turned off, simply returns pt.
If dst is null, a new PicPoint is allocated and the result is stored in this new point.
If src and dst are the same objects, the input point is correctly overwritten with the result.

Parameters:
ptSrc - the source point in model-coordinates.
ptDst - a point that stores the result
Returns:
ptDst for convenience

getSnapStepIndex

public static int getSnapStepIndex(double snapStep)
Utilities to retrieve an index from a given snapStep in PREDEFINED_SNAP_STEPS

Returns:
index of the given snap step in array "PREDEFINED_SNAP_STEPS" returns -1 if not found.

getGridStepIndex

public static int getGridStepIndex(double gridStep)
Utilities to retrieve an index from a given gridStep in PREDEFINED_SNAP_STEPS

Returns:
index of the given grid step in array "PREDEFINED_GRID_STEPS" returns -1 if not found.

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org