JHotDraw 7.4.1

org.jhotdraw.draw.tool
Class CreationTool

java.lang.Object
  extended by org.jhotdraw.beans.AbstractBean
      extended by org.jhotdraw.draw.tool.AbstractTool
          extended by org.jhotdraw.draw.tool.CreationTool
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, Tool
Direct Known Subclasses:
ImageTool, SVGCreateFromFileTool, TextAreaCreationTool, TextCreationTool

public class CreationTool
extends AbstractTool

A Tool to create a new figure by drawing its bounds. The figure to be created is specified by a prototype.

To create a figure using the CreationTool, the user does the following mouse gestures on a DrawingView:

  1. Press the mouse button over the DrawingView. This defines the start point of the Figure bounds.
  2. Drag the mouse while keeping the mouse button pressed, and then release the mouse button. This defines the end point of the Figure bounds.
The CreationTool works well with most figures that fit into a rectangular shape or that concist of a single straight line. For figures that need additional editing after these mouse gestures, the use of a specialized creation tool is recommended. For example the TextTool allows to enter the text into a TextFigure after the user has performed the mouse gestures.

Alltough the mouse gestures might be fitting for the creation of a connection, the CreationTool is not suited for the creation of a ConnectionFigure. Use the ConnectionTool for this type of figures instead.


Design Patterns

Prototype
The creation tool creates new figures by cloning a prototype figure object. That's the reason why Figure extends the Cloneable interface.
Prototype: Figure; Client: CreationTool.


Version:
$Id: CreationTool.java 604 2010-01-09 12:00:29Z rawcoder $
Author:
Werner Randelshofer
See Also:
Serialized Form

Field Summary
protected  Figure createdFigure
          The created figure.
protected  java.awt.Dimension minimalSize
          We set the figure to this minimal size, if it is smaller than the minimal size treshold.
protected  java.awt.Dimension minimalSizeTreshold
          Treshold for which we create a larger shape of a minimal size.
protected  java.lang.String presentationName
          A localized name for this tool.
protected  Figure prototype
          The prototype for new figures.
protected  java.util.Map<AttributeKey,java.lang.Object> prototypeAttributes
          Attributes to be applied to the created ConnectionFigure.
 
Fields inherited from class org.jhotdraw.draw.tool.AbstractTool
anchor, editor, isWorking, listenerList
 
Fields inherited from class org.jhotdraw.beans.AbstractBean
propertySupport
 
Constructor Summary
CreationTool(Figure prototype)
          Creates a new instance with the specified prototype but without an attribute set.
CreationTool(Figure prototype, java.util.Map<AttributeKey,java.lang.Object> attributes)
          Creates a new instance with the specified prototype but without an attribute set.
CreationTool(Figure prototype, java.util.Map<AttributeKey,java.lang.Object> attributes, java.lang.String name)
          Deprecated. This constructor might go away, because the name parameter is not used.
CreationTool(java.lang.String prototypeClassName)
          Creates a new instance.
CreationTool(java.lang.String prototypeClassName, java.util.Map<AttributeKey,java.lang.Object> attributes)
           
CreationTool(java.lang.String prototypeClassName, java.util.Map<AttributeKey,java.lang.Object> attributes, java.lang.String name)
           
 
Method Summary
 void activate(DrawingEditor editor)
          Activates the tool for the given editor.
protected  Figure createFigure()
           
protected  void creationFinished(Figure createdFigure)
          This method allows subclasses to do perform additonal user interactions after the new figure has been created.
 void deactivate(DrawingEditor editor)
          Deactivates the tool.
protected  Figure getAddedFigure()
           
protected  Figure getCreatedFigure()
           
 Figure getPrototype()
           
 boolean isToolDoneAfterCreation()
          Returns true, if this tool fires toolDone immediately after a new figure has been created.
 void mouseDragged(java.awt.event.MouseEvent evt)
           
 void mousePressed(java.awt.event.MouseEvent evt)
           
 void mouseReleased(java.awt.event.MouseEvent evt)
           
 void setToolDoneAfterCreation(boolean newValue)
          If this is set to false, the CreationTool does not fire toolDone after a new Figure has been created.
 void updateCursor(DrawingView view, java.awt.Point p)
           
 
