org.jhotdraw.draw
Class GridConstrainer
- java.lang.Object
-
- org.jhotdraw.beans.AbstractBean
-
- org.jhotdraw.draw.AbstractConstrainer
-
- org.jhotdraw.draw.GridConstrainer
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Constrainer
public class GridConstrainer extends AbstractConstrainer
Constrains a point such that it falls on a grid.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description doubleconstrainAngle(double angle)Constrains the given angle (in radians).java.awt.geom.Point2D.DoubleconstrainPoint(java.awt.geom.Point2D.Double p)Constrains a point to the closest grid point in any direction.java.awt.geom.Rectangle2D.DoubleconstrainRectangle(java.awt.geom.Rectangle2D.Double r)Constrains the placement of a rectangle towards the closest constrainment in any direction.voiddraw(java.awt.Graphics2D g, DrawingView view)Draws the constrainer grid for the specified drawing view.doublegetHeight()intgetMajorGridSpacing()Spacing between major grid lines.doublegetTheta()doublegetWidth()booleanisVisible()doublerotateAngle(double angle, RotationDirection dir)Moves the given angle (in radians) to the closest constrained orientation in the specified direction.voidsetHeight(double newValue)voidsetMajorGridSpacing(int newValue)Spacing between major grid lines.voidsetTheta(double newValue)voidsetVisible(boolean newValue)voidsetWidth(double newValue)java.lang.StringtoString()java.awt.geom.Point2D.DoubletranslatePoint(java.awt.geom.Point2D.Double p, TranslationDirection dir)Moves a point to the closest grid point in a direction.java.awt.geom.Rectangle2D.DoubletranslateRectangle(java.awt.geom.Rectangle2D.Double r, TranslationDirection dir)Moves a rectangle to the closest constrained location in the specified direction.-
Methods inherited from class org.jhotdraw.draw.AbstractConstrainer
addChangeListener, clone, removeChangeListener
-
Methods inherited from class org.jhotdraw.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Constructor Detail
-
GridConstrainer
public GridConstrainer()
Creates a new instance with a grid of 1x1.
-
GridConstrainer
public GridConstrainer(double width, double height)Creates a new instance with the specified grid size, and by 11.25° (in degrees) for rotations. The grid is visible.- Parameters:
width- The width of a grid cell.height- The height of a grid cell.
-
GridConstrainer
public GridConstrainer(double width, double height, boolean visible)Creates a new instance with the specified grid size. and by 11.25° (in degrees) for rotations.- Parameters:
width- The width of a grid cell.height- The height of a grid cell.visible- Wether the grid is visible or not.
-
GridConstrainer
public GridConstrainer(double width, double height, double theta, boolean visible)Creates a new instance with the specified grid size.- Parameters:
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.
-
-
Method Detail
-
getWidth
public double getWidth()
-
getHeight
public double getHeight()
-
getTheta
public double getTheta()
-
setWidth
public void setWidth(double newValue)
-
setHeight
public void setHeight(double newValue)
-
setTheta
public void setTheta(double newValue)
-
constrainPoint
public java.awt.geom.Point2D.Double constrainPoint(java.awt.geom.Point2D.Double p)
Constrains a point to the closest grid point in any direction.- Parameters:
p- A point on the drawing.- Returns:
- Returns the constrained point.
-
translatePoint
public 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.- Parameters:
p- A point on the drawing.dir- A direction.- Returns:
- Returns the constrained point.
-
constrainRectangle
public java.awt.geom.Rectangle2D.Double constrainRectangle(java.awt.geom.Rectangle2D.Double r)
Description copied from interface:ConstrainerConstrains the placement of a rectangle towards the closest constrainment in any direction.This method changes the location of the rectangle which is passed as a parameter. This method does not change the size of the rectangle.
- Parameters:
r- A rectangle on the drawing.- Returns:
- Returns the constrained rectangle.
-
translateRectangle
public java.awt.geom.Rectangle2D.Double translateRectangle(java.awt.geom.Rectangle2D.Double r, TranslationDirection dir)Description copied from interface:ConstrainerMoves a rectangle to the closest constrained location in the specified direction.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.
- Parameters:
r- A rectangle on the drawing.dir- A direction.- Returns:
- Returns the constrained rectangle.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isVisible
public boolean isVisible()
-
setVisible
public void setVisible(boolean newValue)
-
getMajorGridSpacing
public int getMajorGridSpacing()
Spacing between major grid lines.
-
setMajorGridSpacing
public void setMajorGridSpacing(int newValue)
Spacing between major grid lines.
-
draw
public void draw(java.awt.Graphics2D g, DrawingView view)Description copied from interface:ConstrainerDraws the constrainer grid for the specified drawing view.
-
constrainAngle
public double constrainAngle(double angle)
Description copied from interface:ConstrainerConstrains the given angle (in radians). This method changes the angle which is passed as a parameter.- Parameters:
angle- The angle (in radians).- Returns:
- The closest constrained angle (in radians).
-
rotateAngle
public double rotateAngle(double angle, RotationDirection dir)Description copied from interface:ConstrainerMoves the given angle (in radians) to the closest constrained orientation in the specified direction.- Parameters:
angle- The angle (in radians).- Returns:
- The closest constrained angle (in radians) in the specified direction.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG