Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| http://www.jpicedt.org
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## jpicedt.graphic.grid
Class Grid

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

public class Grid
extends Object

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

- Provides the ability to find a nearest-neighbour point on the grid, given a point in model-coordinate, using current snap-step value
- Offers several paint schemes (grid step)

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

Field Summary
`static Color` | `colorDEFAULT` default colour used to paint grid lines
`static String` | `DASH` paint grid lines using dashed lines
`static double` | `gridStepDEFAULT`
`static boolean` | `isVisibleDEFAULT` default for visible state
`static String` | `KEY_GRID_COLOR` key used to fetch the grid colour from the Properties object
`static String` | `KEY_GRID_STEP` key used to fetch the grid step from the Properties object
`static String` | `KEY_LINE_STYLE` key used to fetch the line style from the Properties object
`static String` | `KEY_SNAP_ON` key used to fetch the snap state from the Properties object
`static String` | `KEY_SNAP_STEP` key used to fetch the snap step from the Properties object
`static String` | `KEY_VISIBLE` key used to fetch the visible state from the Properties object
`static String` | `lineStyleDEFAULT` default style used to paint grid lines
`static String[]` | `PREDEFINED_GRID_STEP_STRINGS`
`static double[]` | `PREDEFINED_GRID_STEPS`
`static String[]` | `PREDEFINED_SNAP_STEP_STRINGS`
`static double[]` | `PREDEFINED_SNAP_STEPS`
`static String[]` | `PREDEFINED_STYLES`
`static boolean` | `snapOnDEFAULT` is snapping active ?
`static double` | `snapStepDEFAULT` default snap step
`static 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, Color gridColor, String lineStyle)` Construct a new Grid
`Grid(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
`Color` | `getColor()`
`double` | `getGridStep()`
`static int` | `getGridStepIndex(double gridStep)` Utilities to retrieve an index from a given gridStep in PREDEFINED_SNAP_STEPS
`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(Graphics2D g, 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(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(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 String[] PREDEFINED_SNAP_STEP_STRINGS

### PREDEFINED_SNAP_STEPS

    public static final double[] PREDEFINED_SNAP_STEPS

### PREDEFINED_GRID_STEP_STRINGS

    public static final String[] PREDEFINED_GRID_STEP_STRINGS

### PREDEFINED_GRID_STEPS

    public static final double[] PREDEFINED_GRID_STEPS

### KEY_VISIBLE

    public static final 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 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 String KEY_GRID_COLOR

  key used to fetch the grid colour from the Properties object

  See Also:
    Constant Field Values

### colorDEFAULT

    public static final Color colorDEFAULT

  default colour used to paint grid lines

### KEY_LINE_STYLE

    public static final String KEY_LINE_STYLE

  key used to fetch the line style from the Properties object

  See Also:
    Constant Field Values

### SOLID

    public static final String SOLID

  paint grid lines using solid lines

  See Also:
    Constant Field Values

### DASH

    public static final String DASH

  paint grid lines using dashed lines

  See Also:
    Constant Field Values

### lineStyleDEFAULT

    public static final String lineStyleDEFAULT

  default style used to paint grid lines

  See Also:
    Constant Field Values

### PREDEFINED_STYLES

    public static final String[] PREDEFINED_STYLES

### KEY_SNAP_ON

    public static final 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 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,
                Color gridColor,
                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(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 Detail

### setColor

    public void setColor(Color gridColor)

  set the colour used to paint the grid

### getColor

    public Color getColor()

  Returns:
    the colour used to paint the grid

### setLineStyle

    public void setLineStyle(String lineStyle)

  set the style used to paint grid lines

### getLineStyle

    public 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(Graphics2D g,
                      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)

### 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.

  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.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| http://www.jpicedt.org
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Submit a bug : syd@jpicedt.org