be.ugent.caagt.swirl.mouse

Interface MouseHandler

Known Implementing Classes:
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.

Field Summary

static MouseHandler
NULL_MOUSE_HANDLER
Mouse handler that does not do anything.

Method Summary

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.

Field Details

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.)

Method Details

canHandle

public boolean canHandle(JComponent parent)
Check whether this handler can work on the given component.

doMouseClicked

public void doMouseClicked(JComponent parent,
                           MouseEvent mouseEvent)
Parameters:
parent - Component for which this handler acts as a controller
mouseEvent - Corresponding mouse event

doMouseDragged

public void doMouseDragged(JComponent parent,
                           MouseEvent mouseEvent,
                           MouseEvent previousEvent,
                           MouseEvent pressedEvent)
Parameters:
parent - Component for which this handler acts as a controller
mouseEvent - Corresponding mouse event
previousEvent - 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).

Parameters:
parent - Component for which this handler acts as a controller
mouseEvent - Corresponding mouse event

doMouseReleased

public void doMouseReleased(JComponent parent,
                            MouseEvent mouseEvent,
                            MouseEvent pressedEvent)
Parameters:
parent - Component for which this handler acts as a controller
mouseEvent - Corresponding mouse event
pressedEvent - 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.

Parameters:
parent - Component for which this handler acts as a controller
mouseEvent - Corresponding mouse event

paintDragging

public void paintDragging(JComponent parent,
                          Graphics g,
                          MouseEvent mouseEvent,
                          MouseEvent previousEvent,
                          MouseEvent pressedEvent)
Parameters:
parent - Component for which this handler acts as a controller
g - Graphics context onto which the visual feedback should be drawn
mouseEvent - Mouse event corresponding to the last drag
pressedEvent - Mouse event that initiated this gesture