aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/awt/src/net/java
diff options
context:
space:
mode:
authorendolf <[email protected]>2006-04-29 22:29:27 +0000
committerendolf <[email protected]>2006-04-29 22:29:27 +0000
commit986c6106aa165d4168f6b8e1216eceb5353fce14 (patch)
tree1a61954c62909e8e4a4b4c578665a4df40d013cf /plugins/awt/src/net/java
parent09bdd72a93f2a5498137d22540d035df87cff174 (diff)
Make version 2 the main jinput version
git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/trunk@139 e343933a-64c8-49c5-92b1-88f2ce3e89e8
Diffstat (limited to 'plugins/awt/src/net/java')
-rw-r--r--plugins/awt/src/net/java/games/input/AWTAxis.java75
-rw-r--r--plugins/awt/src/net/java/games/input/AWTButton.java79
-rw-r--r--plugins/awt/src/net/java/games/input/AWTEnvironmentPlugin.java20
-rw-r--r--plugins/awt/src/net/java/games/input/AWTKeyMap.java289
-rw-r--r--plugins/awt/src/net/java/games/input/AWTKeyboard.java341
-rw-r--r--plugins/awt/src/net/java/games/input/AWTMouse.java321
6 files changed, 593 insertions, 532 deletions
diff --git a/plugins/awt/src/net/java/games/input/AWTAxis.java b/plugins/awt/src/net/java/games/input/AWTAxis.java
deleted file mode 100644
index daa2e12..0000000
--- a/plugins/awt/src/net/java/games/input/AWTAxis.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * Copyright (C) 2004 Jeremy Booth ([email protected])
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer. Redistributions in binary
- * form must reproduce the above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * The name of the author may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
- * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
- */
-package net.java.games.input;
-
-/**
- * @author Jeremy
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Style - Code Templates
- */
-public class AWTAxis extends AbstractComponent {
-
- private float value = 0.0f;
-
- /**
- * @param name
- * @param id
- */
- protected AWTAxis(String name, Identifier id) {
- super(name, id);
- }
-
- /**
- * Returns the data from the last time the control has been polled.
- * If this axis is a button, the value returned will be either 0.0f or 1.0f.
- * If this axis is normalized, the value returned will be between -1.0f and
- * 1.0f.
- * @return 0.0f by default, can be overridden
- */
- public float getPollData() {
- return value;
- }
-
- /* (non-Javadoc)
- * @see net.java.games.input.Component#isRelative()
- */
- public boolean isRelative() {
- return false;
- }
-
- /**
- * Returns whether or not the axis is analog, or false if it is digital.
- * @return false by default, can be overridden
- */
- public boolean isAnalog() {
- return true;
- }
-
- void setValue(float value) {
- this.value = value;
- }
-}
diff --git a/plugins/awt/src/net/java/games/input/AWTButton.java b/plugins/awt/src/net/java/games/input/AWTButton.java
deleted file mode 100644
index 6e36d16..0000000
--- a/plugins/awt/src/net/java/games/input/AWTButton.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * Copyright (C) 2004 Jeremy Booth ([email protected])
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer. Redistributions in binary
- * form must reproduce the above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * The name of the author may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
- * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
- */
-package net.java.games.input;
-
-/**
- * @author Jeremy
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Style - Code Templates
- */
-public class AWTButton extends AbstractComponent {
-
- private boolean value = false;
-
- /**
- * @param name
- * @param id
- */
- protected AWTButton(String name, Identifier id) {
- super(name, id);
- }
-
- /* (non-Javadoc)
- * @see net.java.games.input.Component#isRelative()
- */
- public boolean isRelative() {
- return false;
- }
-
- /**
- * Returns whether or not the axis is analog, or false if it is digital.
- * @return false by default, can be overridden
- */
- public boolean isAnalog() {
- return false;
- }
-
- /**
- * Returns the data from the last time the control has been polled.
- * If this axis is a button, the value returned will be either 0.0f or 1.0f.
- * If this axis is normalized, the value returned will be between -1.0f and
- * 1.0f.
- * @return 0.0f by default, can be overridden
- */
- public float getPollData() {
- if(value) {
- return 1.0f;
- } else {
- return 0.0f;
- }
- }
-
- void setValue(boolean value) {
- this.value = value;
- }
-}
diff --git a/plugins/awt/src/net/java/games/input/AWTEnvironmentPlugin.java b/plugins/awt/src/net/java/games/input/AWTEnvironmentPlugin.java
index a155db5..96e5986 100644
--- a/plugins/awt/src/net/java/games/input/AWTEnvironmentPlugin.java
+++ b/plugins/awt/src/net/java/games/input/AWTEnvironmentPlugin.java
@@ -31,24 +31,16 @@ import net.java.games.util.plugins.Plugin;
/**
* @author Jeremy
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Style - Code Templates
+ * @author elias
*/
public class AWTEnvironmentPlugin extends ControllerEnvironment implements Plugin {
-
- /** The two controllers */
- private Controller[] controllers = new Controller[2];
+ private final Controller[] controllers;
+
+ public AWTEnvironmentPlugin() {
+ this.controllers = new Controller[]{new AWTKeyboard(), new AWTMouse()};
+ }
- /* (non-Javadoc)
- * @see net.java.games.input.ControllerEnvironment#getControllers()
- */
public Controller[] getControllers() {
- if((controllers[0] == null) && (controllers[1] == null)) {
- controllers[0] = new AWTKeyboard("AWTKeyboard");
- controllers[1] = new AWTMouse("AWTMouse");
- }
return controllers;
}
-
}
diff --git a/plugins/awt/src/net/java/games/input/AWTKeyMap.java b/plugins/awt/src/net/java/games/input/AWTKeyMap.java
new file mode 100644
index 0000000..cb0c548
--- /dev/null
+++ b/plugins/awt/src/net/java/games/input/AWTKeyMap.java
@@ -0,0 +1,289 @@
+/**
+ * Copyright (C) 2004 Jeremy Booth ([email protected])
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions and
+ * the following disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * The name of the author may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
+ */
+package net.java.games.input;
+
+import java.awt.event.KeyEvent;
+
+/**
+ * @author Jeremy
+ * @author elias
+ */
+final class AWTKeyMap {
+ public final static Component.Identifier.Key mapKeyCode(int key_code) {
+ switch (key_code) {
+ case KeyEvent.VK_0:
+ return Component.Identifier.Key._0;
+ case KeyEvent.VK_1:
+ return Component.Identifier.Key._1;
+ case KeyEvent.VK_2:
+ return Component.Identifier.Key._2;
+ case KeyEvent.VK_3:
+ return Component.Identifier.Key._3;
+ case KeyEvent.VK_4:
+ return Component.Identifier.Key._4;
+ case KeyEvent.VK_5:
+ return Component.Identifier.Key._5;
+ case KeyEvent.VK_6:
+ return Component.Identifier.Key._6;
+ case KeyEvent.VK_7:
+ return Component.Identifier.Key._7;
+ case KeyEvent.VK_8:
+ return Component.Identifier.Key._8;
+ case KeyEvent.VK_9:
+ return Component.Identifier.Key._9;
+
+ case KeyEvent.VK_Q:
+ return Component.Identifier.Key.Q;
+ case KeyEvent.VK_W:
+ return Component.Identifier.Key.W;
+ case KeyEvent.VK_E:
+ return Component.Identifier.Key.E;
+ case KeyEvent.VK_R:
+ return Component.Identifier.Key.R;
+ case KeyEvent.VK_T:
+ return Component.Identifier.Key.T;
+ case KeyEvent.VK_Y:
+ return Component.Identifier.Key.Y;
+ case KeyEvent.VK_U:
+ return Component.Identifier.Key.U;
+ case KeyEvent.VK_I:
+ return Component.Identifier.Key.I;
+ case KeyEvent.VK_O:
+ return Component.Identifier.Key.O;
+ case KeyEvent.VK_P:
+ return Component.Identifier.Key.P;
+ case KeyEvent.VK_A:
+ return Component.Identifier.Key.A;
+ case KeyEvent.VK_S:
+ return Component.Identifier.Key.S;
+ case KeyEvent.VK_D:
+ return Component.Identifier.Key.D;
+ case KeyEvent.VK_F:
+ return Component.Identifier.Key.F;
+ case KeyEvent.VK_G:
+ return Component.Identifier.Key.G;
+ case KeyEvent.VK_H:
+ return Component.Identifier.Key.H;
+ case KeyEvent.VK_J:
+ return Component.Identifier.Key.J;
+ case KeyEvent.VK_K:
+ return Component.Identifier.Key.K;
+ case KeyEvent.VK_L:
+ return Component.Identifier.Key.L;
+ case KeyEvent.VK_Z:
+ return Component.Identifier.Key.Z;
+ case KeyEvent.VK_X:
+ return Component.Identifier.Key.X;
+ case KeyEvent.VK_C:
+ return Component.Identifier.Key.C;
+ case KeyEvent.VK_V:
+ return Component.Identifier.Key.V;
+ case KeyEvent.VK_B:
+ return Component.Identifier.Key.B;
+ case KeyEvent.VK_N:
+ return Component.Identifier.Key.N;
+ case KeyEvent.VK_M:
+ return Component.Identifier.Key.M;
+
+ case KeyEvent.VK_F1:
+ return Component.Identifier.Key.F1;
+ case KeyEvent.VK_F2:
+ return Component.Identifier.Key.F2;
+ case KeyEvent.VK_F3:
+ return Component.Identifier.Key.F3;
+ case KeyEvent.VK_F4:
+ return Component.Identifier.Key.F4;
+ case KeyEvent.VK_F5:
+ return Component.Identifier.Key.F5;
+ case KeyEvent.VK_F6:
+ return Component.Identifier.Key.F6;
+ case KeyEvent.VK_F7:
+ return Component.Identifier.Key.F7;
+ case KeyEvent.VK_F8:
+ return Component.Identifier.Key.F8;
+ case KeyEvent.VK_F9:
+ return Component.Identifier.Key.F9;
+ case KeyEvent.VK_F10:
+ return Component.Identifier.Key.F10;
+ case KeyEvent.VK_F11:
+ return Component.Identifier.Key.F11;
+ case KeyEvent.VK_F12:
+ return Component.Identifier.Key.F12;
+
+ case KeyEvent.VK_ESCAPE:
+ return Component.Identifier.Key.ESCAPE;
+ case KeyEvent.VK_MINUS:
+ return Component.Identifier.Key.MINUS;
+ case KeyEvent.VK_EQUALS:
+ return Component.Identifier.Key.EQUALS;
+ case KeyEvent.VK_BACK_SPACE:
+ return Component.Identifier.Key.BACKSLASH;
+ case KeyEvent.VK_TAB:
+ return Component.Identifier.Key.TAB;
+ case KeyEvent.VK_OPEN_BRACKET:
+ return Component.Identifier.Key.LBRACKET;
+ case KeyEvent.VK_CLOSE_BRACKET:
+ return Component.Identifier.Key.RBRACKET;
+ case KeyEvent.VK_SEMICOLON:
+ return Component.Identifier.Key.SEMICOLON;
+ case KeyEvent.VK_QUOTE:
+ return Component.Identifier.Key.APOSTROPHE;
+ case KeyEvent.VK_NUMBER_SIGN:
+ return Component.Identifier.Key.GRAVE;
+ case KeyEvent.VK_BACK_SLASH:
+ return Component.Identifier.Key.BACKSLASH;
+ case KeyEvent.VK_PERIOD:
+ return Component.Identifier.Key.PERIOD;
+ case KeyEvent.VK_SLASH:
+ return Component.Identifier.Key.SLASH;
+ case KeyEvent.VK_MULTIPLY:
+ return Component.Identifier.Key.MULTIPLY;
+ case KeyEvent.VK_SPACE:
+ return Component.Identifier.Key.SPACE;
+ case KeyEvent.VK_CAPS_LOCK:
+ return Component.Identifier.Key.CAPITAL;
+ case KeyEvent.VK_NUM_LOCK:
+ return Component.Identifier.Key.NUMLOCK;
+ case KeyEvent.VK_SCROLL_LOCK:
+ return Component.Identifier.Key.SCROLL;
+ case KeyEvent.VK_NUMPAD7:
+ return Component.Identifier.Key.NUMPAD7;
+ case KeyEvent.VK_NUMPAD8:
+ return Component.Identifier.Key.NUMPAD8;
+ case KeyEvent.VK_NUMPAD9:
+ return Component.Identifier.Key.NUMPAD9;
+ case KeyEvent.VK_SUBTRACT:
+ return Component.Identifier.Key.SUBTRACT;
+ case KeyEvent.VK_NUMPAD4:
+ return Component.Identifier.Key.NUMPAD4;
+ case KeyEvent.VK_NUMPAD5:
+ return Component.Identifier.Key.NUMPAD5;
+ case KeyEvent.VK_NUMPAD6:
+ return Component.Identifier.Key.NUMPAD6;
+ case KeyEvent.VK_ADD:
+ return Component.Identifier.Key.ADD;
+ case KeyEvent.VK_NUMPAD1:
+ return Component.Identifier.Key.NUMPAD1;
+ case KeyEvent.VK_NUMPAD2:
+ return Component.Identifier.Key.NUMPAD2;
+ case KeyEvent.VK_NUMPAD3:
+ return Component.Identifier.Key.NUMPAD3;
+ case KeyEvent.VK_NUMPAD0:
+ return Component.Identifier.Key.NUMPAD0;
+ case KeyEvent.VK_DECIMAL:
+ return Component.Identifier.Key.DECIMAL;
+
+ case KeyEvent.VK_KANA:
+ return Component.Identifier.Key.KANA;
+ case KeyEvent.VK_CONVERT:
+ return Component.Identifier.Key.CONVERT;
+ case KeyEvent.VK_NONCONVERT:
+ return Component.Identifier.Key.NOCONVERT;
+
+ case KeyEvent.VK_CIRCUMFLEX:
+ return Component.Identifier.Key.CIRCUMFLEX;
+ case KeyEvent.VK_AT:
+ return Component.Identifier.Key.AT;
+ case KeyEvent.VK_COLON:
+ return Component.Identifier.Key.COLON;
+ case KeyEvent.VK_UNDERSCORE:
+ return Component.Identifier.Key.UNDERLINE;
+ case KeyEvent.VK_KANJI:
+ return Component.Identifier.Key.KANJI;
+
+ case KeyEvent.VK_STOP:
+ return Component.Identifier.Key.STOP;
+
+ case KeyEvent.VK_DIVIDE:
+ return Component.Identifier.Key.DIVIDE;
+
+ case KeyEvent.VK_PAUSE:
+ return Component.Identifier.Key.PAUSE;
+ case KeyEvent.VK_HOME:
+ return Component.Identifier.Key.HOME;
+ case KeyEvent.VK_UP:
+ return Component.Identifier.Key.UP;
+ case KeyEvent.VK_PAGE_UP:
+ return Component.Identifier.Key.PAGEUP;
+ case KeyEvent.VK_LEFT:
+ return Component.Identifier.Key.LEFT;
+ case KeyEvent.VK_RIGHT:
+ return Component.Identifier.Key.RIGHT;
+ case KeyEvent.VK_END:
+ return Component.Identifier.Key.END;
+ case KeyEvent.VK_DOWN:
+ return Component.Identifier.Key.DOWN;
+ case KeyEvent.VK_PAGE_DOWN:
+ return Component.Identifier.Key.PAGEDOWN;
+ case KeyEvent.VK_INSERT:
+ return Component.Identifier.Key.INSERT;
+ case KeyEvent.VK_DELETE:
+ return Component.Identifier.Key.DELETE;
+ default:
+ return Component.Identifier.Key.UNKNOWN;
+ }
+ }
+
+ public final static Component.Identifier.Key map(KeyEvent event) {
+ int key_code = event.getKeyCode();
+ int key_location = event.getKeyLocation();
+ switch (key_code) {
+ case KeyEvent.VK_CONTROL:
+ if (key_location == KeyEvent.KEY_LOCATION_RIGHT)
+ return Component.Identifier.Key.RCONTROL;
+ else
+ return Component.Identifier.Key.LCONTROL;
+ case KeyEvent.VK_SHIFT:
+ if (key_location == KeyEvent.KEY_LOCATION_RIGHT)
+ return Component.Identifier.Key.RSHIFT;
+ else
+ return Component.Identifier.Key.LSHIFT;
+ case KeyEvent.VK_ALT:
+ if (key_location == KeyEvent.KEY_LOCATION_RIGHT)
+ return Component.Identifier.Key.RALT;
+ else
+ return Component.Identifier.Key.LALT;
+ //this is 1.5 only
+/* case KeyEvent.VK_WINDOWS:
+ if (key_location == KeyEvent.KEY_LOCATION_RIGHT)
+ return Component.Identifier.Key.RWIN;
+ else
+ return Component.Identifier.Key.LWIN;*/
+ case KeyEvent.VK_ENTER:
+ if (key_location == KeyEvent.KEY_LOCATION_NUMPAD)
+ return Component.Identifier.Key.NUMPADENTER;
+ else
+ return Component.Identifier.Key.RETURN;
+ case KeyEvent.VK_COMMA:
+ if (key_location == KeyEvent.KEY_LOCATION_NUMPAD)
+ return Component.Identifier.Key.NUMPADCOMMA;
+ else
+ return Component.Identifier.Key.COMMA;
+ default:
+ return mapKeyCode(key_code);
+ }
+ }
+}
diff --git a/plugins/awt/src/net/java/games/input/AWTKeyboard.java b/plugins/awt/src/net/java/games/input/AWTKeyboard.java
index dba9b0e..dafd4df 100644
--- a/plugins/awt/src/net/java/games/input/AWTKeyboard.java
+++ b/plugins/awt/src/net/java/games/input/AWTKeyboard.java
@@ -30,233 +30,142 @@ import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.KeyEvent;
+import java.util.List;
+import java.util.ArrayList;
+
+import java.io.IOException;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
/**
* @author Jeremy
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Style - Code Templates
+ * @author elias
*/
-public class AWTKeyboard extends StandardKeyboard implements AWTEventListener {
-
- private boolean[] buttonValues;
+final class AWTKeyboard extends Keyboard implements AWTEventListener {
+ private final List awt_events = new ArrayList();
+ private Event[] processed_events;
+ private int processed_events_index;
- private int[] buttonMap;
-
- /**
- * @param name
- */
- protected AWTKeyboard(String name) {
- super(name);
-
- buttonValues = new boolean[getComponents().length];
- buttonMap = new int[65535]; //has to be this big, as the values of KeyEvent keys are large
-
- buttonMap[KeyEvent.VK_0] = Component.Identifier.Key._0.getKeyIndex();
- buttonMap[KeyEvent.VK_1] = Component.Identifier.Key._1.getKeyIndex();
- buttonMap[KeyEvent.VK_2] = Component.Identifier.Key._2.getKeyIndex();
- buttonMap[KeyEvent.VK_3] = Component.Identifier.Key._3.getKeyIndex();
- buttonMap[KeyEvent.VK_4] = Component.Identifier.Key._4.getKeyIndex();
- buttonMap[KeyEvent.VK_5] = Component.Identifier.Key._5.getKeyIndex();
- buttonMap[KeyEvent.VK_6] = Component.Identifier.Key._6.getKeyIndex();
- buttonMap[KeyEvent.VK_7] = Component.Identifier.Key._7.getKeyIndex();
- buttonMap[KeyEvent.VK_8] = Component.Identifier.Key._8.getKeyIndex();
- buttonMap[KeyEvent.VK_9] = Component.Identifier.Key._9.getKeyIndex();
-
- buttonMap[KeyEvent.VK_Q] = Component.Identifier.Key.Q.getKeyIndex();
- buttonMap[KeyEvent.VK_W] = Component.Identifier.Key.W.getKeyIndex();
- buttonMap[KeyEvent.VK_E] = Component.Identifier.Key.E.getKeyIndex();
- buttonMap[KeyEvent.VK_R] = Component.Identifier.Key.R.getKeyIndex();
- buttonMap[KeyEvent.VK_T] = Component.Identifier.Key.T.getKeyIndex();
- buttonMap[KeyEvent.VK_Y] = Component.Identifier.Key.Y.getKeyIndex();
- buttonMap[KeyEvent.VK_U] = Component.Identifier.Key.U.getKeyIndex();
- buttonMap[KeyEvent.VK_I] = Component.Identifier.Key.I.getKeyIndex();
- buttonMap[KeyEvent.VK_O] = Component.Identifier.Key.O.getKeyIndex();
- buttonMap[KeyEvent.VK_P] = Component.Identifier.Key.P.getKeyIndex();
- buttonMap[KeyEvent.VK_A] = Component.Identifier.Key.A.getKeyIndex();
- buttonMap[KeyEvent.VK_S] = Component.Identifier.Key.S.getKeyIndex();
- buttonMap[KeyEvent.VK_D] = Component.Identifier.Key.D.getKeyIndex();
- buttonMap[KeyEvent.VK_F] = Component.Identifier.Key.F.getKeyIndex();
- buttonMap[KeyEvent.VK_G] = Component.Identifier.Key.G.getKeyIndex();
- buttonMap[KeyEvent.VK_H] = Component.Identifier.Key.H.getKeyIndex();
- buttonMap[KeyEvent.VK_J] = Component.Identifier.Key.J.getKeyIndex();
- buttonMap[KeyEvent.VK_K] = Component.Identifier.Key.K.getKeyIndex();
- buttonMap[KeyEvent.VK_L] = Component.Identifier.Key.L.getKeyIndex();
- buttonMap[KeyEvent.VK_Z] = Component.Identifier.Key.Z.getKeyIndex();
- buttonMap[KeyEvent.VK_X] = Component.Identifier.Key.X.getKeyIndex();
- buttonMap[KeyEvent.VK_C] = Component.Identifier.Key.C.getKeyIndex();
- buttonMap[KeyEvent.VK_V] = Component.Identifier.Key.V.getKeyIndex();
- buttonMap[KeyEvent.VK_B] = Component.Identifier.Key.B.getKeyIndex();
- buttonMap[KeyEvent.VK_N] = Component.Identifier.Key.N.getKeyIndex();
- buttonMap[KeyEvent.VK_M] = Component.Identifier.Key.M.getKeyIndex();
-
- buttonMap[KeyEvent.VK_F1] = Component.Identifier.Key.F1.getKeyIndex();
- buttonMap[KeyEvent.VK_F2] = Component.Identifier.Key.F2.getKeyIndex();
- buttonMap[KeyEvent.VK_F3] = Component.Identifier.Key.F3.getKeyIndex();
- buttonMap[KeyEvent.VK_F4] = Component.Identifier.Key.F4.getKeyIndex();
- buttonMap[KeyEvent.VK_F5] = Component.Identifier.Key.F5.getKeyIndex();
- buttonMap[KeyEvent.VK_F6] = Component.Identifier.Key.F6.getKeyIndex();
- buttonMap[KeyEvent.VK_F7] = Component.Identifier.Key.F7.getKeyIndex();
- buttonMap[KeyEvent.VK_F8] = Component.Identifier.Key.F8.getKeyIndex();
- buttonMap[KeyEvent.VK_F9] = Component.Identifier.Key.F9.getKeyIndex();
- buttonMap[KeyEvent.VK_F10] = Component.Identifier.Key.F10.getKeyIndex();
- buttonMap[KeyEvent.VK_F11] = Component.Identifier.Key.F11.getKeyIndex();
- buttonMap[KeyEvent.VK_F12] = Component.Identifier.Key.F12.getKeyIndex();
-
- buttonMap[KeyEvent.VK_ESCAPE] = Component.Identifier.Key.ESCAPE.getKeyIndex();
- buttonMap[KeyEvent.VK_MINUS] = Component.Identifier.Key.MINUS.getKeyIndex();
- buttonMap[KeyEvent.VK_EQUALS] = Component.Identifier.Key.EQUALS.getKeyIndex();
- buttonMap[KeyEvent.VK_BACK_SPACE] = Component.Identifier.Key.BACKSLASH.getKeyIndex();
- buttonMap[KeyEvent.VK_TAB] = Component.Identifier.Key.TAB.getKeyIndex();
- buttonMap[KeyEvent.VK_OPEN_BRACKET] = Component.Identifier.Key.LBRACKET.getKeyIndex();
- buttonMap[KeyEvent.VK_CLOSE_BRACKET] = Component.Identifier.Key.RBRACKET.getKeyIndex();
- //Enter is a special one
- //Control is a special one
- buttonMap[KeyEvent.VK_SEMICOLON] = Component.Identifier.Key.SEMICOLON.getKeyIndex();
- buttonMap[KeyEvent.VK_QUOTE] = Component.Identifier.Key.APOSTROPHE.getKeyIndex();
- buttonMap[KeyEvent.VK_NUMBER_SIGN] = Component.Identifier.Key.GRAVE.getKeyIndex();
- //Shift is a special one
- buttonMap[KeyEvent.VK_BACK_SLASH] = Component.Identifier.Key.BACKSLASH.getKeyIndex();
- //Comma is special
- buttonMap[KeyEvent.VK_PERIOD] = Component.Identifier.Key.PERIOD.getKeyIndex();
- buttonMap[KeyEvent.VK_SLASH] = Component.Identifier.Key.SLASH.getKeyIndex();
- buttonMap[KeyEvent.VK_MULTIPLY] = Component.Identifier.Key.MULTIPLY.getKeyIndex();
- //Alt is a special one
- buttonMap[KeyEvent.VK_SPACE] = Component.Identifier.Key.SPACE.getKeyIndex();
- buttonMap[KeyEvent.VK_CAPS_LOCK] = Component.Identifier.Key.CAPITAL.getKeyIndex();
- buttonMap[KeyEvent.VK_NUM_LOCK] = Component.Identifier.Key.NUMLOCK.getKeyIndex();
- buttonMap[KeyEvent.VK_SCROLL_LOCK] = Component.Identifier.Key.SCROLL.getKeyIndex();
- buttonMap[KeyEvent.VK_NUMPAD7] = Component.Identifier.Key.NUMPAD7.getKeyIndex();
- buttonMap[KeyEvent.VK_NUMPAD8] = Component.Identifier.Key.NUMPAD8.getKeyIndex();
- buttonMap[KeyEvent.VK_NUMPAD9] = Component.Identifier.Key.NUMPAD9.getKeyIndex();
- buttonMap[KeyEvent.VK_SUBTRACT] = Component.Identifier.Key.SUBTRACT.getKeyIndex();
- buttonMap[KeyEvent.VK_NUMPAD4] = Component.Identifier.Key.NUMPAD4.getKeyIndex();
- buttonMap[KeyEvent.VK_NUMPAD5] = Component.Identifier.Key.NUMPAD5.getKeyIndex();
- buttonMap[KeyEvent.VK_NUMPAD6] = Component.Identifier.Key.NUMPAD6.getKeyIndex();
- buttonMap[KeyEvent.VK_ADD] = Component.Identifier.Key.ADD.getKeyIndex();
- buttonMap[KeyEvent.VK_NUMPAD1] = Component.Identifier.Key.NUMPAD1.getKeyIndex();
- buttonMap[KeyEvent.VK_NUMPAD2] = Component.Identifier.Key.NUMPAD2.getKeyIndex();
- buttonMap[KeyEvent.VK_NUMPAD3] = Component.Identifier.Key.NUMPAD3.getKeyIndex();
- buttonMap[KeyEvent.VK_NUMPAD0] = Component.Identifier.Key.NUMPAD0.getKeyIndex();
- buttonMap[KeyEvent.VK_DECIMAL] = Component.Identifier.Key.DECIMAL.getKeyIndex();
-
- buttonMap[KeyEvent.VK_KANA] = Component.Identifier.Key.KANA.getKeyIndex();
- buttonMap[KeyEvent.VK_CONVERT] = Component.Identifier.Key.CONVERT.getKeyIndex();
- buttonMap[KeyEvent.VK_NONCONVERT] = Component.Identifier.Key.NOCONVERT.getKeyIndex();
+ protected AWTKeyboard() {
+ super("AWTKeyboard", createComponents(), new Controller[]{}, new Rumbler[]{});
+ Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
+ resizeEventQueue(EVENT_QUEUE_DEPTH);
+ }
- buttonMap[KeyEvent.VK_CIRCUMFLEX] = Component.Identifier.Key.CIRCUMFLEX.getKeyIndex();
- buttonMap[KeyEvent.VK_AT] = Component.Identifier.Key.AT.getKeyIndex();
- buttonMap[KeyEvent.VK_COLON] = Component.Identifier.Key.COLON.getKeyIndex();
- buttonMap[KeyEvent.VK_UNDERSCORE] = Component.Identifier.Key.UNDERLINE.getKeyIndex();
- buttonMap[KeyEvent.VK_KANJI] = Component.Identifier.Key.KANJI.getKeyIndex();
-
- buttonMap[KeyEvent.VK_STOP] = Component.Identifier.Key.STOP.getKeyIndex();
+ private final static Component[] createComponents() {
+ List components = new ArrayList();
+ Field[] vkey_fields = KeyEvent.class.getFields();
+ for (int i = 0; i < vkey_fields.length; i++) {
+ Field vkey_field = vkey_fields[i];
+ try {
+ if (Modifier.isStatic(vkey_field.getModifiers()) && vkey_field.getType() == int.class &&
+ vkey_field.getName().startsWith("VK_")) {
+ int vkey_code = vkey_field.getInt(null);
+ Component.Identifier.Key key_id = AWTKeyMap.mapKeyCode(vkey_code);
+ if (key_id != Component.Identifier.Key.UNKNOWN)
+ components.add(new Key(key_id));
+ }
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ components.add(new Key(Component.Identifier.Key.RCONTROL));
+ components.add(new Key(Component.Identifier.Key.LCONTROL));
+ components.add(new Key(Component.Identifier.Key.RSHIFT));
+ components.add(new Key(Component.Identifier.Key.LSHIFT));
+ components.add(new Key(Component.Identifier.Key.RALT));
+ components.add(new Key(Component.Identifier.Key.LALT));
+ components.add(new Key(Component.Identifier.Key.NUMPADENTER));
+ components.add(new Key(Component.Identifier.Key.RETURN));
+ components.add(new Key(Component.Identifier.Key.NUMPADCOMMA));
+ components.add(new Key(Component.Identifier.Key.COMMA));
+ return (Component[])components.toArray(new Component[]{});
+ }
- buttonMap[KeyEvent.VK_DIVIDE] = Component.Identifier.Key.DIVIDE.getKeyIndex();
+ private final void resizeEventQueue(int size) {
+ processed_events = new Event[size];
+ for (int i = 0; i < processed_events.length; i++)
+ processed_events[i] = new Event();
+ processed_events_index = 0;
+ }
+
+ protected final void setDeviceEventQueueSize(int size) throws IOException {
+ resizeEventQueue(size);
+ }
- buttonMap[KeyEvent.VK_PAUSE] = Component.Identifier.Key.PAUSE.getKeyIndex();
- buttonMap[KeyEvent.VK_HOME] = Component.Identifier.Key.HOME.getKeyIndex();
- buttonMap[KeyEvent.VK_UP] = Component.Identifier.Key.UP.getKeyIndex();
- buttonMap[KeyEvent.VK_PAGE_UP] = Component.Identifier.Key.PAGEUP.getKeyIndex();
- buttonMap[KeyEvent.VK_LEFT] = Component.Identifier.Key.LEFT.getKeyIndex();
- buttonMap[KeyEvent.VK_RIGHT] = Component.Identifier.Key.RIGHT.getKeyIndex();
- buttonMap[KeyEvent.VK_END] = Component.Identifier.Key.END.getKeyIndex();
- buttonMap[KeyEvent.VK_DOWN] = Component.Identifier.Key.DOWN.getKeyIndex();
- buttonMap[KeyEvent.VK_PAGE_DOWN] = Component.Identifier.Key.PAGEDOWN.getKeyIndex();
- buttonMap[KeyEvent.VK_INSERT] = Component.Identifier.Key.INSERT.getKeyIndex();
- buttonMap[KeyEvent.VK_DELETE] = Component.Identifier.Key.DELETE.getKeyIndex();
-
- //Windows key is a special one
+ public final synchronized void eventDispatched(AWTEvent event) {
+ if (event instanceof KeyEvent)
+ awt_events.add(event);
+ }
- // start working
- Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
- }
+ public final synchronized void pollDevice() throws IOException {
+ for (int i = 0; i < awt_events.size(); i++) {
+ KeyEvent event = (KeyEvent)awt_events.get(i);
+ processEvent(event);
+ }
+ awt_events.clear();
+ }
- /* (non-Javadoc)
- * @see net.java.games.input.Keyboard#isKeyPressed(net.java.games.input.Keyboard.Key)
- */
- protected boolean isKeyPressed(Key key) {
- int keyId = ((Component.Identifier.Key)key.getIdentifier()).getKeyIndex();
- return buttonValues[keyId];
+ private final void processEvent(KeyEvent event) {
+ Component.Identifier.Key key_id = AWTKeyMap.map(event);
+ if (key_id == null)
+ return;
+ Key key = (Key)getComponent(key_id);
+ if (key == null)
+ return;
+ long nanos = event.getWhen()*1000000L;
+ if (event.getID() == KeyEvent.KEY_PRESSED) {
+ //the key was pressed
+ addEvent(key, 1, nanos);
+ } else if (event.getID() == KeyEvent.KEY_RELEASED) {
+ KeyEvent nextPress = (KeyEvent)Toolkit.getDefaultToolkit().getSystemEventQueue().peekEvent(KeyEvent.KEY_PRESSED);
+ if ((nextPress == null) || (nextPress.getWhen() != event.getWhen())) {
+ //the key came really came up
+ addEvent(key, 0, nanos);
+ }
+ }
}
- /* (non-Javadoc)
- * @see net.java.games.input.Controller#poll()
- */
- public boolean poll() {
- return true;
- }
+ private final void addEvent(Key key, float value, long nanos) {
+ key.setValue(value);
+ if (processed_events_index < processed_events.length)
+ processed_events[processed_events_index++].set(key, value, nanos);
+ }
- /* (non-Javadoc)
- * @see java.awt.event.AWTEventListener#eventDispatched(java.awt.AWTEvent)
- */
- public void eventDispatched(AWTEvent event) {
- if(event instanceof KeyEvent) {
- KeyEvent keyEvent = (KeyEvent)event;
- if(keyEvent.getID() == KeyEvent.KEY_PRESSED) {
- //the key was pressed
- //System.out.println("Key pressed KeyCode: " + keyEvent.getKeyCode() + " KeyChar: " + keyEvent.getKeyChar());
- buttonValues[findKeyIndex(keyEvent)] = true;
- } else if(keyEvent.getID() == KeyEvent.KEY_RELEASED) {
- KeyEvent nextPress = (KeyEvent)Toolkit.getDefaultToolkit().getSystemEventQueue().peekEvent(KeyEvent.KEY_PRESSED);
-
- if ((nextPress == null) || (nextPress.getWhen() != keyEvent.getWhen())) {
- //the key came really came up
- //System.out.println("Key released KeyCode: " + keyEvent.getKeyCode() + " KeyChar: " + keyEvent.getKeyChar());
- buttonValues[findKeyIndex(keyEvent)] = false;
- }
- } else {
- //System.out.println("AWTKeyboard: Ignoring event " + keyEvent.getID());
- }
- } else {
- throw new IllegalArgumentException("AWTKeyboard not expecting event of type " + event.getClass().getName());
- }
- }
+ protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException {
+ if (processed_events_index == 0)
+ return false;
+ processed_events_index--;
+ event.set(processed_events[0]);
+ Event tmp = processed_events[0];
+ processed_events[0] = processed_events[processed_events_index];
+ processed_events[processed_events_index] = tmp;
+ return true;
+ }
- private int findKeyIndex(KeyEvent keyEvent) {
- int buttonIndex = 0;
- if(keyEvent.getKeyCode() == KeyEvent.VK_CONTROL) {
- if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_LEFT) {
- buttonIndex = Component.Identifier.Key.LCONTROL.getKeyIndex();
- } else if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_RIGHT) {
- buttonIndex = Component.Identifier.Key.RCONTROL.getKeyIndex();
- }
- } else if(keyEvent.getKeyCode() == KeyEvent.VK_SHIFT) {
- if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_LEFT) {
- buttonIndex = Component.Identifier.Key.LSHIFT.getKeyIndex();
- } else if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_RIGHT) {
- buttonIndex = Component.Identifier.Key.RSHIFT.getKeyIndex();
- }
- } else if(keyEvent.getKeyCode() == KeyEvent.VK_ALT) {
- if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_LEFT) {
- buttonIndex = Component.Identifier.Key.LALT.getKeyIndex();
- } else if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_RIGHT) {
- buttonIndex = Component.Identifier.Key.RALT.getKeyIndex();
- }
-//this is 1.5 only
-/* } else if(keyEvent.getKeyCode() == KeyEvent.VK_WINDOWS) {
- if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_LEFT) {
- buttonIndex = Component.Identifier.Key.LWIN.getKeyIndex();
- } else if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_RIGHT) {
- buttonIndex = Component.Identifier.Key.RWIN.getKeyIndex();
- }*/
- } else if(keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
- if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_NUMPAD) {
- buttonIndex = Component.Identifier.Key.NUMPADENTER.getKeyIndex();
- } else {
- buttonIndex = Component.Identifier.Key.RETURN.getKeyIndex();
- }
- } else if(keyEvent.getKeyCode() == KeyEvent.VK_COMMA) {
- if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_NUMPAD) {
- buttonIndex = Component.Identifier.Key.NUMPADCOMMA.getKeyIndex();
- } else {
- buttonIndex = Component.Identifier.Key.COMMA.getKeyIndex();
- }
- } else {
- buttonIndex = buttonMap[keyEvent.getKeyCode()];
- }
- if(buttonIndex == 0 ) {
- System.out.println("Unrecognised key: " + keyEvent.getKeyCode() + " (" + keyEvent.getKeyLocation() + " " + keyEvent.getKeyChar() + ")");
- }
- return buttonIndex;
- }
+
+ private final static class Key extends AbstractComponent {
+ private float value;
+
+ public Key(Component.Identifier.Key key_id) {
+ super(key_id.getName(), key_id);
+ }
+
+ public final void setValue(float value) {
+ this.value = value;
+ }
+
+ protected final float poll() {
+ return value;
+ }
+
+ public final boolean isAnalog() {
+ return false;
+ }
+
+ public final boolean isRelative() {
+ return false;
+ }
+ }
}
diff --git a/plugins/awt/src/net/java/games/input/AWTMouse.java b/plugins/awt/src/net/java/games/input/AWTMouse.java
index ed76ed6..37c8eee 100644
--- a/plugins/awt/src/net/java/games/input/AWTMouse.java
+++ b/plugins/awt/src/net/java/games/input/AWTMouse.java
@@ -33,165 +33,190 @@ import java.awt.event.AWTEventListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
+import java.util.List;
+import java.util.ArrayList;
+
+import java.io.IOException;
+
/**
* @author Jeremy
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Style - Code Templates
+ * @author elias
*/
-public class AWTMouse extends Mouse implements AWTEventListener {
-
- private AWTAxis xMove = new AWTAxis("X", Component.Identifier.Axis.X);
- private AWTAxis yMove = new AWTAxis("Y", Component.Identifier.Axis.Y);
- private AWTAxis zMove = new AWTAxis("Wheel", Component.Identifier.Axis.SLIDER);
-
- private AWTButton button1 = new AWTButton("Left", Component.Identifier.Button.LEFT);
- private AWTButton button2 = new AWTButton("Middle", Component.Identifier.Button.MIDDLE);
- private AWTButton button3 = new AWTButton("Right", Component.Identifier.Button.RIGHT);
-
- private Point oldMouseLocation = new Point(0,0);
- private Point newMouseLocation = new Point(0,0);
- private int scrollAmount = 0;
- private boolean button1Value = false;
- private boolean button2Value = false;
- private boolean button3Value = false;
-
- /**
- * @param name
- */
- protected AWTMouse(String name) {
- super(name);
+final class AWTMouse extends Mouse implements AWTEventListener {
+ private final static int EVENT_X = 1;
+ private final static int EVENT_Y = 2;
+ private final static int EVENT_BUTTON = 4;
+
+ private final List awt_events = new ArrayList();
+ private final List processed_awt_events = new ArrayList();
+
+ private int event_state = EVENT_X;
+
+ protected AWTMouse() {
+ super("AWTMouse", createComponents(), new Controller[]{}, new Rumbler[]{});
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK);
- this.ball = new AWTMouseBall(xMove, yMove, zMove);
- this.buttons = new AWTMouseButtons(new AWTMouseButton(button1), new AWTMouseButton(button2), new AWTMouseButton(button3));
}
- /* (non-Javadoc)
- * @see net.java.games.input.Controller#poll()
- */
- public boolean poll() {
- button1.setValue(button1Value);
- button2.setValue(button2Value);
- button3.setValue(button3Value);
-
- zMove.setValue(scrollAmount);
- scrollAmount = 0;
-
- //System.out.println("old mouse location " + oldMouseLocation);
- //System.out.println("new mouse location " + newMouseLocation);
- yMove.setValue((float)(newMouseLocation.getY() - oldMouseLocation.getY()));
- xMove.setValue((float)(newMouseLocation.getX() - oldMouseLocation.getX()));
- oldMouseLocation.setLocation(newMouseLocation.getLocation());
- //newMouseLocation.setLocation(0,0);
-
- return true;
- }
+ private final static Component[] createComponents() {
+ return new Component[]{new Axis(Component.Identifier.Axis.X),
+ new Axis(Component.Identifier.Axis.Y),
+ new Axis(Component.Identifier.Axis.Z),
+ new Button(Component.Identifier.Button.LEFT),
+ new Button(Component.Identifier.Button.MIDDLE),
+ new Button(Component.Identifier.Button.RIGHT)};
+ }
- /* (non-Javadoc)
- * @see java.awt.event.AWTEventListener#eventDispatched(java.awt.AWTEvent)
- */
- public void eventDispatched(AWTEvent event) {
- //System.out.println("AWTMouse: From: " + arg0.getSource() + " - " + arg0);
- if(event instanceof MouseWheelEvent) {
+ private final void processButtons(int button_enum, float value) {
+ Button button = getButton(button_enum);
+ if (button != null)
+ button.setValue(value);
+ }
+
+ private final Button getButton(int button_enum) {
+ switch (button_enum) {
+ case MouseEvent.BUTTON1:
+ return (Button)getLeft();
+ case MouseEvent.BUTTON2:
+ return (Button)getMiddle();
+ case MouseEvent.BUTTON3:
+ return (Button)getRight();
+ case MouseEvent.NOBUTTON:
+ default:
+ // Unknown button
+ return null;
+ }
+ }
+
+ private final void processEvent(AWTEvent event) throws IOException {
+ if (event instanceof MouseWheelEvent) {
MouseWheelEvent mwe = (MouseWheelEvent)event;
- scrollAmount += mwe.getWheelRotation();
- //System.out.println("New scroll amount: " + scrollAmount);
- }
- if(event instanceof MouseEvent) {
+ Axis wheel = (Axis)getWheel();
+ wheel.setValue(wheel.poll() + mwe.getWheelRotation());
+ } else if (event instanceof MouseEvent) {
MouseEvent me = (MouseEvent)event;
- newMouseLocation.setLocation(me.getPoint());
- //System.out.println("Mouse moved to " + newMouseLocation);
- if(me.getID() == MouseEvent.MOUSE_PRESSED) {
- //System.out.println("Button was pressed");
- if(me.getButton() == MouseEvent.BUTTON1) {
- //System.out.println("Button 1 was pressed");
- button1Value = true;
- } else if(me.getButton() == MouseEvent.BUTTON2) {
- //System.out.println("Button 2 was pressed");
- button2Value = true;
- } else if(me.getButton() == MouseEvent.BUTTON3) {
- //System.out.println("Button 3 was pressed");
- button3Value = true;
- }
- } else if(me.getID() == MouseEvent.MOUSE_RELEASED) {
- //ystem.out.println("Button was released");
- if(me.getButton() == MouseEvent.BUTTON1) {
- //System.out.println("Button 1 was released");
- button1Value = false;
- } else if(me.getButton() == MouseEvent.BUTTON2) {
- //System.out.println("Button 2 was released");
- button2Value = false;
- } else if(me.getButton() == MouseEvent.BUTTON3) {
- //System.out.println("Button 3 was released");
- button3Value = false;
- }
- } else {
- //System.out.println("Mouse event ID " + me.getID() + " (" + me.getClass().getName() + ")");
- }
- } else {
- System.out.println("AWTMouse got an event of type " + event.getClass().getName());
- }
- }
+ Axis x = (Axis)getX();
+ Axis y = (Axis)getY();
+ x.setValue(me.getX());
+ y.setValue(me.getY());
+ switch (me.getID()) {
+ case MouseEvent.MOUSE_PRESSED:
+ processButtons(me.getButton(), 1f);
+ break;
+ case MouseEvent.MOUSE_RELEASED:
+ processButtons(me.getButton(), 0f);
+ break;
+ default:
+ break;
+ }
+ }
+ }
- /** Mouse ball under AWT
- */
- private class AWTMouseBall extends Ball {
- /** Constructs the new mouse ball
- * @param x The x axis
- * @param y The y axis
- * @param wheel The mouse wheel axis
- */
- public AWTMouseBall(Component x, Component y, Component wheel) {
- super(AWTMouse.this.getName() + " ball");
- this.x = x;
- this.y = y;
- this.wheel = wheel;
+ public final synchronized void pollDevice() throws IOException {
+ Axis wheel = (Axis)getWheel();
+ wheel.setValue(0);
+ for (int i = 0; i < awt_events.size(); i++) {
+ AWTEvent event = (AWTEvent)awt_events.get(i);
+ processEvent(event);
+ processed_awt_events.add(event);
}
- }
+ awt_events.clear();
+ }
- /** Mouse buttons under AWT
- */
- private class AWTMouseButtons extends Buttons {
- /** Creates the new mouse's buttons
- * @param left Left mouse button
- * @param right Right mouse button
- * @param middle Middle mouse button
- */
- public AWTMouseButtons(Button left, Button right, Button middle) {
- super(AWTMouse.this.getName() + " buttons");
- this.left = left;
- this.right = right;
- this.middle = middle;
- }
- }
+ protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException {
+ while (true) {
+ if (processed_awt_events.isEmpty())
+ return false;
+ AWTEvent awt_event = (AWTEvent)processed_awt_events.get(0);
+ if (awt_event instanceof MouseWheelEvent) {
+ MouseWheelEvent awt_wheel_event = (MouseWheelEvent)awt_event;
+ long nanos = awt_wheel_event.getWhen()*1000000L;
+ event.set(getWheel(), awt_wheel_event.getWheelRotation(), nanos);
+ processed_awt_events.remove(0);
+ } else if (awt_event instanceof MouseEvent) {
+ MouseEvent mouse_event = (MouseEvent)awt_event;
+ long nanos = mouse_event.getWhen()*1000000L;
+ switch (event_state) {
+ case EVENT_X:
+ event_state = EVENT_Y;
+ event.set(getX(), mouse_event.getX(), nanos);
+ return true;
+ case EVENT_Y:
+ event_state = EVENT_BUTTON;
+ event.set(getY(), mouse_event.getY(), nanos);
+ return true;
+ case EVENT_BUTTON:
+ processed_awt_events.remove(0);
+ event_state = EVENT_X;
+ Button button = getButton(mouse_event.getButton());
+ if (button != null) {
+ switch (mouse_event.getID()) {
+ case MouseEvent.MOUSE_PRESSED:
+ event.set(button, 1f, nanos);
+ return true;
+ case MouseEvent.MOUSE_RELEASED:
+ event.set(button, 0f, nanos);
+ return true;
+ default:
+ break;
+ }
+ }
+ break;
+ default:
+ throw new RuntimeException("Unknown event state: " + event_state);
+ }
+ }
+ }
+ }
- /** AWT specific mouse buttons
- */
- private class AWTMouseButton extends Mouse.Button {
- /** The real Axis
- */
- private Component realAxis;
-
- /** Construct an AWT mouse button from the given axis
- * @param axis The axis that holds the data
- */
- public AWTMouseButton(Component axis) {
- super(axis.getName(), (Component.Identifier.Button)axis.getIdentifier());
- this.realAxis = axis;
- }
-
- /** Returns true f this axis is relative
- * @return Always returns false for a mouse button
- */
- public boolean isRelative() {
- return false;
- }
-
- /** Returns the data for this mouse button
- * @return Retursn this mouse buttons value
- */
- public float getPollData(){
- return realAxis.getPollData();
- }
- }
+ public final synchronized void eventDispatched(AWTEvent event) {
+ awt_events.add(event);
+ }
+
+ final static class Axis extends AbstractComponent {
+ private float value;
+
+ public Axis(Component.Identifier.Axis axis_id) {
+ super(axis_id.getName(), axis_id);
+ }
+
+ public final boolean isRelative() {
+ return false;
+ }
+
+ public final boolean isAnalog() {
+ return true;
+ }
+
+ protected final void setValue(float value) {
+ this.value = value;
+ }
+
+ protected final float poll() throws IOException {
+ return value;
+ }
+ }
+
+ final static class Button extends AbstractComponent {
+ private float value;
+
+ public Button(Component.Identifier.Button button_id) {
+ super(button_id.getName(), button_id);
+ }
+
+ protected final void setValue(float value) {
+ this.value = value;
+ }
+
+ protected final float poll() throws IOException {
+ return value;
+ }
+
+ public final boolean isAnalog() {
+ return false;
+ }
+
+ public final boolean isRelative() {
+ return false;
+ }
+ }
}