Interface Tool
-
- All Superinterfaces:
- java.util.EventListener, java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener
- All Known Subinterfaces:
- DragTracker, HandleTracker, SelectAreaTracker
- All Known Implementing Classes:
- AbstractTool, BezierTool, ConnectionTool, CreationTool, DefaultDragTracker, DefaultHandleTracker, DefaultSelectAreaTracker, DelegationSelectionTool, DnDTracker, ImageTool, PathTool, PathTool, SelectionTool, SVGCreateFromFileTool, TextAreaCreationTool, TextAreaEditingTool, TextCreationTool, TextEditingTool
public interface Tool extends java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.KeyListenerA tool defines a mode of aDrawingEditor. All input events targeted to the activeDrawingViewof 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
InputMapof the drawing editor and then invokes the corresponding action in theActionMapof 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.
Design PatternsFramework
The following interfaces define the contracts of a framework for structured drawing editors:
Contract:Drawing,Figure,DrawingView,DrawingEditor,HandleandTool.Mediator
DrawingEditoracts as a mediator for coordinating drawing tools and drawing views:
Mediator:DrawingEditor; Colleagues:DrawingView,Tool.Mediator
DrawingEditoracts as a mediator for coordinating keyboard input fromTools and Swing action objects:
Mediator:DrawingEditor; Colleagues:Tool, javax.swing.Action.Observer
State changes of tools can be observed by other objects. SpecificallyDrawingEditorobserves area invalidations of tools and repaints its active drawing view accordingly.
Subject:Tool; Observer:ToolListener; Event:ToolEvent; Concrete Observer:DrawingEditor.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description voidactivate(DrawingEditor editor)Activates the tool for the given editor.voidaddToolListener(ToolListener l)Adds a listener for this tool.voiddeactivate(DrawingEditor editor)Deactivates the tool.voiddraw(java.awt.Graphics2D g)Draws the tool.voideditCopy()Copies the selection into the clipboard.voideditCut()Cuts the selection into the clipboard.voideditDelete()Deletes the selection.voideditDuplicate()Duplicates the selection.voideditPaste()Pastes the contents of the clipboard.java.lang.StringgetToolTipText(DrawingView view, java.awt.event.MouseEvent evt)Returns the tooltip text for a mouse event on a drawing view.voidremoveToolListener(ToolListener l)Removes a listener for this tool.booleansupportsHandleInteraction()Returns true, if this tool lets the user interact with handles.
-
-
-
Method Detail
-
activate
void activate(DrawingEditor editor)
Activates the tool for the given editor. This method is called whenever the user switches to this tool.
-
deactivate
void deactivate(DrawingEditor editor)
Deactivates the tool. This method is called whenever the user switches to another tool.
-
addToolListener
void addToolListener(ToolListener l)
Adds a listener for this tool.
-
removeToolListener
void removeToolListener(ToolListener l)
Removes a listener for this tool.
-
draw
void draw(java.awt.Graphics2D g)
Draws the tool.
-
editDelete
void editDelete()
Deletes the selection. Depending on the tool, this could be selected figures, selected points or selected text.
-
editCut
void editCut()
Cuts the selection into the clipboard. Depending on the tool, this could be selected figures, selected points or selected text.
-
editCopy
void editCopy()
Copies the selection into the clipboard. Depending on the tool, this could be selected figures, selected points or selected text.
-
editDuplicate
void editDuplicate()
Duplicates the selection. Depending on the tool, this could be selected figures, selected points or selected text.
-
editPaste
void editPaste()
Pastes the contents of the clipboard. Depending on the tool, this could be selected figures, selected points or selected text.
-
getToolTipText
@Nullable java.lang.String getToolTipText(DrawingView view, java.awt.event.MouseEvent evt)
Returns the tooltip text for a mouse event on a drawing view.- Parameters:
view- A drawing view.evt- A mouse event.- Returns:
- A tooltip text or null.
-
supportsHandleInteraction
boolean supportsHandleInteraction()
Returns true, if this tool lets the user interact with handles.Handles may draw differently, if interaction is not possible.
- Returns:
- True, if this tool supports interaction with the handles.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG