JHotDraw 6.0b1

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.

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)
           
protected  void checkUsable()
           
protected  AbstractTool.EventDispatcher createEventDispatcher()
           
protected  ViewChangeListener createViewChangeListener()
           
 void deactivate()
          Deactivates the tool.
 Drawing drawing()
          Gets the tool's drawing.
 DrawingEditor editor()
          Gets the tool's editor.
 Drawing getActiveDrawing()
           
 DrawingView getActiveView()
           
protected  int getAnchorX()
          The anchor point is usually the first mouse click performed with this tool.
protected  int getAnchorY()
          The anchor point is usually the first mouse click performed with this tool.
protected  AbstractTool.EventDispatcher getEventDispatcher()
           
 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)
           
protected  void setAnchorX(int newAnchorX)
          The anchor point is usually the first mouse click performed with this tool.
protected  void setAnchorY(int newAnchorY)
          The anchor point is usually the first mouse click performed with this tool.
protected  void setEditor(DrawingEditor newDrawingEditor)
           
 void setEnabled(boolean newIsEnabled)
           
 void setUndoActivity(Undoable newUndoActivity)
           
 void setUsable(boolean newIsUsable)
           
protected  void setView(DrawingView newDrawingView)
           
 DrawingView view()
          Gets the tool's view (convienence method).
protected  void viewCreated(DrawingView view)
          Sent when a new view is created
protected  void viewDestroying(DrawingView view)
          Send when an existing view is about to be destroyed.
protected  void viewSelectionChanged(DrawingView oldView, DrawingView newView)
          Fired when the selected view changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, 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

viewSelectionChanged

protected void viewSelectionChanged(DrawingView oldView,
                                    DrawingView newView)
Fired when the selected view changes. Subclasses should always call super. ViewSelectionChanged() this allows the tools state to be updated and referenced to the new view.


viewCreated

protected void viewCreated(DrawingView view)
Sent when a new view is created


viewDestroying

protected void viewDestroying(DrawingView view)
Send when an existing view is about to be destroyed.


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

setEditor

protected void setEditor(DrawingEditor newDrawingEditor)

view

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


setView

protected void setView(DrawingView newDrawingView)

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()

setAnchorX

protected void setAnchorX(int newAnchorX)
The anchor point is usually the first mouse click performed with this tool.

See Also:
mouseDown(java.awt.event.MouseEvent, int, int)

getAnchorX

protected int getAnchorX()
The anchor point is usually the first mouse click performed with this tool.

Returns:
the anchor X coordinate for the interaction
See Also:
mouseDown(java.awt.event.MouseEvent, int, int)

setAnchorY

protected void setAnchorY(int newAnchorY)
The anchor point is usually the first mouse click performed with this tool.

See Also:
mouseDown(java.awt.event.MouseEvent, int, int)

getAnchorY

protected int getAnchorY()
The anchor point is usually the first mouse click performed with this tool.

Returns:
the anchor Y coordinate for the interaction
See Also:
mouseDown(java.awt.event.MouseEvent, int, int)

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

getEventDispatcher

protected AbstractTool.EventDispatcher getEventDispatcher()

createEventDispatcher

protected AbstractTool.EventDispatcher createEventDispatcher()

createViewChangeListener

protected ViewChangeListener createViewChangeListener()

checkUsable

protected void checkUsable()

JHotDraw 6.0b1