public class GridConstrainer extends AbstractConstrainer
changeEvent, listenerList
propertySupport
Constructor and Description |
---|
GridConstrainer()
Creates a new instance with a grid of 1x1.
|
GridConstrainer(double width,
double height)
Creates a new instance with the specified grid size,
and by 11.25° (in degrees) for rotations.
|
GridConstrainer(double width,
double height,
boolean visible)
Creates a new instance with the specified grid size.
|
GridConstrainer(double width,
double height,
double theta,
boolean visible)
Creates a new instance with the specified grid size.
|
Modifier and Type | Method and Description |
---|---|
double |
constrainAngle(double angle)
Constrains the given angle (in radians).
|
java.awt.geom.Point2D.Double |
constrainPoint(java.awt.geom.Point2D.Double p)
Constrains a point to the closest grid point in any direction.
|
protected java.awt.geom.Point2D.Double |
constrainPoint(java.awt.geom.Point2D.Double p,
TranslationDirection dir)
Constrains the placement of a point towards a direction.
|
java.awt.geom.Rectangle2D.Double |
constrainRectangle(java.awt.geom.Rectangle2D.Double r)
Constrains the placement of a rectangle towards the closest constrainment
in any direction.
|
protected java.awt.geom.Rectangle2D.Double |
constrainRectangle(java.awt.geom.Rectangle2D.Double r,
TranslationDirection dir)
Constrains the placement of a rectangle towards a direction.
|
void |
draw(java.awt.Graphics2D g,
DrawingView view)
Draws the constrainer grid for the specified drawing view.
|
double |
getHeight() |
int |
getMajorGridSpacing()
Spacing between major grid lines.
|
double |
getTheta() |
double |
getWidth() |
boolean |
isVisible() |
double |
rotateAngle(double angle,
RotationDirection dir)
Moves the given angle (in radians) to the closest constrained orientation
in the specified direction.
|
void |
setHeight(double newValue) |
void |
setMajorGridSpacing(int newValue)
Spacing between major grid lines.
|
void |
setTheta(double newValue) |
void |
setVisible(boolean newValue) |
void |
setWidth(double newValue) |
java.lang.String |
toString() |
java.awt.geom.Point2D.Double |
translatePoint(java.awt.geom.Point2D.Double p,
TranslationDirection dir)
Moves a point to the closest grid point in a direction.
|
java.awt.geom.Rectangle2D.Double |
translateRectangle(java.awt.geom.Rectangle2D.Double r,
TranslationDirection dir)
Moves a rectangle to the closest constrained location in the
specified direction.
|
addChangeListener, clone, fireStateChanged, removeChangeListener
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
public GridConstrainer()
public GridConstrainer(double width, double height)
width
- The width of a grid cell.height
- The height of a grid cell.public GridConstrainer(double width, double height, boolean visible)
width
- The width of a grid cell.height
- The height of a grid cell.visible
- Wether the grid is visible or not.public GridConstrainer(double width, double height, double theta, boolean visible)
width
- The width of a grid cell.height
- The height of a grid cell.theta
- The theta for rotations in radians.visible
- Wether the grid is visible or not.public double getWidth()
public double getHeight()
public double getTheta()
public void setWidth(double newValue)
public void setHeight(double newValue)
public void setTheta(double newValue)
public java.awt.geom.Point2D.Double constrainPoint(java.awt.geom.Point2D.Double p)
p
- A point on the drawing.protected java.awt.geom.Point2D.Double constrainPoint(java.awt.geom.Point2D.Double p, TranslationDirection dir)
This method changes the point which is passed as a parameter.
p
- A point on the drawing.dir
- A direction.public java.awt.geom.Point2D.Double translatePoint(java.awt.geom.Point2D.Double p, TranslationDirection dir)
p
- A point on the drawing.dir
- A direction.public java.awt.geom.Rectangle2D.Double constrainRectangle(java.awt.geom.Rectangle2D.Double r)
Constrainer
This method changes the location of the rectangle which is passed as a parameter. This method does not change the size of the rectangle.
r
- A rectangle on the drawing.protected java.awt.geom.Rectangle2D.Double constrainRectangle(java.awt.geom.Rectangle2D.Double r, TranslationDirection dir)
This method changes the location of the rectangle which is passed as a parameter. This method does not change the size of the rectangle.
r
- A rectangle on the drawing.dir
- A direction.public java.awt.geom.Rectangle2D.Double translateRectangle(java.awt.geom.Rectangle2D.Double r, TranslationDirection dir)
Constrainer
This method changes the location of the rectangle which is passed as a parameter. This method only performs a translation - it does not change the size of the rectangle.
r
- A rectangle on the drawing.dir
- A direction.public java.lang.String toString()
toString
in class java.lang.Object
public boolean isVisible()
public void setVisible(boolean newValue)
public int getMajorGridSpacing()
public void setMajorGridSpacing(int newValue)
public void draw(java.awt.Graphics2D g, DrawingView view)
Constrainer
public double constrainAngle(double angle)
Constrainer
angle
- The angle (in radians).public double rotateAngle(double angle, RotationDirection dir)
Constrainer
angle
- The angle (in radians).