edu.neu.ccs.gui
Class MutatableWrapper

java.lang.Object
  |
  +--edu.neu.ccs.gui.AbstractPaintable
        |
        +--edu.neu.ccs.gui.AbstractMutatablePaintable
              |
              +--edu.neu.ccs.gui.MutatableWrapper
All Implemented Interfaces:
MutatablePaintable, Paintable, SupportsPropertyChange

public class MutatableWrapper
extends AbstractMutatablePaintable

The class MutatableWrapper will wrap a Paintable object to obtain an object that implements MutatablePaintable and SupportsPropertyChange.

In 2.3.2, the method getBounds2D was modified to use the default Bounds2D rectangle if that rectangle is non-null before making any other tests or computations.

Since:
2.3

Field Summary
static String SET_PAINTABLE
          Bound property name for set paintable.
 
Fields inherited from class edu.neu.ccs.gui.AbstractMutatablePaintable
SET_MUTATOR
 
Fields inherited from class edu.neu.ccs.gui.AbstractPaintable
SET_DEFAULT_BOUNDS2D, SET_DEFAULT_CENTER, SET_OPACITY, SET_VISIBLE
 
Constructor Summary
MutatableWrapper()
          The constructor that leaves the paintable unspecified.
MutatableWrapper(Paintable paintable)
          The constructor to specify the paintable to be wrapped.
MutatableWrapper(Paintable paintable, AffineTransform mutator)
          The constructor to specify the paintable to be wrapped and the initial mutator.
 
Method Summary
 void addPostMutation(Mutator.Strategy strategy)
          Applies a Mutator.Strategy object to the paintable by composition on the left using the mutated center to construct the post-mutation.
 void addPreMutation(Mutator.Strategy strategy)
          Applies a Mutator.Strategy object to the paintable by composition on the right using the original center to construct the pre-mutation.
 boolean contains(double x, double y)
          Tests if a point specified by coordinates is inside the mutated paintable.
 Rectangle2D getBounds2D()
          Returns the bounds of the paintable based on the default settings or on more detailed computations.
 Point2D getCenter()
          If the current paintable is null, this method returns new Point2D.Double().
 Rectangle2D getOriginalBounds2D()
          If the current paintable is null, this method returns new Rectangle2D.Double().
 Point2D getOriginalCenter()
          If the current paintable is null, this method returns new Point2D.Double().
 Paintable getPaintable()
          Returns the wrapped paintable.
 void paint(Graphics g)
          Paints onto a Graphics context using information from the wrapped paintable and from the mutator.
 void setPaintable(Paintable paintable)
          Sets the paintable to be wrapped.
 
Methods inherited from class edu.neu.ccs.gui.AbstractMutatablePaintable
addPostMutation, addPreMutation, getMutator, getMutatorInverse, move, move, setMutator
 
Methods inherited from class edu.neu.ccs.gui.AbstractPaintable
addForwardingListener, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListeners, addPropertyChangeListeners, applyOpacity, contains, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getDefaultBounds2D, getDefaultCenter, getForwardingListener, getOpacity, getPreparedGraphics2D, getPropertyChangeListeners, getPropertyChangeListeners, hasListeners, isVisible, possiblyContains, removeAndAddForwardingListener, removeForwardingListener, removePropertyChangeListener, removePropertyChangeListener, setDefaultBounds2D, setDefaultCenter, setOpacity, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.neu.ccs.gui.Paintable
contains, getOpacity, getPreparedGraphics2D, isVisible, setOpacity, setVisible
 

Field Detail

SET_PAINTABLE

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

See Also:
Constant Field Values
Constructor Detail

MutatableWrapper

public MutatableWrapper()
The constructor that leaves the paintable unspecified.

See Also:
MutatableWrapper(Paintable), MutatableWrapper(Paintable, AffineTransform)

MutatableWrapper

public MutatableWrapper(Paintable paintable)
The constructor to specify the paintable to be wrapped.

Parameters:
paintable - the paintable to be wrapped
See Also:
MutatableWrapper(), MutatableWrapper(Paintable, AffineTransform)

MutatableWrapper

public MutatableWrapper(Paintable paintable,
                        AffineTransform mutator)
The constructor to specify the paintable to be wrapped and the initial mutator.

Parameters:
paintable - the paintable to be wrapped
mutator - the initial mutator
See Also:
MutatableWrapper(), MutatableWrapper(Paintable)
Method Detail

