edu.neu.ccs.gui
Class ClippingWrapper

java.lang.Object
  extended byedu.neu.ccs.gui.AbstractPaintable
      extended byedu.neu.ccs.gui.ClippingWrapper
All Implemented Interfaces:
JPTConstants, Paintable, SupportsPropertyChange, SwingConstants

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.5, the class was refactored to be consistent with the new Paintable interface and the new AbstractPaintable class.

In 2.4.0, this class was updated to be consistent with refinements to the Paintable interface.

Since:
2.3
Version:
2.4.0

Field Summary
private  Shape clippingshape
          The clipping shape.
private  Paintable paintable
          The wrapped paintable.
 
Fields inherited from class edu.neu.ccs.gui.AbstractPaintable
SET_BACKGROUND_PAINT, SET_BACKGROUND_TILE
 
Fields inherited from interface edu.neu.ccs.gui.Paintable
REMOVE_PAINTABLE, SET_CLIPPING_SHAPE, SET_DEFAULT_BOUNDS2D, SET_DEFAULT_CENTER, SET_DEFAULT_ORIGINAL_BOUNDS2D, SET_DEFAULT_ORIGINAL_CENTER, SET_MUTATOR, SET_OPACITY, SET_PAINTABLE, SET_VISIBLE, SHIFT_PAINTABLE
 
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
 
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
 XRect getActualBounds2D()
          Returns the actual bounds of the clipped paintable or null if the result is effectively empty.
 Shape getClippingShape()
          Returns the clipping shape.
 Paintable getPaintable()
          Returns the wrapped paintable.
 boolean originalContains(double x, double y)
          Tests if a point specified by coordinates is inside the clipped 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 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, addPostMutation, addPostMutation, addPreMutation, addPreMutation, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListeners, addPropertyChangeListeners, affinetransform, applyOpacity, clearBackgroundPaint, clearBackgroundTile, clearBothBackgrounds, contains, contains, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackgroundPaint, getBackgroundTile, getBounds2D, getCenter, getCorner, getDefaultBounds2D, getDefaultCenter, getDefaultOriginalBounds2D, getDefaultOriginalCenter, getForwardingListener, getMutator, getMutatorInverse, getOpacity, getOriginalBounds2D, getOriginalCenter, getPreparedGraphics2D, getPropertyChangeListeners, getPropertyChangeListeners, glide, glidereflect, hasListeners, hreflect, isVisible, lineartransform, makeSnapshot, move, move, moveCenterTo, moveCenterTo, moveCornerTo, moveCornerTo, mutate, mutate, originalContains, paint, paintAsTiles, paintAsTiles, paintAsTiles, paintAt, paintAt, paintAt, paintAt, possiblyContains, reflect, removeAndAddForwardingListener, removeForwardingListener, removePropertyChangeListener, removePropertyChangeListener, rotate, scale, scale, setBackgroundPaint, setBackgroundTile, setDefaultBounds2D, setDefaultCenter, setDefaultOriginalBounds2D, setDefaultOriginalCenter, setMutator, setMutator, setOpacity, setVisible, shear, vreflect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

paintable

private Paintable paintable
The wrapped paintable.


clippingshape

private Shape clippingshape
The clipping shape.

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

originalPaint

public final void originalPaint(Graphics g)

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

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

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

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

getActualBounds2D

public final XRect getActualBounds2D()

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

Since the internal paintable may have a mutation or defaults this method calls getBounds2D on the internal paintable. Hence any mutation or defaults set for the internal paintable are respected.

Then, if the clipping shape is non-null, its bounds are intersected with the paintable bounds. If the resulting bounds are non-trivial, they are returned. Otherwise, null is returned.

Specified by:
getActualBounds2D in interface Paintable
Specified by:
getActualBounds2D in class AbstractPaintable
Returns:
a copy of the 2-dimensional bounds of the original paintable clipped to the wrapper
See Also:
AbstractPaintable.getBounds2D()

originalContains

public final boolean originalContains(double x,
                                      double y)

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

Specified by:
originalContains in interface Paintable
Specified by:
originalContains in class AbstractPaintable
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 clipped paintable

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)