com.rolemodelsoft.drawlet.basics
Class AbstractFigure

java.lang.Object
  |
  +--com.rolemodelsoft.drawlet.basics.AbstractPaintable
        |
        +--com.rolemodelsoft.drawlet.basics.AbstractFigure
Direct Known Subclasses:
AbstractShape, TextLabel

public abstract class AbstractFigure
extends AbstractPaintable
implements Figure

This provides basic default functionality for Figures that are assumed to be movable but not necessarily reshapable, and that have observers that want to know when their location changes. It provides very basic functionality for most operations and forces concrete subclasses to define, at a minimum: paint(Graphics); getBounds(); basicTranslate(int,int);

See Also:
Serialized Form

Field Summary
protected  java.util.Vector listeners
          The Figure's listeners.
protected  java.util.Vector locationListeners
          The Figure's location listeners.
 
Fields inherited from interface com.rolemodelsoft.drawlet.Figure
FILL_COLOR_PROPERTY, LINE_COLOR_PROPERTY, LOCATION_PROPERTY, RELATION_PROPERTY, SHAPE_PROPERTY, SIZE_PROPERTY, STRING_PROPERTY, STYLE_PROPERTY, TEXT_COLOR_PROPERTY
 
Constructor Summary
AbstractFigure()
           
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list.
 void addRelatedLocationListener(RelatedLocationListener listener)
          Add a RelatedLocationListener to the listener list.
protected  void basicMove(int x, int y)
          Moves the Figure to a new location.
protected abstract  void basicTranslate(int x, int y)
          Moves the Figure in the x and y direction.
protected  void changedLocation(java.awt.Point oldPoint)
          Denote that location changed.
protected  void changedShape(java.awt.Rectangle oldBounds)
          Denote that the shape changed.
protected  void changedSize(java.awt.Dimension oldDimension)
          Denote that size changed.
 boolean contains(Figure figure)
          Checks whether the specified Figure is "inside" this Figure.
 boolean contains(int x, int y)
          Checks whether a specified x,y location is "inside" this Figure.
 boolean contains(java.awt.Rectangle box)
          Checks whether a specified Rectangle is "inside" this Figure, where the Rectangle and this Figure are in the same coordinate system By default, just check if its topLeft and bottomRight is inside the receiver.
protected  void deleteLocationListeners()
          Deletes all location listeners.
 void disconnect()
          Called to allow the Figure to respond to being disconnected.
 java.lang.Object duplicate()
          Duplicates the receiver.
 java.lang.Object duplicateIn(java.util.Hashtable duplicates)
          Duplicates the receiver into the given Hashtable.
 Handle editTool(int x, int y)
          Answers a Handle that will provide editing capabilities on the receiver, or null.
protected  int estimatedDuplicateSize()
          Answers the expected number of significant duplicates when duplicating the receiver.
static Figure figureFromLocator(Locator aLocator)
          Answer the figure, if any, associated with the locator.
protected  void fireLocationChange(java.beans.PropertyChangeEvent event)
          Denote that location changed.
protected  void firePropertyChange(java.beans.PropertyChangeEvent event)
          Report a property update to any registered listeners.
protected  void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Report a property update to any registered listeners.
protected  void fireRelationChange(java.beans.PropertyChangeEvent event)
          Report that the relation has changed.
protected  void fireShapeChange(java.beans.PropertyChangeEvent event)
          Report that the shape changed.
protected  void fireSizeChange(java.beans.PropertyChangeEvent event)
          Report that the size changed.
abstract  java.awt.Rectangle getBounds()
          Returns the current rectangular area covered by this figure.
 Handle[] getHandles()
          Answer the handles associated with the receiver.
protected  java.awt.Point getLocation()
          Answer a point indicating the location of the receiver...
 Locator getLocator()
          Returns the current locator of this figure.
 DrawingStyle getStyle()
          Answer the style which defines how to paint the figure.
 boolean intersects(Figure anotherFigure)
          Answers whether the receiver intersects another figure.
 boolean intersects(java.awt.Rectangle box)
          Answers whether the receiver intersects a Rectangular area.
 boolean isObsolete()
          Answers whether the receiver is obsolete True if some event has happened that makes this a meaningless object.
 boolean isWithin(Figure anotherFigure)
          Answers whether the receiver is fully within another Figure.
 boolean isWithin(java.awt.Rectangle box)
          Answers whether the receiver is fully within a Rectangular area.
 Locator locatorAt(int x, int y)
          Answers a locator corresponding to a significant point on the receiver.
 void move(int x, int y)
          Moves the Figure to a new location.
 void move(Locator locator)
          Moves the Figure to a new location.
abstract  void paint(java.awt.Graphics g)
          Paints the figure.
 void postDuplicate(java.util.Hashtable duplicates)
          After a series of Figures are duplicated, this can be sent to each of the duplicates to resolve any changes they might like to reconcile.
 java.util.Enumeration relatedLocationListeners()
          Answer with an enumeration over the RelatedLocationListeners.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove the PropertyChangeListener from the listener list.
 void removeRelatedLocationListener(RelatedLocationListener listener)
          Remove the RelatedLocationListener from the listener list.
 Locator requestConnection(Figure requestor, int x, int y)
          Answers a Locator corresponding to a significant point on the receiver that will serve as a connection to the other figure.
protected  void resetLocationCache()
          Flush caches with respect to determining location.
 void setBounds(int x, int y, int width, int height)
          Reshapes the Figure to the specified bounding box.
 void setSize(java.awt.Dimension d)
          Resizes the receiver to the specified dimension.
 void setSize(int width, int height)
          Resizes the receiver to the specified width and height.
 void setStyle(DrawingStyle style)
          Set the style defining how to paint the receiver.
 void translate(int x, int y)
          Moves the Figure in the x and y direction.
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractPaintable
getBottom, getHeight, getLeft, getRight, getSize, getTop, getWidth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

protected transient java.util.Vector listeners
The Figure's listeners.

locationListeners

protected java.util.Vector locationListeners
The Figure's location listeners.
Constructor Detail

AbstractFigure

public AbstractFigure()
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list.
Specified by:
addPropertyChangeListener in interface Figure
Parameters:
listener - The PropertyChangeListener to be added

addRelatedLocationListener

public void addRelatedLocationListener(RelatedLocationListener listener)
Add a RelatedLocationListener to the listener list.
Specified by:
addRelatedLocationListener in interface Figure
Parameters:
listener - The RelatedLocationListener to be added

basicMove

protected void basicMove(int x,
                         int y)
Moves the Figure to a new location. The x and y coordinates are in the parent's coordinate space.
Parameters:
x - the x coordinate
y - the y coordinate
See Also:
#location, #reshape

basicTranslate

protected abstract void basicTranslate(int x,
                                       int y)
Moves the Figure in the x and y direction. Subclasses should probably provide synchronized versions if they're modifying attributes of the receiver.
Parameters:
x - amount to move in the x direction
y - amount to move in the y direction
See Also:
#location, translate(int, int)

changedLocation

protected void changedLocation(java.awt.Point oldPoint)
Denote that location changed.
Parameters:
point - the old location.

changedShape

protected void changedShape(java.awt.Rectangle oldBounds)
Denote that the shape changed. Assume that the shape has changed even if the bounds haven't.
Parameters:
oldBounds - the old bounds.

changedSize

protected void changedSize(java.awt.Dimension oldDimension)
Denote that size changed.
Parameters:
oldDimension - the old dimensions.

contains

public boolean contains(int x,
                        int y)
Checks whether a specified x,y location is "inside" this Figure. x and y are defined to be relative to the coordinate system of this figure. By default, just check if it is within the receiver's bounds. Subclasses may wish to do something more sophisticated.
Specified by:
contains in interface Figure
Parameters:
x - the x coordinate
y - the y coordinate
Returns:
boolean value of true if the specified x,y location is "inside" this Figure; false otherwise.
See Also:
isWithin(com.rolemodelsoft.drawlet.Figure)

contains

public boolean contains(Figure figure)
Checks whether the specified Figure is "inside" this Figure. The Figures are assumed to share the same coordinate system. By default, just check if it is within the receiver's bounds. Subclasses may wish to do something more sophisticated.
Specified by:
contains in interface Figure
Parameters:
figure - the Figure to test for inclusion
Returns:
boolean value of true if the specified Figure is completely "inside" this Figure; false otherwise.
See Also:
isWithin(com.rolemodelsoft.drawlet.Figure)

contains

public boolean contains(java.awt.Rectangle box)
Checks whether a specified Rectangle is "inside" this Figure, where the Rectangle and this Figure are in the same coordinate system By default, just check if its topLeft and bottomRight is inside the receiver. Subclasses may wish to do something more sophisticated.
Specified by:
contains in interface Figure
Parameters:
box - the rectangle to test for inclusion
Returns:
boolean value of true if the specified Rectangle is "inside" this Figure; false otherwise.

deleteLocationListeners

protected void deleteLocationListeners()
Deletes all location listeners. Though this is public, caution should be used before anything other than "this" does.

disconnect

public void disconnect()
Called to allow the Figure to respond to being disconnected. Should clean up as appropriate if the figure is no longer valid.
Specified by:
disconnect in interface Figure

duplicate

