edu.neu.ccs.gui
Class ShapePaintable

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

public class ShapePaintable
extends AbstractPaintable

A ShapePaintable creates an AbstractPaintable using a Shape object and other related data.

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.

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, the class was updated to be consistent with refinements to the Paintable interface.

Also, in 2.4.0, the default paint mode was changed from FILL to DRAW and the thickness for the stroke was changed to 2. The reason for this is aesthetic: when a shape is made up of disconnected sections, doing a FILL operation can produce bizarre results; therefore it seems more natural to make DRAW the default.

Finally, in 2.4.0, constructors were added to use a PathList to make a ShapePaintable.

Since:
2.3
Version:
2.4.0

Field Summary
static Paint DEFAULT_DRAWPAINT
          Default draw paint: Color.black.
static Stroke DEFAULT_DRAWSTROKE
          Default draw stroke: BasicStroke(2).
static Paint DEFAULT_FILLPAINT
          Default fill paint: Color.black.
static PaintMode DEFAULT_PAINTMODE
          Default paint mode: PaintMode.DRAW.
private  Paint drawpaint
          The draw paint.
private  Stroke drawstroke
          The draw stroke.
private  Paint fillpaint
          The fill paint.
private  PaintMode paintmode
          The paint mode.
static String SET_DRAW_PAINT
          Bound property name for set draw paint.
static String SET_DRAW_STROKE
          Bound property name for set draw stroke.
static String SET_FILL_PAINT
          Bound property name for set fill paint.
static String SET_PAINT_MODE
          Bound property name for set paint mode.
static String SET_SHAPE
          Bound property name for set shape.
private  Shape shape
          The shape.
 
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
ShapePaintable()
          The default constructor.
ShapePaintable(PathList pathlist)
          The constructor to specify the shape via a path list.
ShapePaintable(PathList pathlist, PaintMode paintmode)
          The constructor to specify the shape via a path list and the paint mode.
ShapePaintable(PathList pathlist, PaintMode paintmode, Paint fillpaint)
          The constructor to specify the shape via a path list, the paint mode, and the fill paint.
ShapePaintable(PathList pathlist, PaintMode paintmode, Paint fillpaint, Paint drawpaint)
          The constructor to specify the shape via a path list, the paint mode, the fill paint, and the draw paint.
ShapePaintable(PathList pathlist, PaintMode paintmode, Paint fillpaint, Paint drawpaint, Stroke drawstroke)
          The constructor to specify the shape via a path list, the paint mode, the fill paint, the draw paint, and the drawstroke.
ShapePaintable(Shape shape)
          The constructor to specify the shape.
ShapePaintable(Shape shape, PaintMode paintmode)
          The constructor to specify the shape and the paint mode.
ShapePaintable(Shape shape, PaintMode paintmode, Paint fillpaint)
          The constructor to specify the shape, the paint mode, and the fill paint.
ShapePaintable(Shape shape, PaintMode paintmode, Paint fillpaint, Paint drawpaint)
          The constructor to specify the shape, the paint mode, the fill paint, and the draw paint.
ShapePaintable(Shape shape, PaintMode paintmode, Paint fillpaint, Paint drawpaint, Stroke drawstroke)
          The constructor to specify the shape, the paint mode, the fill paint, the draw paint, and the drawstroke.
 
Method Summary
 XRect getActualBounds2D()
          Returns the actual bounds of the original paintable or null if the paintable is effectively empty.
 Paint getDrawPaint()
          Returns the draw paint.
 Stroke getDrawStroke()
          Return the draw stroke.
 Paint getFillPaint()
          Returns the fill paint.
 Shape getOutline()
          Returns the Shape that represents the outline of the rendered paint region taking into account the PaintMode.
 PaintMode getPaintMode()
          Returns the paint mode.
 Shape getShape()
          Returns the shape of the paintable.
 Shape getStrokedShape()
          Returns the shape of the stroked boundary taking into account the shape of the paintable and the draw stroke.
 boolean originalContains(double x, double y)
          Tests if a point specified by coordinates 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 setDrawMode()
          Sets the paint mode to draw the shape.
 void setDrawPaint(Paint drawpaint)
          Sets the draw paint.
 void setDrawStroke(Stroke drawstroke)
          Sets the draw stroke.
 void setFillDrawMode()
          Sets the paint mode to fill and draw the shape.
 void setFillMode()
          Sets the paint mode to fill the shape.
 void setFillPaint(Paint fillpaint)
          Sets the fill paint.
 void setPaintMode(PaintMode paintmode)
          Sets the paint mode.
 void setShape(Shape shape)
          Sets the shape of the paintable.
 
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

