com.rolemodelsoft.drawlet.basics
Class SimpleDrawing

java.lang.Object
  |
  +--com.rolemodelsoft.drawlet.basics.AbstractPaintable
        |
        +--com.rolemodelsoft.drawlet.basics.SimpleDrawing

public class SimpleDrawing
extends AbstractPaintable
implements Drawing

This provides basic functionality necessary to provide a meaningful working version of a Drawing.

See Also:
Serialized Form

Field Summary
protected  java.awt.Color backgroundColor
          The background color.
protected  boolean dynamicSize
          Stores whether this drawing is to be sized dynamically or not.
protected  java.util.Vector figures
          The figures which appear on the canvas.
protected  int height
          The height of the drawing.
protected  java.util.Vector listeners
          The property change listeners.
protected  int width
          The width of the drawing.
 
Fields inherited from interface com.rolemodelsoft.drawlet.Drawing
SIZE_PROPERTY, STYLE_PROPERTY
 
Constructor Summary
SimpleDrawing()
          Create a new instance of a Drawing
SimpleDrawing(int width, int height)
          Create a new instance of a Drawing
 
Method Summary
 void addFigure(Figure figure)
          Add the figure to the contents of the canvas.
 void addFigureBehind(Figure figure, Figure existingFigure)
          Add the figure to the contents of the canvas, sticking it behind an existingFigure which is already there.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list.
protected  void changedSize(java.awt.Dimension oldDimension)
          Denote that size changed.
protected  java.awt.Color defaultBackgroundColor()
          Answer the default color for this Drawing's background.
protected  boolean defaultDynamicSize()
          Answer the default for whether this Drawing should be dynamically sized.
protected  java.util.Vector defaultFigures()
          Answer the default Vector to contain this Drawing's figures.
protected  int defaultWidth()
          Answer the default width for this Drawing.
 Figure figureAt(int x, int y)
          Answer the figure at a given point
 FigureEnumeration figures()
          Answer a FigureEnumeration over the figures of the receiver.
protected  void firePropertyChange(java.beans.PropertyChangeEvent event)
          Report a property update to any registered listeners.
 java.awt.Rectangle getBounds()
          Returns the current rectangular area covered by the receiver.
 java.awt.Dimension getSize()
          Returns the current size of the receiver.
 DrawingStyle getStyle()
          Get the style defining how to paint on the canvas.
 boolean isDynamicSize()
          Answers whether this Drawing is currently dynamically sized or not.
 void moveFigureBehind(Figure figure, Figure existingFigure)
          Move the figure behind an existingFigure if it is not already there.
 void moveFigureInFront(Figure figure, Figure existingFigure)
          Move the figure in front of an existingFigure if it is not already there.
 void moveFigureToBack(Figure figure)
          Move the figure behind all other figures.
 void moveFigureToFront(Figure figure)
          Move the figure in front of all other figures.
 Figure otherFigureAt(Figure excludedFigure, int x, int y)
          Answer the figure at a given point excluding the identified figure
 void paint(java.awt.Graphics g)
          Paints the component.
protected  void paintAll(java.awt.Graphics g)
          Paints everything in the receiver.
protected  void paintBackground(java.awt.Graphics g)
          Paints the background of the receiver.
protected  void paintCompletely(java.awt.Graphics g)
          Paints everything in the receiver, ignoring the clipping region.
 void removeFigure(Figure figure)
          Remove the figure.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove a PropertyChangeListener from the listener list.
 void setDynamicSize(boolean dynamicSize)
          Sets whether this Drawing is dynamically sized or not.
 void setSize(java.awt.Dimension d)
          Sets the current size covered by this drawing.
 void setSize(int width, int height)
          Sets the current size covered by this drawing.
 void setStyle(DrawingStyle style)
          Set the style defining how to paint on the canvas.
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractPaintable
getBottom, getHeight, getLeft, getRight, getTop, getWidth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

figures

protected java.util.Vector figures
The figures which appear on the canvas.

width

protected int width
The width of the drawing.

height

protected int height
The height of the drawing.

listeners

protected transient java.util.Vector listeners
The property change listeners.

backgroundColor

protected java.awt.Color backgroundColor
The background color.

dynamicSize

protected boolean dynamicSize
Stores whether this drawing is to be sized dynamically or not.
Constructor Detail

SimpleDrawing

public SimpleDrawing()
Create a new instance of a Drawing

SimpleDrawing

public SimpleDrawing(int width,
                     int height)
Create a new instance of a Drawing
Method Detail

addFigure

public void addFigure(Figure figure)
Add the figure to the contents of the canvas.
Parameters:
figure - the figure to add

addFigureBehind

public void addFigureBehind(Figure figure,
                            Figure existingFigure)
Add the figure to the contents of the canvas, sticking it behind an existingFigure which is already there. Reflect the change if it's visible. Become an observer on the figure.
Parameters:
figure - the figure to add
existingFigure - the figure to which the new figure should be behind

addPropertyChangeListener

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

changedSize

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