paint

public final void paint(Graphics g)

Paints onto a Graphics context using information from the wrapped paintable and from the mutator.

If the current paintable is null, this method will not paint.

Specified by:
paint in interface Paintable
Specified by:
paint in class AbstractPaintable
Parameters:
g - the graphics context on which to paint

setPaintable

public final void setPaintable(Paintable paintable)

Sets the paintable to be wrapped.

The paintable may be set to null to eliminate the paintable. This object will then paint nothing.

Fires property change: SET_PAINTABLE.

Parameters:
paintable - the paintable to be wrapped
See Also:
getPaintable()

getPaintable

public final Paintable getPaintable()
Returns the wrapped paintable.

Returns:
the wrapped paintable
See Also:
setPaintable(Paintable)

getBounds2D

public final Rectangle2D getBounds2D()

Returns the bounds of the paintable based on the default settings or on more detailed computations.

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

Otherwise, if the current paintable is null, this method returns new Rectangle2D.Double().

Otherwise, this method returns the value computed by the method inherited from its superclass.

Specified by:
getBounds2D in interface Paintable
Overrides:
getBounds2D in class AbstractMutatablePaintable
Returns:
a copy of the 2-dimensional bounds of the mutated paintable
See Also:
AbstractMutatablePaintable.getBounds2D(), getOriginalBounds2D(), AbstractPaintable.setDefaultBounds2D(Rectangle2D), AbstractPaintable.getDefaultBounds2D()

getCenter

public final Point2D getCenter()

If the current paintable is null, this method returns new Point2D.Double().

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

Otherwise, this method returns the value computed by the method inherited from its superclass.

Specified by:
getCenter in interface Paintable
Overrides:
getCenter in class AbstractMutatablePaintable
Returns:
a copy the center of the mutated paintable
See Also:
AbstractMutatablePaintable.getCenter(), getOriginalCenter(), AbstractPaintable.setDefaultCenter(Point2D), AbstractPaintable.getDefaultCenter()

getOriginalBounds2D

public final Rectangle2D getOriginalBounds2D()

If the current paintable is null, this method returns new Rectangle2D.Double().

Otherwise, returns a copy of the 2-dimensional bounds of the original paintable.

Specified by:
getOriginalBounds2D in interface MutatablePaintable
Specified by:
getOriginalBounds2D in class AbstractMutatablePaintable
Returns:
a copy of the 2-dimensional bounds of the original paintable
See Also:
AbstractMutatablePaintable.getBounds2D()

getOriginalCenter

public final Point2D getOriginalCenter()

If the current paintable is null, this method returns new Point2D.Double().

Otherwise, returns a copy the center of the original paintable.

Specified by:
getOriginalCenter in interface MutatablePaintable
Specified by:
getOriginalCenter in class AbstractMutatablePaintable
Returns:
a copy the center of the original paintable
See Also:
AbstractMutatablePaintable.getCenter()

addPreMutation

public final void addPreMutation(Mutator.Strategy strategy)

Applies a Mutator.Strategy object to the paintable by composition on the right using the original center to construct the pre-mutation.

If the current paintable is null, this method does nothing.

Fires property change: SET_MUTATOR.

Specified by:
addPreMutation in interface MutatablePaintable
Overrides:
addPreMutation in class AbstractMutatablePaintable
Parameters:
strategy - the mutator strategy to apply
See Also:
AbstractMutatablePaintable.setMutator(AffineTransform), AbstractMutatablePaintable.addPostMutation(AffineTransform), AbstractMutatablePaintable.getMutator()

addPostMutation

public final void addPostMutation(Mutator.Strategy strategy)

Applies a Mutator.Strategy object to the paintable by composition on the left using the mutated center to construct the post-mutation.

If the current paintable is null, this method does nothing.

Fires property change: SET_MUTATOR.

Specified by:
addPostMutation in interface MutatablePaintable
Overrides:
addPostMutation in class AbstractMutatablePaintable
Parameters:
strategy - the mutator strategy to apply
See Also:
AbstractMutatablePaintable.setMutator(AffineTransform), AbstractMutatablePaintable.addPreMutation(AffineTransform), AbstractMutatablePaintable.getMutator()

contains

public final boolean contains(double x,
                              double y)

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

This method returns false if one or more of the following conditions occurs:

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