DEFAULT_PAINTMODE

public static final PaintMode DEFAULT_PAINTMODE
Default paint mode: PaintMode.DRAW.


DEFAULT_FILLPAINT

public static final Paint DEFAULT_FILLPAINT
Default fill paint: Color.black.


DEFAULT_DRAWPAINT

public static final Paint DEFAULT_DRAWPAINT
Default draw paint: Color.black.


DEFAULT_DRAWSTROKE

public static final Stroke DEFAULT_DRAWSTROKE
Default draw stroke: BasicStroke(2).


SET_SHAPE

public static final String SET_SHAPE
Bound property name for set shape.

See Also:
Constant Field Values

SET_PAINT_MODE

public static final String SET_PAINT_MODE
Bound property name for set paint mode.

See Also:
Constant Field Values

SET_FILL_PAINT

public static final String SET_FILL_PAINT
Bound property name for set fill paint.

See Also:
Constant Field Values

SET_DRAW_PAINT

public static final String SET_DRAW_PAINT
Bound property name for set draw paint.

See Also:
Constant Field Values

SET_DRAW_STROKE

public static final String SET_DRAW_STROKE
Bound property name for set draw stroke.

See Also:
Constant Field Values

shape

private Shape shape
The shape.


paintmode

private PaintMode paintmode
The paint mode.


fillpaint

private Paint fillpaint
The fill paint.


drawpaint

private Paint drawpaint
The draw paint.


drawstroke

private Stroke drawstroke
The draw stroke.

Constructor Detail

ShapePaintable

public ShapePaintable()

The default constructor.

Default settings:

Other constructors using Shape:

There are a similar set of constructors using PathList.


ShapePaintable

public ShapePaintable(Shape shape)

The constructor to specify the shape.

Parameters:
shape - the shape to paint

ShapePaintable

public ShapePaintable(Shape shape,
                      PaintMode paintmode)

The constructor to specify the shape and the paint mode.

Any null parameters are ignored.

Parameters:
shape - the shape to paint
paintmode - the paint mode

ShapePaintable

public ShapePaintable(Shape shape,
                      PaintMode paintmode,
                      Paint fillpaint)

The constructor to specify the shape, the paint mode, and the fill paint.

Any null parameters are ignored.

Parameters:
shape - the shape to paint
paintmode - the paint mode
fillpaint - the paint to use for filling

ShapePaintable

public ShapePaintable(Shape shape,
                      PaintMode paintmode,
                      Paint fillpaint,
                      Paint drawpaint)

The constructor to specify the shape, the paint mode, the fill paint, and the draw paint.

Any null parameters are ignored.

Parameters:
shape - the shape to paint
paintmode - the paint mode
fillpaint - the paint to use for filling
drawpaint - the paint to use for drawing

ShapePaintable

public ShapePaintable(Shape shape,
                      PaintMode paintmode,
                      Paint fillpaint,
                      Paint drawpaint,
                      Stroke drawstroke)

The constructor to specify the shape, the paint mode, the fill paint, the draw paint, and the drawstroke.

Any null parameters are ignored.

Parameters:
shape - the shape to paint
paintmode - the paint mode
fillpaint - the paint to use for filling
drawpaint - the paint to use for drawing
drawstroke - the stroke to use for drawing

ShapePaintable

public ShapePaintable(PathList pathlist)

The constructor to specify the shape via a path list.

Parameters:
pathlist - the pathlist to make the shape to paint

ShapePaintable

public ShapePaintable(PathList pathlist,
                      PaintMode paintmode)

The constructor to specify the shape via a path list and the paint mode.

Any null parameters are ignored.

Parameters:
pathlist - the pathlist to make the shape to paint
paintmode - the paint mode

ShapePaintable

public ShapePaintable(PathList pathlist,
                      PaintMode paintmode,
                      Paint fillpaint)

