org.jhotdraw.draw.tool
Class CreationTool
- java.lang.Object
-
- org.jhotdraw.beans.AbstractBean
-
- org.jhotdraw.draw.tool.AbstractTool
-
- 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
AToolto 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:- Press the mouse button over the DrawingView. This defines the start point of the Figure bounds.
- Drag the mouse while keeping the mouse button pressed, and then release the mouse button. This defines the end point of the Figure bounds.
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 PatternsPrototype
The creation tool creates new figures by cloning a prototype figure object. That's the reason whyFigureextends theCloneableinterface.
Prototype:Figure; Client:CreationTool.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidactivate(DrawingEditor editor)Activates the tool for the given editor.voiddeactivate(DrawingEditor editor)Deactivates the tool.FiguregetPrototype()booleanisToolDoneAfterCreation()Returns true, if this tool fires toolDone immediately after a new figure has been created.voidmouseDragged(java.awt.event.MouseEvent evt)voidmousePressed(java.awt.event.MouseEvent evt)voidmouseReleased(java.awt.event.MouseEvent evt)voidsetToolDoneAfterCreation(boolean newValue)If this is set to false, the CreationTool does not fire toolDone after a new Figure has been created.voidupdateCursor(DrawingView view, java.awt.Point p)-
Methods inherited from class org.jhotdraw.draw.tool.AbstractTool
addToolListener, addUndoableEditListener, draw, editCopy, editCut, editDelete, editDuplicate, editPaste, getActionMap, getInputMap, getToolTipText, isActive, keyPressed, keyReleased, keyTyped, mouseClicked, mouseEntered, mouseExited, mouseMoved, removeToolListener, removeUndoableEditListener, setActionMap, setInputMap, supportsHandleInteraction
-
Methods inherited from class org.jhotdraw.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, clone, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Constructor Detail
-
CreationTool
public CreationTool(java.lang.String prototypeClassName)
Creates a new instance.
-
CreationTool
public CreationTool(java.lang.String prototypeClassName, @Nullable java.util.Map<AttributeKey,java.lang.Object> attributes)
-
CreationTool
public CreationTool(java.lang.String prototypeClassName, @Nullable java.util.Map<AttributeKey,java.lang.Object> attributes, @Nullable 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, @Nullable 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, @Nullable java.util.Map<AttributeKey,java.lang.Object> attributes, @Nullable 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:ToolActivates the tool for the given editor. This method is called whenever the user switches to this tool.- Specified by:
activatein interfaceTool- Overrides:
activatein classAbstractTool
-
deactivate
public void deactivate(DrawingEditor editor)
Description copied from interface:ToolDeactivates the tool. This method is called whenever the user switches to another tool.- Specified by:
deactivatein interfaceTool- Overrides:
deactivatein classAbstractTool
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent evt)
- Specified by:
mousePressedin interfacejava.awt.event.MouseListener- Overrides:
mousePressedin classAbstractTool
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent evt)
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent evt)
- Specified by:
mouseReleasedin interfacejava.awt.event.MouseListener- Overrides:
mouseReleasedin classAbstractTool
-
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:
updateCursorin classAbstractTool
-
-
DataMelt 3.0 © DataMelt by jWork.ORG