JHotDraw 7.4.1

org.jhotdraw.draw.tool
Class AbstractTool

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

public abstract class AbstractTool
extends AbstractBean
implements Tool

This abstract class can be extended to implement a Tool.


Design Patterns

Proxy
To remove the need for null-handling, AbstractTool makes use of a proxy for DrawingEditor. Subject: DrawingEditor; Proxy: DrawingEditorProxy; Client: AbstractTool.


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

Field Summary
protected  java.awt.Point anchor
           
protected  DrawingEditor 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()
          Override this method to create a tool-specific action map, which overrides the action map of the drawing edtior.
protected  javax.swing.InputMap createInputMap()
          Override this method to create a tool-specific input map, which overrides the input map of the drawing edtior.
 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 fireBoundsInvalidated(java.awt.Rectangle invalidatedArea)
          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)
           
protected  void maybeFireBoundsInvalidated(java.awt.Rectangle invalidatedArea)
          Notify all listenerList that have registered interest for notification on this event type.
 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, getPropertyChangeListeners, 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

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
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()
Override this method to create a tool-specific input map, which overrides the input map of the drawing edtior.

The implementation of this class returns null.


createActionMap

protected javax.swing.ActionMap createActionMap()
Override this method to create a tool-specific action map, which overrides the action map of the drawing edtior.

The implementation of this class returns null.


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.


maybeFireBoundsInvalidated

protected void maybeFireBoundsInvalidated(java.awt.Rectangle invalidatedArea)
Notify all listenerList that have registered interest for notification on this event type. Note: This method only fires an event, if the invalidated area is outside of the canvas bounds.


fireBoundsInvalidated

protected void fireBoundsInvalidated(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.

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