org.jagatoo.input.devices
Class Mouse

java.lang.Object
  extended by org.jagatoo.input.devices.InputDevice
      extended by org.jagatoo.input.devices.Mouse
All Implemented Interfaces:
Enableable
Direct Known Subclasses:
AWTMouse, JInputMouse, LWJGLMouse, SWTMouse

public abstract class Mouse
extends InputDevice

This is the base-class for all Mouse implementations.
Applications should always use instances as Mouse, but never cast them to the concrete implementation.
Instances can only be created/retrieved through an InputDeviceFactory.


Constructor Summary
protected Mouse(MouseFactory sourceFactory, InputSourceWindow sourceWindow, EventQueue eventQueue, java.lang.String name, int numButtons, boolean hasWheel)
           
 
Method Summary
protected  void addButtonsState(int buttonState)
          Adds bits to the button-state's bitmask.
protected  void addButtonsState(MouseButton button)
          Adds bits to the button-state's bitmask.
 void addMouseListener(MouseListener l)
          Adds a MouseListener to the list of instances being notifed on mouse events.
 void addMouseStopListener(MouseStopListener l)
          Adds a MouseStopListener to this Mouse to be notified when the mouse has stopped being moved (for a while).
abstract  void centerMouse()
          Centers the mouse cursor on the source-window.
 void destroy()
          Destroys the InputDevice.
protected abstract  void destroyImpl()
          Destroys the Mouse.
 void fireMouseEvent(MouseEvent e, boolean consumeEvent)
          This method simply forwards to the concrete fire* methods.
 void fireOnMouseButtonClicked(MouseButtonClickedEvent e, boolean consumeEvent)
          Fires a MouseButtonClickedEvent and pushes it back to the pool, if consumeEvent is true.
 void fireOnMouseButtonPressed(MouseButtonPressedEvent e, boolean consumeEvent)
          Fires a MouseButtonPressedEvent and pushes it back to the pool, if consumeEvent is true.
 void fireOnMouseButtonReleased(MouseButtonReleasedEvent e, boolean consumeEvent)
          Fires a MouseButtonReleasedEvent and pushes it back to the pool, if consumeEvent is true.
 void fireOnMouseMoved(MouseMovedEvent e, boolean consumeEvent)
          Fires a MouseMovedEvent and pushes it back to the pool, if consumeEvent is true.
 void fireOnMouseWheelMoved(MouseWheelEvent e, boolean consumeEvent)
          Fires a MouseWheelEvent and pushes it back to the pool, if consumeEvent is true.
 MouseButton getButton(int index)
           
 int getButtonsCount()
           
 int getButtonsState()
           
 InputState getButtonState(MouseButton button)
           
 int getCurrentX()
           
 int getCurrentY()
           
 MouseFactory getSourceFactory()
           
 int getState(DeviceComponent component)
          This method returns an abstract input-state for the given DeviceComponent.
 MouseWheel getWheel()
           
 MouseAxis getXAxis()
           
 MouseAxis getYAxis()
           
protected  void handleClickedEvents(long when, long threshold)
          Checks, if there are pending clicked-events and compares their when-times with the current when and threshold and fires the events, if necessary.
 boolean hasListener()
           
 boolean hasMouseListener()
           
 boolean isAbsolute()
           
 boolean isButtonPressed(MouseButton button)
           
protected  void notifyMouseStopManager(long nanoTime)
           
protected  MouseButtonPressedEvent prepareMouseButtonPressedEvent(MouseButton button, long when)
          Prepares a MouseButtonPressedEvent for being fired.
protected  MouseButtonReleasedEvent prepareMouseButtonReleasedEvent(MouseButton button, long when)
          Prepares a MouseButtonReleasedEvent for being fired.
protected  MouseMovedEvent prepareMouseMovedEvent(int x, int y, int dx, int dy, long when)
          Prepares a MouseMovedEvent for being fired.
protected  MouseWheelEvent prepareMouseWheelMovedEvent(int wheelDelta, boolean isPageMove, long when)
          Prepares a MouseWheelEvent for being fired.
protected  void removeButtonsState(int buttonState)
          Removes bits from the button-state's bitmask.
protected  void removeButtonsState(MouseButton button)
          Removes bits from the button-state's bitmask.
 void removeMouseListener(MouseListener l)
          Removes a MouseListener from the list of notified instances.
 void removeMouseStopListener(MouseStopListener l)
          Removes a MouseStopListener from the list of notified instances.
 void setAbsolute(boolean absolute)
          Makes this Mouse an absolute mouse (only delta positions become valid) or relative.
protected abstract  void setAbsoluteImpl(boolean absolute)
          Makes this Mouse an absolute mouse (only delta positions become valid) or relative.
protected  void setButtonsState(int buttonState)
          Sets the new button-state.
protected  void setPosition(int x, int y)
          This method stores the positional values and may do some additional implementation dependent stuff.
protected  void storePosition(int x, int y)
          This method simply stores the positional values.
 java.lang.String toString()
          
 void update(InputSystem is, EventQueue eventQueue, long nanoTime)
          Processes pending events from the system and directly fires them (notifes the listeners).
protected abstract  void updateMouse(InputSystem is, EventQueue eventQueue, long nanoTime)
          Processes pending events from the system and directly fires them (notifes the listeners).
 
Methods inherited from class org.jagatoo.input.devices.InputDevice
addInputStateListener, collectEvents, consumePendingEvents, equals, fireStateEventsAndDoActions, getEventQueue, getName, getSourceWindow, hasInputStateListener, isEnabled, onDeviceRegistered, onDeviceUnregistered, removeInputStateListener, setEnabled
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Mouse

protected Mouse(MouseFactory sourceFactory,
                InputSourceWindow sourceWindow,
                EventQueue eventQueue,
                java.lang.String name,
                int numButtons,
                boolean hasWheel)
         throws InputSystemException
Throws:
InputSystemException
Method Detail

getSourceFactory

public final MouseFactory getSourceFactory()
Returns:
the MouseFactory, that created this instance.

notifyMouseStopManager

protected final void notifyMouseStopManager(long nanoTime)

getXAxis

public final MouseAxis getXAxis()
Returns:
the MouseAxis instance for this Mouse's X-axis.

getYAxis

public final MouseAxis getYAxis()
Returns:
the MouseAxis instance for this Mouse's Y-axis.

setPosition

protected void setPosition(int x,
                           int y)
                    throws InputSystemException
This method stores the positional values and may do some additional implementation dependent stuff.

Parameters:
x -
y -
Throws:
InputSystemException

centerMouse

public abstract void centerMouse()
                          throws InputSystemException
Centers the mouse cursor on the source-window.

Throws:
InputSystemException

storePosition

protected void storePosition(int x,
                             int y)
This method simply stores the positional values.

Parameters:
x -
y -

getCurrentX

public final int getCurrentX()
Returns:
the current x-position of this Mouse.

getCurrentY

public final int getCurrentY()
Returns:
the current y-position of this Mouse.

getButtonsCount

public final int getButtonsCount()
Returns:
the number of ControllerButtons mounted to this Controller.

getButton

public final MouseButton getButton(int index)
Returns:
the number of ControllerButtons mounted to this Controller.

setButtonsState

protected void setButtonsState(int buttonState)
Sets the new button-state.

Parameters:
buttonState -

addButtonsState

protected void addButtonsState(int buttonState)
Adds bits to the button-state's bitmask.

Parameters:
buttonState -

addButtonsState

protected void addButtonsState(MouseButton button)
Adds bits to the button-state's bitmask.

Parameters:
button -

removeButtonsState

protected void removeButtonsState(int buttonState)
Removes bits from the button-state's bitmask.

Parameters:
buttonState -

removeButtonsState

protected void removeButtonsState(MouseButton button)
Removes bits from the button-state's bitmask.

Parameters:
button -

getButtonsState

public final int getButtonsState()
Returns:
a bitmask with set bits for all pressed buttons.

getWheel

public final MouseWheel getWheel()
Returns:
the MouseWheel mounted to this Mouse.

isButtonPressed

public final boolean isButtonPressed(MouseButton button)
Parameters:
button -
Returns:
true, if the queried MouseButton is pressed on this Mouse.

getButtonState

public final InputState getButtonState(MouseButton button)
Parameters:
button -
Returns:
the appropriate state.

getState

public int getState(DeviceComponent component)
             throws InputSystemRuntimeException
This method returns an abstract input-state for the given DeviceComponent. Note, that only supported components are accepted.

Specified by:
getState in class InputDevice
Returns:
the current state of the given component on this device.
Throws:
InputSystemRuntimeException

addMouseStopListener

public void addMouseStopListener(MouseStopListener l)
Adds a MouseStopListener to this Mouse to be notified when the mouse has stopped being moved (for a while).

Parameters:
l -

removeMouseStopListener

public void removeMouseStopListener(MouseStopListener l)
Removes a MouseStopListener from the list of notified instances.

Parameters:
l -

hasMouseListener

public final boolean hasMouseListener()
Returns:
true, of at least one MouseStopListener is currently registered.

hasListener

public final boolean hasListener()
Returns:
true, if one of InputDevice.hasInputStateListener() or hasMouseListener() return true.

addMouseListener

public void addMouseListener(MouseListener l)
Adds a MouseListener to the list of instances being notifed on mouse events.

Parameters:
l -

removeMouseListener

public void removeMouseListener(MouseListener l)
Removes a MouseListener from the list of notified instances.

Parameters:
l -

prepareMouseButtonPressedEvent

protected final MouseButtonPressedEvent prepareMouseButtonPressedEvent(MouseButton button,
                                                                       long when)
Prepares a MouseButtonPressedEvent for being fired.
The event is not fired from this method.
This method cares about the current button-state.

