org.jhotdraw.standard
Class AbstractTool

java.lang.Object
  extended by org.jhotdraw.standard.AbstractTool
All Implemented Interfaces:
Tool
Direct Known Subclasses:
ActionTool, AreaTracker, ConnectionTool, CreationTool, DragNDropTool, DragTracker, HandleTracker, NullTool, PolygonTool, ScribbleTool, SelectAreaTracker, SelectionTool, URLTool, ZoomTool

public abstract class AbstractTool
extends java.lang.Object
implements Tool

Default implementation support for Tools.

Version:
<$CURRENT_VERSION$>
See Also:
DrawingView, Tool

Nested Class Summary
static class AbstractTool.EventDispatcher
           
 
Constructor Summary
AbstractTool(DrawingEditor newDrawingEditor)
          Constructs a tool for the given view.
 
Method Summary
 void activate()
          Activates the tool for use on the given view.
 void addToolListener(ToolListener newToolListener)
           
 void deactivate()
          Deactivates the tool.
 Drawing drawing()
          Gets the tool's drawing.
 DrawingEditor editor()
          Gets the tool's editor.
 Drawing getActiveDrawing()
           
 DrawingView getActiveView()
           
 Undoable getUndoActivity()
           
 boolean isActive()
          An active tool is the currently selected tool in the DrawingView.
 boolean isEnabled()
          A tool must be enabled in order to use it and to activate/deactivate it.
 boolean isUsable()
          Tests if the tool can be used or "executed."
 void keyDown(java.awt.event.KeyEvent evt, int key)
          Handles key down events in the drawing view.
 void mouseDown(java.awt.event.MouseEvent e, int x, int y)
          Handles mouse down events in the drawing view.
 void mouseDrag(java.awt.event.MouseEvent e, int x, int y)
          Handles mouse drag events in the drawing view.
 void mouseMove(java.awt.event.MouseEvent evt, int x, int y)
          Handles mouse moves (if the mouse button is up).
 void mouseUp(java.awt.event.MouseEvent e, int x, int y)
          Handles mouse up in the drawing view.
 void removeToolListener(ToolListener oldToolListener)
           
 void setEnabled(boolean newIsEnabled)
           
 void setUndoActivity(Undoable newUndoActivity)
           
 void setUsable(boolean newIsUsable)
           
 DrawingView view()
          Gets the tool's view (convienence method).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTool

public AbstractTool(DrawingEditor newDrawingEditor)
Constructs a tool for the given view.

Method Detail

activate

public void activate()
Activates the tool for use on the given view. This method is called whenever the user switches to this tool. Use this method to reinitialize a tool. Since tools will be disabled unless it is useable, there will always be an active view when this is called. based on isUsable() Tool should never be activated if the view is null. Ideally, the dditor should take care of that.

Specified by:
activate in interface Tool

deactivate

public void deactivate()
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

mouseDown

public void mouseDown(java.awt.event.MouseEvent e,
                      int x,
                      int y)
Handles mouse down events in the drawing view.

Specified by:
mouseDown in interface Tool

mouseDrag

public void mouseDrag(java.awt.event.MouseEvent e,
                      int x,
                      int y)
Handles mouse drag events in the drawing view.

Specified by:
mouseDrag in interface Tool

mouseUp

public void mouseUp(java.awt.event.MouseEvent e,
                    int x,
                    int y)
Handles mouse up in the drawing view.

Specified by:
mouseUp in interface Tool

mouseMove

public void mouseMove(java.awt.event.MouseEvent evt,
                      int x,
                      int y)
Handles mouse moves (if the mouse button is up).

Specified by:
mouseMove in interface Tool

keyDown

public void keyDown(java.awt.event.KeyEvent evt,
                    int key)
Handles key down events in the drawing view.

Specified by:
keyDown in interface Tool

drawing

public Drawing drawing()
Gets the tool's drawing.


getActiveDrawing

public Drawing getActiveDrawing()

editor

public DrawingEditor editor()
Gets the tool's editor.

Specified by:
editor in interface Tool

view

public DrawingView view()
Gets the tool's view (convienence method).


getActiveView

public DrawingView getActiveView()

isUsable

public boolean isUsable()
Tests if the tool can be used or "executed."

Specified by:
isUsable in interface Tool
See Also:
Tool.isEnabled(), Tool.isUsable()

setUsable

public void setUsable(boolean newIsUsable)
Specified by:
setUsable in interface Tool

setEnabled

public void setEnabled(boolean newIsEnabled)
Specified by:
setEnabled in interface Tool

isEnabled

public boolean isEnabled()
Description copied from interface: Tool
A tool must be enabled in order to use it and to activate/deactivate it. Typically, the program enables or disables a tool.

Specified by:
isEnabled in interface Tool
See Also:
Tool.isUsable(), Tool.isActive()

getUndoActivity

public Undoable getUndoActivity()
Specified by:
getUndoActivity in interface Tool

setUndoActivity

public void setUndoActivity(Undoable newUndoActivity)
Specified by:
setUndoActivity in interface Tool

isActive

public boolean isActive()
Description copied from interface: Tool
An active tool is the currently selected tool in the DrawingView. A tool can be activated/deactivated by calling the activate()/deactivate() method.

Specified by:
isActive in interface Tool
Returns:
true if the tool is the selected tool in the DrawingView, false otherwise
See Also:
Tool.isEnabled(), Tool.isUsable()

addToolListener

public void addToolListener(ToolListener newToolListener)
Specified by:
addToolListener in interface Tool

removeToolListener

public void removeToolListener(ToolListener oldToolListener)
Specified by:
removeToolListener in interface Tool