be.ugent.caagt.swirl.mouse
Interface MouseHandler
- NullMouseHandler
public interface MouseHandler
Handles certain types of mouse events and provides visual feedback. Mouse handlers
are intended to be registered with a
MouseTool
.
The
parent component, i.e., the component for which
the handler acts as a controller, is handed as an extra parameter to each method.
This eases sharing of handler objects between components and in most cases
should allow mouse handlers to be singleton objects.
Note that this component is not necessarily the source of the mouse events.
Handlers are linked in a chain of responsibility. To indicate that
a handler is responsible
for a given mouse gesture it should consume the mouse pressed event
at the end of the methods
doMousePressed(JComponent,MouseEvent)
,
doMouseClicked(JComponent,MouseEvent)
and
doPopup(JComponent,MouseEvent)
.
The mouse gesture ends with the subsequent release of the mouse button.
Note that to be able to distinguish between a 'mouse clicked' and a 'mouse down'
the method
doMousePressed(JComponent,MouseEvent)
is only invoked as soon as the mouse is first
dragged.
boolean | canHandle(JComponent parent) - Check whether this handler can work on the given component.
|
void | doMouseClicked(JComponent parent, MouseEvent mouseEvent) - Invoked when the mouse was clicked, i.e.
|
void | doMouseDragged(JComponent parent, MouseEvent mouseEvent, MouseEvent previousEvent, MouseEvent pressedEvent) - Invoked when the mouse pointer was dragged, i.e., moved
while the button is down.
|
void | doMousePressed(JComponent parent, MouseEvent mouseEvent) - Invoked when the mouse was pressed down and then dragged
for the first time.
|
void | doMouseReleased(JComponent parent, MouseEvent mouseEvent, MouseEvent pressedEvent) - Invoked when the mouse pointer was released after it was dragged.
|
void | doPopup(JComponent parent, MouseEvent mouseEvent) - Invoked when a popup gesture was invoked and the
mouse did not actually move while the button was down.
|
void | paintDragging(JComponent parent, Graphics g, MouseEvent mouseEvent, MouseEvent previousEvent, MouseEvent pressedEvent) - Paint visual feedback while dragging the mouse.
|
NULL_MOUSE_HANDLER
public static final MouseHandler NULL_MOUSE_HANDLER
Mouse handler that does not do anything. (For use in
the 'null object' design pattern.)
canHandle
public boolean canHandle(JComponent parent)
Check whether this handler can work on the given component.
doMouseClicked
public void doMouseClicked(JComponent parent,
MouseEvent mouseEvent)
Invoked when the mouse was clicked, i.e. the button was pressed
and released without moving. If the click was a popup gesture for
the current platform, then
doPopup(JComponent,MouseEvent)
is invoked instead.
Handlers should consume the event if they take responsibility for this
mouse gesture.
parent
- Component for which this handler acts as a controllermouseEvent
- Corresponding mouse event
doMouseDragged
public void doMouseDragged(JComponent parent,
MouseEvent mouseEvent,
MouseEvent previousEvent,
MouseEvent pressedEvent)
Invoked when the mouse pointer was dragged, i.e., moved
while the button is down. Will not be called when the
corresponding
doMousePressed(JComponent,MouseEvent)
event
was not consumed by this object.
parent
- Component for which this handler acts as a controllermouseEvent
- Corresponding mouse eventpreviousEvent
- Pressed or dragged event before this event.pressedEvent
- Mouse event that initiated this gesture
doMousePressed
public void doMousePressed(JComponent parent,
MouseEvent mouseEvent)
Invoked when the mouse was pressed down and then dragged
for the first time.
Handlers should consume the event if they take responsibility for the
mouse gesture started by this press (and ending with the subsequent
release of the button).
parent
- Component for which this handler acts as a controllermouseEvent
- Corresponding mouse event
doMouseReleased
public void doMouseReleased(JComponent parent,
MouseEvent mouseEvent,
MouseEvent pressedEvent)
parent
- Component for which this handler acts as a controllermouseEvent
- Corresponding mouse eventpressedEvent
- Mouse event that initiated this gesture
doPopup
public void doPopup(JComponent parent,
MouseEvent mouseEvent)
Invoked when a popup gesture was invoked and the
mouse did not actually move while the button was down.
Handlers should consume the event if they take responsibility for this
mouse gesture.
parent
- Component for which this handler acts as a controllermouseEvent
- Corresponding mouse event
paintDragging
public void paintDragging(JComponent parent,
Graphics g,
MouseEvent mouseEvent,
MouseEvent previousEvent,
MouseEvent pressedEvent)
parent
- Component for which this handler acts as a controllerg
- Graphics context onto which the visual feedback should be drawnmouseEvent
- Mouse event corresponding to the last dragpressedEvent
- Mouse event that initiated this gesture