edu.neu.ccs.gui
Interface Paintable

All Superinterfaces:
JPTConstants, SupportsPropertyChange, SwingConstants
All Known Implementing Classes:
AbstractPaintable

public interface Paintable
extends SupportsPropertyChange, JPTConstants

Paintable describes an object that can paint onto a graphics context.

As of 2.4.0, the former interface MutatablePaintable has been merged into Paintable. Furthermore, the interface MutatablePaintable has been removed from the Java Power Tools as has the class AbstractMutatablePaintable.

Much programming experience proved that splitting the design into two interfaces and two abstract classes was more hassle than it was worth. Although splittling the design into two classes was conceptually simple, it made programming much more difficult since the necessary facilities were not all available everywhere.

The new Paintable interface also includes methods that have proven to be useful but which required explicit coding in earlier versions of JPT. These methods are now available automatically in the base class AbstractPaintable.

In fact, all but three of the methods specified in this interface have default definitions in AbstractPaintable. The three abstract methods in that class are:

Therefore, it is relatively easy to create a Paintable in a direct manner by extending AbstractPaintable. However, it is even easier to use the existing JPT Paintable classes to handle shapes, images, and text directly, and to create composites of simpler paintables via PaintableSequence.

As of 2.4.0, the interface Paintable extends the interface SupportsPropertyChange. This makes explicit a relationship that was true de facto in earlier releases of JPT since the class AbstractPaintable has always implemented SupportsPropertyChange.

In 2.6.0, the notion of a background paint was refactored from Tile into required “set” and “get” methods in this interface and corresponding implementation in the base class AbstractPaintable.

Also, in 2.6.0, support was added to use a paintable as a tile for a rectangle. Once this facility was in place, we added the option for one paintable to use another paintable as a background tile that will paint the bounding box of the primary paintable before that paintable itself paints.

The order of painting should now be:

Of course, no painting takes place if the paintable is set to be invisible.

Finally, in 2.6.0, as a convenience, Paintable also extends the interface of constants JPTConstants.

In 2.6.0c, added the method makeSnapshot.

Since:
2.3
Version:
2.6.0c
See Also:
AbstractPaintable, SupportsPropertyChange, JPTConstants

Field Summary
static String REMOVE_PAINTABLE
          Bound property name to remove paintables.
static String SET_CLIPPING_SHAPE
          Bound property name for set clipping shape.
static String SET_DEFAULT_BOUNDS2D
          Bound property name for set default bounds2D.
static String SET_DEFAULT_CENTER
          Bound property name for set default center.
static String SET_DEFAULT_ORIGINAL_BOUNDS2D
          Bound property name for set default original bounds2D.
static String SET_DEFAULT_ORIGINAL_CENTER
          Bound property name for set default originalcenter.
static String SET_MUTATOR
          Bound property name for set mutator.
static String SET_OPACITY
          Bound property name for set opacity.
static String SET_PAINTABLE
          Bound property name for set paintables.
static String SET_VISIBLE
          Bound property name for set visible.
static String SHIFT_PAINTABLE
          Bound property name to shift paintables within a sequence.
 
Fields inherited from interface edu.neu.ccs.util.JPTConstants
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Method Summary
 void addPostMutation(AffineTransform M)
          Composes the current mutator on the left with the given transform provided that the given transform is invertible.
 void addPostMutation(Mutator.Strategy strategy)
          Applies a Mutator.Strategy object to the paintable by constructing an affine transform using the mutated center of the paintable and then calling addPostMutation with this transform as the argument.
 void addPreMutation(AffineTransform M)
          Composes the current mutator on the right with the given transform provided that the given transform is invertible and the paintable object supports this operation.
 void addPreMutation(Mutator.Strategy strategy)
          Applies a Mutator.Strategy object to the paintable by constructing an affine transform using the original center of the paintable and then calling addPreMutation with this transform as the argument.
 void affinetransform(double m00, double m10, double m01, double m11, double m02, double m12)
          Apply the affine transform given by the matrix coefficients m00, m10, m01, m11, m02, m12 as if the transform were centered at the center of the paintable.
 void applyOpacity(Graphics2D h)
          Apply the current opacity to calculate and set a net opacity for the given graphics context.
 void clearBackgroundPaint()
          Clear the background paint.
 void clearBackgroundTile()
          Clear the background tile.
 void clearBothBackgrounds()
          Clear the background paint and the background tile.
 boolean contains(double x, double y)
          Tests if a point specified by coordinates is inside the paintable.
 boolean contains(Point2D p)
          Tests if a specified point is inside the paintable.
 XRect getActualBounds2D()
          Returns the actual bounds of the original paintable or null if the paintable is effectively empty.
 Paint getBackgroundPaint()
          Returns the background paint.
 Paintable getBackgroundTile()
          Returns the background tile.
 XRect getBounds2D()
          Returns a copy of the 2-dimensional bounds of the paintable.
 XPoint2D getCenter()
          Returns a copy of the center of the paintable.
 XPoint2D getCorner()
          Returns a copy of the corner of the paintable.
 XRect getDefaultBounds2D()
          Returns a copy of the default Bounds2D rectangle, that is, the default for computation of getBounds2D.
 XPoint2D getDefaultCenter()
          Returns a copy of the default center, that is, the default for computation of getCenter.
 XRect getDefaultOriginalBounds2D()
          Returns a copy of the default original Bounds2D rectangle, that is, the default for computation of getOriginalBounds2D.
 XPoint2D getDefaultOriginalCenter()
          Returns a copy of the default original center, that is, the default for computation of getOriginalCenter.
 AffineTransform getMutator()
          Returns a copy of the existing mutator transform.
 AffineTransform getMutatorInverse()
          Returns a copy of the existing mutator inverse transform.
 float getOpacity()
          Returns the opacity value of this paintable between 0 and 1.
 XRect getOriginalBounds2D()
          Returns a copy of the 2-dimensional bounds of the original paintable prior to any mutation.
 XPoint2D getOriginalCenter()
          Returns a copy of the original center of the paint region.
 Graphics2D getPreparedGraphics2D(Graphics g)
          Returns a copy of the given graphics context after modifying the copy to clip to within the bounds region, to set anti-aliasing on, and to apply the opacity of this paintable if needed.
 void glide(double degrees, double distance)
          Glides (translates) the paintable along a glide line at the given angle in degrees and the given glide distance.
 void glidereflect(double degrees, double distance)
          Glide-reflects the paintable along the line through its center at the given angle in degrees and the given glide distance.
 void hreflect()
          Reflects the paintable along a horizontal axis through its center.
 boolean isVisible()
          Returns the current visibility property of this paintable.
 void lineartransform(double m00, double m10, double m01, double m11)
          Apply the linear transform given by the matrix coefficients m00, m10, m01, m11 as if the transform were centered at the center of the paintable.
 BufferedImage makeSnapshot()
          Constructs a BufferedImage object that is the same size as the bounding box of this paintable and then paints this paintable onto the buffered image with a suitable translation back to the origin.
 void move(double dx, double dy)
          Moves the paintable by a translation using the data in the point specified by coordinates.
 void move(Point2D p)
          Moves the paintable by a translation using the data in the point.
 void moveCenterTo(double x, double y)
          Moves the paintable by a translation in such a way that the paintable center specified by getCenter will move to the given point specified in coordinates.
 void moveCenterTo(Point2D p)
          Moves the paintable by a translation in such a way that the paintable center specified by getCenter will move to the given point.
 void moveCornerTo(double x, double y)
          Moves the paintable by a translation in such a way that the paintable corner specified by getCorner will move to the given point specified in coordinates.
 void moveCornerTo(Point2D p)
          Moves the paintable by a translation in such a way that the paintable corner specified by getCorner will move to the given point.
 void mutate(AffineTransform M)
          This method should always be implemented to do exactly the same operation as the corresponding method addPostMutation.
 void mutate(Mutator.Strategy strategy)
          This method should always be implemented to do exactly the same operation as the corresponding method addPostMutation.
 boolean originalContains(double x, double y)
          Tests if a point specified by coordinates is inside the original paintable without mutation.
 boolean originalContains(Point2D p)
          Tests if a specified point is inside the original paintable without mutation.
 void originalPaint(Graphics g)
          Paints onto a Graphics context using information from this object but without the use of the mutator transform.
 void paint(Graphics g)
          Paints onto a Graphics context using information from this object.
 void paintAsTiles(Graphics g, double w, double h)
          Repeatedly paints this object as a tile that covers the rectangle (0,0,w,h) in the graphics context g.
 void paintAsTiles(Graphics g, double x, double y, double w, double h)
          Repeatedly paints this object as a tile that covers the rectangle (x,y,w,h) in the graphics context g.
 void paintAsTiles(Graphics g, Rectangle2D rect)
          Repeatedly paints this object as a tile that covers the given rectangle in the graphics context g.
 void paintAt(Graphics g, AffineTransform T, double x, double y)
          Without changing the paintable or the graphics context, paint the paintable in a translated position specified by the point in coordinates and the affine transform T; before painting the transform T should be applied to the point.
 void paintAt(Graphics g, AffineTransform T, Point2D p)
          Without changing the paintable or the graphics context, paint the paintable in a translated position specified by the point in coordinates and the affine transform T; before painting the transform T should be applied to the point.
 void paintAt(Graphics g, double x, double y)
          Without changing the paintable or the graphics context, paint the paintable in a translated position specified by the point in coordinates.
 void paintAt(Graphics g, Point2D p)
          Without changing the paintable or the graphics context, paint the paintable in a translated position specified by the point.
 void reflect(double degrees)
          Reflects the paintable along the line through its center at the given angle in degrees.
 void rotate(double degrees)
          Rotates the paintable about its center by the given angle in degrees.
 void scale(double s)
          Scales the paintable about its center by the given factor s uniformly in all directions.
 void scale(double degrees, double s, double t)
          Scales the paintable about its center by the given factor s along the main axis at the given angle in degrees and the given factor t along the perpendicular axis.
 void setBackgroundPaint(Paint background)
          Sets the background paint.
 void setBackgroundTile(Object object)
          Sets the background tile paintable.
 void setDefaultBounds2D(Rectangle2D rectangle)
          Sets the default Bounds2D rectangle, that is, the default for computation of getBounds2D.
 void setDefaultCenter(Point2D center)
          Sets the default center, that is, the default for computation of getCenter.
 void setDefaultOriginalBounds2D(Rectangle2D rectangle)
          Sets the default original Bounds2D rectangle, that is, the default for computation of getOriginalBounds2D.
 void setDefaultOriginalCenter(Point2D center)
          Sets the default original center, that is, the default for computation of getOriginalCenter.
 void setMutator(AffineTransform M)
          Sets the mutator transform to the given transform provided that the given transform is invertible and the paintable object supports this operation.
 void setMutator(Mutator.Strategy strategy)
          Applies a Mutator.Strategy object to the paintable by constructing an affine transform using the original center of the paintable and then calling setMutation with this transform as the argument.
 void setOpacity(float opacity)
          Sets the opacity of this paintable to a value between 0 and 1.
 void setVisible(boolean visible)
          Sets the visibility property of this paintable.
 void shear(double degrees, double s)
          Shears the paintable about its center and with shear factor s along the line at the given angle in degrees.
 void vreflect()
          Reflects the paintable along a vertical axis through its center.
 