Parameters:
button -
when -
Returns:
the new event from the pool or null, if no events are currently accepted.

fireOnMouseButtonPressed

public final void fireOnMouseButtonPressed(MouseButtonPressedEvent e,
                                           boolean consumeEvent)
Fires a MouseButtonPressedEvent and pushes it back to the pool, if consumeEvent is true.

Parameters:
e -
consumeEvent -

prepareMouseButtonReleasedEvent

protected final MouseButtonReleasedEvent prepareMouseButtonReleasedEvent(MouseButton button,
                                                                         long when)
Prepares a MouseButtonReleasedEvent for being fired.
The event is not fired from this method.
This method cares about the current button-state.

Parameters:
button -
when -
Returns:
the new event from the pool or null, if no events are currently accepted.

fireOnMouseButtonReleased

public final void fireOnMouseButtonReleased(MouseButtonReleasedEvent e,
                                            boolean consumeEvent)
Fires a MouseButtonReleasedEvent and pushes it back to the pool, if consumeEvent is true.

Parameters:
e -
consumeEvent -

fireOnMouseButtonClicked

public final void fireOnMouseButtonClicked(MouseButtonClickedEvent e,
                                           boolean consumeEvent)
Fires a MouseButtonClickedEvent and pushes it back to the pool, if consumeEvent is true.

Parameters:
e -
consumeEvent -

handleClickedEvents

protected final void handleClickedEvents(long when,
                                         long threshold)
Checks, if there are pending clicked-events and compares their when-times with the current when and threshold and fires the events, if necessary.

Parameters:
when -
threshold -

prepareMouseMovedEvent

protected final MouseMovedEvent prepareMouseMovedEvent(int x,
                                                       int y,
                                                       int dx,
                                                       int dy,
                                                       long when)
Prepares a MouseMovedEvent for being fired.
The event is not fired from this method.
This method also notifies the MouseStopManager, so that it can track, when the mouse has stopped.

Parameters:
button -
when -
Returns:
the new event from the pool or null, if no events are currently accepted.

fireOnMouseMoved

public final void fireOnMouseMoved(MouseMovedEvent e,
                                   boolean consumeEvent)
Fires a MouseMovedEvent and pushes it back to the pool, if consumeEvent is true.

Parameters:
e -
consumeEvent -

prepareMouseWheelMovedEvent

protected final MouseWheelEvent prepareMouseWheelMovedEvent(int wheelDelta,
                                                            boolean isPageMove,
                                                            long when)
Prepares a MouseWheelEvent for being fired.
The event is not fired from this method.
This method updates the wheel-state.

Parameters:
button -
when -
Returns:
the new event from the pool or null, if no events are currently accepted.

fireOnMouseWheelMoved

public final void fireOnMouseWheelMoved(MouseWheelEvent e,
                                        boolean consumeEvent)
Fires a MouseWheelEvent and pushes it back to the pool, if consumeEvent is true.

Parameters:
e -
consumeEvent -

fireMouseEvent

public final void fireMouseEvent(MouseEvent e,
                                 boolean consumeEvent)
This method simply forwards to the concrete fire* methods.

Parameters:
e -
consumeEvent -

setAbsoluteImpl

protected abstract void setAbsoluteImpl(boolean absolute)
                                 throws InputSystemException
Makes this Mouse an absolute mouse (only delta positions become valid) or relative. This method is implicitly called by setAbsolute(boolean), but only if the value has changed.

Parameters:
absolute -
Throws:
InputSystemException

setAbsolute

public final void setAbsolute(boolean absolute)
                       throws InputSystemException
Makes this Mouse an absolute mouse (only delta positions become valid) or relative.

Parameters:
absolute -
Throws:
InputSystemException

isAbsolute

public final boolean isAbsolute()
Returns:
whether this Mouse is absolute or not.

updateMouse

protected abstract void updateMouse(InputSystem is,
                                    EventQueue eventQueue,
                                    long nanoTime)
                             throws InputSystemException
Processes pending events from the system and directly fires them (notifes the listeners).
This method also flushes the EventQueue, if the previously called InputDevice.collectEvents(InputSystem, EventQueue, long) method placed events into it.

Parameters:
is -
eventQueue -
nanoTime -
Throws:
InputSystemException

update

public void update(InputSystem is,
                   EventQueue eventQueue,
                   long nanoTime)
            throws InputSystemException
Processes pending events from the system and directly fires them (notifes the listeners).
This method also flushes the EventQueue, if the previously called InputDevice.collectEvents(InputSystem, EventQueue, long) method placed events into it.

Specified by:
update in class InputDevice
Throws:
InputSystemException

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

destroyImpl

protected abstract void destroyImpl()
                             throws InputSystemException
Destroys the Mouse.

Throws:
InputSystemException

destroy

public final void destroy()
                   throws InputSystemException
Destroys the InputDevice. This must be called when the InputDevice is unregistered.

Specified by:
destroy in class InputDevice
Throws:
InputSystemException