The constructor to specify the shape via a path list, the paint mode, and the fill paint.

Any null parameters are ignored.

Parameters:
pathlist - the pathlist to make the shape to paint
paintmode - the paint mode
fillpaint - the paint to use for filling

ShapePaintable

public ShapePaintable(PathList pathlist,
                      PaintMode paintmode,
                      Paint fillpaint,
                      Paint drawpaint)

The constructor to specify the shape via a path list, the paint mode, the fill paint, and the draw paint.

Any null parameters are ignored.

Parameters:
pathlist - the pathlist to make the shape to paint
paintmode - the paint mode
fillpaint - the paint to use for filling
drawpaint - the paint to use for drawing

ShapePaintable

public ShapePaintable(PathList pathlist,
                      PaintMode paintmode,
                      Paint fillpaint,
                      Paint drawpaint,
                      Stroke drawstroke)

The constructor to specify the shape via a path list, the paint mode, the fill paint, the draw paint, and the drawstroke.

Any null parameters are ignored.

Parameters:
pathlist - the pathlist to make the shape to paint
paintmode - the paint mode
fillpaint - the paint to use for filling
drawpaint - the paint to use for drawing
drawstroke - the stroke to use for drawing
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 current shape or the graphics context is null, this method will not paint.

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 original paintable or null if the paintable is effectively empty.

Specified by:
getActualBounds2D in interface Paintable
Specified by:
getActualBounds2D in class AbstractPaintable

originalContains

public final boolean originalContains(double x,
                                      double y)

Tests if a point specified by coordinates is inside the original 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 original paintable

setShape

public final void setShape(Shape shape)

Sets the shape of the paintable.

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

Fires property change: SET_SHAPE.

Parameters:
shape - the shape to paint

getShape

public final Shape getShape()
Returns the shape of the paintable.

Returns:
the shape

getStrokedShape

public final Shape getStrokedShape()

Returns the shape of the stroked boundary taking into account the shape of the paintable and the draw stroke.

If getShape returns null, then this method returns null also.

Returns:
the stroked shape

getOutline

public Shape getOutline()

Returns the Shape that represents the outline of the rendered paint region taking into account the PaintMode.

The following notes describe the behavior of this method in the case of the paint modes defined in class PaintMode.

If the PaintMode is FILL then returns the same shape as getShape.

If the PaintMode is DRAW then returns the same shape as getStrokedShape.

If the PaintMode is FILL_DRAW then returns the union of the shapes returned by getShape and getStrokedShape.

Returns:
the rendered paint region

setFillPaint

public final void setFillPaint(Paint fillpaint)

Sets the fill paint.

A null parameter is ignored.

Fires property change: SET_FILL_PAINT.

Parameters:
fillpaint - the paint to use for filling

getFillPaint

public final Paint getFillPaint()
Returns the fill paint.

Returns:
the fill paint

setDrawPaint

public final void setDrawPaint(Paint drawpaint)

Sets the draw paint.

A null parameter is ignored.

Fires property change: SET_DRAW_PAINT.

Parameters:
drawpaint - the paint to use for drawing

getDrawPaint

public final Paint getDrawPaint()
Returns the draw paint.

Returns:
the draw paint

setDrawStroke

public final void setDrawStroke(Stroke drawstroke)

Sets the draw stroke.

A null parameter is ignored.

Fires property change: SET_DRAW_STROKE.

Parameters:
drawstroke - the stroke to use for drawing

getDrawStroke

public final Stroke getDrawStroke()
Return the draw stroke.


setPaintMode

public final void setPaintMode(PaintMode paintmode)

Sets the paint mode.

A null parameter is ignored.

Fires property change: SET_PAINT_MODE.

Parameters:
paintmode - the paint mode

getPaintMode

public final PaintMode getPaintMode()
Returns the paint mode.

Returns:
the paint mode

setFillMode

public final void setFillMode()

Sets the paint mode to fill the shape.

Fires property change: SET_PAINT_MODE.


setDrawMode

public final void setDrawMode()

Sets the paint mode to draw the shape.

Fires property change: SET_PAINT_MODE.


setFillDrawMode

public final void setFillDrawMode()

Sets the paint mode to fill and draw the shape.

Fires property change: SET_PAINT_MODE.