Methods inherited from interface edu.neu.ccs.gui.SupportsPropertyChange
addForwardingListener, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListeners, addPropertyChangeListeners, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getForwardingListener, getPropertyChangeListeners, getPropertyChangeListeners, hasListeners, removeAndAddForwardingListener, removeForwardingListener, removePropertyChangeListener, removePropertyChangeListener
 

Field Detail

SET_DEFAULT_BOUNDS2D

public static final String SET_DEFAULT_BOUNDS2D
Bound property name for set default bounds2D.

See Also:
Constant Field Values

SET_DEFAULT_CENTER

public static final String SET_DEFAULT_CENTER
Bound property name for set default center.

See Also:
Constant Field Values

SET_DEFAULT_ORIGINAL_BOUNDS2D

public static final String SET_DEFAULT_ORIGINAL_BOUNDS2D
Bound property name for set default original bounds2D.

See Also:
Constant Field Values

SET_DEFAULT_ORIGINAL_CENTER

public static final String SET_DEFAULT_ORIGINAL_CENTER
Bound property name for set default originalcenter.

See Also:
Constant Field Values

SET_VISIBLE

public static final String SET_VISIBLE
Bound property name for set visible.

See Also:
Constant Field Values

SET_OPACITY

public static final String SET_OPACITY
Bound property name for set opacity.

See Also:
Constant Field Values

SET_MUTATOR

public static final String SET_MUTATOR
Bound property name for set mutator.

See Also:
Constant Field Values

SET_PAINTABLE

public static final String SET_PAINTABLE
Bound property name for set paintables.

See Also:
Constant Field Values

REMOVE_PAINTABLE

public static final String REMOVE_PAINTABLE
Bound property name to remove paintables.

See Also:
Constant Field Values

SHIFT_PAINTABLE

public static final String SHIFT_PAINTABLE
Bound property name to shift paintables within a sequence.

See Also:
Constant Field Values

SET_CLIPPING_SHAPE

public static final String SET_CLIPPING_SHAPE
Bound property name for set clipping shape.

See Also:
Constant Field Values
Method Detail

paint

public void paint(Graphics g)

Paints onto a Graphics context using information from this object.

A recommended implementation should adopt the following policy:

Whatever the implementation, when this method call is complete, the internal state of g should be unchanged.

Parameters:
g - the graphics context on which to paint

paintAt

public void paintAt(Graphics g,
                    double x,
                    double y)

Without changing the paintable or the graphics context, paint the paintable in a translated position specified by the point in coordinates.

In particular, paintAt(g,0,0) should be equivalent to paint(g).

Recommendation: The paintAt methods are intended to be used if a designer wants to define a paintable at or near the origin of coordinates and then independently compute or retrieve the position at which the paintable will be painted. If the paintAt methods are used, it is recommended that the programmer avoid mutating the paintable directly since that will almost certainly lead to confusion and bugs. Either use mutation or use paintAt but not both.

Parameters:
g - the graphics context on which to paint
x - the x-translation
y - the y-translation

paintAt

public void paintAt(Graphics g,
                    Point2D p)

Without changing the paintable or the graphics context, paint the paintable in a translated position specified by the point.

Recommendation: The paintAt methods are intended to be used if a designer wants to define a paintable at or near the origin of coordinates and then independently compute or retrieve the position at which the paintable will be painted. If the paintAt methods are used, it is recommended that the programmer avoid mutating the paintable directly since that will almost certainly lead to confusion and bugs. Either use mutation or use paintAt but not both.

Parameters:
g - the graphics context on which to paint
p - the translation vector

paintAt

public void paintAt(Graphics g,
                    AffineTransform T,
                    double x,
                    double y)

Without changing the paintable or the graphics context, paint the paintable in a translated position specified by the point in coordinates and the affine transform T; before painting the transform T should be applied to the point.

The application of this facility is to apply a transform to the position of painting that should be applied to the position alone and NOT to the paintable or to the graphics context.

For example, if T is a reflection through a horizontal axis that places the origin (0,0) at the lower left of a panel, then it would probably be a very bad idea to apply the reflection to the graphics context (which turns every object upside down) or to the paintable (which turns the paintable upside down). The transform should be applied to the position alone.

Recommendation: The paintAt methods are intended to be used if a designer wants to define a paintable at or near the origin of coordinates and then independently compute or retrieve the position at which the paintable will be painted. If the paintAt methods are used, it is recommended that the programmer avoid mutating the paintable directly since that will almost certainly lead to confusion and bugs. Either use mutation or use paintAt but not both.

Parameters:
g - the graphics context on which to paint
T - the affine transform to apply to the translation point
x - the original x-translation before transformation
y - the original y-translation before transformation

paintAt

public void paintAt(Graphics g,
                    AffineTransform T,
                    Point2D p)

Without changing the paintable or the graphics context, paint the paintable in a translated position specified by the point in coordinates and the affine transform T; before painting the transform T should be applied to the point.

The application of this facility is to apply a transform to the position of painting that should be applied to the position alone and NOT to the paintable or to the graphics context.

For example, if T is a reflection through a horizontal axis that places the origin (0,0) at the lower left of a panel, then it would probably be a very bad idea to apply the reflection to the graphics context (which turns every object upside down) or to the paintable (which turns the paintable upside down). The transform should be applied to the position alone.

Recommendation: The paintAt methods are intended to be used if a designer wants to define a paintable at or near the origin of coordinates and then independently compute or retrieve the position at which the paintable will be painted. If the paintAt methods are used, it is recommended that the programmer avoid mutating the paintable directly since that will almost certainly lead to confusion and bugs. Either use mutation or use paintAt but not both.

Parameters:
g - the graphics context on which to paint
T - the affine transform to apply to the translation point
p - the original translation point before transformation

paintAsTiles

public void paintAsTiles(Graphics g,
                         double x,
                         double y,
                         double w,
                         double h)

Repeatedly paints this object as a tile that covers the rectangle (x,y,w,h) in the graphics context g. The painting is clipped to this rectangle. The graphics context is unchanged when this method is done.

This method should work appropriately if the width or height is negative.

The method should do nothing if:

Parameters:
g - the graphics context
x - the x-corner of the rectangle to tile
y - the y-corner of the rectangle to tile
w - the width of the rectangle to tile
h - the height of the rectangle to tile

paintAsTiles

public void paintAsTiles(Graphics g,
                         double w,
                         double h)

Repeatedly paints this object as a tile that covers the rectangle (0,0,w,h) in the graphics context g. The painting is clipped to this rectangle. The graphics context is unchanged when this method is done.

This method should work appropriately if the width or height is negative.

The method should do nothing if:

Parameters:
g - the graphics context
w - the width of the rectangle to tile
h - the height of the rectangle to tile

paintAsTiles

public void paintAsTiles(Graphics g,
                         Rectangle2D rect)

Repeatedly paints this object as a tile that covers the given rectangle in the graphics context g. The painting is clipped to this rectangle. The graphics context is unchanged when this method is done.

The method should do nothing if:

Parameters:
g - the graphics context
rect - the rectangle to tile

getPreparedGraphics2D

public Graphics2D getPreparedGraphics2D(Graphics g)

Returns a copy of the given graphics context after modifying the copy to clip to within the bounds region, to set anti-aliasing on, and to apply the opacity of this paintable if needed.

For convenience, the graphics context should be returned as a Graphics2D object.

It is recommended that this method be used in the implementation of the paint method.

Parameters:
g - the given graphics context to copy
Returns:
a suitably prepared copy of the given graphics context

makeSnapshot

public BufferedImage makeSnapshot()

Constructs a BufferedImage object that is the same size as the bounding box of this paintable and then paints this paintable onto the buffered image with a suitable translation back to the origin.

This method creates a snapshot of the current visual state of this paintable.

The BufferedImage returned will have size at least 1-by-1 even if this paintable has 0 width or height.


getBounds2D

public XRect getBounds2D()

Returns a copy of the 2-dimensional bounds of the paintable.

A recommended implementation should adopt the following policy:

If the value of getDefaultBounds2D is non-null, then return this value.

Otherwise, return a reasonable estimate of the bounds within computational constraints.

This method must not return null.

Returns:
a copy of the 2-dimensional bounds of the paintable

getCenter

public XPoint2D getCenter()

Returns a copy of the center of the paintable.

A recommended implementation should adopt the following policy:

If the value of getDefaultCenter is non-null, then return this value.

Otherwise, return a computed value of the center.

This method must not return null.

Returns:
a copy the center of the paintable

getCorner

public XPoint2D getCorner()

Returns a copy of the corner of the paintable.

The corner should be the top-left corner of the bounds rectangle returned by getBounds2D.

Returns:
a copy the corner of the paintable

contains

public boolean contains(double x,
                        double y)

Tests if a point specified by coordinates is inside the paintable.

Parameters:
x - the x-coordinate of the point
y - the y-coordinate of the point
Returns:
whether or not a specified point is inside the paintable

contains

public boolean contains(Point2D p)

Tests if a specified point is inside the paintable.

Parameters:
p - a specified point
Returns:
whether or not a specified point is inside the paintable

setVisible

public void setVisible(boolean visible)

Sets the visibility property of this paintable.

The default for the visibility property should be true

.

Fires property change: SET_VISIBLE.

Parameters:
visible - the visibility setting

isVisible

public boolean isVisible()
Returns the current visibility property of this paintable.


setOpacity

public void setOpacity(float opacity)

Sets the opacity of this paintable to a value between 0 and 1.

Note that an opacity of 0 will make the paintable invisible. This is not recommended. Instead use setVisible(false).

Fires property change: SET_OPACITY.

Parameters:
opacity - the opacity of this paintable

getOpacity

public float getOpacity()
Returns the opacity value of this paintable between 0 and 1.


setBackgroundPaint

public void setBackgroundPaint(Paint background)

Sets the background paint.

The paint may be set to null to eliminate background painting.

Parameters:
background - the background paint

getBackgroundPaint

public Paint getBackgroundPaint()
Returns the background paint.

Returns:
the background paint.

clearBackgroundPaint

public void clearBackgroundPaint()
Clear the background paint.


setBackgroundTile

public void setBackgroundTile(Object object)

Sets the background tile paintable. The object passed should be a paintable or be convertible to a paintable via the method ComponentFactory.makePaintable.

The object may be set to null to eliminate background tiling.

Parameters:
object - the background tile object

getBackgroundTile

public Paintable getBackgroundTile()
Returns the background tile.

Returns:
the background tile.

clearBackgroundTile

public void clearBackgroundTile()
Clear the background tile.


clearBothBackgrounds

public void clearBothBackgrounds()
Clear the background paint and the background tile.


setMutator

public void setMutator(AffineTransform M)

Sets the mutator transform to the given transform provided that the given transform is invertible and the paintable object supports this operation.

If the given transform is not invertible, the method does nothing.

Fires property change: SET_MUTATOR.

Remarks:

If the paintable object maintains a mutator object that transforms the paintable, then this method should set that mutator. Moreover, in this case, the method getMutator should return a copy of that mutator.

If the paintable object distributes mutation to internal data then this method may or may not make sense. The documentation of the implementation should state what, if anything, is done by this method. In particular, it is valid for the method getMutator to return an identity transform if no mutator is maintained explicitly.

Parameters:
M - the invertible affine transform to set as the mutator

addPreMutation

public void addPreMutation(AffineTransform M)

Composes the current mutator on the right with the given transform provided that the given transform is invertible and the paintable object supports this operation.

If the given transform is not invertible, the method does nothing.

Fires property change: SET_MUTATOR.

Remarks:

Normally, the action of the new mutator will be to apply the given transform and then to apply the old mutator.

If the paintable object distributes mutation to internal data then this method may or may not make sense. The documentation of the implementation should state what, if anything, is done by this method.

Parameters:
M - the invertible affine transform to compose

addPostMutation

public void addPostMutation(AffineTransform M)

Composes the current mutator on the left with the given transform provided that the given transform is invertible.

If the given transform is not invertible, the method does nothing.

Fires property change: SET_MUTATOR.

Remarks:

Normally, the action of the new mutator will be to apply the old mutator and then to apply the given transform.

This method should always have a meaningful interpretation for a paintable, that is, it should always be possible to apply a mutation that follows earlier mutations. If this method is implemented in a non-standard fashion, the documentation should state what is done.

Parameters:
M - the invertible affine transform to compose

setMutator

public void setMutator(Mutator.Strategy strategy)

Applies a Mutator.Strategy object to the paintable by constructing an affine transform using the original center of the paintable and then calling setMutation with this transform as the argument.

Fires property change: SET_MUTATOR.

This method may be implemented in a more sophisticated fashion if that is appropriate for a particular paintable.

Parameters:
strategy - the mutator strategy to apply

addPreMutation

public void addPreMutation(Mutator.Strategy strategy)

Applies a Mutator.Strategy object to the paintable by constructing an affine transform using the original center of the paintable and then calling addPreMutation with this transform as the argument.

Fires property change: SET_MUTATOR.

This method may be implemented in a more sophisticated fashion if that is appropriate for a particular paintable.

Parameters:
strategy - the mutator strategy to apply

addPostMutation

public void addPostMutation(Mutator.Strategy strategy)

Applies a Mutator.Strategy object to the paintable by constructing an affine transform using the mutated center of the paintable and then calling addPostMutation with this transform as the argument.

Fires property change: SET_MUTATOR.

This method may be implemented in a more sophisticated fashion if that is appropriate for a particular paintable.

Parameters:
strategy - the mutator strategy to apply

getMutator

public AffineTransform getMutator()

Returns a copy of the existing mutator transform.

If the implementation chooses to distribute transforms to sub-objects, then this method may validly always return the identity transform.

Returns:
a copy of the existing mutator transform

getMutatorInverse

public AffineTransform getMutatorInverse()

Returns a copy of the existing mutator inverse transform.

If the implementation chooses to distribute transforms to sub-objects, then this method may validly always return the identity transform.

Returns:
a copy of the existing mutator inverse transform

mutate

public void mutate(AffineTransform M)

This method should always be implemented to do exactly the same operation as the corresponding method addPostMutation. In other words, this should simply be a convenience method with a short name.

Parameters:
M - the invertible affine transform to compose
See Also:
addPostMutation(AffineTransform)

mutate

public void mutate(Mutator.Strategy strategy)

This method should always be implemented to do exactly the same operation as the corresponding method addPostMutation. In other words, this should simply be a convenience method with a short name.

Parameters:
strategy - the mutator strategy to apply
See Also:
addPostMutation(Mutator.Strategy)

move

public void move(double dx,
                 double dy)

Moves the paintable by a translation using the data in the point specified by coordinates.

Parameters:
dx - the x-coordinate of the translation
dy - the y-coordinate of the translation

move

public void move(Point2D p)

Moves the paintable by a translation using the data in the point.

Parameters:
p - the translation vector

moveCenterTo

public void moveCenterTo(double x,
                         double y)

Moves the paintable by a translation in such a way that the paintable center specified by getCenter will move to the given point specified in coordinates.

Parameters:
x - the x-coordinate of the desired center
y - the y-coordinate of the desired center

moveCenterTo

public void moveCenterTo(Point2D p)

Moves the paintable by a translation in such a way that the paintable center specified by getCenter will move to the given point.

Parameters:
p - the desired center

moveCornerTo

public void moveCornerTo(double x,
                         double y)

Moves the paintable by a translation in such a way that the paintable corner specified by getCorner will move to the given point specified in coordinates.

Parameters:
x - the x-coordinate of the desired corner
y - the y-coordinate of the desired corner

moveCornerTo

public void moveCornerTo(Point2D p)

Moves the paintable by a translation in such a way that the paintable corner specified by getCorner will move to the given point.

Parameters:
p - the desired corner

rotate

public void rotate(double degrees)

Rotates the paintable about its center by the given angle in degrees.

Parameters:
degrees - the rotation angle in degrees

reflect

public void reflect(double degrees)
Reflects the paintable along the line through its center at the given angle in degrees.

Parameters:
degrees - the angle in degrees of the line of reflection

hreflect

public void hreflect()
Reflects the paintable along a horizontal axis through its center.


vreflect

public void vreflect()
Reflects the paintable along a vertical axis through its center.


scale

public void scale(double s)

Scales the paintable about its center by the given factor s uniformly in all directions.

Parameters:
s - the scale in all directions

scale

public void scale(double degrees,
                  double s,
                  double t)

Scales the paintable about its center by the given factor s along the main axis at the given angle in degrees and the given factor t along the perpendicular axis.

Parameters:
degrees - the angle in degrees of the main scaling axis
s - the scale factor along the axis at angle degrees
t - the scale factor along the axis at angle degrees+90

shear

public void shear(double degrees,
                  double s)

Shears the paintable about its center and with shear factor s along the line at the given angle in degrees.

In the special case when the center is at (0,0) and the angle in degrees is 0, this corresponds to the transform: (u,v) maps to (u+s*v,v), which fixes the x-axis and shears parallel to that axis.

In the general case, the fixed axis for the shear is the line at the given angle degrees through the center.

Parameters:
degrees - the angle in degrees of the fixed axis for shear
s - determines the amount of shear along lines parallel to the fixed axis for shear

glide

public void glide(double degrees,
                  double distance)

Glides (translates) the paintable along a glide line at the given angle in degrees and the given glide distance.

Equivalent to specifing a translation via polar coordinates with the angle in degrees specified first and the distance specified second. The reason for specifying degrees first here is to be consistent with the usage of all other methods that have degrees as a parameter.

Parameters:
degrees - the angle in degrees of the line of glide
distance - the translation distance along the line of glide

glidereflect

public void glidereflect(double degrees,
                         double distance)
Glide-reflects the paintable along the line through its center at the given angle in degrees and the given glide distance.

Parameters:
degrees - the angle in degrees of the line of glide reflection
distance - the translation distance along the line of glide reflection

lineartransform

public void lineartransform(double m00,
                            double m10,
                            double m01,
                            double m11)

Apply the linear transform given by the matrix coefficients m00, m10, m01, m11 as if the transform were centered at the center of the paintable. In other words, before applying the given transform, adjust it so that the center of the paintable remains fixed.

Note that the two coefficients of column 0 are given first and the two coefficients of column 1 are given next.

Parameters:
m00 - the matrix coefficient in row 0 column 0
m10 - the matrix coefficient in row 1 column 0
m01 - the matrix coefficient in row 0 column 1
m11 - the matrix coefficient in row 1 column 1

affinetransform

public void affinetransform(double m00,
                            double m10,
                            double m01,
                            double m11,
                            double m02,
                            double m12)

Apply the affine transform given by the matrix coefficients m00, m10, m01, m11, m02, m12 as if the transform were centered at the center of the paintable.

Note that the two coefficients of column 0 are given first, the two coefficients of column 1 are given next, and the two coefficients of column 2 are given last.

Parameters:
m00 - the matrix coefficient in row 0 column 0
m10 - the matrix coefficient in row 1 column 0
m01 - the matrix coefficient in row 0 column 1
m11 - the matrix coefficient in row 1 column 1
m02 - the matrix coefficient in row 0 column 2
m12 - the matrix coefficient in row 1 column 2

originalPaint

public void originalPaint(Graphics g)

Paints onto a Graphics context using information from this object but without the use of the mutator transform.

This method should be the foundation for the paint methods that use the mutator.

The designer of this method should assume that issues such as visibility, opacity, clipping, antialiasing, and mutation will be taken care of by the paint methods. Therefore, this method need only paint what must be painted with no adjustments.

Whatever the implementation, when this method call is complete, the internal state of g should be unchanged.

