public class SelectionTool extends AbstractTool
A selection tool is in one of three states: 1) area
selection, 2) figure dragging, 3) handle manipulation. The different
states are handled by different tracker objects: the
DefaultSelectAreaTracker
, the DefaultDragTracker
and the
DefaultHandleTracker
.
A Figure can be selected by clicking at it. Holding the alt key or the ctrl key down, selects the Figure behind it.
Strategy
The different behavior states of the selection tool are implemented by
trackers.
Context: SelectionTool
; State: DragTracker
,
HandleTracker
, SelectAreaTracker
.
Chain of responsibility
Mouse and keyboard events of the user occur on the drawing view, and are
preprocessed by the DragTracker
of a SelectionTool
. In
turn DragTracker
invokes "track" methods on a Handle
which in
turn changes an aspect of a figure.
Client: SelectionTool
; Handler: DragTracker
, Handle
.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SELECT_BEHIND_ENABLED_PROPERTY
Constant for the name of the selectBehindEnabled property.
|
anchor, editor, isWorking, listenerList
propertySupport
Constructor and Description |
---|
SelectionTool()
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
activate(DrawingEditor editor)
Activates the tool for the given editor.
|
void |
deactivate(DrawingEditor editor)
Deactivates the tool.
|
void |
draw(java.awt.Graphics2D g)
Draws the tool.
|
protected DragTracker |
getDragTracker(Figure f)
Method to get a
DragTracker which handles user interaction
for dragging the specified figure. |
protected HandleTracker |
getHandleTracker(Handle handle)
Method to get a
HandleTracker which handles user interaction
for the specified handle. |
protected SelectAreaTracker |
getSelectAreaTracker()
Method to get a
SelectAreaTracker which handles user interaction
for selecting an area on the drawing. |
boolean |
isSelectBehindEnabled()
Returns the value of the selectBehindEnabled property.
|
void |
keyPressed(java.awt.event.KeyEvent e)
The Tool uses the InputMap to determine what to do, when a key is pressed.
|
void |
keyReleased(java.awt.event.KeyEvent evt) |
void |
keyTyped(java.awt.event.KeyEvent evt) |
void |
mouseClicked(java.awt.event.MouseEvent evt) |
void |
mouseDragged(java.awt.event.MouseEvent evt) |
void |
mouseEntered(java.awt.event.MouseEvent evt) |
void |
mouseExited(java.awt.event.MouseEvent evt) |
void |
mouseMoved(java.awt.event.MouseEvent evt) |
void |
mousePressed(java.awt.event.MouseEvent evt) |
void |
mouseReleased(java.awt.event.MouseEvent evt) |
void |
setDragTracker(DragTracker newValue)
Method to set a
DragTracker . |
void |
setHandleTracker(HandleTracker newValue)
Method to set a
HandleTracker . |
void |
setSelectAreaTracker(SelectAreaTracker newValue)
Method to set a
SelectAreaTracker . |
void |
setSelectBehindEnabled(boolean newValue)
Sets the selectBehindEnabled property.
|
protected void |
setTracker(Tool newTracker) |
boolean |
supportsHandleInteraction()
Returns true, if this tool lets the user interact with handles.
|
addToolListener, addUndoableEditListener, constrainPoint, constrainPoint, createActionMap, createInputMap, editCopy, editCut, editDelete, editDuplicate, editPaste, fireAreaInvalidated, fireAreaInvalidated, fireBoundsInvalidated, fireToolDone, fireToolStarted, getActionMap, getDrawing, getEditor, getInputMap, getToolTipText, getView, isActive, maybeFireBoundsInvalidated, removeToolListener, removeUndoableEditListener, setActionMap, setInputMap, updateCursor, viewToDrawing
addPropertyChangeListener, addPropertyChangeListener, clone, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
public static final java.lang.String SELECT_BEHIND_ENABLED_PROPERTY
public void setSelectBehindEnabled(boolean newValue)
newValue
- The new value.public boolean isSelectBehindEnabled()
public void activate(DrawingEditor editor)
Tool
activate
in interface Tool
activate
in class AbstractTool
public void deactivate(DrawingEditor editor)
Tool
deactivate
in interface Tool
deactivate
in class AbstractTool
public void keyPressed(java.awt.event.KeyEvent e)
AbstractTool
keyPressed
in interface java.awt.event.KeyListener
keyPressed
in class AbstractTool
public void keyReleased(java.awt.event.KeyEvent evt)
keyReleased
in interface java.awt.event.KeyListener
keyReleased
in class AbstractTool
public void keyTyped(java.awt.event.KeyEvent evt)
keyTyped
in interface java.awt.event.KeyListener
keyTyped
in class AbstractTool
public void mouseClicked(java.awt.event.MouseEvent evt)
mouseClicked
in interface java.awt.event.MouseListener
mouseClicked
in class AbstractTool
public void mouseDragged(java.awt.event.MouseEvent evt)
public void mouseEntered(java.awt.event.MouseEvent evt)
mouseEntered
in interface java.awt.event.MouseListener
mouseEntered
in class AbstractTool
public void mouseExited(java.awt.event.MouseEvent evt)
mouseExited
in interface java.awt.event.MouseListener
mouseExited
in class AbstractTool
public void mouseMoved(java.awt.event.MouseEvent evt)
mouseMoved
in interface java.awt.event.MouseMotionListener
mouseMoved
in class AbstractTool
public void mouseReleased(java.awt.event.MouseEvent evt)
mouseReleased
in interface java.awt.event.MouseListener
mouseReleased
in class AbstractTool
public void draw(java.awt.Graphics2D g)
Tool
draw
in interface Tool
draw
in class AbstractTool
public void mousePressed(java.awt.event.MouseEvent evt)
mousePressed
in interface java.awt.event.MouseListener
mousePressed
in class AbstractTool
protected void setTracker(Tool newTracker)
protected HandleTracker getHandleTracker(Handle handle)
HandleTracker
which handles user interaction
for the specified handle.protected DragTracker getDragTracker(Figure f)
DragTracker
which handles user interaction
for dragging the specified figure.protected SelectAreaTracker getSelectAreaTracker()
SelectAreaTracker
which handles user interaction
for selecting an area on the drawing.public void setHandleTracker(HandleTracker newValue)
HandleTracker
. If you specify null, the
SelectionTool
uses the DefaultHandleTracker
.public void setSelectAreaTracker(SelectAreaTracker newValue)
SelectAreaTracker
. If you specify null, the
SelectionTool
uses the DefaultSelectAreaTracker
.public void setDragTracker(DragTracker newValue)
DragTracker
. If you specify null, the
SelectionTool
uses the DefaultDragTracker
.public boolean supportsHandleInteraction()
Handles may draw differently, if interaction is not possible.
supportsHandleInteraction
in interface Tool
supportsHandleInteraction
in class AbstractTool