defaultBackgroundColor

protected java.awt.Color defaultBackgroundColor()
Answer the default color for this Drawing's background.
Returns:
a Color representing this Drawing's background color.

defaultDynamicSize

protected boolean defaultDynamicSize()
Answer the default for whether this Drawing should be dynamically sized.
Returns:
a boolean representing whether this Drawing should be dynamically sized by default.

defaultFigures

protected java.util.Vector defaultFigures()
Answer the default Vector to contain this Drawing's figures.
Returns:
a Vector to contain this Drawing's figures.

defaultWidth

protected int defaultWidth()
Answer the default width for this Drawing.
Returns:
an integer representing this Drawing's default width.

figureAt

public Figure figureAt(int x,
                       int y)
Answer the figure at a given point
Parameters:
x - the x coordinate
y - the y coordinate
Returns:
the Figure at x,y; null if none found

figures

public FigureEnumeration figures()
Answer a FigureEnumeration over the figures of the receiver.
Returns:
a FigureEnumeration over the figures of the receiver

firePropertyChange

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

getBounds

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

getSize

public java.awt.Dimension getSize()
Returns the current size of the receiver.
Specified by:
getSize in interface Drawing
Overrides:
getSize in class AbstractPaintable
Returns:
a Dimension representing the current size.

getStyle

public DrawingStyle getStyle()
Get the style defining how to paint on the canvas.
Specified by:
getStyle in interface Drawing
Returns:
the receivers current DrawingStyle

isDynamicSize

public boolean isDynamicSize()
Answers whether this Drawing is currently dynamically sized or not.
Specified by:
isDynamicSize in interface Drawing
Returns:
a boolean value of true if this drawing is dynamically sized; false otherwise.

moveFigureBehind

public void moveFigureBehind(Figure figure,
                             Figure existingFigure)
Move the figure behind an existingFigure if it is not already there.
Parameters:
figure - the figure to move
existingFigure - the figure to which the new figure should be behind
Throws:
java.lang.IllegalArgumentException - if one or both figures are unknown to receiver.

moveFigureInFront

public void moveFigureInFront(Figure figure,
                              Figure existingFigure)
Move the figure in front of an existingFigure if it is not already there.
Parameters:
figure - the figure to move
existingFigure - the figure to which the new figure should be in front
Throws:
java.lang.IllegalArgumentException - if one or both figures are unknown to receiver.

moveFigureToBack

public void moveFigureToBack(Figure figure)
Move the figure behind all other figures.
Parameters:
figure - the figure to move
Throws:
java.lang.IllegalArgumentException - if figure is unknown to receiver.

moveFigureToFront

public void moveFigureToFront(Figure figure)
Move the figure in front of all other figures.
Parameters:
figure - the figure to move
Throws:
java.lang.IllegalArgumentException - if figure is unknown to receiver.

otherFigureAt

public Figure otherFigureAt(Figure excludedFigure,
                            int x,
                            int y)
Answer the figure at a given point excluding the identified figure
Parameters:
figure - the figure to exclude from the search
x - the x coordinate
y - the y coordinate
Returns:
the Figure at the given point, excluding the specified figure; null if none found

paint

public void paint(java.awt.Graphics g)
Paints the component.
Specified by:
paint in interface Drawing
Overrides:
paint in class AbstractPaintable
Parameters:
g - the specified Graphics window

paintAll

protected void paintAll(java.awt.Graphics g)
Paints everything in the receiver. Don't bother asking figures to paint themselves if they are not in the clipped region.
Parameters:
g - the specified Graphics window

paintBackground

protected void paintBackground(java.awt.Graphics g)
Paints the background of the receiver.
Parameters:
g - the specified Graphics window

paintCompletely

protected void paintCompletely(java.awt.Graphics g)
Paints everything in the receiver, ignoring the clipping region.
Parameters:
g - the specified Graphics window

removeFigure

public void removeFigure(Figure figure)
Remove the figure. We may want to also tell the figure to dispose of itself completely... currently this is left up to the sender to allow them to do other things before disposing. This is somewhat arbitraty however and a different approach may be desired by different implementations.
Parameters:
figure - the figure to remove

removePropertyChangeListener

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

setDynamicSize

public void setDynamicSize(boolean dynamicSize)
Sets whether this Drawing is dynamically sized or not.
Specified by:
setDynamicSize in interface Drawing
Parameters:
dynamicSize - a boolean specifying this drawing's new dynamic size state.

setSize

public void setSize(int width,
                    int height)
Sets the current size covered by this drawing.
Specified by:
setSize in interface Drawing
Parameters:
width - an integer representing the new width.
height - an integer representing the new height.

setSize

public void setSize(java.awt.Dimension d)
Sets the current size covered by this drawing.
Specified by:
setSize in interface Drawing
Parameters:
d - a Dimension representing the new size.

setStyle

public void setStyle(DrawingStyle style)
Set the style defining how to paint on the canvas.
Specified by:
setStyle in interface Drawing
Parameters:
style - the specified DrawingStyle