com.rolemodelsoft.drawlet.basics
Class SimpleDrawingCanvas

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

public class SimpleDrawingCanvas
extends AbstractPaintable
implements InputEventHandler, DrawingCanvas, ComponentHolder, java.beans.PropertyChangeListener

This provides basic functionality necessary to provide a meaningful working version of a DrawingCanvas that can be tied to a Component in an AWT Application. It is expected that this would serve as the base for these sort of Components, but not required.

See Also:
Serialized Form

Field Summary
protected static int buffer
          The amount to add to drawings which are dynamically sized.
protected static java.awt.datatransfer.Clipboard clipboard
          A place to hold figures that are cut or copied.
protected  java.awt.Component component
          The Component we are associated with.
protected  Drawing drawing
          The drawing we are displaying/manipulating.
protected  java.util.Hashtable figureHandles
          A mapping of figures to their associated handles.
protected  java.util.Vector handles
          The handles that may take control of events.
protected  int height
          The height of the canvas.
protected  java.util.Vector selections
          The figures which are currently selected for further operations.
protected  DrawingStyle style
          The style with which it is expected new figures will be drawn.
protected  InputEventHandler tool
          The tool which is the first thing we look to in order to handle events.
protected  int width
          The width of the canvas.
 
Constructor Summary
SimpleDrawingCanvas()
          Default constructor