Parameters:
g - the graphics context on which to paint

getOriginalBounds2D

public XRect getOriginalBounds2D()

Returns a copy of the 2-dimensional bounds of the original paintable prior to any mutation.

A recommended implementation should adopt the following policy:

If the value of getDefaultOriginalBounds2D is non-null, then return this value.

If the value of getActualBounds2D is non-null, then return this value.

Otherwise, return new XRect().

This method must not return null.

Returns:
a copy of the 2-dimensional bounds of the original paintable

getActualBounds2D

public XRect getActualBounds2D()

Returns the actual bounds of the original paintable or null if the paintable is effectively empty.


getOriginalCenter

public XPoint2D getOriginalCenter()

Returns a copy of the original center of the paint region.

A recommended implementation should adopt the following policy:

If the value of getDefaultOriginalCenter is non-null, then return this value.

Otherwise, return a computed value of the center.

This method must not return null.

Returns:
a copy of the center of the paint region

originalContains

public boolean originalContains(double x,
                                double y)

Tests if a point specified by coordinates is inside the original paintable without mutation.

Parameters:
x - the x-coordinate of the point
y - the y-coordinate of the point
Returns:
whether or not a specified point is inside the original paintable

originalContains

public boolean originalContains(Point2D p)

Tests if a specified point is inside the original paintable without mutation.

Parameters:
p - a specified Point2D
Returns:
whether or not a specified point is inside the original paintable

applyOpacity

public void applyOpacity(Graphics2D h)

Apply the current opacity to calculate and set a net opacity for the given graphics context.

The following conditions must hold:

In the case that the graphics context has a Composite set of type AlphaComposite with rule SRC_OVER, then the net opacity is the product of the current opacity of this object and the alpha value of the context's AlphaComposite.

Otherwise the net opacity equals the current opacity of this object.

It is recommended that this method be used in the implementation of the getPreparedGraphics2D method.

Parameters:
h - the graphics context whose opacity will be changed

setDefaultBounds2D

public void setDefaultBounds2D(Rectangle2D rectangle)

Sets the default Bounds2D rectangle, that is, the default for computation of getBounds2D.

It is valid to set the default Bounds2D rectangle to null to force a computation of the bounds. Setting the default Bounds2D rectangle to a rectangle with zero width or height should be equivalent to setting it to null.

Fires property change: SET_DEFAULT_BOUNDS2D.

Parameters:
rectangle - the default Bounds2D rectangle

getDefaultBounds2D

public XRect getDefaultBounds2D()

Returns a copy of the default Bounds2D rectangle, that is, the default for computation of getBounds2D.

Returns null to signal no setting.

Returns:
a copy of the default Bounds2D rectangle

setDefaultCenter

public void setDefaultCenter(Point2D center)

Sets the default center, that is, the default for computation of getCenter.

It is valid to set the default center to null to force a computation of the center.

Fires property change: SET_DEFAULT_CENTER.

Parameters:
center - the default center

getDefaultCenter

public XPoint2D getDefaultCenter()

Returns a copy of the default center, that is, the default for computation of getCenter.

Returns null to signal no setting.

Returns:
a copy of the default center

setDefaultOriginalBounds2D

public void setDefaultOriginalBounds2D(Rectangle2D rectangle)

Sets the default original Bounds2D rectangle, that is, the default for computation of getOriginalBounds2D.

It is valid to set the default original Bounds2D rectangle to null to force a computation of the bounds. Setting the default original Bounds2D rectangle to a rectangle with zero width or height should be equivalent to setting it to null.

Fires property change: SET_DEFAULT_ORIGINAL_BOUNDS2D.

Parameters:
rectangle - the default original Bounds2D rectangle

getDefaultOriginalBounds2D

public XRect getDefaultOriginalBounds2D()

Returns a copy of the default original Bounds2D rectangle, that is, the default for computation of getOriginalBounds2D.

Returns null to signal no setting.

Returns:
a copy of the default original Bounds2D rectangle

setDefaultOriginalCenter

public void setDefaultOriginalCenter(Point2D center)

Sets the default original center, that is, the default for computation of getOriginalCenter.

It is valid to set the default original center to null to force a computation of the center.

Fires property change: SET_DEFAULT_ORIGINAL_CENTER.

Parameters:
center - the default original center

getDefaultOriginalCenter

public XPoint2D getDefaultOriginalCenter()

Returns a copy of the default original center, that is, the default for computation of getOriginalCenter.

Returns null to signal no setting.

Returns:
a copy of the default original center