be.ugent.caagt.swirl.mouse
Interface MouseHandler

All 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(javax.swing.JComponent, java.awt.event.MouseEvent), doMouseClicked(javax.swing.JComponent, java.awt.event.MouseEvent) and doPopup(javax.swing.JComponent, java.awt.event.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(javax.swing.JComponent, java.awt.event.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(javax.swing.JComponent parent)
          Check whether this handler can work on the given component.
 void doMouseClicked(javax.swing.JComponent parent, java.awt.event.MouseEvent mouseEvent)
          Invoked when the mouse was clicked, i.e.
 void doMouseDragged(javax.swing.JComponent parent, java.awt.event.MouseEvent mouseEvent, java.awt.event.MouseEvent previousEvent, java.awt.event.MouseEvent pressedEvent)
          Invoked when the mouse pointer was dragged, i.e., moved while the button is down.
 void doMousePressed(javax.swing.JComponent parent, java.awt.event.MouseEvent mouseEvent)
          Invoked when the mouse was pressed down and then dragged for the first time.
 void doMouseReleased(javax.swing.JComponent parent, java.awt.event.MouseEvent mouseEvent, java.awt.event.MouseEvent pressedEvent)
          Invoked when the mouse pointer was released after it was dragged.
 void doPopup(javax.swing.JComponent parent, java.awt.event.MouseEvent mouseEvent)
          Invoked when a popup gesture was invoked and the mouse did not actually move while the button was down.
 void paintDragging(javax.swing.JComponent parent, java.awt.Graphics g, java.awt.event.MouseEvent mouseEvent, java.awt.event.MouseEvent previousEvent, java.awt.event.MouseEvent pressedEvent)
          Paint visual feedback while dragging the mouse.
 

Field Detail

NULL_MOUSE_HANDLER

static final MouseHandler NULL_MOUSE_HANDLER
Mouse handler that does not do anything. (For use in the 'null object' design pattern.)

Method Detail

doMouseClicked

void doMouseClicked(javax.swing.JComponent parent,
                    java.awt.event.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(javax.swing.JComponent, java.awt.event.MouseEvent) is invoked instead.

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

doPopup

void doPopup(javax.swing.JComponent parent,
             java.awt.event.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

doMousePressed

void doMousePressed(javax.swing.JComponent parent,
                    java.awt.event.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

doMouseDragged

void doMouseDragged(javax.swing.JComponent parent,
                    java.awt.event.MouseEvent mouseEvent,
                    java.awt.event.MouseEvent previousEvent,
                    java.awt.event.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(javax.swing.JComponent, java.awt.event.MouseEvent) event was not consumed by this object.

Parameters:
parent - Component for which this handler acts as a controller
mouseEvent - Corresponding mouse event
pressedEvent - Mouse event that initiated this gesture
previousEvent - Pressed or dragged event before this event.

doMouseReleased

void doMouseReleased(javax.swing.JComponent parent,
                     java.awt.event.MouseEvent mouseEvent,
                     java.awt.event.MouseEvent pressedEvent)
Invoked when the mouse pointer was released after it was dragged. Will not be called when the corresponding doMousePressed(javax.swing.JComponent, java.awt.event.MouseEvent) event was not consumed by this object.

Parameters:
parent - Component for which this handler acts as a controller
mouseEvent - Corresponding mouse event
pressedEvent - Mouse event that initiated this gesture

paintDragging

void paintDragging(javax.swing.JComponent parent,
                   java.awt.Graphics g,
                   java.awt.event.MouseEvent mouseEvent,
                   java.awt.event.MouseEvent previousEvent,
                   java.awt.event.MouseEvent pressedEvent)
Paint visual feedback while dragging the mouse. Will not be called when the corresponding doMousePressed(javax.swing.JComponent, java.awt.event.MouseEvent) event was not consumed by this object.

Parameters:
parent - Component for which this handler acts as a controller
pressedEvent - Mouse event that initiated this gesture
mouseEvent - Mouse event corresponding to the last drag
g - Graphics context onto which the visual feedback should be drawn

canHandle

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