JHotDraw 6.0b1

org.jhotdraw.standard
Class CreationTool

java.lang.Object
  extended by org.jhotdraw.standard.AbstractTool
      extended by org.jhotdraw.standard.CreationTool
All Implemented Interfaces:
Tool
Direct Known Subclasses:
CompositeFigureCreationTool, NestedCreationTool, PertFigureCreationTool, TextAreaTool, TextTool

public class CreationTool
extends AbstractTool

A tool to create new figures. The figure to be created is specified by a prototype.


Design Patterns

 o Prototype
CreationTool creates new figures by cloning a prototype.


See Also:
Figure, Object.clone()

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jhotdraw.standard.AbstractTool
AbstractTool.EventDispatcher
 
Constructor Summary
protected CreationTool(DrawingEditor newDrawingEditor)
          Constructs a CreationTool without a prototype.
  CreationTool(DrawingEditor newDrawingEditor, Figure prototype)
          Initializes a CreationTool with the given prototype.
 
Method Summary
 void activate()
          Sets the cross hair cursor.
protected  Figure createFigure()
          Creates a new figure by cloning the prototype.
protected  Undoable createUndoActivity()
          Factory method for undo activity
 void deactivate()
          Deactivates the tool.
protected  Figure getAddedFigure()
          Gets the figure that was actually added Note, this can be a different figure from the one which has been created.
protected  java.util.List getAddedFigures()
          Gets the list of currently added figure
protected  Figure getCreatedFigure()
          Gets the currently created figure
protected  Figure getPrototypeFigure()
          As the name suggests this CreationTool uses the Prototype design pattern.
 void mouseDown(java.awt.event.MouseEvent e, int x, int y)
          Creates a new figure by cloning the prototype.
 void mouseDrag(java.awt.event.MouseEvent e, int x, int y)
          Adjusts the extent of the created figure
 void mouseUp(java.awt.event.MouseEvent e, int x, int y)
          Checks if the created figure is empty.
protected  void setAddedFigure(Figure newAddedFigure)
          Sets the addedFigure attribute of the CreationTool object
protected  void setAddedFigures(java.util.List newAddedFigures)
          Sets the addedFigures attribute of the CreationTool object
protected  void setCreatedFigure(Figure newCreatedFigure)
          Sets the createdFigure attribute of the CreationTool object
protected  void setPrototypeFigure(Figure newPrototypeFigure)
          As the name suggests this CreationTool uses the Prototype design pattern.
 
Methods inherited from class org.jhotdraw.standard.AbstractTool
addToolListener, checkUsable, createEventDispatcher, createViewChangeListener, drawing, editor, getActiveDrawing, getActiveView, getAnchorX, getAnchorY, getEventDispatcher, getUndoActivity, isActive, isEnabled, isUsable, keyDown, mouseMove, removeToolListener, setAnchorX, setAnchorY, setEditor, setEnabled, setUndoActivity, setUsable, setView, view, viewCreated, viewDestroying, viewSelectionChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CreationTool

public CreationTool(DrawingEditor newDrawingEditor,
                    Figure prototype)
Initializes a CreationTool with the given prototype.


CreationTool

protected CreationTool(DrawingEditor newDrawingEditor)
Constructs a CreationTool without a prototype. This is for subclassers overriding createFigure.

Method Detail

activate

public void activate()
Sets the cross hair cursor.

Specified by:
activate in interface Tool
Overrides:
activate in class AbstractTool

deactivate

public void deactivate()
Description copied from class: AbstractTool
Deactivates the tool. This method is called whenever the user switches to another tool. Use this method to do some clean-up when the tool is switched. Subclassers should always call super.deactivate. An inactive tool should never be deactivated

Specified by:
deactivate in interface Tool
Overrides:
deactivate in class AbstractTool
See Also:
Tool.deactivate()

mouseDown

public void mouseDown(java.awt.event.MouseEvent e,
                      int x,
                      int y)
Creates a new figure by cloning the prototype.

Specified by:
mouseDown in interface Tool
Overrides:
mouseDown in class AbstractTool

createFigure

protected Figure createFigure()
Creates a new figure by cloning the prototype.


mouseDrag

public void mouseDrag(java.awt.event.MouseEvent e,
                      int x,
                      int y)
Adjusts the extent of the created figure

Specified by:
mouseDrag in interface Tool
Overrides:
mouseDrag in class AbstractTool

mouseUp

public void mouseUp(java.awt.event.MouseEvent e,
                    int x,
                    int y)
Checks if the created figure is empty. If it is, the figure is removed from the drawing.

Specified by:
mouseUp in interface Tool
Overrides:
mouseUp in class AbstractTool
See Also:
Figure.isEmpty()

setPrototypeFigure

protected void setPrototypeFigure(Figure newPrototypeFigure)
As the name suggests this CreationTool uses the Prototype design pattern. Thus, the prototype figure which is used to create new figures of the same type by cloning the original prototype figure.

Parameters:
newPrototypeFigure - figure to be cloned to create new figures

getPrototypeFigure

protected Figure getPrototypeFigure()
As the name suggests this CreationTool uses the Prototype design pattern. Thus, the prototype figure which is used to create new figures of the same type by cloning the original prototype figure.

Returns:
figure to be cloned to create new figures

getAddedFigures

protected java.util.List getAddedFigures()
Gets the list of currently added figure


setAddedFigures

protected void setAddedFigures(java.util.List newAddedFigures)
Sets the addedFigures attribute of the CreationTool object


getCreatedFigure

protected Figure getCreatedFigure()
Gets the currently created figure


setCreatedFigure

protected void setCreatedFigure(Figure newCreatedFigure)
Sets the createdFigure attribute of the CreationTool object


getAddedFigure

protected Figure getAddedFigure()
Gets the figure that was actually added Note, this can be a different figure from the one which has been created.


setAddedFigure

protected void setAddedFigure(Figure newAddedFigure)
Sets the addedFigure attribute of the CreationTool object


createUndoActivity

protected Undoable createUndoActivity()
Factory method for undo activity


JHotDraw 6.0b1