JHotDraw 7.5.1

org.jhotdraw.draw
Interface Constrainer

All Known Implementing Classes:
AbstractConstrainer, GridConstrainer

@NotNull
public interface Constrainer

A constrainer constrains editing operations performed by Tools and Handles on a DrawingView.

Constrainer objects are associated to DrawingView's.

Constrainers can draw themselves onto the drawing view to visualize the constraints that they impose. Typically by drawing a grid of some kind.


Design Patterns

Strategy
Editing can be constrained by a constrainer which is associated to a drawing view.
Context: DrawingView; Strategy: Constrainer.


Version:
$Id: Constrainer.java 654 2010-06-25 13:27:08Z rawcoder $
Author:
Werner Randelshofer

Method Summary
 void addChangeListener(javax.swing.event.ChangeListener listener)
          Adds a change listener.
 double constrainAngle(double angle)
          Constrains the given angle (in radians).
 java.awt.geom.Point2D.Double constrainPoint(java.awt.geom.Point2D.Double p)
          Constrains the placement of a point towards the closest constraint in any 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.
 void draw(java.awt.Graphics2D g, DrawingView view)
          Draws the constrainer grid for the specified drawing view.
 void removeChangeListener(javax.swing.event.ChangeListener listener)
          Removes a change listener.
 double rotateAngle(double angle, RotationDirection dir)
          Moves the given angle (in radians) to the closest constrained orientation in the specified direction.
 java.awt.geom.Point2D.Double translatePoint(java.awt.geom.Point2D.Double p, TranslationDirection dir)
          Moves a point to the closest constrained location in the specified 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.
 

Method Detail

constrainPoint

java.awt.geom.Point2D.Double constrainPoint(java.awt.geom.Point2D.Double p)
Constrains the placement of a point towards the closest constraint in any direction.

This method changes the point which is passed as a parameter.

Parameters:
p - A point on the drawing.
Returns:
Returns the constrained point.

translatePoint

java.awt.geom.Point2D.Double translatePoint(java.awt.geom.Point2D.Double p,
                                            TranslationDirection dir)
Moves a point to the closest constrained location in the specified direction.

This method changes the point which is passed as a parameter.

Parameters:
p - A point on the drawing.
dir - A direction.
Returns:
Returns the constrained point.

constrainRectangle

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.

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

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.

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.

constrainAngle

double constrainAngle(double angle)
Constrains 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

double rotateAngle(double angle,
                   RotationDirection dir)
Moves 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.

draw

void draw(java.awt.Graphics2D g,
          DrawingView view)
Draws the constrainer grid for the specified drawing view.


addChangeListener

void addChangeListener(javax.swing.event.ChangeListener listener)
Adds a change listener.


removeChangeListener

void removeChangeListener(javax.swing.event.ChangeListener listener)
Removes a change listener.


Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.