org.jhotdraw.draw
Class AbstractTool

java.lang.Object
  extended by org.jhotdraw.beans.AbstractBean
      extended by org.jhotdraw.draw.AbstractTool
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:
BezierTool, BidirectionalConnectionTool, ConnectionTool, CreationTool, DefaultDragTracker, DefaultHandleTracker, DefaultSelectAreaTracker, DnDTracker, SelectionTool, TextAreaEditingTool, TextEditingTool

public abstract class AbstractTool
extends AbstractBean
implements Tool

AbstractTool.

Version:
5.0 2007-11-05 Changed superclass from Object to AbstractBean.
4.0 2007-04-29 Replaced code in method keyPressed by an InputMap and a ActionMap.
3.0 2006-02-15 Updated to handle multiple views.
2.0 2006-01-14 Changed to support double precision coordinates.
1.0 2003-12-01 Derived from JHotDraw 5.4b1.
Author:
Werner Randelshofer
See Also:
Serialized Form

Field Summary
private  javax.swing.ActionMap actionMap
          The action map of the tool.
protected  java.awt.Point anchor
           
protected  DrawingEditor editor
           
private  DrawingEditorProxy editorProxy
           
private  javax.swing.InputMap inputMap
          The input map of the tool.
private  boolean isActive
          This is set to true, if this is the active tool of the editor.
protected  boolean isWorking
          This is set to true, while the tool is doing some work.
protected  javax.swing.event.EventListenerList listenerList
           
 
Fields inherited from class org.jhotdraw.beans.AbstractBean
propertySupport
 
Constructor Summary
AbstractTool()
          Creates a new instance.
 
Method Summary
 void activate(DrawingEditor editor)
          Activates the tool for the given editor.
 void addToolListener(ToolListener l)
          Adds a listener for this tool.
 void addUndoableEditListener(javax.swing.event.UndoableEditListener l)
           
protected  java.awt.geom.Point2D.Double constrainPoint(java.awt.Point p)
           
protected  java.awt.geom.Point2D.Double constrainPoint(java.awt.geom.Point2D.Double p)
           
protected  javax.swing.ActionMap createActionMap()
           
protected  javax.swing.InputMap createInputMap()
           
 void deactivate(DrawingEditor editor)
          Deactivates the tool.
 void draw(java.awt.Graphics2D g)
          Draws the tool.
 void editCopy()
          Copies the selection into the clipboard.
 void editCut()
          Cuts the selection into the clipboard.
 void editDelete()
          Deletes the selection.
 void editDuplicate()
          Duplicates the selection.
 void editPaste()
          Pastes the contents of the clipboard.
protected  void fireAreaInvalidated(java.awt.Rectangle invalidatedArea)
          Notify all listenerList that have registered interest for notification on this event type.
protected  void fireAreaInvalidated(java.awt.geom.Rectangle2D.Double r)
          Notify all listenerList that have registered interest for notification on this event type.
protected  void fireToolDone()
          Notify all listenerList that have registered interest for notification on this event type.
protected  void fireToolStarted(DrawingView view)
          Notify all listenerList that have registered interest for notification on this event type.
 javax.swing.ActionMap getActionMap()
          Gets the action map of the Tool
protected  Drawing getDrawing()
           
protected  DrawingEditor getEditor()
           
 javax.swing.InputMap getInputMap()
          Gets the input map of the Tool
 java.lang.String getToolTipText(DrawingView view, java.awt.event.MouseEvent evt)
          Returns the tooltip text for a mouse event on a drawing view.
protected  DrawingView getView()
           
 boolean isActive()
           
 void keyPressed(java.awt.event.KeyEvent evt)
          The Tool uses the InputMap to determine what to do, when a key is pressed.
 void keyReleased(java.awt.event.KeyEvent evt)
           
 void keyTyped(java.awt.event.KeyEvent evt)
           
 void mouseClicked(java.awt.event.MouseEvent evt)
           
 void mouseEntered(java.awt.event.MouseEvent evt)
           
 void mouseExited(java.awt.event.MouseEvent evt)
           
 void mouseMoved(java.awt.event.MouseEvent evt)
           
 void mousePressed(java.awt.event.MouseEvent evt)
           
 void mouseReleased(java.awt.event.MouseEvent evt)
           
 void removeToolListener(ToolListener l)
          Removes a listener for this tool.
 void removeUndoableEditListener(javax.swing.event.UndoableEditListener l)
           
 void setActionMap(javax.swing.ActionMap newValue)
          Sets the ActionMap for the Tool.
 void setInputMap(javax.swing.InputMap newValue)
          Sets the InputMap for the Tool.
 boolean supportsHandleInteraction()
          Returns true, if this tool lets the user interact with handles.
 void updateCursor(DrawingView view, java.awt.Point p)
           
protected  java.awt.geom.Point2D.Double viewToDrawing(java.awt.Point p)
           
 
Methods inherited from class org.jhotdraw.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, clone, firePropertyChange, firePropertyChange, firePropertyChange, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.awt.event.MouseMotionListener
mouseDragged
 

Field Detail

isActive

private boolean isActive
This is set to true, if this is the active tool of the editor.


isWorking