public java.lang.Object duplicate()
Duplicates the receiver. Copy non-transient observers... let postDuplicate resolve whether observers have also been copied.
Returns:
an Object which is a duplicate of the receiver

duplicateIn

public java.lang.Object duplicateIn(java.util.Hashtable duplicates)
Duplicates the receiver into the given Hashtable. Copy non-transient observers... let postDuplicate resolve whether observers have also been copied.
Parameters:
duplicates - the Hashtable to put the new duplicate in
Returns:
an Object which is a duplicate of the receiver

editTool

public Handle editTool(int x,
                       int y)
Answers a Handle that will provide editing capabilities on the receiver, or null. By default, answer null. Subclasses may wish to provide something more meaningful.
Specified by:
editTool in interface Figure
Parameters:
x - the x coordinate to potentially begin editing
y - the y coordinate to potentially begin editing
Returns:
a Handle that will provide default capabilities on the receiver, or null if there is no default

estimatedDuplicateSize

protected int estimatedDuplicateSize()
Answers the expected number of significant duplicates when duplicating the receiver. Subclasses may wish to override.

figureFromLocator

public static Figure figureFromLocator(Locator aLocator)
Answer the figure, if any, associated with the locator. This can be a useful utility to determine whether or not a particular locator is tied to some figure.
Parameters:
aLocator - the Locator to mine for figures
Returns:
the Figure associated with the locator, or null if none

fireLocationChange

protected void fireLocationChange(java.beans.PropertyChangeEvent event)
Denote that location changed.
Parameters:
event -  

firePropertyChange

protected void firePropertyChange(java.beans.PropertyChangeEvent event)
Report a property update to any registered listeners.
Parameters:
event - the PropertyChangeEvent to report.

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
Report a property update to any registered listeners. No event is fired if old and new are equal and non-null.
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.

fireRelationChange

protected void fireRelationChange(java.beans.PropertyChangeEvent event)
Report that the relation has changed.
Parameters:
event - the actual PropertyChangeEvent to report.

fireShapeChange

protected void fireShapeChange(java.beans.PropertyChangeEvent event)
Report that the shape changed.
Parameters:
event - the actual PropertyChangeEvent to report.

fireSizeChange

protected void fireSizeChange(java.beans.PropertyChangeEvent event)
Report that the size changed.
Parameters:
event - the actual PropertyChangeEvent to report.

getBounds

public abstract java.awt.Rectangle getBounds()
Returns the current rectangular area covered by this figure.
Overrides:
getBounds in class AbstractPaintable
Returns:
a Rectangle representing the current rectangular area covered by this figure

getHandles

public Handle[] getHandles()
Answer the handles associated with the receiver. By default, there are none. Subclasses may wish to provide other handles that may allow for editing the receiver in some way.
Specified by:
getHandles in interface Figure
Returns:
an array of the Handles associated with the receiver

getLocation

protected java.awt.Point getLocation()
Answer a point indicating the location of the receiver... typically the topLeft. NOTE: This may not correspond to the point indicated by getLocator() as this method is often used to determine the position before a Locator has already been affected.
Returns:
a Point indicating the location of the receiver

getLocator

public Locator getLocator()
Returns the current locator of this figure. This may or may not represent the top left of the receiver's area. By default, it does. Subclasses may wish to provide something more meaningful.
Specified by:
getLocator in interface Figure
Returns:
the current Locator of this figure

getStyle

public DrawingStyle getStyle()
Answer the style which defines how to paint the figure.
Specified by:
getStyle in interface Figure
Returns:
the DrawingStyle which defines how to paint the figure

intersects

public boolean intersects(Figure anotherFigure)
Answers whether the receiver intersects another figure. By default, just check if the bounds intersect. Subclasses may wish to do something more sophisticated.
Specified by:
intersects in interface Figure
Parameters:
anotherFigure - the figure the receiver is potentially intersecting.
Returns:
boolean value of true if the receiver intersects the specified figure; false otherwise.
See Also:
#bounds

intersects

public boolean intersects(java.awt.Rectangle box)
Answers whether the receiver intersects a Rectangular area. By default, just check if the bounds intersects. Subclasses may wish to do something more sophisticated.
Specified by:
intersects in interface Figure
Parameters:
box - the Rectangular area
Returns:
boolean value of true if the receiver intersects the specified Rectangular area; false otherwise.
See Also:
#bounds

isObsolete

public boolean isObsolete()
Answers whether the receiver is obsolete True if some event has happened that makes this a meaningless object.
Specified by:
isObsolete in interface Figure
Returns:
boolean value of true if the receiver is obsolete; false otherwise.

isWithin