SimpleDrawingCanvas(Drawing 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 addHandle(Handle handle)
          Add the handle to the receiver.
 void addHandles(Figure figure)
          Add the handles corresponding to the figure to the receiver.
 void addHandles(Figure figure, Handle[] handles)
          Add the handles to the receiver, associating them the given figure.
protected  void addHandles(Handle[] handles)
          Add the handles to the receiver.
 void addSelection(Figure figure)
          Add the figure to the selections.
protected  void clearHandles()
          Remove all the handles from the receiver.
 void clearSelections()
          Remove all the selections of the receiver.
 void copySelections()
          Copy the selections.
 void cutSelections()
          Cut the selections
protected  java.awt.Color defaultComponentBackground()
          Answer the default color for the Component background.
protected static Drawing defaultDrawing()
          Answer the default/initial Drawing to use.
protected  java.util.Hashtable defaultFigureHandles()
          Answer the default/initial figureHandles to use.
protected  java.util.Vector defaultHandles()
          Answer the default/initial handles to use.
protected  int defaultHeight()
          Answer the default/initial height to use.
protected  java.util.Vector defaultSelections()
          Answer the default/initial selections to use.
protected  DrawingStyle defaultStyle()
          Answer the default/initial DrawingStyle to use.
protected  InputEventHandler defaultTool()
          Answer the default/initial tool to use.
protected  int defaultWidth()
          Answer the default/initial width to use.
 void deleteSelections()
          Delete the selections
protected  void drawingSizeChange()
          Called when the Drawing's size changes.
protected  java.util.Vector duplicateFigures(java.util.Vector toCopy)
          Duplicate all of the figures and return a new Vector
 Figure figureAt(int x, int y)
          Answer the figure at a given point
protected  void figureChange(java.beans.PropertyChangeEvent evt)
          Called when a figure changes.
protected  void figureLocationChange(java.beans.PropertyChangeEvent evt)
          Called when a figure's location changes.
 FigureEnumeration figures()
          Answer a FiguresEnumeration over the figures of the receiver.
protected  void figureShapeChange(java.beans.PropertyChangeEvent evt)
          Called when a figure's shape changes.
protected  void figureSizeChange(java.beans.PropertyChangeEvent evt)
          Called when a figure's size changes.
 java.awt.Rectangle getBounds()
          Returns the current bounds of the receiver.
protected  java.awt.datatransfer.Clipboard getClipboard()
          Answers the Clipboard for this canvas.
 java.awt.Component getComponent()
          Answers the Component we are drawing/displaying.
protected  Figure getFigureFromString(java.lang.String string)
          Answer a Figure (or null) created based on the string (e.g.
protected  java.util.Vector getFromClipboard()
          Answer the stuff on the clipboard
protected  java.util.Vector getFromClipboard(java.awt.datatransfer.Clipboard clipboard)
          Answer the stuff on the clipboard
protected  java.util.Vector getFromSystemClipboard()
          Answer the stuff on the system clipboard
protected  java.awt.Color getHandleColor()
          Answer the Color to use in displaying handles.
 Handle[] getHandles()
          Answer the handles of the receiver.
 Locator getLocator(int x, int y)
          Answer the proper locator to be used for the given coordinates.
 Figure[] getSelections()
          Answer the selections of the receiver.
 java.awt.Dimension getSize()
          Returns the current size of the receiver.
 DrawingStyle getStyle()
          Answer the style which defines how to paint on the canvas.
protected  java.awt.datatransfer.Clipboard getSystemClipboard()
          Answer the system Clipboard.
 InputEventHandler getTool()
          Answer the active tool
 Handle handleAt(int x, int y)
          Answer the handle at a given point
protected  void ignoreDrawing()
          Stop listening to all of the figures of the drawing.
protected  void ignoreFigure(Figure figure)
          Stop listening to the specified figure.
 void keyPressed(java.awt.event.KeyEvent e)
          Invoked when a key has been pressed.
 void keyReleased(java.awt.event.KeyEvent e)
          Invoked when a key has been released.
 void keyTyped(java.awt.event.KeyEvent e)
          Invoked when a key has been typed.
protected  void listenToDrawing()
          Begin listening to all of the figures of the drawing.
protected  void listenToFigure(Figure figure)
          Begin listening to the specified figure.
protected  java.awt.Dimension minimumSize()
          Returns the minimum size of the receiver.
 void mouseClicked(java.awt.event.MouseEvent e)
          Invoked when the mouse has been clicked on a component.
 void mouseDragged(java.awt.event.MouseEvent e)
          Invoked when a mouse button is pressed on a component and then dragged.
 void mouseEntered(java.awt.event.MouseEvent e)
          Invoked when the mouse enters a component.
 void mouseExited(java.awt.event.MouseEvent e)
          Invoked when the mouse exits a component.
 void mouseMoved(java.awt.event.MouseEvent e)
          Invoked when the mouse button has been moved on a component (with no buttons no down).
 void mousePressed(java.awt.event.MouseEvent e)
          Invoked when a mouse button has been pressed on a component.
 void mouseReleased(java.awt.event.MouseEvent e)
          Invoked when a mouse button has been released on a component.
 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.
 void moveSelectionsToBack()
          Move the selected figures behind all other figures.
 void moveSelectionsToFront()
          Move the selected figures 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 canvas.
protected  void paintBackground(java.awt.Graphics g)
          Paints the background of the canvas.
protected  void paintForeground(java.awt.Graphics g)
          Paints the foreground of the canvas.
protected  void paintHandles(java.awt.Graphics g)
          Paints the handles on the canvas.
 void paste()
          Paste from the clipboard.
 void pasteFromSystem()
          Paste from the system clipboard.
protected  void processKey(java.awt.event.KeyEvent evt)
          Called if a character is typed.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          Called when a property changes.
protected  void putToClipboard(java.util.Vector stuff)
          Add the stuff to the clipboard
 void removeFigure(Figure figure)
          Remove the figure.
 void removeHandle(Handle handle)
          Remove the handle from the receiver.
 void removeHandles(Figure figure)
          Remove the handles corresponding to the figure to the receiver NOTE: Although this is public, it is assumed that most handles will be added/removed automatically through the process of selection, but some tools may wish to be more selective.
protected  void removeHandles(Handle[] handles)
          Remove the handles to the receiver.
 void removeSelection(Figure figure)
          Remove the figure from the selections.
protected  void repaint()
          Repaint the canvas.
 void repaint(java.awt.Rectangle rectangle)
          Repaints part of the canvas.
 void select(Figure figure)
          Make the figure the only selection Reflect the change if it's visible.
 void setComponent(java.awt.Component component)
          Set the Component to draw/display.
 void setDrawing(Drawing newDrawing)
          Set the drawing associated with this canvas.
 void setSize(java.awt.Dimension size)
          Set the size of the receiver.
 void setSize(int width, int height)
          Set the size of the receiver.
 void setStyle(DrawingStyle style)
          Set the style defining how to paint on the canvas.
 void setTool(InputEventHandler newTool)
          Set the active tool
 void toggleSelection(Figure figure)
          Toggle whether or not the figure is selected Reflect the change if it's visible.
 void toolTaskCompleted(InputEventHandler tool)
          Take appropriate action when the tool has completed its task.
protected  java.util.Vector validateOrder(java.util.Vector unordered)
          Answer a Vector containing the figures in the same order they appear in the receiver.
 
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

clipboard

protected static java.awt.datatransfer.Clipboard clipboard
A place to hold figures that are cut or copied. Currently, this is a rather primitive approach.

buffer

protected static final int buffer
The amount to add to drawings which are dynamically sized.

drawing

protected Drawing drawing
The drawing we are displaying/manipulating.

component

protected java.awt.Component component
The Component we are associated with.

tool

protected InputEventHandler tool
The tool which is the first thing we look to in order to handle events.

selections

protected java.util.Vector selections
The figures which are currently selected for further operations.

handles

protected java.util.Vector handles
The handles that may take control of events. Typically these are attached to figures, but not always.

figureHandles

protected java.util.Hashtable figureHandles
A mapping of figures to their associated handles. This is typically used to allow for proper clean up if figures are removed, but may be used for other purposes.

style

protected DrawingStyle style
The style with which it is expected new figures will be drawn.

width

protected int width
The width of the canvas.

height

protected int height
The height of the canvas.
Constructor Detail

SimpleDrawingCanvas

public SimpleDrawingCanvas()
Default constructor

SimpleDrawingCanvas

public SimpleDrawingCanvas(Drawing drawing)
Parameters:
drawing - the drawing to construct this canvas with
Method Detail

addFigure

public void addFigure(Figure figure)
Add the figure to the contents of the canvas. Reflect the change if it's visible. Become an observer on the figure.
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

addHandle

public void addHandle(Handle handle)
Add the handle to the receiver. Reflect the change if it's visible. NOTE: Although this is public, it is assumed that most handles will be added/removed automatically through the process of selection.
Specified by:
addHandle in interface DrawingCanvas
Parameters:
handle - the handle to add

addHandles

protected void addHandles(Handle[] handles)
Add the handles to the receiver. Reflect the change if it's visible.
Parameters:
handles - the array of handles to add

addHandles

public void addHandles(Figure figure)
Add the handles corresponding to the figure to the receiver. NOTE: Although this is public, it is assumed that most handles will be added/removed automatically through the process of selection, but some tools may wish to be more selective.
Specified by:
addHandles in interface DrawingCanvas
Parameters:
figure - the figure for which handles should be added.

addHandles

public void addHandles(Figure figure,
                       Handle[] handles)
Add the handles to the receiver, associating them the given figure. NOTE: Although this is public, it is assumed that most handles will be added/removed automatically through the process of selection, but some tools may wish to be more selective.
Specified by:
addHandles in interface DrawingCanvas
Parameters:
figure - the figure for which handles are associated.
handles - the handles to add.

addSelection

public void addSelection(Figure figure)
Add the figure to the selections. Reflect the change if it's visible.
Specified by:
addSelection in interface DrawingCanvas
Parameters:
figure - the Figure to add

clearHandles

protected void clearHandles()
Remove all the handles from the receiver. Reflect the change if it's visible.

clearSelections

public void clearSelections()
Remove all the selections of the receiver. Reflect the change if it's visible. Remove any obsolete figures which were selected.
Specified by:
clearSelections in interface DrawingCanvas

copySelections

public void copySelections()
Copy the selections. Make sure the copies are in the same order as the originals appeared.

cutSelections

public void cutSelections()
Cut the selections

defaultComponentBackground

protected java.awt.Color defaultComponentBackground()
Answer the default color for the Component background.
Returns:
Color

defaultDrawing

protected static Drawing defaultDrawing()
Answer the default/initial Drawing to use.
Returns:
the default/initial Drawing to use

defaultFigureHandles

protected java.util.Hashtable defaultFigureHandles()
Answer the default/initial figureHandles to use.
Returns:
Hashtable

defaultHandles

protected java.util.Vector defaultHandles()
Answer the default/initial handles to use.
Returns:
Vector

defaultHeight

protected int defaultHeight()
Answer the default/initial height to use.
Returns:
the default/initial height to use

defaultSelections

protected java.util.Vector defaultSelections()
Answer the default/initial selections to use.
Returns:
Vector

defaultStyle

protected DrawingStyle defaultStyle()
Answer the default/initial DrawingStyle to use.

defaultTool

protected InputEventHandler defaultTool()
Answer the default/initial tool to use.
Returns:
the default/initial InputEventHandler (tool) to use

defaultWidth

protected int defaultWidth()
Answer the default/initial width to use.
Returns:
the default/initial width to use

deleteSelections

public void deleteSelections()
Delete the selections

drawingSizeChange

protected void drawingSizeChange()
Called when the Drawing's size changes.

duplicateFigures

protected java.util.Vector duplicateFigures(java.util.Vector toCopy)
Duplicate all of the figures and return a new Vector
Parameters:
toCopy - the vector of figures to copy
Returns:
a new Vector containing all of the figures

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 the given point; null if none found

figureChange

protected void figureChange(java.beans.PropertyChangeEvent evt)
Called when a figure changes.

figureLocationChange

protected void figureLocationChange(java.beans.PropertyChangeEvent evt)
Called when a figure's location changes.

figures

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

figureShapeChange

protected void figureShapeChange(java.beans.PropertyChangeEvent evt)
Called when a figure's shape changes.

figureSizeChange

protected void figureSizeChange(java.beans.PropertyChangeEvent evt)
Called when a figure's size changes.

getBounds

public java.awt.Rectangle getBounds()
Returns the current bounds of the receiver.
Overrides:
getBounds in class AbstractPaintable
Returns:
a Rectangle representing the current bounds

getClipboard

protected java.awt.datatransfer.Clipboard getClipboard()
Answers the Clipboard for this canvas.
Returns:
the Clipboard for this canvas.

getComponent

public java.awt.Component getComponent()
Answers the Component we are drawing/displaying.
Specified by:
getComponent in interface ComponentHolder
Returns:
the Component we are drawing/displaying.

getFigureFromString

protected Figure getFigureFromString(java.lang.String string)
Answer a Figure (or null) created based on the string (e.g. from the clipboard)
Parameters:
string - the string to create the new figure from
Returns:
a new Figure created from the string

getFromClipboard

protected java.util.Vector getFromClipboard()
Answer the stuff on the clipboard
Returns:
the clipboard as a Vector

getFromClipboard

protected java.util.Vector getFromClipboard(java.awt.datatransfer.Clipboard clipboard)
Answer the stuff on the clipboard
Parameters:
clipboard - the Clipboard to get the data from.
Returns:
the clipboard as a Vector

getFromSystemClipboard

protected java.util.Vector getFromSystemClipboard()
Answer the stuff on the system clipboard
Returns:
the clipboard as a Vector

getHandleColor

protected java.awt.Color getHandleColor()
Answer the Color to use in displaying handles.
Returns:
the Color to use when displaying handles

getHandles

public Handle[] getHandles()
Answer the handles of the receiver. The returned array and its contents should be treated as read-only.
Specified by:
getHandles in interface DrawingCanvas
Returns:
an array of Handles representing the handles of the receiver; should be treated as read-only

getLocator

public Locator getLocator(int x,
                          int y)
Answer the proper locator to be used for the given coordinates. This method adjusts depending on whether the drawing is dynamically sized or not.
Specified by:
getLocator in interface DrawingCanvas
Parameters:
x - the x coordinate to return a Locator for.
y - the y coordinate to return a Locator for.
Returns:
a Locator corresponding to the given x and y coordinates.

getSelections

public Figure[] getSelections()
Answer the selections of the receiver. The returned array and its contents should be treated as read-only.
Specified by:
getSelections in interface DrawingCanvas
Returns:
an array of Figures representing the selections of the receiver; should be treated as read-only

getSize

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

getStyle

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

getSystemClipboard

protected java.awt.datatransfer.Clipboard getSystemClipboard()
Answer the system Clipboard.
Returns:
the Clipboard for the system. At this point (i.e. in Java 1.1) this is basically only good for strings.

getTool

public InputEventHandler getTool()
Answer the active tool
Specified by:
getTool in interface DrawingCanvas
Returns:
the active InputEventHandler (tool)

handleAt

public Handle handleAt(int x,
                       int y)
Answer the handle at a given point
Specified by:
handleAt in interface DrawingCanvas
Parameters:
x - the x coordinate
y - the y coordinate
Returns:
the Handle at the given point; null if none found

ignoreDrawing

protected void ignoreDrawing()
Stop listening to all of the figures of the drawing.

ignoreFigure

protected void ignoreFigure(Figure figure)
Stop listening to the specified figure.
Parameters:
figure - the figure to stop listening to

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Invoked when a key has been pressed.
Parameters:
e - the event

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Invoked when a key has been released.
Parameters:
e - the event

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Invoked when a key has been typed. This event occurs when a key press is followed by a key release.
Parameters:
e - the event

listenToDrawing

protected void listenToDrawing()
Begin listening to all of the figures of the drawing.

listenToFigure

protected void listenToFigure(Figure figure)
Begin listening to the specified figure.
Parameters:
figure - the figure to begin listening to

minimumSize

protected java.awt.Dimension minimumSize()
Returns the minimum size of the receiver.
Returns:
a Dimension representing the minimum size.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Invoked when the mouse has been clicked on a component.
Parameters:
e - the event

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Invoked when a mouse button is pressed on a component and then dragged. Mouse drag events will continue to be delivered to the component where the first originated until the mouse button is released (regardless of whether the mouse position is within the bounds of the component).
Parameters:
e - the event

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Invoked when the mouse enters a component.
Parameters:
e - the event

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Invoked when the mouse exits a component.
Parameters:
e - the event

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Invoked when the mouse button has been moved on a component (with no buttons no down).
Parameters:
e - the event

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Invoked when a mouse button has been pressed on a component.
Parameters:
e - the event

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Invoked when a mouse button has been released on a component.
Parameters:
e - the event

moveFigureBehind

public void moveFigureBehind(Figure figure,
                             Figure existingFigure)
Move the figure behind an existingFigure if it is not already there. Reflect the change if it's visible.
Parameters:
figure - the figure to move
existingFigure - the figure to which the new figure should be behind

moveFigureInFront

public void moveFigureInFront(Figure figure,
                              Figure existingFigure)
Move the figure in front of an existingFigure if it is not already there. Reflect the change if it's visible.
Parameters:
figure - the figure to move
existingFigure - the figure to which the new figure should be in front

moveFigureToBack

public void moveFigureToBack(Figure figure)
Move the figure behind all other figures. Reflect the change if it's visible.
Parameters:
figure - the figure to move

moveFigureToFront

public void moveFigureToFront(Figure figure)
Move the figure in front of all other figures. Reflect the change if it's visible.
Parameters:
figure - the figure to move

moveSelectionsToBack

public void moveSelectionsToBack()
Move the selected figures behind all other figures. Reflect the change if it's visible.

moveSelectionsToFront

public void moveSelectionsToFront()
Move the selected figures in front of all other figures. Reflect the change if it's visible.

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 identified figure; null if none found

paint

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

paintBackground

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

paintForeground

protected void paintForeground(java.awt.Graphics g)
Paints the foreground of the canvas.
Parameters:
g - the specified Graphics window

paintHandles

protected void paintHandles(java.awt.Graphics g)
Paints the handles on the canvas. Don't bother asking handles to paint themselves if they are not in the clipped region.
Parameters:
g - the specified Graphics window

paste

public void paste()
Paste from the clipboard. NOTE: Currently multiple pastes of the same thing shows up in the same place. Need to review entire approach to copy/cut/paste based on 1.1 model.

pasteFromSystem

public void pasteFromSystem()
Paste from the system clipboard. NOTE: Currently multiple pastes of the same thing shows up in the same place. Need to review entire approach to copy/cut/paste based on 1.1 model.

processKey

protected void processKey(java.awt.event.KeyEvent evt)
Called if a character is typed. Handle special keys to perform certain operations.
Parameters:
evt - the event
See Also:
keyTyped(java.awt.event.KeyEvent)

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Called when a property changes.
Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
evt - the event

putToClipboard

protected void putToClipboard(java.util.Vector stuff)
Add the stuff to the clipboard
Parameters:
stuff - the vector to add to the clipboard

removeFigure

public void removeFigure(Figure figure)
Remove the figure. Reflect the change if it's visible. Remove the receiver as an Observer of the figure and disconnect the figure completely.
Parameters:
figure - the figure to remove

removeHandle

public void removeHandle(Handle handle)
Remove the handle from the receiver. Reflect the change if it's visible. NOTE: Although this is public, it is assumed that most handles will be added/removed automatically through the process of selection. Since it is public, don't assume the handle asked for is actually present.
Specified by:
removeHandle in interface DrawingCanvas
Parameters:
handle - the handle to remove

removeHandles

protected void removeHandles(Handle[] handles)
Remove the handles to the receiver. Reflect the change if it's visible.
Parameters:
handles - the array of handles to be removed

removeHandles

public void removeHandles(Figure figure)
Remove the handles corresponding to the figure to the receiver NOTE: Although this is public, it is assumed that most handles will be added/removed automatically through the process of selection, but some tools may wish to be more selective.
Specified by:
removeHandles in interface DrawingCanvas
Parameters:
figure - the figure for which handles should be removed.

removeSelection

public void removeSelection(Figure figure)
Remove the figure from the selections. Reflect the change if it's visible. If a figure is obsolete, remove it.
Specified by:
removeSelection in interface DrawingCanvas
Parameters:
figure - the figure being deselected

repaint

protected void repaint()
Repaint the canvas.

repaint

public void repaint(java.awt.Rectangle rectangle)
Repaints part of the canvas. This will result in a call to update as soon as possible.
Specified by:
repaint in interface DrawingCanvas
Parameters:
rectangle - is the region to be repainted
See Also:
repaint()

select

public void select(Figure figure)
Make the figure the only selection Reflect the change if it's visible.
Specified by:
select in interface DrawingCanvas
Parameters:
figure - the figure being deselected

setComponent

public void setComponent(java.awt.Component component)
Set the Component to draw/display.
Specified by:
setComponent in interface ComponentHolder
Parameters:
component - the component to draw/display.

setDrawing

public void setDrawing(Drawing newDrawing)
Set the drawing associated with this canvas. Reflect the change if it's visible. Become an observer on the drawing.
Parameters:
newDrawing - the drawing to associate with

setSize

public void setSize(int width,
                    int height)
Set the size of the receiver.
Specified by:
setSize in interface DrawingCanvas
Parameters:
width - the new width of the receiver.
width - the new height of the receiver.

setSize

public void setSize(java.awt.Dimension size)
Set the size of the receiver.
Specified by:
setSize in interface DrawingCanvas
Parameters:
size - the new size of the receiver.

setStyle

public void setStyle(DrawingStyle style)
Set the style defining how to paint on the canvas. Change the foreground and background of the component immediately.
Specified by:
setStyle in interface DrawingCanvas
Parameters:
style - the specified DrawingStyle

setTool

public void setTool(InputEventHandler newTool)
Set the active tool
Specified by:
setTool in interface DrawingCanvas
Parameters:
newTool - the tool to make active

toggleSelection

public void toggleSelection(Figure figure)
Toggle whether or not the figure is selected Reflect the change if it's visible.
Specified by:
toggleSelection in interface DrawingCanvas
Parameters:
figure - the figure of interest

toolTaskCompleted

public void toolTaskCompleted(InputEventHandler tool)
Take appropriate action when the tool has completed its task. Default behavior is to do nothing. Subclasses may wish to give control back to another tool.
Specified by:
toolTaskCompleted in interface DrawingCanvas
Parameters:
tool - the tool which completed its task

validateOrder

protected java.util.Vector validateOrder(java.util.Vector unordered)
Answer a Vector containing the figures in the same order they appear in the receiver.
Parameters:
unordered - the Vector of figures that need to be ordered
Returns:
a Vector containing the figures in the same order they appear in the receiver