edu.neu.ccs.gui
Class AbstractPaintable

java.lang.Object
  |
  +--edu.neu.ccs.gui.AbstractPaintable
All Implemented Interfaces:
Paintable, SupportsPropertyChange
Direct Known Subclasses:
AbstractMutatablePaintable, ClippingWrapper, ImagePaintable, ImagePaintableLite, ShapePaintable, TextPaintable

public abstract class AbstractPaintable
extends Object
implements Paintable, SupportsPropertyChange

The abstract class AbstractPaintable defines objects that implement Paintable and SupportsPropertyChange.

Since:
2.3

Field Summary
static String SET_DEFAULT_BOUNDS2D
          Bound property name for set default bounds2D.
static String SET_DEFAULT_CENTER
          Bound property name for set default center.
static String SET_OPACITY
          Bound property name for set opacity.
static String SET_VISIBLE
          Bound property name for set visible.
 
Constructor Summary
AbstractPaintable()
           
 
Method Summary
 void addForwardingListener(Object object)
          Add the forwarding listener as a property change listener for the given object if the object supports property change.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list.
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list for a specific property.
 void addPropertyChangeListeners(PropertyChangeListener[] listeners)
          Add all items in the given PropertyChangeListener array to the listener list.
 void addPropertyChangeListeners(String propertyName, PropertyChangeListener[] listeners)
          Add all items in the given PropertyChangeListener array to the listener list for a specific property.
 void applyOpacity(Graphics2D h)
          Applies the current opacity to calculate and set a net opacity.
 boolean contains(Point2D p)
          Tests if a specified point is inside the paintable.
 void firePropertyChange(PropertyChangeEvent evt)
          Fire an existing PropertyChangeEvent to any registered listeners.
 void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, byte oldValue, byte newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, char oldValue, char newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, double oldValue, double newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, float oldValue, float newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, int oldValue, int newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, long oldValue, long newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, Object oldValue, Object newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, short oldValue, short newValue)
          Report a bound property update to any registered listeners.
abstract  Rectangle2D getBounds2D()
          Returns a copy of the 2-dimensional bounds of the paint region affected by the paint method.
 Point2D getCenter()
          Returns a copy of the center of the paint region.
 Rectangle2D getDefaultBounds2D()
          Returns a copy of the default Bounds2D rectangle.
 Point2D getDefaultCenter()
          Returns a copy of the default center.
 PropertyChangeForwardingListener getForwardingListener()
          Returns the PropertyChangeForwardingListener that will forward the property change events it receives to this object.
 float getOpacity()
          Returns the opacity value of this paintable between 0 and 1.
 Graphics2D getPreparedGraphics2D(Graphics g)
          Returns a copy of the given graphics context after modifying the copy to set anti-aliasing on, to clip to within the bounds region, and to apply the opacity of this paintable if needed.
 PropertyChangeListener[] getPropertyChangeListeners()
          Returns an array of all listeners that were added to this object.
 PropertyChangeListener[] getPropertyChangeListeners(String propertyName)
          Returns an array of all listeners that were added to this object and associated with the named property.
 boolean hasListeners(String propertyName)
          Check if there are any listeners for a specific property.
 boolean isVisible()
          Returns the current visibility property of this paintable.
abstract  void paint(Graphics g)
          Paints onto a Graphics context using information from this object.
protected  boolean possiblyContains(double x, double y)
          Tests if a point specified by coordinates is possibly inside the paintable.
 void removeAndAddForwardingListener(Object oldobject, Object newobject)
          Remove the forwarding listener as a property change listener for the old object if the old object supports property change and add the forwarding listener as a property change listener for the new object if the new object supports property change.
 void removeForwardingListener(Object object)
          Remove the forwarding listener as a property change listener for the given object if the object supports property change.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Remove a PropertyChangeListener from the listener list.
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Remove a PropertyChangeListener for a specific property.
 void setDefaultBounds2D(Rectangle2D rectangle)
          Sets the default Bounds2D rectangle.
 void setDefaultCenter(Point2D center)
          Sets the default center.
 void setOpacity(float opacity)
          Sets the opacity of this paintable to a value between 0 and 1.
 void setVisible(boolean visible)
          Sets the visibility property of this paintable.
 
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
 

Field Detail

SET_DEFAULT_BOUNDS2D

public static final String SET_DEFAULT_BOUNDS2D
Bound property name for set default bounds2D.

See Also:
Constant Field Values

SET_DEFAULT_CENTER

public static final String SET_DEFAULT_CENTER
Bound property name for set default center.

See Also:
Constant Field Values

SET_VISIBLE

public static final String SET_VISIBLE
Bound property name for set visible.

See Also:
Constant Field Values

SET_OPACITY

public static final String SET_OPACITY
Bound property name for set opacity.

See Also:
Constant Field Values
Constructor Detail

AbstractPaintable

public AbstractPaintable()
Method Detail

