net.sf.latexdraw.glib.ui
Class LMagneticGrid

java.lang.Object
  extended by net.sf.latexdraw.glib.ui.LMagneticGrid
All Implemented Interfaces:
Preferenciable, Modifiable

public class LMagneticGrid
extends java.lang.Object
implements Preferenciable, Modifiable

This class defines a magnetic grid.

This file is part of LaTeXDraw
Copyright (c) 2005-2012 Arnaud BLOUIN

LaTeXDraw is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

LaTeXDraw is distributed without any warranty; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

01/21/08

Version:
3.0
Author:
Arnaud BLOUIN

Nested Class Summary
static class LMagneticGrid.GridStyle
          This enumeration contains the different style of a magnetic grid.
 
Field Summary
protected  ICanvas canvas
          The canvas that paints the grid.
protected  int gridSpacing
          defines the spacing between the lines of the grid.
protected  int height
          The height of the grid.
protected  boolean isMagnetic
          Allows to know if the grid is magnetic or not.
protected  boolean modified
          Defined if the canvas has been modified.
static java.awt.BasicStroke STROKE
          The stroke of the grid.
protected  LMagneticGrid.GridStyle style
          The style of the grid.
protected  int width
          The width of the grid.
 
Constructor Summary
LMagneticGrid(int width, int height, ICanvas canvas)
          Creates the magnetic grid.
 
Method Summary
 ICanvas getCanvas()
           
 int getGridSpacing()
           
 int getHeight()
           
 double getMagneticGridGap()
           
 LMagneticGrid.GridStyle getStyle()
           
 IPoint getTransformedPointToGrid(java.awt.geom.Point2D pt)
          Transform a point to another "stick" to the magnetic grid.
 int getWidth()
           
 boolean isGridDisplayed()
           
 boolean isMagnetic()
           
 boolean isModified()
           
 boolean isPersonalGrid()
           
 void load(boolean generalPreferences, java.lang.String nsURI, org.w3c.dom.Element meta)
          Loads data save in an XML document.
 void paint(java.awt.Graphics2D gaph)
          Paints the magnetic grid is activated.
protected  void paintMainLines(java.awt.Graphics2D graph, double gap)
           
protected  void paintSubLines(java.awt.Graphics2D graph)
           
 void reinitGrid()
          Reinitialises the magnetic grid.
 void save(boolean generalPreferences, java.lang.String nsURI, org.w3c.dom.Document document, org.w3c.dom.Element root)
          Saves the parameters of the instrument into an XML tag.
 void setGridSpacing(int gridSpacing)
           
 void setMagnetic(boolean isMagnetic)
           
 void setModified(boolean modified)
          Sets the Modifiable object as modified.
 void setSize(int width, int height)
          Sets the size of the magnetic grid.
 void setStyle(LMagneticGrid.GridStyle style)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STROKE

public static final java.awt.BasicStroke STROKE
The stroke of the grid.


isMagnetic

protected boolean isMagnetic
Allows to know if the grid is magnetic or not.


gridSpacing

protected int gridSpacing
defines the spacing between the lines of the grid.


width

protected int width
The width of the grid.


height

protected int height
The height of the grid.


style

protected LMagneticGrid.GridStyle style
The style of the grid.


canvas

protected ICanvas canvas
The canvas that paints the grid.


modified

protected boolean modified
Defined if the canvas has been modified.

Constructor Detail

LMagneticGrid

public LMagneticGrid(int width,
                     int height,
                     ICanvas canvas)
Creates the magnetic grid.

Parameters:
width - The width of the grid.
height - The height of the grid.
canvas - The canvas in which the grid will work.
Throws:
java.lang.IllegalArgumentException - if the given parameters are not valid.
Since:
2.0
Method Detail

paint

public void paint(java.awt.Graphics2D gaph)
Paints the magnetic grid is activated.

Parameters:
gaph - The graphics in which the grid will be drawn.
Since:
3.0

