com.rolemodelsoft.drawlet.basics
Class ConstructionTool

java.lang.Object
  |
  +--com.rolemodelsoft.drawlet.basics.AbstractInputEventHandler
        |
        +--com.rolemodelsoft.drawlet.basics.CanvasTool
              |
              +--com.rolemodelsoft.drawlet.basics.ConstructionTool
Direct Known Subclasses:
LabelTool, PrototypeConstructionTool, ShapeTool

public abstract class ConstructionTool
extends CanvasTool

This abstract class offers a simple base for Tools which create new Figures and place them on a drawing canvas. Concrete subclasses need to supply, at minmum: basicNewFigure(int,int); some means of initializing canvas (e.g. Constructor)


Field Summary
protected  Figure figure
          The figure the receiver is currently constructing (or null if the tool is not active).
 
Fields inherited from class com.rolemodelsoft.drawlet.basics.CanvasTool
canvas
 
Constructor Summary
ConstructionTool()
           
 
Method Summary
protected abstract  Figure basicNewFigure(int x, int y)
          Create and answer a new Figure.
 void mouseDragged(java.awt.event.MouseEvent e)
          Called if the mouse is dragged (the mouse button is down and mouse is moving).
 void mousePressed(java.awt.event.MouseEvent e)
          Called if the mouse is pressed.
 void mouseReleased(java.awt.event.MouseEvent e)
          Called if the mouse is released.
protected  Figure newFigure(int x, int y)
          Create and answer a new Figure.
protected  void setProperties(Figure aFigure)
          Set the properties of aFigure.
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.CanvasTool
getX, getY
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractInputEventHandler
keyPressed, keyReleased, keyTyped, mouseClicked, mouseDoubleClicked, mouseEntered, mouseExited, mouseMoved, mouseSingleClicked
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

figure

protected Figure figure
The figure the receiver is currently constructing (or null if the tool is not active).
Constructor Detail

ConstructionTool

public ConstructionTool()
Method Detail

basicNewFigure

protected abstract Figure basicNewFigure(int x,
                                         int y)
Create and answer a new Figure.
Parameters:
x - the x coordinate
y - the y coordinate
Returns:
a new Figure

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Called if the mouse is dragged (the mouse button is down and mouse is moving). By default, move the figure we created, if we have one. Consume the event since we handle it.
Overrides:
mouseDragged in class AbstractInputEventHandler
Parameters:
e - the event

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Called if the mouse is pressed. By default, create a new figure and add it to the canvas. Subclasses may wish to consider newFigure() instead of this method. Consume the event since we handle it.
Overrides:
mousePressed in class AbstractInputEventHandler
Parameters:
e - the event
See Also:
newFigure(int, int)

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Called if the mouse is released. By default, we're done constructing and manipulating the figure, so forget about the figure and prepare to create a new one, in addition to inherited behavior.
Overrides:
mouseReleased in class CanvasTool
Parameters:
e - the event

newFigure

protected Figure newFigure(int x,
                           int y)
Create and answer a new Figure. This is a TemplateMethod/FactoryMethod. hooks are basicNewFigure() and setProperties().
Parameters:
x - the x coordinate
y - the y coordinate
Returns:
a newly created Figure
See Also:
basicNewFigure(int, int), setProperties(com.rolemodelsoft.drawlet.Figure)

setProperties

protected void setProperties(Figure aFigure)
Set the properties of aFigure. By default, use the canvas' style to set that of aFigure.
Parameters:
aFigure - the Figure to set properties.