paint

public abstract void paint(Graphics g)

Paints onto a Graphics context using information from this object.

When this method call is complete, the internal state of g should be unchanged.

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

getBounds2D

public abstract Rectangle2D getBounds2D()

Returns a copy of the 2-dimensional bounds of the paint region affected by the paint method.

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

getCenter

public Point2D getCenter()

Returns a copy of the center of the paint region.

In this class, the method is implemented to return the center of the rectangle returned by the method getBounds2D.

However, a derived class may override this method if the object geometry suggests a different result.

Specified by:
getCenter in interface Paintable
Returns:
a copy of the center of the paint region
See Also:
setDefaultCenter(Point2D), getDefaultCenter()

setDefaultBounds2D

public final void setDefaultBounds2D(Rectangle2D rectangle)

Sets the default Bounds2D rectangle.

If the default Bounds2D rectangle is non-null, then a derived class may choose to use this default rather than perform a computation to obtain more exact bounds. Thus, the use of this default is optional rather than mandatory.

It is valid to set the default Bounds2D rectangle to null to force a computation of the bounds. Setting the default Bounds2D rectangle to a rectangle with zero width or height is equivalent to setting it to null.

A derived class should specify whether it uses the default Bounds2D rectangle in cases when it is non-null.

Fires property change: SET_DEFAULT_BOUNDS2D.

Parameters:
rectangle - the default Bounds2D rectangle
See Also:
getBounds2D(), getDefaultBounds2D()

getDefaultBounds2D

public final Rectangle2D getDefaultBounds2D()
Returns a copy of the default Bounds2D rectangle.

Returns:
a copy of the default Bounds2D rectangle
See Also:
getBounds2D(), setDefaultBounds2D(Rectangle2D)

setDefaultCenter

public final void setDefaultCenter(Point2D center)

Sets the default center.

If the default center is non-null, then a derived class may choose to use this default rather than perform a computation to obtain a more exact center. Thus, the use of this default is optional rather than mandatory.

It is valid to set the default center to null to force a computation of the center.

A derived class should specify whether it uses the default center in cases when it is non-null.

Fires property change: SET_DEFAULT_CENTER.

Parameters:
center - the default center
See Also:
getCenter(), getDefaultCenter()

getDefaultCenter

public final Point2D getDefaultCenter()
Returns a copy of the default center.

Returns:
a copy of the default center
See Also:
getCenter(), setDefaultCenter(Point2D)

contains

public final boolean contains(Point2D p)

Tests if a specified point is inside the paintable.

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

Specified by:
contains in interface Paintable
Parameters:
p - a specified Point2D
Returns:
whether or not a specified point is inside the paintable

possiblyContains

protected final boolean possiblyContains(double x,
                                         double y)

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

This method returns true if and only if:

This is a helper method for implementing contains.

Parameters:
x - the x-coordinate of the point
y - the y-coordinate of the point
Returns:
whether or not a specified point is possibly inside the paintable

setVisible

public final void setVisible(boolean visible)

Sets the visibility property of this paintable.

The default for the visibility property should be true

.

Fires property change: SET_VISIBLE.

Specified by:
setVisible in interface Paintable
Parameters:
visible - the visibility setting
See Also:
isVisible(), setOpacity(float), getOpacity()

isVisible

public final boolean isVisible()
Returns the current visibility property of this paintable.

Specified by:
isVisible in interface Paintable
See Also:
setVisible(boolean), setOpacity(float), getOpacity()

setOpacity

public final void setOpacity(float opacity)

Sets the opacity of this paintable to a value between 0 and 1.

Note that an opacity of 0 will make the paintable invisible. This is not recommended. Instead use setVisible(false).

Fires property change: SET_OPACITY.

Specified by:
setOpacity in interface Paintable
Parameters:
opacity - the opacity of this paintable
See Also:
getOpacity(), setVisible(boolean), isVisible()

getOpacity

public final float getOpacity()
Returns the opacity value of this paintable between 0 and 1.

Specified by:
getOpacity in interface Paintable
Returns:
the opacity of this paintable
See Also:
setOpacity(float), setVisible(boolean), isVisible()

applyOpacity

public final void applyOpacity(Graphics2D h)

Applies the current opacity to calculate and set a net opacity.

The following conditions must hold:

In the case that the graphics context has a Composite set of type AlphaComposite with rule SRC_OVER, then the net opacity is the product of the current opacity of this object and the alpha value of the AlphaComposite.

Otherwise the net opacity equals the current opacity of this object.

Parameters:
h - the graphics context whose opacity will be changed

getPreparedGraphics2D

public final Graphics2D getPreparedGraphics2D(Graphics g)

Returns a copy of the given graphics context after modifying the copy to set anti-aliasing on, to clip to within the bounds region, and to apply the opacity of this paintable if needed.

For convenience, the graphics context is returned as a Graphics2D object.