public boolean isWithin(Figure anotherFigure)
Answers whether the receiver is fully within another Figure. By default, we ask the other figure if the receiver is inside it. Subclasses may want to do something more sophisticated.
Specified by:
isWithin in interface Figure
Parameters:
anotherFigure - the figure the receiver is potentially inside.
Returns:
boolean value of true if the receiver is fully within the Figure specified; false otherwise.
See Also:
#inside

isWithin

public boolean isWithin(java.awt.Rectangle box)
Answers whether the receiver is fully within a Rectangular area. By default, just check if the topLeft and bottomRight are inside the area. Subclasses may wish to do something more sophisticated.
Specified by:
isWithin in interface Figure
Parameters:
box - the Rectangular area
Returns:
boolean value of true if the receiver is fully within the Rectangle specified; false otherwise.
See Also:
#left, #top, #right, #bottom

locatorAt

public Locator locatorAt(int x,
                         int y)
Answers a locator corresponding to a significant point on the receiver. By default, answer a point with the same relative position as the x and y are at the time of the request.
Specified by:
locatorAt in interface Figure
Parameters:
x - the x coordinate of the requested locator
y - the y coordinate of the requested locator
Returns:
a Locator corresponding to a significant point on the receiver

move

public void move(int x,
                 int y)
Moves the Figure to a new location. The x and y coordinates are in the parent's coordinate space. Let observers know what changed. This is a TemplateMethod with hooks: resetLocationCache() basicMove() changedLocation()
Specified by:
move in interface Figure
Parameters:
x - the x coordinate
y - the y coordinate
See Also:
#location

move

public void move(Locator locator)
Moves the Figure to a new location. Note: Subclasses may wish to update dependencies based on this new location
Specified by:
move in interface Figure
Parameters:
locator - the Locator which identifies the desired x, y coordinates.
See Also:
getLocator()

paint

public abstract void paint(java.awt.Graphics g)
Paints the figure.
Overrides:
paint in class AbstractPaintable
Parameters:
g - the specified Graphics window

postDuplicate

public void postDuplicate(java.util.Hashtable duplicates)
After a series of Figures are duplicated, this can be sent to each of the duplicates to resolve any changes they might like to reconcile. In this case, get rid of observers and replace them with any duplicates available.
Parameters:
duplicates - a Hashtable where originals as keys and duplicates as elements

relatedLocationListeners

public java.util.Enumeration relatedLocationListeners()
Answer with an enumeration over the RelatedLocationListeners.
Specified by:
relatedLocationListeners in interface Figure
Tags copied from interface: Figure
Returns:
an Enumeration over the RelatedLocationListeners

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove the PropertyChangeListener from the listener list.
Specified by:
removePropertyChangeListener in interface Figure
Parameters:
listener - The PropertyChangeListener to be removed

removeRelatedLocationListener

public void removeRelatedLocationListener(RelatedLocationListener listener)
Remove the RelatedLocationListener from the listener list.
Specified by:
removeRelatedLocationListener in interface Figure
Parameters:
listener - The RelatedLocationListener to be removed

requestConnection

public Locator requestConnection(Figure requestor,
                                 int x,
                                 int y)
Answers a Locator corresponding to a significant point on the receiver that will serve as a connection to the other figure. By default, make it the middle of the receiver. Subclasses may wish to do something more meaningful.
Specified by:
requestConnection in interface Figure
Parameters:
x - the x coordinate of the requested locator
y - the y coordinate of the requested locator

resetLocationCache

protected void resetLocationCache()
Flush caches with respect to determining location. This is a hook method. Subclasses may wish to override.

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Reshapes the Figure to the specified bounding box. By default, ignore width and height. Subclasses may wish to override.
Specified by:
setBounds in interface Figure
Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the figure
height - the height of the figure
See Also:
move(int, int)

setSize

public void setSize(int width,
                    int height)
Resizes the receiver to the specified width and height. By default, do nothing. Subclasses may wish to override.
Specified by:
setSize in interface Figure
Parameters:
width - the width of the figure
height - the height of the figure

setSize

public void setSize(java.awt.Dimension d)
Resizes the receiver to the specified dimension.
Specified by:
setSize in interface Figure
Parameters:
d - the figure dimension
See Also:
AbstractPaintable.getSize(), setBounds(int, int, int, int)

setStyle

public void setStyle(DrawingStyle style)
Set the style defining how to paint the receiver. The default is to ignore the style. Most subclasses will want to do something more useful.
Specified by:
setStyle in interface Figure
Parameters:
style - the specified DrawingStyle

translate

public void translate(int x,
                      int y)
Moves the Figure in the x and y direction. Let observers know what changed. This is a TemplateMethod with hooks: resetLocationCache() basicTranslate() changedLocation()
Specified by:
translate in interface Figure
Parameters:
x - amount to move in the x direction
y - amount to move in the y direction
See Also:
#location