edu.neu.ccs.gui
Class ClippingWrapper

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

public class ClippingWrapper
extends AbstractPaintable

The class ClippingWrapper will wrap a Paintable and a clipping Shape to obtain a Paintable that clips the original Paintable to the Shape.

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_CLIPPING_SHAPE
          Bound property name for set paintable.
static String SET_PAINTABLE
          Bound property name for set paintable.
 
Fields inherited from class edu.neu.ccs.gui.AbstractPaintable
SET_DEFAULT_BOUNDS2D, SET_DEFAULT_CENTER, SET_OPACITY, SET_VISIBLE
 
Constructor Summary
ClippingWrapper()
          The constructor that leaves the paintable and clipping shape as null.
ClippingWrapper(Paintable paintable)
          The constructor to specify the paintable to be wrapped.
ClippingWrapper(Paintable paintable, Shape clippingshape)
          The constructor to specify the paintable to be wrapped and the clipping shape.
 
Method Summary
 boolean contains(double x, double y)
          Tests if a point specified by coordinates is inside the this object.
 Rectangle2D getBounds2D()
          Returns the bounds of the paintable based on the default settings or on more detailed computations.
 Point2D getCenter()
          If the wrapped paintable is null, this method returns new Point2D.Double().
 Shape getClippingShape()
          Returns the clipping shape.
 Paintable getPaintable()
          Returns the wrapped paintable.
 void paint(Graphics g)
          Paints onto a Graphics context by clipping the painting of the wrapped paintable to the clipping shape.
 void setClippingShape(Shape clippingshape)
          Sets the clipping shape.
 void setPaintable(Paintable paintable)
          Sets the paintable to be wrapped.
 
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
 

Field Detail

SET_PAINTABLE

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

See Also:
Constant Field Values

SET_CLIPPING_SHAPE

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

See Also:
Constant Field Values
Constructor Detail

ClippingWrapper

public ClippingWrapper()
The constructor that leaves the paintable and clipping shape as null.

See Also:
ClippingWrapper(Paintable), ClippingWrapper(Paintable, Shape)

ClippingWrapper

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

Parameters:
paintable - the paintable to be wrapped
See Also:
ClippingWrapper(), ClippingWrapper(Paintable, Shape)

ClippingWrapper

public ClippingWrapper(Paintable paintable,
                       Shape clippingshape)
The constructor to specify the paintable to be wrapped and the clipping shape.

Parameters:
paintable - the paintable to be wrapped
clippingshape - the clipping shape
See Also:
ClippingWrapper(), ClippingWrapper(Paintable)
Method Detail

paint

public final void paint(Graphics g)

Paints onto a Graphics context by clipping the painting of the wrapped paintable to the clipping shape.

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

If the clipping shape is null, no clipping will be done.

Specified by:
paint in interface Paintable
Specified by:
paint in class AbstractPaintable
Parameters:
g - the graphics context on which to paint
See Also:
AbstractPaintable.getPreparedGraphics2D(Graphics)

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)

setClippingShape

public final void setClippingShape(Shape clippingshape)

Sets the clipping shape.

The clipping shape may be set to null to eliminate special clipping of the wrapped paintable.

Fires property change: SET_CLIPPING_SHAPE.

Parameters:
clippingshape - the clipping shape
See Also:
getClippingShape()

getClippingShape

public final Shape getClippingShape()
Returns the clipping shape.

Returns:
the clipping shape
See Also:
setClippingShape(Shape)

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 wrapped paintable is null, this method returns new Rectangle2D.Double().

Otherwise, the bounds of the wrapped paintable are used before clipping. If the clipping shape is non-null, then the paintable bounds are clipped to the bounds of the clipping shape. The resulting bounds are then returned.

Specified by:
getBounds2D in interface Paintable
Specified by:
getBounds2D in class AbstractPaintable
Returns:
the bounds of this object
See Also:
AbstractPaintable.setDefaultBounds2D(Rectangle2D), AbstractPaintable.getDefaultBounds2D()

getCenter

public final Point2D getCenter()

If the wrapped 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 center of the wrapped paintable.

Specified by:
getCenter in interface Paintable
Overrides:
getCenter in class AbstractPaintable
Returns:
the center of this object
See Also:
AbstractPaintable.setDefaultCenter(Point2D), AbstractPaintable.getDefaultCenter()

contains

public final boolean contains(double x,
                              double y)

Tests if a point specified by coordinates is inside the this object.

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