Specified by:
getPreparedGraphics2D in interface Paintable
Parameters:
g - the given graphics context to copy
Returns:
a suitably prepared copy of the given graphics context

addPropertyChangeListener

public final void addPropertyChangeListener(PropertyChangeListener listener)

Add a PropertyChangeListener to the listener list. The listener is registered for all properties.

Specified by:
addPropertyChangeListener in interface SupportsPropertyChange
Parameters:
listener - the PropertyChangeListener to be added

addPropertyChangeListener

public final void addPropertyChangeListener(String propertyName,
                                            PropertyChangeListener listener)

Add a PropertyChangeListener to the listener list for a specific property. The listener will be invoked only when a call on firePropertyChange names that specific property.

Specified by:
addPropertyChangeListener in interface SupportsPropertyChange
Parameters:
propertyName - the name of the property to listen on
listener - the PropertyChangeListener to be added

addPropertyChangeListeners

public final void addPropertyChangeListeners(PropertyChangeListener[] listeners)

Add all items in the given PropertyChangeListener array to the listener list. These items are registered for all properties.

Specified by:
addPropertyChangeListeners in interface SupportsPropertyChange
Parameters:
listeners - the PropertyChangeListener array to be added

addPropertyChangeListeners

public final void addPropertyChangeListeners(String propertyName,
                                             PropertyChangeListener[] listeners)

Add all items in the given PropertyChangeListener array to the listener list for a specific property. These items will be invoked only when a call on firePropertyChange names that specific property.

Specified by:
addPropertyChangeListeners in interface SupportsPropertyChange
Parameters:
listeners - the PropertyChangeListener array to be added

removePropertyChangeListener

public final void removePropertyChangeListener(PropertyChangeListener listener)

Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

Specified by:
removePropertyChangeListener in interface SupportsPropertyChange
Parameters:
listener - the PropertyChangeListener to be removed

removePropertyChangeListener

public final void removePropertyChangeListener(String propertyName,
                                               PropertyChangeListener listener)

Remove a PropertyChangeListener for a specific property.

Specified by:
removePropertyChangeListener in interface SupportsPropertyChange
Parameters:
propertyName - the name of the property that was listened on
listener - the PropertyChangeListener to be removed

getPropertyChangeListeners

public final PropertyChangeListener[] getPropertyChangeListeners()

Returns an array of all listeners that were added to this object.

Specified by:
getPropertyChangeListeners in interface SupportsPropertyChange
Returns:
an array with all listeners

getPropertyChangeListeners

public final PropertyChangeListener[] getPropertyChangeListeners(String propertyName)

Returns an array of all listeners that were added to this object and associated with the named property.

Specified by:
getPropertyChangeListeners in interface SupportsPropertyChange
Parameters:
propertyName - the name of the property to seek
Returns:
an array with all listeners for the given named property

hasListeners

public final boolean hasListeners(String propertyName)

Check if there are any listeners for a specific property.

Specified by:
hasListeners in interface SupportsPropertyChange
Parameters:
propertyName - the name of the property to check
Returns:
whether or not there are any listeners for a specific property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     Object oldValue,
                                     Object newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal and non-null.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     boolean oldValue,
                                     boolean newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     char oldValue,
                                     char newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     byte oldValue,
                                     byte newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     short oldValue,
                                     short newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     int oldValue,
                                     int newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     long oldValue,
                                     long newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     float oldValue,
                                     float newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     double oldValue,
                                     double newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(PropertyChangeEvent evt)

Fire an existing PropertyChangeEvent to any registered listeners. No event is fired if the given event's old and new values are equal and non-null.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
evt - the PropertyChangeEvent object

getForwardingListener

public final PropertyChangeForwardingListener getForwardingListener()

Returns the PropertyChangeForwardingListener that will forward the property change events it receives to this object.

Specified by:
getForwardingListener in interface SupportsPropertyChange
Returns:
the forwarding listener

addForwardingListener

public final void addForwardingListener(Object object)
Add the forwarding listener as a property change listener for the given object if the object supports property change.

Specified by:
addForwardingListener in interface SupportsPropertyChange
Parameters:
object - the object that should add the forwarding listener

removeForwardingListener

public final void removeForwardingListener(Object object)
Remove the forwarding listener as a property change listener for the given object if the object supports property change.

Specified by:
removeForwardingListener in interface SupportsPropertyChange
Parameters:
object - the object that should remove the forwarding listener

removeAndAddForwardingListener

public final void removeAndAddForwardingListener(Object oldobject,
                                                 Object newobject)
Remove the forwarding listener as a property change listener for the old object if the old object supports property change and add the forwarding listener as a property change listener for the new object if the new object supports property change.

Specified by:
removeAndAddForwardingListener in interface SupportsPropertyChange
Parameters:
oldobject - the old object that should remove the forwarding listener
newobject - the new object that should add the forwarding listener