com.jme.input
Class MouseInput

java.lang.Object
  extended by com.jme.input.Input
      extended by com.jme.input.MouseInput
Direct Known Subclasses:
AWTMouseInput, DummyMouseInput, LWJGLMouseInput, SWTMouseInput

public abstract class MouseInput
extends Input

MouseInput defines an interface to communicate with the mouse input device. The status of spcific buttons can be queried via the isButtonDown(int) method. Position data can be queried by various get methods. For each button that is pressed or released as well as for movement of mouse or wheel an event is generated which can be received by a MouseInputListener, these are subsribed via addListener(MouseInputListener). Handling of events is done inside the update() method.

Version:
$Id: MouseInput.java 4336 2009-05-03 20:57:01Z christoph.luder $
Author:
Mark Powell

Field Summary
static java.lang.String INPUT_AWT
           
static java.lang.String INPUT_LWJGL
           
protected  java.util.ArrayList<MouseInputListener> listeners
          list of event listeners.
 
Constructor Summary
MouseInput()
           
 
Method Summary
 void addListener(MouseInputListener listener)
          Subscribe a listener to receive mouse events.
abstract  void clear()
           
abstract  void clearButton(int buttonCode)
           
 boolean containsListener(MouseInputListener listener)
          Check if a listener is allready added to this MouseInput
protected abstract  void destroy()
          destroy cleans up the native mouse interface.
static void destroyIfInitalized()
          Destroy the input if it was initialized.
static MouseInput get()
           
abstract  int getButtonCount()
           
abstract  int getButtonIndex(java.lang.String buttonName)
          getButtonIndex gets the button code for a given button name.
abstract  java.lang.String getButtonName(int buttonIndex)
          getButtonName gets the button name for a given button code.
 java.util.ArrayList<MouseInputListener> getListeners()
          Get all added mouse listeners
static java.lang.Class<?> getProvider()
          Query current provider for input.
abstract  int getWheelDelta()
          getWheelDelta gets the change in the mouse wheel.
abstract  int getWheelRotation()
           
abstract  int getXAbsolute()
          getXAbsolute gets the absolute x axis value.
abstract  int getXDelta()
          getXDelta gets the change along the x axis.
abstract  int getYAbsolute()
          getYAbsolute gets the absolute y axis value.
abstract  int getYDelta()
          getYDelta gets the change along the y axis.
abstract  boolean isButtonDown(int buttonCode)
          isButtonDown returns true if a given button is pressed, false if it is not pressed.
abstract  boolean isCursorVisible()
          isCursorVisible