paintSubLines

protected void paintSubLines(java.awt.Graphics2D graph)

paintMainLines

protected void paintMainLines(java.awt.Graphics2D graph,
                              double gap)

getTransformedPointToGrid

public IPoint getTransformedPointToGrid(java.awt.geom.Point2D pt)
Transform a point to another "stick" to the magnetic grid.

Parameters:
pt - The point to transform.
Returns:
The transformed point or if there is no magnetic grid, a clone of the given point.
Since:
1.8

getMagneticGridGap

public double getMagneticGridGap()
Returns:
The gap between the lines of the magnetic grid.
Since:
1.9

reinitGrid

public void reinitGrid()
Reinitialises the magnetic grid.

Since:
3.0

isMagnetic

public boolean isMagnetic()
Returns:
True: the grid is magnetic.
Since:
2.0.0

setMagnetic

public void setMagnetic(boolean isMagnetic)
Parameters:
isMagnetic - True: the grid will be magnetic.
Since:
2.0.0

getGridSpacing

public int getGridSpacing()
Returns:
The new spacing between lines of the personal grid.
Since:
3.0

setGridSpacing

public void setGridSpacing(int gridSpacing)
Parameters:
gridSpacing - The new spacing between lines of the personal grid.
Since:
3.0

isPersonalGrid

public boolean isPersonalGrid()
Returns:
True: the grid is magnetic.
Since:
2.0.0

getWidth

public int getWidth()
Returns:
The width of the magnetic grid.
Since:
2.0.0

getHeight

public int getHeight()
Returns:
The height of the magnetic grid.
Since:
2.0.0

setSize

public void setSize(int width,
                    int height)
Sets the size of the magnetic grid.

Parameters:
width - The new width.
height - The new height.
Since:
3.0

getStyle

public LMagneticGrid.GridStyle getStyle()
Returns:
The style of the magnetic grid.
Since:
2.0.0

setStyle

public void setStyle(LMagneticGrid.GridStyle style)
Parameters:
style - The new style of the grid. If null, nothing is performed.
Since:
3.0

isGridDisplayed

public boolean isGridDisplayed()
Returns:
True: The magnetic grid must be displayed.
Since:
2.0.0

getCanvas

public ICanvas getCanvas()
Returns:
the canvas which displays the grid.
Since:
3.0

setModified

public void setModified(boolean modified)
Description copied from interface: Modifiable
Sets the Modifiable object as modified.

Specified by:
setModified in interface Modifiable
Parameters:
modified - True: the element is will tagged as modified.

isModified

public boolean isModified()
Specified by:
isModified in interface Modifiable
Returns:
True: the object has been modified. False otherwise.

save

public void save(boolean generalPreferences,
                 java.lang.String nsURI,
                 org.w3c.dom.Document document,
                 org.w3c.dom.Element root)
Description copied from interface: Preferenciable
Saves the parameters of the instrument into an XML tag.

Specified by:
save in interface Preferenciable
Parameters:
generalPreferences - True: this operation is called to save the general preferences of the interactive system. Otherwise, it is called to save a presentation in a document. This parameter is useful when different information must be saved during a presentation backup or a general preferences backup.
nsURI - The namespace that must be added to tags corresponding to the instrument's parameters.
document - The XML document.
root - The root element that will contains the instrument's parameters.

load

public void load(boolean generalPreferences,
                 java.lang.String nsURI,
                 org.w3c.dom.Element meta)
Description copied from interface: Preferenciable
Loads data save in an XML document.

Specified by:
load in interface Preferenciable
Parameters:
generalPreferences - True: this operation is called to load the general preferences of the interactive system. Otherwise, it is called to load a presentation in a document. This parameter is useful when different information must be loaded during a presentation backup or a general preferences backup.
nsURI - The namespace that must be added to tags corresponding to the instrument's parameters.
meta - The meta data element.