protected boolean isWorking
This is set to true, while the tool is doing some work. This prevents the currentView from being changed when a mouseEnter event is received.


editor

protected DrawingEditor editor

anchor

protected java.awt.Point anchor

listenerList

protected javax.swing.event.EventListenerList listenerList

editorProxy

private DrawingEditorProxy editorProxy

inputMap

private javax.swing.InputMap inputMap
The input map of the tool.


actionMap

private javax.swing.ActionMap actionMap
The action map of the tool.

Constructor Detail

AbstractTool

public AbstractTool()
Creates a new instance.

Method Detail

addUndoableEditListener

public void addUndoableEditListener(javax.swing.event.UndoableEditListener l)

removeUndoableEditListener

public void removeUndoableEditListener(javax.swing.event.UndoableEditListener l)

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

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

isActive

public boolean isActive()

getView

protected DrawingView getView()

getEditor

protected DrawingEditor getEditor()

getDrawing

protected Drawing getDrawing()

viewToDrawing

protected java.awt.geom.Point2D.Double viewToDrawing(java.awt.Point p)

constrainPoint

protected java.awt.geom.Point2D.Double constrainPoint(java.awt.Point p)

constrainPoint

protected java.awt.geom.Point2D.Double constrainPoint(java.awt.geom.Point2D.Double p)

setInputMap

public void setInputMap(javax.swing.InputMap newValue)
Sets the InputMap for the Tool.

See Also:
keyPressed(java.awt.event.KeyEvent), setActionMap(javax.swing.ActionMap)

getInputMap

public javax.swing.InputMap getInputMap()
Gets the input map of the Tool


setActionMap

public void setActionMap(javax.swing.ActionMap newValue)
Sets the ActionMap for the Tool.

See Also:
keyPressed(java.awt.event.KeyEvent)

getActionMap

public javax.swing.ActionMap getActionMap()
Gets the action map of the Tool


editDelete

public void editDelete()
Deletes the selection. Depending on the tool, this could be selected figures, selected points or selected text.

Specified by:
editDelete in interface Tool

editCut

public void editCut()
Cuts the selection into the clipboard. Depending on the tool, this could be selected figures, selected points or selected text.

Specified by:
editCut in interface Tool

editCopy

public void editCopy()
Copies the selection into the clipboard. Depending on the tool, this could be selected figures, selected points or selected text.

Specified by:
editCopy in interface Tool

editDuplicate

public void editDuplicate()
Duplicates the selection. Depending on the tool, this could be selected figures, selected points or selected text.

Specified by:
editDuplicate in interface Tool

editPaste

public void editPaste()
Pastes the contents of the clipboard. Depending on the tool, this could be selected figures, selected points or selected text.

Specified by:
editPaste in interface Tool

keyReleased

public void keyReleased(java.awt.event.KeyEvent evt)
Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent evt)
Specified by:
keyTyped in interface java.awt.event.KeyListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent evt)
The Tool uses the InputMap to determine what to do, when a key is pressed. If the corresponding value of the InputMap is a String, the ActionMap of the tool is used, to find the action to be performed. If the corresponding value of the InputMap is a ActionListener, the actionPerformed method of the ActionListener is performed.

Specified by:
keyPressed in interface java.awt.event.KeyListener

createInputMap

protected javax.swing.InputMap createInputMap()

createActionMap

protected javax.swing.ActionMap createActionMap()

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent evt)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent evt)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent evt)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent evt)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mousePressed

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

mouseReleased

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

addToolListener

public void addToolListener(ToolListener l)
Description copied from interface: Tool
Adds a listener for this tool.

Specified by:
addToolListener in interface Tool

removeToolListener

public void removeToolListener(ToolListener l)
Description copied from interface: Tool
Removes a listener for this tool.

Specified by:
removeToolListener in interface Tool

fireToolStarted

protected void fireToolStarted(DrawingView view)
Notify all listenerList that have registered interest for notification on this event type.


fireToolDone

protected void fireToolDone()
Notify all listenerList that have registered interest for notification on this event type.


fireAreaInvalidated

protected void fireAreaInvalidated(java.awt.geom.Rectangle2D.Double r)
Notify all listenerList that have registered interest for notification on this event type.


fireAreaInvalidated

protected void fireAreaInvalidated(java.awt.Rectangle invalidatedArea)
Notify all listenerList that have registered interest for notification on this event type.


draw

public void draw(java.awt.Graphics2D g)
Description copied from interface: Tool
Draws the tool.

Specified by:
draw in interface Tool

updateCursor

public void updateCursor(DrawingView view,
                         java.awt.Point p)

getToolTipText

public java.lang.String getToolTipText(DrawingView view,
                                       java.awt.event.MouseEvent evt)
Description copied from interface: Tool
Returns the tooltip text for a mouse event on a drawing view.

Specified by:
getToolTipText in interface Tool
Parameters:
view - A drawing view.
evt - A mouse event.
Returns:
A tooltip text or null.

supportsHandleInteraction

public boolean supportsHandleInteraction()
Returns true, if this tool lets the user interact with handles.

Handles may draw differently, if interaction is not possible.

Specified by:
supportsHandleInteraction in interface Tool
Returns:
True, if this tool supports interaction with the handles.