static boolean isInited()
          isInited returns true if the key class is not setup already (ie.
 void removeListener(MouseInputListener listener)
          Unsubscribe a listener.
 void removeListeners()
          Remove all listeners and disable event generation.
abstract  void setCursorPosition(int x, int y)
           
abstract  void setCursorVisible(boolean v)
          setCursorVisible sets the visiblity of the hardware cursor.
abstract  void setHardwareCursor(java.net.URL file)
          setHardwareCursor sets the image to use for the hardware cursor.
abstract  void setHardwareCursor(java.net.URL file, Image[] images, int[] delays, int xHotspot, int yHotspot)
          This method will set an animated harware cursor.
abstract  void setHardwareCursor(java.net.URL file, int xHotspot, int yHotspot)
          setHardwareCursor sets the image and hotspot position to use for the hardware cursor.
static void setProvider(java.lang.Class value)
          Change the provider used for mouse input.
static void setProvider(java.lang.String value)
          Change the provider used for mouse input.
abstract  void update()
          Updates the state of the mouse (position and button states).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

protected java.util.ArrayList<MouseInputListener> listeners
list of event listeners.


INPUT_LWJGL

public static final java.lang.String INPUT_LWJGL

INPUT_AWT

public static final java.lang.String INPUT_AWT
See Also:
Constant Field Values
Constructor Detail

MouseInput

public MouseInput()
Method Detail

get

public static MouseInput get()
Returns:
the input instance, implementation is determined by querying getProvider()

getProvider

public static java.lang.Class<?> getProvider()
Query current provider for input.

Returns:
currently selected provider

setProvider

public static void setProvider(java.lang.String value)
Change the provider used for mouse input. Default is INPUT_LWJGL.

Parameters:
value - new provider class name
Throws:
java.lang.IllegalStateException - if called after first call of get(). Note that get is called when creating the DisplaySystem.
java.lang.IllegalArgumentException - if the specified class cannot be found using Class.forName(String)

setProvider

public static void setProvider(java.lang.Class value)
Change the provider used for mouse input. Default is InputSystem.INPUT_SYSTEM_LWJGL.

Parameters:
value - new provider
Throws:
java.lang.IllegalStateException - if called after first call of get(). Note that get is called when creating the DisplaySystem.

destroy

protected abstract void destroy()
destroy cleans up the native mouse interface. Destroy is protected now - please is destroyIfInitalized().


getButtonIndex

public abstract int getButtonIndex(java.lang.String buttonName)
getButtonIndex gets the button code for a given button name.

Parameters:
buttonName - the name to get the code for.
Returns:
the code for the given button name.

isButtonDown

public abstract boolean isButtonDown(int buttonCode)
isButtonDown returns true if a given button is pressed, false if it is not pressed.

Parameters:
buttonCode - the button code to check.
Returns:
true if the button is pressed, false otherwise.

getButtonName

public abstract java.lang.String getButtonName(int buttonIndex)
getButtonName gets the button name for a given button code.

Parameters:
buttonIndex - the code to get the name for.
Returns:
the name for the given button code.

isInited

public static boolean isInited()
isInited returns true if the key class is not setup already (ie. .get() was not yet called).

Returns:
true if it is initialized and ready for use, false otherwise.

getWheelDelta

public abstract int getWheelDelta()
getWheelDelta gets the change in the mouse wheel.

Returns:
the change in the mouse wheel.

getXDelta

public abstract int getXDelta()
getXDelta gets the change along the x axis.

Returns:
the change along the x axis.

getYDelta

public abstract int getYDelta()
getYDelta gets the change along the y axis.

Returns:
the change along the y axis.

getXAbsolute

public abstract int getXAbsolute()
getXAbsolute gets the absolute x axis value.

Returns:
the absolute x axis value.

getYAbsolute

public abstract int getYAbsolute()
getYAbsolute gets the absolute y axis value.

Returns:
the absolute y axis value.

update

public abstract void update()
Updates the state of the mouse (position and button states). Invokes event listeners synchronously.

Specified by:
update in class Input

setCursorVisible

public abstract void setCursorVisible(boolean v)
setCursorVisible sets the visiblity of the hardware cursor.

Parameters:
v - true turns the cursor on false turns it off

isCursorVisible

public abstract boolean isCursorVisible()
isCursorVisible

Returns:
the visibility of the hardware cursor

setHardwareCursor

public abstract void setHardwareCursor(java.net.URL file)
setHardwareCursor sets the image to use for the hardware cursor.

Parameters:
file - URL to cursor image

setHardwareCursor

public abstract void setHardwareCursor(java.net.URL file,
                                       int xHotspot,
                                       int yHotspot)
setHardwareCursor sets the image and hotspot position to use for the hardware cursor.

Parameters:
file - URL to cursor image
xHotspot - Cursor X hotspot position
yHotspot - Cursor Y hotspot position

setHardwareCursor

public abstract void setHardwareCursor(java.net.URL file,
                                       Image[] images,
                                       int[] delays,
                                       int xHotspot,
                                       int yHotspot)
This method will set an animated harware cursor.

Parameters:
file - in this method file is only used as a key for cursor cashing
images - the animation frames
delays - delays between changing each frame
xHotspot - from image left
yHotspot - from image bottom

addListener

public void addListener(MouseInputListener listener)
Subscribe a listener to receive mouse events. Enable event generation.

Parameters:
listener - to be subscribed

removeListener

public void removeListener(MouseInputListener listener)
Unsubscribe a listener. Disable event generation if no more listeners.

Parameters:
listener - to be unsuscribed
See Also:
addListener(com.jme.input.MouseInputListener)

removeListeners

public void removeListeners()
Remove all listeners and disable event generation.


containsListener

public boolean containsListener(MouseInputListener listener)
Check if a listener is allready added to this MouseInput

Parameters:
listener - listener to check for
Returns:
true if listener is contained in the listenerlist

getListeners

public java.util.ArrayList<MouseInputListener> getListeners()
Get all added mouse listeners

Returns:
ArrayList of listeners added to this MouseInput

destroyIfInitalized

public static void destroyIfInitalized()
Destroy the input if it was initialized.


getWheelRotation

public abstract int getWheelRotation()
Returns:
absolte wheel rotation

getButtonCount

public abstract int getButtonCount()
Returns:
number of mouse buttons

setCursorPosition

public abstract void setCursorPosition(int x,
                                       int y)

clear

public abstract void clear()

clearButton

public abstract void clearButton(int buttonCode)