public interface Tool
extends java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.KeyListener
DrawingEditor
. All input events
targeted to the active DrawingView
of the drawing editor are
forwarded to its current tool.
Tools inform listeners when they are done with an interaction by calling the ToolListener's toolDone() method. The Tools are created once and reused. They are initialized/deinitialized with activate()/deactivate().
Tools are used for user interaction. Unlike figures, a tool works with the user interface coordinates of the DrawingView. The user interface coordinates are expressed in integer pixels.
A Tool forwards UndoableEdit events to the Drawing object onto which it is performing changes.
If a tool does not handle a specific keyboard event, it looks up the
InputMap
of the drawing editor and then invokes the
corresponding action in the ActionMap
of the drawing editor.
A tool can have an InputMap and ActionMap of its own which take precedence
over the ones provided by the drawing editor.
Framework
The following interfaces define the contracts of a framework for structured
drawing editors:
Contract: Drawing
, Figure
, DrawingView
,
DrawingEditor
, Handle
and Tool
.
Mediator
DrawingEditor
acts as a mediator for coordinating drawing tools
and drawing views:
Mediator: DrawingEditor
; Colleagues: DrawingView
, Tool
.
Mediator
DrawingEditor
acts as a mediator for coordinating keyboard input from
Tool
s and Swing action objects:
Mediator: DrawingEditor
; Colleagues: Tool
, javax.swing.Action.
Observer
State changes of tools can be observed by other objects. Specifically
DrawingEditor
observes area invalidations of tools and repaints
its active drawing view accordingly.
Subject: Tool
; Observer: ToolListener
; Event:
ToolEvent
; Concrete Observer: DrawingEditor
.
Modifier and Type | Method and Description |
---|---|
void |
activate(DrawingEditor editor)
Activates the tool for the given editor.
|
void |
addToolListener(ToolListener l)
Adds a listener for this tool.
|
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.
|
java.lang.String |
getToolTipText(DrawingView view,
java.awt.event.MouseEvent evt)
Returns the tooltip text for a mouse event on a drawing view.
|
void |
removeToolListener(ToolListener l)
Removes a listener for this tool.
|
boolean |
supportsHandleInteraction()
Returns true, if this tool lets the user interact with handles.
|
void activate(DrawingEditor editor)
void deactivate(DrawingEditor editor)
void addToolListener(ToolListener l)
void removeToolListener(ToolListener l)
void draw(java.awt.Graphics2D g)
void editDelete()
void editCut()
void editCopy()
void editDuplicate()
void editPaste()
java.lang.String getToolTipText(DrawingView view, java.awt.event.MouseEvent evt)
view
- A drawing view.evt
- A mouse event.boolean supportsHandleInteraction()
Handles may draw differently, if interaction is not possible.