edu.neu.ccs.gui
Class ShapePaintable

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

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.

Since:
2.3

Field Summary
static Paint DEFAULT_DRAWPAINT
          Default draw paint: Color.black.
static Stroke DEFAULT_DRAWSTROKE
          Default draw stroke: BasicStroke(1).
static Paint DEFAULT_FILLPAINT
          Default fill paint: Color.black.
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.
 
Fields inherited from class edu.neu.ccs.gui.AbstractPaintable
SET_DEFAULT_BOUNDS2D, SET_DEFAULT_CENTER, SET_OPACITY, SET_VISIBLE
 
Constructor Summary
ShapePaintable()
          The default constructor.
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
 boolean contains(double x, double y)
          Tests if a point specified by coordinates is inside the paintable.
 Rectangle2D getBounds2D()
          Returns the bounds of the paintable based on the default settings or on more detailed computations.
 Point2D getCenter()
          If the current shape is null, this method returns new Point2D.Double().
 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.
 void paint(Graphics g)
          Paints onto a Graphics context using information from this object.
 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, 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

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(1).


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
Constructor Detail

ShapePaintable

public ShapePaintable()

The default constructor.

Default settings:

  • Shape: null
  • Paint Mode: FILL
  • Fill Color: Color.black
  • Draw Color: Color.black
  • Draw Stroke: BasicStroke(1)

See Also:
ShapePaintable(Shape), ShapePaintable(Shape, PaintMode), ShapePaintable(Shape, PaintMode, Paint), ShapePaintable(Shape, PaintMode, Paint, Paint), ShapePaintable(Shape, PaintMode, Paint, Paint, Stroke)

ShapePaintable

public ShapePaintable(Shape shape)

The constructor to specify the shape.

Parameters:
shape - the shape to paint
See Also:
ShapePaintable(), ShapePaintable(Shape, PaintMode), ShapePaintable(Shape, PaintMode, Paint), ShapePaintable(Shape, PaintMode, Paint, Paint), ShapePaintable(Shape, PaintMode, Paint, Paint, Stroke)

ShapePaintable

public ShapePaintable(Shape shape,
                      PaintMode paintmode)

The constructor to specify the shape and the paint mode.

Any null parameters other than shape are ignored.

Parameters:
shape - the shape to paint
paintmode - the paint mode
See Also:
ShapePaintable(), ShapePaintable(Shape), ShapePaintable(Shape, PaintMode, Paint), ShapePaintable(Shape, PaintMode, Paint, Paint), ShapePaintable(Shape, PaintMode, Paint, Paint, Stroke)

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 other than shape are ignored.

Parameters:
shape - the shape to paint
paintmode - the paint mode
fillpaint - the paint to use for filling
See Also:
ShapePaintable(), ShapePaintable(Shape), ShapePaintable(Shape, PaintMode), ShapePaintable(Shape, PaintMode, Paint, Paint), ShapePaintable(Shape, PaintMode, Paint, Paint, Stroke)

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 other than shape 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
See Also:
ShapePaintable(), ShapePaintable(Shape), ShapePaintable(Shape, PaintMode), ShapePaintable(Shape, PaintMode, Paint), ShapePaintable(Shape, PaintMode, Paint, Paint, Stroke)

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 other than shape 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
See Also:
ShapePaintable(), ShapePaintable(Shape), ShapePaintable(Shape, PaintMode), ShapePaintable(Shape, PaintMode, Paint), ShapePaintable(Shape, PaintMode, Paint, Paint)
Method Detail

paint

public final void paint(Graphics g)

Paints onto a Graphics context using information from this object.

If the current shape or the graphics context 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
See Also:
AbstractPaintable.getPreparedGraphics2D(Graphics)

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 shape is null or has zero width or height, this method returns new Rectangle2D.Double().

Otherwise, this method computes the 2-dimensional bounds of the paint region affected by the paint method and returns this rectangle.

Specified by:
getBounds2D in interface Paintable
Specified by:
getBounds2D in class AbstractPaintable
Returns:
the 2-dimensional bounds of the paint region
See Also:
AbstractPaintable.getBounds2D(), AbstractPaintable.setDefaultBounds2D(Rectangle2D), AbstractPaintable.getDefaultBounds2D()

getCenter

public final Point2D getCenter()

If the current shape 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 AbstractPaintable
Returns:
a copy of the center of the paint region
See Also:
AbstractPaintable.getCenter(), AbstractPaintable.setDefaultCenter(Point2D), AbstractPaintable.getDefaultCenter()

contains

public final boolean contains(double x,
                              double y)

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

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
See Also:
getShape(), getStrokedShape(), getOutline()

getShape

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

Returns:
the shape
See Also:
setShape(Shape), getStrokedShape(), getOutline()

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
See Also:
setShape(Shape), getShape(), getOutline()

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
See Also:
setShape(Shape), getShape(), getStrokedShape()

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
See Also:
getFillPaint()

getFillPaint

public final Paint getFillPaint()
Returns the fill paint.

Returns:
the fill paint
See Also:
setFillPaint(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
See Also:
getDrawPaint()

getDrawPaint

public final Paint getDrawPaint()
Returns the draw paint.

Returns:
the draw paint
See Also:
setDrawPaint(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
See Also:
getDrawStroke()

getDrawStroke

public final Stroke getDrawStroke()
Return the draw stroke.

See Also:
setDrawStroke(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
See Also:
getPaintMode(), setFillMode(), setDrawMode(), setFillDrawMode()

getPaintMode

public final PaintMode getPaintMode()
Returns the paint mode.

Returns:
the paint mode
See Also:
setPaintMode(PaintMode), setFillMode(), setDrawMode(), setFillDrawMode()

setFillMode

public final void setFillMode()

Sets the paint mode to fill the shape.

Fires property change: SET_PAINT_MODE.

See Also:
setPaintMode(PaintMode), getPaintMode(), setDrawMode(), setFillDrawMode()

setDrawMode

public final void setDrawMode()

Sets the paint mode to draw the shape.

Fires property change: SET_PAINT_MODE.

See Also:
setPaintMode(PaintMode), getPaintMode(), setFillMode(), setFillDrawMode()

setFillDrawMode

public final void setFillDrawMode()

Sets the paint mode to fill and draw the shape.

Fires property change: SET_PAINT_MODE.

See Also:
setPaintMode(PaintMode), getPaintMode(), setFillMode(), setDrawMode()