JHotDraw 6.0b1

org.jhotdraw.framework
Interface Tool

All Known Implementing Classes:
AbstractTool, ActionTool, AreaTracker, BorderTool, CompositeFigureCreationTool, ConnectedTextTool, ConnectionTool, CreationTool, CustomSelectionTool, DragNDropTool, DragTracker, HandleTracker, HTMLTextAreaTool, MySelectionTool, NestedCreationTool, NullTool, PertFigureCreationTool, PolygonTool, ScribbleTool, SelectAreaTracker, SelectionTool, SplitConnectionTool, TextAreaTool, TextTool, UndoableTool, URLTool, ZoomAreaTracker, ZoomTool

public interface Tool

A tool defines a mode of the drawing view. All input events targeted to the drawing view are forwarded to its current tool.

Tools inform their editor when they are done with an interaction by calling the editor's toolDone() method. The Tools are created once and reused. They are initialized/deinitialized with activate()/deactivate().


Design Patterns

 o State
Tool plays the role of the State. In encapsulates all state specific behavior. DrawingView plays the role of the StateContext. A tool can be in the following states:
disabled<->enabled[unusable<->usable[active<->inactive]] <->always_usable[active<->inactive]<->disabled
where each square bracket indicates a state nesting level and arrows possible state transitions. Unusable tools are always inactive as well and disabled tools are always unusable as well. State changes are propagated to registered ToolListeners.

See Also:
DrawingView

Method Summary
 void activate()
          Activates the tool for the given view.
 void addToolListener(ToolListener newToolListener)
           
 void deactivate()
          Deactivates the tool.
 DrawingEditor editor()
           
 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()
          A usable tool is a enabled and either active or inactive.
 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 enableUsableCheck)
           
 void setUndoActivity(Undoable newUndoableActivity)
           
 void setUsable(boolean newIsUsable)
           
 

Method Detail

isActive

boolean isActive()
An active tool is the currently selected tool in the DrawingView. A tool can be activated/deactivated by calling the activate()/deactivate() method.

Returns:
true if the tool is the selected tool in the DrawingView, false otherwise
See Also:
isEnabled(), isUsable()

activate

void activate()
Activates the tool for the given view. This method is called whenever the user switches to this tool. Use this method to reinitialize a tool. Note, a valid view must be present in order for the tool to accept activation


deactivate

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.


mouseDown

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


mouseDrag

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


mouseUp

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


mouseMove

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


keyDown

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


isEnabled

boolean isEnabled()
A tool must be enabled in order to use it and to activate/deactivate it. Typically, the program enables or disables a tool.

See Also:
isUsable(), isActive()

setEnabled

void setEnabled(boolean enableUsableCheck)

isUsable

boolean isUsable()
A usable tool is a enabled and either active or inactive. Typically, the tool should be able to determine itself whether it is usable or not.

See Also:
isEnabled(), isUsable()

setUsable

void setUsable(boolean newIsUsable)

editor

DrawingEditor editor()

getUndoActivity

Undoable getUndoActivity()

setUndoActivity

void setUndoActivity(Undoable newUndoableActivity)

addToolListener

void addToolListener(ToolListener newToolListener)

removeToolListener

void removeToolListener(ToolListener oldToolListener)

JHotDraw 6.0b1