|
Eclipse GEF 2.1 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.eclipse.gef.util.FlagSupport | +--org.eclipse.gef.tools.AbstractTool
The base implementation for Tool
s. The base implementation provides a
framework for a state machine which processes mouse and keyboard input. The
state machine consists of a series of states identified by int
s. Each
mouse or keyboard event results in a transition, sometimes to the same state in which
the input was received. The interesting transitions have corresponding actions
assigned to them, such as handleDragStarted()
.
The base implementation performs no state transitions by default, but does route events to different method handlers based on state. It is up to subclasses to set the appropriate states.
There are two broad "categories" of methods on AbstractTool. There are the methods
defined on the Tool
interface which handle the job of receiving raw user input.
For example, mouseDrag(MouseEvent, EditPartViewer)
. Then, there are the
methods which correspond to higher-level interpretation of these events, such as handleDragInProgress()
, which is called from mouseMove(...)
, but
only when the drag threshold has been passed. These methods are generally
more subclass-friendly. Subclasses should not override the methods which
receive raw input.
Nested Class Summary | |
static class |
AbstractTool.Input
Allows the user to access mouse and keyboard input. |
Field Summary | |
protected static int |
MAX_FLAG
The highest-bit flag being used. |
protected static int |
MAX_STATE
The maximum state flag defined by this class |
protected static int |
MOUSE_BUTTON_ANY
constant used to indicate any of the 3 mouse buttons. |
protected static int |
MOUSE_BUTTON1
constant used for mouse button 1. |
protected static int |
MOUSE_BUTTON2
constant used for mouse button 2. |
protected static int |
MOUSE_BUTTON3
constant used for mouse button 3. |
protected static int |
STATE_ACCESSIBLE_DRAG
The state indicating that the keyboard is being used to perform a drag that is normally done using the mouse. |
protected static int |
STATE_ACCESSIBLE_DRAG_IN_PROGRESS
The state indicating that a keyboard drag is in progress. |
protected static int |
STATE_DRAG
The state indicating that one or more buttons is pressed, but the user has not moved past the drag threshold. |
protected static int |
STATE_DRAG_IN_PROGRESS
The state indicating that the drag detection theshold has been passed, and a drag is in progress. |
protected static int |
STATE_INITIAL
The first state that a tool is in. |
protected static int |
STATE_INVALID
The state indicating that an input event has invalidated the interaction. |
protected static int |
STATE_TERMINAL
The final state for a tool to be in. |
Fields inherited from interface org.eclipse.gef.RequestConstants |
REQ_ADD, REQ_ALIGN, REQ_ALIGN_CHILDREN, REQ_CONNECTION_END, REQ_CONNECTION_START, REQ_CREATE, REQ_CREATE_BENDPOINT, REQ_DELETE, REQ_DELETE_DEPENDANT, REQ_DIRECT_EDIT, REQ_MOVE, REQ_MOVE_BENDPOINT, REQ_MOVE_CHILDREN, REQ_OPEN, REQ_ORPHAN, REQ_ORPHAN_CHILDREN, REQ_RECONNECT_SOURCE, REQ_RECONNECT_TARGET, REQ_RESIZE, REQ_RESIZE_CHILDREN, REQ_SELECTION, REQ_SELECTION_HOVER |
Constructor Summary | |
AbstractTool()
|
Method Summary | |
void |
activate()
Activates the tool. |
protected void |
addFeedback(IFigure figure)
Convenience method to add the given figure to the feedback layer. |
protected Cursor |
calculateCursor()
Returns the appropriate cursor for the tools current state. |
void |
commitDrag()
Added for compatibility. |
protected List |
createOperationSet()
Returns a new List of editparts that this tool is operating on. |
void |
deactivate()
Deactivates the tool. |
protected void |
debug(String message)
Prints a string in the GEF Debug console if the Tools debug option is selected. |
protected void |
executeCurrentCommand()
Execute the currently active command. |
void |
focusGained(FocusEvent event,
EditPartViewer viewer)
Called when a viewer that the editor controls gains focus. |
void |
focusLost(FocusEvent event,
EditPartViewer viewer)
Called when a viewer that the editor controls loses focus. |
protected Command |
getCommand()
Returns a new, updated command based on the tools current properties. |
protected abstract String |
getCommandName()
Returns the identifier of the command that is being sought. |
protected Command |
getCurrentCommand()
Returns the currently cached command. |
protected AbstractTool.Input |
getCurrentInput()
Returns the input object encapsulating the current mouse and keyboard state. |
protected EditPartViewer |
getCurrentViewer()
Return the viewer that the tool is currently receiving input from, or null . |
protected abstract String |
getDebugName()
Returns the debug name for this tool. |
protected String |
getDebugNameForState(int state)
Returns a String representation of the given state for debug purposes. |
protected Cursor |
getDefaultCursor()
Returns the cursor used under normal conditions. |
protected Cursor |
getDisabledCursor()
Returns the cursor used under abnormal conditions. |
protected EditDomain |
getDomain()
Returns the EditDomain. |
protected Dimension |
getDragMoveDelta()
Return the number of pixels that the mouse has been moved since that drag was started. |
protected Point |
getLocation()
Returns the current x, y position of the mouse cursor. |
protected List |
getOperationSet()
Lazily creates and returns the list of editparts on which the tool operates. |
protected Point |
getStartLocation()
Returns the starting mouse location for the current tool operation. |
protected int |
getState()
Returns the tool's current state. |
protected boolean |
handleButtonDown(int button)
Called when the mouse button has been pressed. |
protected boolean |
handleButtonUp(int button)
Called when the mouse button has been released. |
protected boolean |
handleDoubleClick(int button)
Called when a mouse double-click occurs. |
protected boolean |
handleDrag()
Called whenever the mouse is being dragged. |
protected boolean |
handleDragInProgress()
Called whenever a mouse is being dragged and the drag threshold has been exceeded. |
protected boolean |
handleDragStarted()
Called only one time during a drag when the drag threshold has been exceeded. |
protected void |
handleFinished()
Called when the current tool operation is to be completed. |
protected boolean |
handleFocusGained()
Handles high-level processing of a focus gained event. |
protected boolean |
handleFocusLost()
Handles high-level processing of a focus lost event. |
protected boolean |
handleHover()
Handles high-level processing of a mouse hover event. |
protected boolean |
handleKeyDown(KeyEvent e)
Handles high-level processing of a key down event. |
protected boolean |
handleKeyUp(KeyEvent e)
Handles high-level processing of a key up event. |
protected boolean |
handleMove()
Handles high-level processing of a mouse move. |
protected boolean |
handleNativeDragFinished(DragSourceEvent event)
Handles when a native drag has ended. |
protected boolean |
handleNativeDragStarted(DragSourceEvent event)
Handles when a native drag has started. |
protected boolean |
handleViewerEntered()
Called when the mouse enters an EditPartViewer. |
protected boolean |
handleViewerExited()
Called when the mouse exits an EditPartViewer. |
protected boolean |
isActive()
Returns true if the tool is active. |
protected boolean |
isHoverActive()
Returns true if the tool is hovering. |
protected boolean |
isInState(int state)
Returns true if the tool is in the given state. |
void |
keyDown(KeyEvent evt,
EditPartViewer viewer)
Receives a KeyDown event for the given viewer. |
void |
keyUp(KeyEvent evt,
EditPartViewer viewer)
Receives a KeyUp event for the given viewer. |
void |
mouseDoubleClick(MouseEvent me,
EditPartViewer viewer)
Handles mouse double click events within a viewer. |
void |
mouseDown(MouseEvent me,
EditPartViewer viewer)
Handles mouse down events within a viewer. |
void |
mouseDrag(MouseEvent me,
EditPartViewer viewer)
Handles mouse drag events within a viewer. |
void |
mouseHover(MouseEvent me,
EditPartViewer viewer)
Handles mouse hover event. within a viewer. |
void |
mouseMove(MouseEvent me,
EditPartViewer viewer)
Handles mouse moves (if the mouse button is up) within a viewer. |
void |
mouseUp(MouseEvent me,
EditPartViewer viewer)
Handles mouse up within a viewer. |
protected boolean |
movedPastThreshold()
Returns true if the threshold has been exceeded during a mouse drag. |
void |
nativeDragFinished(DragSourceEvent event,
EditPartViewer viewer)
Called when a native drag ends on a Viewer. |
void |
nativeDragStarted(DragSourceEvent event,
EditPartViewer viewer)
Called when a native drag begins on a Viewer. |
protected void |
reactivate()
Calls deactivate() and then activate() . |
protected void |
refreshCursor()
Sets the cursor being displayed to the appropriate cursor. |
protected void |
releaseToolCapture()
Releases tool capture. |
protected void |
removeFeedback(IFigure figure)
Convenience method to removes a figure from the feedback layer. |
protected void |
resetFlags()
Resets all flags to their initial values. |
protected void |
setCurrentCommand(Command c)
Used to cache a command obtained from getCommand() . |
protected void |
setCursor(Cursor cursor)
Shows the given cursor on the current viewer. |
void |
setDefaultCursor(Cursor cursor)
Sets the default cursor. |
void |
setDisabledCursor(Cursor cursor)
Sets the disabled cursor. |
void |
setEditDomain(EditDomain domain)
Sets the EditDomain. |
protected void |
setHoverActive(boolean value)
Sets whether the hover flag is true or false. |
protected void |
setStartLocation(Point p)
Sets the start mouse location, typically for a drag operation. |
protected void |
setState(int state)
Sets the tools state. |
protected void |
setToolCapture()
Sets tool capture. |
void |
setUnloadWhenFinished(boolean value)
Setting this to true will cause the tool to be unloaded after one
operation has completed. |
void |
setViewer(EditPartViewer viewer)
Sets the active EditPartViewer. |
protected boolean |
stateTransition(int start,
int end)
Returns true if the give state transition succeeds. |
protected boolean |
unloadWhenFinished()
Returns true if the tool is set to unload when its current operation is
complete. |
void |
viewerEntered(MouseEvent me,
EditPartViewer viewer)
Receives the mouse entered event. |
void |
viewerExited(MouseEvent me,
EditPartViewer viewer)
Handles the mouse exited event. |
Methods inherited from class org.eclipse.gef.util.FlagSupport |
getFlag, setFlag |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final int STATE_TERMINAL
protected static final int STATE_INITIAL
activate()
.
protected static final int STATE_DRAG
STATE_DRAG_IN_PROGRESS
is entered.
protected static final int STATE_DRAG_IN_PROGRESS
protected static final int STATE_INVALID
protected static final int STATE_ACCESSIBLE_DRAG
protected static final int STATE_ACCESSIBLE_DRAG_IN_PROGRESS
protected static final int MAX_STATE
protected static final int MOUSE_BUTTON1
protected static final int MOUSE_BUTTON2
protected static final int MOUSE_BUTTON3
protected static final int MOUSE_BUTTON_ANY
protected static final int MAX_FLAG
Constructor Detail |
public AbstractTool()
Method Detail |
public void activate()
activate
in interface Tool
deactivate()
protected void addFeedback(IFigure figure)
figure
- the feedback being addedprotected Cursor calculateCursor()
null
is returned. Otherwise, either the default or
disabled cursor is returned, based on the existence of a current command, and whether
that current command is executable.
Subclasses may override or extend this method to calculate the appropriate cursor based on other conditions.
null
or a cursor to be displayed.getDefaultCursor()
,
getDisabledCursor()
,
getCurrentCommand()
public void commitDrag()
DragTracker.commitDrag()
was added for accessibility
reasons. Since all tool implementations must inherit from this base class, then
implementing this method here avoids breaking subclasses that implemented the DragTracker
interface.
protected List createOperationSet()
getOperationSet()
, and its result is cached.
By default, the operations set is the current viewer's entire selection. Subclasses may override this method to filter or alter the operation set as necessary.
public void deactivate()
deactivate
in interface Tool
activate()
protected void debug(String message)
message
- a message for the debug trace toolpublic void focusGained(FocusEvent event, EditPartViewer viewer)
focusGained
in interface Tool
event
- The SWT focus eventviewer
- The viewer that the focus event is over.public void focusLost(FocusEvent event, EditPartViewer viewer)
focusLost
in interface Tool
event
- The SWT focus eventviewer
- The viewer that the focus event is over.protected void executeCurrentCommand()
protected Command getCommand()
protected abstract String getCommandName()
protected Command getCurrentCommand()
setCurrentCommand(Command)
protected AbstractTool.Input getCurrentInput()
protected EditPartViewer getCurrentViewer()
null
. The last viewer to dispatch an event is defined as the current
viewer. Current viewer is automatically updated as events are received, and is set to
null
on deactivate()
.
protected abstract String getDebugName()
protected String getDebugNameForState(int state)
state
- the state
protected Cursor getDefaultCursor()
setDefaultCursor(Cursor)
protected Cursor getDisabledCursor()
calculateCursor()
,
setDisabledCursor(Cursor)
protected EditDomain getDomain()
protected Dimension getDragMoveDelta()
getStartLocation()
protected Point getLocation()
protected List getOperationSet()
null
, in which case createOperationSet()
is called,
and its results cached until the tool is deactivated.
protected Point getStartLocation()
protected int getState()
protected boolean handleButtonDown(int button)
false
is returned. Subclasses may override this method to interpret
the meaning of a mouse down. Returning true
indicates that the button down
was handled in some way.
button
- which button went down
true
if the buttonDown was handledprotected boolean handleButtonUp(int button)
false
is returned. Subclasses may override this method to interpret the
mouse up. Returning true
indicates that the mouse up was handled in some
way.
button
- the button being released
true
if the button up was handledmouseUp(MouseEvent, EditPartViewer)
protected boolean handleDoubleClick(int button)
false
is returned. Subclasses may override this method to interpret
double-clicks. Returning true
indicates that the event was handled in
some way.
button
- which button was double-clicked
true
if the event was handledmouseDoubleClick(MouseEvent, EditPartViewer)
protected boolean handleDrag()
handleDragInProgress()
starts getting called. By default, nothing
happens, and false
is returned. Subclasses may override this method to
interpret a drag. Returning true
indicates that the drag was handled in
some way.
true
if the drag is handledmouseDrag(MouseEvent, EditPartViewer)
protected boolean handleDragInProgress()
handleDrag()
is called. This
method gets called repeatedly for every mouse move during the drag. By default, nothing
happens and false
is returned. Subclasses may override this method to
interpret the drag. Returning true
indicates that the drag was handled.
true
if the drag was handledmovedPastThreshold()
,
mouseDrag(MouseEvent, EditPartViewer)
protected boolean handleDragStarted()
false
is returned. Subclasses may override
to interpret the drag starting. Returning true
indicates that the event
was handled.
movedPastThreshold()
,
mouseDrag(MouseEvent, EditPartViewer)
protected void handleFinished()
Subclasses should extend this method to first do whatever it is that the tool does, and
then call super
.
unloadWhenFinished()
protected boolean handleFocusGained()
false
is returned. Subclasses may override this method to interpret the
focus gained event. Return true
to indicate that the event was processed.
true
if the event was handledfocusGained(FocusEvent, EditPartViewer)
protected boolean handleFocusLost()
false
is returned. Subclasses may override this method to interpret the
focus lost event. Return true
to indicate that the event was processed.
true
if the event was handledfocusLost(FocusEvent, EditPartViewer)
protected boolean handleHover()
false
is returned. Subclasses may override this method to interpret the
hover. Return true
to indicate that the hover was handled.
true
if the hover was handledmouseHover(MouseEvent, EditPartViewer)
protected boolean handleKeyDown(KeyEvent e)
true
is returned. Subclasses may extend this method to interpret
additional key down events. Returns true
if the given key down was
handled.
e
- the key event
true
if the key down was handled.keyDown(KeyEvent, EditPartViewer)
protected boolean handleKeyUp(KeyEvent e)
false
. Subclasses may extend this method to process key up events.
Returns true
if the key up was processed in some way.
e
- the key event
true
if the event was handledkeyUp(KeyEvent, EditPartViewer)
protected boolean handleMove()
false
. Subclasses may extend this method to process mouse moves.
Returns true
if the mouse move was processed.
true
if the mouse move was handledmouseMove(MouseEvent, EditPartViewer)
protected boolean handleNativeDragFinished(DragSourceEvent event)
false
. Subclasses may extend this method to process native drags ending.
event
- the drag event
true
if the native drag finished was handledprotected boolean handleNativeDragStarted(DragSourceEvent event)
false
. Subclasses may extend this method to process native drag starts.
When a native drag starts, all subsequent mouse events will not be received, including the mouseUp event. The only event that will be received is the drag finished event.
event
- the drag event
true
if the native drag start was handledprotected boolean handleViewerEntered()
false
. Subclasses may extend this method to process the viewer enter.
Returns true
to indicate if the viewer entered was process in some way.
true
if the viewer entered was handledprotected boolean handleViewerExited()
false
. Subclasses may extend this method to process viewer exits. Returns
true
to indicate if the viewer exited was process in some way.
true
if the viewer exited was handledprotected boolean isActive()
true
if the tool is active.
true
if activeprotected boolean isHoverActive()
true
if the tool is hovering.
true
if hoveringprotected boolean isInState(int state)
true
if the tool is in the given state.
state
- the state being queried
true
if the tool is in the given statepublic void keyDown(KeyEvent evt, EditPartViewer viewer)
handleKeyDown(KeyEvent)
.
keyDown
in interface Tool
evt
- the key eventviewer
- the origininating viewerpublic void keyUp(KeyEvent evt, EditPartViewer viewer)
handleKeyUp(KeyEvent)
.
keyUp
in interface Tool
evt
- the key eventviewer
- the origininating viewerprotected boolean movedPastThreshold()
true
if the threshold has been exceeded during a mouse drag.
true
if the threshold has been exceededpublic void nativeDragFinished(DragSourceEvent event, EditPartViewer viewer)
Tool
mouseUp(..)
will not occur
once a native drag has started. The Tool should correct its state to handle this
lost Event.
nativeDragFinished
in interface Tool
event
- the SWT DragSourceEventviewer
- the Viewer on which a native drag startedTool.nativeDragStarted(DragSourceEvent, EditPartViewer)
public void nativeDragStarted(DragSourceEvent event, EditPartViewer viewer)
Tool
mouseUp(..)
will not occur
once a native drag has started. The Tool should correct its state to handle this
lost Event.
nativeDragStarted
in interface Tool
event
- the SWT DragSourceEventviewer
- the Viewer on which a native drag startedTool.nativeDragStarted(DragSourceEvent, EditPartViewer)
public void mouseDoubleClick(MouseEvent me, EditPartViewer viewer)
handleDoubleClick(int)
.
mouseDoubleClick
in interface Tool
me
- the mouse eventviewer
- the originating viewerpublic void mouseDown(MouseEvent me, EditPartViewer viewer)
handleButtonDown(int)
.
mouseDown
in interface Tool
me
- the mouse eventviewer
- the originating viewerpublic void mouseDrag(MouseEvent me, EditPartViewer viewer)
handleDrag()
and/or handleDragInProgress()
.
mouseDrag
in interface Tool
me
- the mouse eventviewer
- the originating viewerpublic void mouseHover(MouseEvent me, EditPartViewer viewer)
handleHover()
.
mouseHover
in interface Tool
me
- the mouse eventviewer
- the originating viewerMouseTrackListener.mouseHover(MouseEvent)
public void mouseMove(MouseEvent me, EditPartViewer viewer)
handleMove()
.
mouseMove
in interface Tool
me
- the mouse eventviewer
- the originating viewerTool.mouseDrag(MouseEvent, EditPartViewer)
public void mouseUp(MouseEvent me, EditPartViewer viewer)
handleButtonUp(int)
.
mouseUp
in interface Tool
me
- the mouse eventviewer
- the originating viewerprotected void reactivate()
deactivate()
and then activate()
.
protected void refreshCursor()
calculateCursor()
.
protected void releaseToolCapture()
setToolCapture()
protected void removeFeedback(IFigure figure)
figure
- the figure being removedprotected void resetFlags()
protected void setCurrentCommand(Command c)
getCommand()
.
c
- the commandgetCurrentCommand()
protected void setCursor(Cursor cursor)
cursor
- the cursor to displaypublic void setDefaultCursor(Cursor cursor)
cursor
- the cursorgetDefaultCursor()
public void setDisabledCursor(Cursor cursor)
cursor
- the cursorgetDisabledCursor()
public void setEditDomain(EditDomain domain)
setEditDomain
in interface Tool
domain
- the edit domaingetDomain()
protected void setHoverActive(boolean value)
value
- whether hover is activeprotected void setStartLocation(Point p)
p
- the start locationprotected void setState(int state)
state
- the new stateprotected void setToolCapture()
public void setUnloadWhenFinished(boolean value)
true
will cause the tool to be unloaded after one
operation has completed. The default value is true
. The tool is
unloaded, and the edit domains default tool will be activated.
value
- whether the tool should be unloaded on completionpublic void setViewer(EditPartViewer viewer)
setViewer
in interface Tool
viewer
- the viewerprotected boolean stateTransition(int start, int end)
true
if the give state transition succeeds. This is a "test and
set" operation, where the tool is tested to be in the specified start state, and if so,
is set to the given end state. The method returns the result of the first test.
start
- the start state being testedend
- the end state
true
if the state transition is successfulprotected final boolean unloadWhenFinished()
true
if the tool is set to unload when its current operation is
complete.
true
if the tool should be unloaded when finishedpublic void viewerEntered(MouseEvent me, EditPartViewer viewer)
handleViewerEntered()
.
FEATURE in SWT: mouseExit comes after mouseEntered on the new . Therefore, if the
current viewer is not null
, it means the exit has not been sent yet by
SWT. To maintain proper ordering, GEF fakes the exit and calls handleViewerExited()
. The real exit will then be ignored.
viewerEntered
in interface Tool
me
- the mouse eventviewer
- the originating viewerpublic void viewerExited(MouseEvent me, EditPartViewer viewer)
handleViewerExited()
.
viewerExited
in interface Tool
me
- the mouse eventviewer
- the originating viewer
|
Eclipse GEF 2.1 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |