fi.hut.tml.xsmiles.mlfc.io.directdevice
Class DirectDevice

java.lang.Object
  extended byfi.hut.tml.xsmiles.mlfc.io.directdevice.DirectDevice
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
DirectDeviceWin

public class DirectDevice
extends java.lang.Object
implements java.lang.Runnable


Field Summary
protected  boolean[] button
           
protected  boolean[] key
           
protected  boolean[] oldbutton
           
protected  boolean[] oldkey
           
protected  int oldrx
           
protected  int oldry
           
protected  int oldrz
           
protected  int oldx
           
protected  int oldy
           
protected  int oldz
           
protected  int rx
           
protected  int ry
           
protected  int rz
           
protected  int x
           
protected  int y
           
protected  int z
           
 
Constructor Summary
protected DirectDevice()
          Private constructor - this class should be instantiated with a call to createInstance().
 
Method Summary
 void addJoystickListener(JoystickListener listener)
          Add a joystick listener to receive joystick chages, This will also start the sampling thread, if not running.
 void addKeyboardListener(KeyboardListener listener)
          Add a keyboard listener to receive key chages, This will also start the sampling thread, if not running.
static DirectDevice createInstance()
          Create a instance of the DirectDevice class - platform dependent class is returned.
 boolean getButton(int num)
          Get joystick button state.
 boolean getKeyboard(int num)
          Get keyboard key state.
 int getRX()
          Get joystick x-axis rotation value.
 int getRY()
          Get joystick y-axis rotation value.
 int getRZ()
          Get joystick z-axis rotation value.
 int getSamplingRate()
          Get joystick state sampling rate.
 int getX()
          Get joystick x-axis value.
 int getY()
          Get joystick y-axis value.
 int getZ()
          Get joystick z-axis value.
 void notifyJoystickListeners()
          Remove a joystick listener,
 void notifyKeyboardListeners()
          Remove a keyboard listener,
 void removeJoystickListener(JoystickListener listener)
          Remove a joystick listener.
 void removeKeyboardListener(KeyboardListener listener)
          Remove a keyboard listener.
 void run()
          This is a thread sampling joystick every interval ms.
protected  void sample()
          Sampling method - this class has a dummy implementation, but platform dependent subclasses are expected to override this and implement their own joystick sampling routine.
 void setSamplingRate(int rate)
          Set joystick state sampling rate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

x

protected int x

y

protected int y

z

protected int z

rx

protected int rx

ry

protected int ry

rz

protected int rz

button

protected boolean[] button

oldx

protected int oldx

oldy

protected int oldy

oldz

protected int oldz

oldrx

protected int oldrx

oldry

protected int oldry

oldrz

protected int oldrz

oldbutton

protected boolean[] oldbutton

key

protected boolean[] key

oldkey

protected boolean[] oldkey
Constructor Detail

DirectDevice

protected DirectDevice()
Private constructor - this class should be instantiated with a call to createInstance().

Method Detail

createInstance

public static DirectDevice createInstance()
Create a instance of the DirectDevice class - platform dependent class is returned. (DirectDeviceWin or DirectDeviceLinux...)


getSamplingRate

public int getSamplingRate()
Get joystick state sampling rate. The joystick is sampled all the time by a thread. This method returns the interval between samples.

Returns:
Sampling rate, in millisecs.

setSamplingRate

public void setSamplingRate(int rate)
Set joystick state sampling rate. The joystick is sampled all the time by a thread. This method sets the interval between samples.

Parameters:
rate - Sampling rate, in millisecs.

sample

protected void sample()
Sampling method - this class has a dummy implementation, but platform dependent subclasses are expected to override this and implement their own joystick sampling routine.


run

public void run()
This is a thread sampling joystick every interval ms. Runs all the time.

Specified by:
run in interface java.lang.Runnable

addJoystickListener

public void addJoystickListener(JoystickListener listener)
Add a joystick listener to receive joystick chages, This will also start the sampling thread, if not running.

Parameters:
listener - Joystick Listener

removeJoystickListener

public void removeJoystickListener(JoystickListener listener)
Remove a joystick listener. Also stops the sampling thread, if no more listeners.

Parameters:
listener - Joystick Listener

notifyJoystickListeners

public void notifyJoystickListeners()
Remove a joystick listener,


addKeyboardListener

public void addKeyboardListener(KeyboardListener listener)
Add a keyboard listener to receive key chages, This will also start the sampling thread, if not running.

Parameters:
listener - Keyboard Listener

removeKeyboardListener

public void removeKeyboardListener(KeyboardListener listener)
Remove a keyboard listener. Also stops the sampling thread, if no more listeners.

Parameters:
listener - Keyboard Listener

notifyKeyboardListeners

public void notifyKeyboardListeners()
Remove a keyboard listener,


getX

public int getX()
Get joystick x-axis value.

Returns:
Joystick x-axis value [-100, 100]

getY

public int getY()
Get joystick y-axis value.

Returns:
Joystick y-axis value [-100, 100]

getZ

public int getZ()
Get joystick z-axis value.

Returns:
Joystick z-axis value [-100, 100]

getRX

public int getRX()
Get joystick x-axis rotation value.

Returns:
Joystick x-axis rotation value [-100, 100]

getRY

public int getRY()
Get joystick y-axis rotation value.

Returns:
Joystick y-axis rotation value [-100, 100]

getRZ

public int getRZ()
Get joystick z-axis rotation value.

Returns:
Joystick z-axis rotation value [-100, 100]

getButton

public boolean getButton(int num)
Get joystick button state.

Parameters:
num - Button number, 0-31
Returns:
Joystick button state, true if pressed, false if unpressed

getKeyboard

public boolean getKeyboard(int num)
Get keyboard key state.

Parameters:
num - Key number (pplatform dependent!)
Returns:
Key state, true if pressed, false if unpressed


X-Smiles 1.2