Methods inherited from class org.jhotdraw.draw.tool.AbstractTool
addToolListener, addUndoableEditListener, constrainPoint, constrainPoint, createActionMap, createInputMap, draw, editCopy, editCut, editDelete, editDuplicate, editPaste, fireAreaInvalidated, fireAreaInvalidated, fireBoundsInvalidated, fireToolDone, fireToolStarted, getActionMap, getDrawing, getEditor, getInputMap, getToolTipText, getView, isActive, keyPressed, keyReleased, keyTyped, maybeFireBoundsInvalidated, mouseClicked, mouseEntered, mouseExited, mouseMoved, removeToolListener, removeUndoableEditListener, setActionMap, setInputMap, supportsHandleInteraction, viewToDrawing
 
Methods inherited from class org.jhotdraw.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, clone, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

prototypeAttributes

protected java.util.Map<AttributeKey,java.lang.Object> prototypeAttributes
Attributes to be applied to the created ConnectionFigure. These attributes override the default attributes of the DrawingEditor.


presentationName

protected java.lang.String presentationName
A localized name for this tool. The presentationName is displayed by the UndoableEdit.


minimalSizeTreshold

protected java.awt.Dimension minimalSizeTreshold
Treshold for which we create a larger shape of a minimal size.


minimalSize

protected java.awt.Dimension minimalSize
We set the figure to this minimal size, if it is smaller than the minimal size treshold.


prototype

protected Figure prototype
The prototype for new figures.


createdFigure

protected Figure createdFigure
The created figure.

Constructor Detail

CreationTool

public CreationTool(java.lang.String prototypeClassName)
Creates a new instance.


CreationTool

public CreationTool(java.lang.String prototypeClassName,
                    java.util.Map<AttributeKey,java.lang.Object> attributes)

CreationTool

public CreationTool(java.lang.String prototypeClassName,
                    java.util.Map<AttributeKey,java.lang.Object> attributes,
                    java.lang.String name)

CreationTool

public CreationTool(Figure prototype)
Creates a new instance with the specified prototype but without an attribute set. The CreationTool clones this prototype each time a new Figure needs to be created. When a new Figure is created, the CreationTool applies the default attributes from the DrawingEditor to it.

Parameters:
prototype - The prototype used to create a new Figure.

CreationTool

public CreationTool(Figure prototype,
                    java.util.Map<AttributeKey,java.lang.Object> attributes)
Creates a new instance with the specified prototype but without an attribute set. The CreationTool clones this prototype each time a new Figure needs to be created. When a new Figure is created, the CreationTool applies the default attributes from the DrawingEditor to it, and then it applies the attributes to it, that have been supplied in this constructor.

Parameters:
prototype - The prototype used to create a new Figure.
attributes - The CreationTool applies these attributes to the prototype after having applied the default attributes from the DrawingEditor.

CreationTool

public CreationTool(Figure prototype,
                    java.util.Map<AttributeKey,java.lang.Object> attributes,
                    java.lang.String name)
Deprecated. This constructor might go away, because the name parameter is not used.

Creates a new instance with the specified prototype and attribute set.

Parameters:
prototype - The prototype used to create a new Figure.
attributes - The CreationTool applies these attributes to the prototype after having applied the default attributes from the DrawingEditor.
name - The name parameter is currently not used.
Method Detail

getPrototype

public Figure getPrototype()

activate

public void activate(DrawingEditor editor)
Description copied from interface: Tool
Activates the tool for the given editor. This method is called whenever the user switches to this tool.

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

deactivate

public void deactivate(DrawingEditor editor)
Description copied from interface: Tool
Deactivates the tool. This method is called whenever the user switches to another tool.

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

mousePressed

public void mousePressed(java.awt.event.MouseEvent evt)
Specified by:
mousePressed in interface java.awt.event.MouseListener
Overrides:
mousePressed in class AbstractTool

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent evt)

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent evt)
Specified by:
mouseReleased in interface java.awt.event.MouseListener
Overrides:
mouseReleased in class AbstractTool

createFigure

protected Figure createFigure()

getCreatedFigure

protected Figure getCreatedFigure()

getAddedFigure

protected Figure getAddedFigure()

creationFinished

protected void creationFinished(Figure createdFigure)
This method allows subclasses to do perform additonal user interactions after the new figure has been created. The implementation of this class just invokes fireToolDone.


setToolDoneAfterCreation

public void setToolDoneAfterCreation(boolean newValue)
If this is set to false, the CreationTool does not fire toolDone after a new Figure has been created. This allows to create multiple figures consecutively.


isToolDoneAfterCreation

public boolean isToolDoneAfterCreation()
Returns true, if this tool fires toolDone immediately after a new figure has been created.


updateCursor

public void updateCursor(DrawingView view,
                         java.awt.Point p)
Overrides:
updateCursor in class AbstractTool

Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.