wiiusej 0.12 clean1 before release

git-svn-id: http://wiiusej.googlecode.com/svn/trunk@158 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
guilhem.duche
2008-06-01 09:50:30 +00:00
parent 2fb184eda3
commit b2c8a6d87d
35 changed files with 1219 additions and 1080 deletions

View File

@@ -36,7 +36,7 @@ public class WiiUseApi {
* *
* @return the only instace of WiiUseApi. * @return the only instace of WiiUseApi.
*/ */
static WiiUseApi getInstance() { protected static WiiUseApi getInstance() {
return instance; return instance;
} }
@@ -334,7 +334,8 @@ public class WiiUseApi {
* Force the bluetooth stack type.(useful only for windows) * Force the bluetooth stack type.(useful only for windows)
* *
* @param bluetoothStackType * @param bluetoothStackType
* must be WiiUseApi.WIIUSE_STACK_UNKNOWN or WiiUseApi.WIIUSE_STACK_MS or * must be WiiUseApi.WIIUSE_STACK_UNKNOWN or
* WiiUseApi.WIIUSE_STACK_MS or
* WiiUseApi.WIIUSE_STACK_BLUESOLEIL. * WiiUseApi.WIIUSE_STACK_BLUESOLEIL.
*/ */
native void windowsSetBluetoothStack(int bluetoothStackType); native void windowsSetBluetoothStack(int bluetoothStackType);

View File

@@ -23,7 +23,6 @@ import javax.swing.event.EventListenerList;
import wiiusej.wiiusejevents.utils.EventsGatherer; import wiiusej.wiiusejevents.utils.EventsGatherer;
import wiiusej.wiiusejevents.utils.WiiUseApiListener; import wiiusej.wiiusejevents.utils.WiiUseApiListener;
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
import wiiusej.wiiusejevents.wiiuseapievents.WiiUseApiEvent; import wiiusej.wiiusejevents.wiiuseapievents.WiiUseApiEvent;
/** /**
@@ -46,14 +45,14 @@ public class WiiUseApiManager extends Thread {
private int connected = -1; private int connected = -1;
private AtomicBoolean running = new AtomicBoolean(false); private AtomicBoolean running = new AtomicBoolean(false);
private boolean leave = false; private boolean leave = false;
public static int WIIUSE_STACK_UNKNOWN = 0; public static int WIIUSE_STACK_UNKNOWN = 0;
public static int WIIUSE_STACK_MS = 1; public static int WIIUSE_STACK_MS = 1;
public static int WIIUSE_STACK_BLUESOLEIL = 2; public static int WIIUSE_STACK_BLUESOLEIL = 2;
public static WiiUseApiManager getInstance() { private static WiiUseApiManager getInstance() {
return instance; return instance;
} }
@@ -112,13 +111,14 @@ public class WiiUseApiManager extends Thread {
* @return an array with connected wiimotes or NULL. * @return an array with connected wiimotes or NULL.
*/ */
private synchronized static Wiimote[] getWiimotesPrivate(int nb, private synchronized static Wiimote[] getWiimotesPrivate(int nb,
boolean rumble, boolean forceStackType, int stackType) { boolean rumble, boolean forceStackType, int stackType) {
WiiUseApiManager manager = getInstance(); WiiUseApiManager manager = getInstance();
if (manager.leave) return null;//wiiusej definitively stopped if (manager.leave)
return null;// wiiusej definitively stopped
if (manager.connected <= 0 && !manager.running.get()) { if (manager.connected <= 0 && !manager.running.get()) {
//connect wiimotes. // connect wiimotes.
int nbWiimotes = manager.connectWiimotes(nb, rumble, int nbWiimotes = manager.connectWiimotes(nb, rumble,
forceStackType, stackType); forceStackType, stackType);
manager.wiimotes = new Wiimote[nbWiimotes]; manager.wiimotes = new Wiimote[nbWiimotes];
@@ -131,7 +131,6 @@ public class WiiUseApiManager extends Thread {
// Set leds on wiimote // Set leds on wiimote
for (Wiimote wiimote : manager.wiimotes) { for (Wiimote wiimote : manager.wiimotes) {
int id = wiimote.getId(); int id = wiimote.getId();
short leds = 0;
if (id % 4 == 0) { if (id % 4 == 0) {
wiimote.setLeds(true, true, true, true); wiimote.setLeds(true, true, true, true);
} else if (id % 4 == 1) { } else if (id % 4 == 1) {
@@ -156,13 +155,13 @@ public class WiiUseApiManager extends Thread {
} }
} }
} }
if (manager.connected == 0) {//no wiimote connected if (manager.connected == 0) {// no wiimote connected
//return empty array // return empty array
return new Wiimote[0]; return new Wiimote[0];
} }
if (!manager.isAlive())//start wiiuseJ polling if (!manager.isAlive())// start wiiuseJ polling
manager.start(); manager.start();
manager.semaphore.release(1); manager.semaphore.release(1);
@@ -208,7 +207,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote to disconnect. * id of the wiimote to disconnect.
*/ */
public void closeConnection(int id) { protected void closeConnection(int id) {
int index = 0; int index = 0;
boolean found = false; boolean found = false;
while (index < wiimotes.length && !found) { while (index < wiimotes.length && !found) {
@@ -236,30 +235,32 @@ public class WiiUseApiManager extends Thread {
* *
* @return the number of wiimotes connected. * @return the number of wiimotes connected.
*/ */
public int getNbConnectedWiimotes() { public static int getNbConnectedWiimotes() {
return connected; return getInstance().connected;
} }
/** /**
* Stop thread and shutdown wiiuse Api. * Stop thread and shutdown wiiuse Api.
*/ */
public void shutdown() { public static void shutdown() {
if (connected > 0) { WiiUseApiManager manager = getInstance();
for (Wiimote wim : wiimotes) { if (manager.connected > 0) {
for (Wiimote wim : manager.wiimotes) {
if (wim != null) if (wim != null)
wim.disconnect(); wim.disconnect();
} }
} }
running.set(false); manager.running.set(false);
wiiuse.cleanUp(); manager.wiiuse.cleanUp();
} }
/** /**
* Stop wiiuseJ definitively for this program. * Stop wiiuseJ definitively for this program. It finishes Wiiusej thread
* and shutdown wiiuse API.
*/ */
public void definitiveShutdown(){ public static void definitiveShutdown() {
leave = true; getInstance().leave = true;
shutdown(); shutdown();
} }
/** /**
@@ -268,7 +269,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void activateRumble(int id) { protected void activateRumble(int id) {
wiiuse.activateRumble(id); wiiuse.activateRumble(id);
} }
@@ -278,7 +279,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void deactivateRumble(int id) { protected void deactivateRumble(int id) {
wiiuse.deactivateRumble(id); wiiuse.deactivateRumble(id);
} }
@@ -288,7 +289,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void activateIRTRacking(int id) { protected void activateIRTRacking(int id) {
wiiuse.activateIRTracking(id); wiiuse.activateIRTracking(id);
} }
@@ -298,7 +299,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void deactivateIRTRacking(int id) { protected void deactivateIRTRacking(int id) {
wiiuse.deactivateIRTracking(id); wiiuse.deactivateIRTracking(id);
} }
@@ -308,7 +309,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void activateMotionSensing(int id) { protected void activateMotionSensing(int id) {
wiiuse.activateMotionSensing(id); wiiuse.activateMotionSensing(id);
} }
@@ -318,7 +319,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void deactivateMotionSensing(int id) { protected void deactivateMotionSensing(int id) {
wiiuse.deactivateMotionSensing(id); wiiuse.deactivateMotionSensing(id);
} }
@@ -328,7 +329,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void activateSmoothing(int id) { protected void activateSmoothing(int id) {
wiiuse.activateSmoothing(id); wiiuse.activateSmoothing(id);
} }
@@ -338,7 +339,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void deactivateSmoothing(int id) { protected void deactivateSmoothing(int id) {
wiiuse.deactivateSmoothing(id); wiiuse.deactivateSmoothing(id);
} }
@@ -348,7 +349,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void activateContinuous(int id) { protected void activateContinuous(int id) {
wiiuse.activateContinuous(id); wiiuse.activateContinuous(id);
} }
@@ -358,7 +359,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void deactivateContinuous(int id) { protected void deactivateContinuous(int id) {
wiiuse.deactivateContinuous(id); wiiuse.deactivateContinuous(id);
} }
@@ -376,7 +377,8 @@ public class WiiUseApiManager extends Thread {
* @param l4 * @param l4
* status of led4. True : ON, False : OFF. * status of led4. True : ON, False : OFF.
*/ */
public void setLeds(int id, boolean l1, boolean l2, boolean l3, boolean l4) { protected void setLeds(int id, boolean l1, boolean l2, boolean l3,
boolean l4) {
wiiuse.setLeds(id, l1, l2, l3, l4); wiiuse.setLeds(id, l1, l2, l3, l4);
} }
@@ -389,7 +391,7 @@ public class WiiUseApiManager extends Thread {
* @param th * @param th
* threshold in degrees. * threshold in degrees.
*/ */
public void setOrientationThreshold(int id, float th) { protected void setOrientationThreshold(int id, float th) {
wiiuse.setOrientThreshold(id, th); wiiuse.setOrientThreshold(id, th);
} }
@@ -402,7 +404,7 @@ public class WiiUseApiManager extends Thread {
* @param th * @param th
* threshold. * threshold.
*/ */
public void setAccelerationThreshold(int id, int th) { protected void setAccelerationThreshold(int id, int th) {
wiiuse.setAccelThreshold(id, th); wiiuse.setAccelThreshold(id, th);
} }
@@ -414,7 +416,7 @@ public class WiiUseApiManager extends Thread {
* @param th * @param th
* threshold. * threshold.
*/ */
public void setAlphaSmoothing(int id, float th) { protected void setAlphaSmoothing(int id, float th) {
wiiuse.setAlphaSmoothing(id, th); wiiuse.setAlphaSmoothing(id, th);
} }
@@ -424,7 +426,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void reSync(int id) { protected void reSync(int id) {
wiiuse.reSync(id); wiiuse.reSync(id);
} }
@@ -434,7 +436,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void setScreenAspectRatio43(int id) { protected void setScreenAspectRatio43(int id) {
wiiuse.setScreenRatio43(id); wiiuse.setScreenRatio43(id);
} }
@@ -444,7 +446,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void setScreenAspectRatio169(int id) { protected void setScreenAspectRatio169(int id) {
wiiuse.setScreenRatio169(id); wiiuse.setScreenRatio169(id);
} }
@@ -454,7 +456,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void setSensorBarAboveScreen(int id) { protected void setSensorBarAboveScreen(int id) {
wiiuse.setSensorBarAboveScreen(id); wiiuse.setSensorBarAboveScreen(id);
} }
@@ -464,7 +466,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void setSensorBarBelowScreen(int id) { protected void setSensorBarBelowScreen(int id) {
wiiuse.setSensorBarBelowScreen(id); wiiuse.setSensorBarBelowScreen(id);
} }
@@ -480,7 +482,7 @@ public class WiiUseApiManager extends Thread {
* @param y * @param y
* y resolution. * y resolution.
*/ */
public void setVirtualResolution(int id, int x, int y) { protected void setVirtualResolution(int id, int x, int y) {
wiiuse.setVirtualScreenResolution(id, x, y); wiiuse.setVirtualScreenResolution(id, x, y);
} }
@@ -490,7 +492,7 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
*/ */
public void getStatus(int id) { protected void getStatus(int id) {
wiiuse.getStatus(id); wiiuse.getStatus(id);
} }
@@ -505,7 +507,8 @@ public class WiiUseApiManager extends Thread {
* The timeout in millisecondsd to wait for an expansion * The timeout in millisecondsd to wait for an expansion
* handshake. * handshake.
*/ */
public void setTimeout(int id, short normalTimeout, short expansionTimeout) { protected void setTimeout(int id, short normalTimeout,
short expansionTimeout) {
wiiuse.setTimeout(id, normalTimeout, expansionTimeout); wiiuse.setTimeout(id, normalTimeout, expansionTimeout);
} }
@@ -519,7 +522,7 @@ public class WiiUseApiManager extends Thread {
* 1, then level will be set to 1. If the level is > 5, then * 1, then level will be set to 1. If the level is > 5, then
* level will be set to 5. * level will be set to 5.
*/ */
public void setIrSensitivity(int id, int level) { protected void setIrSensitivity(int id, int level) {
wiiuse.setIrSensitivity(id, level); wiiuse.setIrSensitivity(id, level);
} }
@@ -532,7 +535,7 @@ public class WiiUseApiManager extends Thread {
* @param th * @param th
* threshold in degrees. * threshold in degrees.
*/ */
public void setNunchukOrientationThreshold(int id, float th) { protected void setNunchukOrientationThreshold(int id, float th) {
wiiuse.setNunchukOrientationThreshold(id, th); wiiuse.setNunchukOrientationThreshold(id, th);
} }
@@ -545,7 +548,7 @@ public class WiiUseApiManager extends Thread {
* @param th * @param th
* threshold. * threshold.
*/ */
public void setNunchukAccelerationThreshold(int id, int th) { protected void setNunchukAccelerationThreshold(int id, int th) {
wiiuse.setNunchukAccelerationThreshold(id, th); wiiuse.setNunchukAccelerationThreshold(id, th);
} }
@@ -606,7 +609,7 @@ public class WiiUseApiManager extends Thread {
System.out.println("No wiimotes connected !"); System.out.println("No wiimotes connected !");
} }
} }
}//end while true }// end while true
} }
@@ -616,7 +619,7 @@ public class WiiUseApiManager extends Thread {
* @param listener * @param listener
* a WiiUseApiListener * a WiiUseApiListener
*/ */
public void addWiiUseApiListener(WiiUseApiListener listener) { protected void addWiiUseApiListener(WiiUseApiListener listener) {
listeners.add(WiiUseApiListener.class, listener); listeners.add(WiiUseApiListener.class, listener);
} }
@@ -626,7 +629,7 @@ public class WiiUseApiManager extends Thread {
* @param listener * @param listener
* a WiiUseApiListener * a WiiUseApiListener
*/ */
public void removeWiiUseApiListener(WiiUseApiListener listener) { protected void removeWiiUseApiListener(WiiUseApiListener listener) {
listeners.remove(WiiUseApiListener.class, listener); listeners.remove(WiiUseApiListener.class, listener);
} }
@@ -635,7 +638,7 @@ public class WiiUseApiManager extends Thread {
* *
* @return the list of WiiUseApiListeners. * @return the list of WiiUseApiListeners.
*/ */
public WiiUseApiListener[] getWiiUseApiListeners() { protected WiiUseApiListener[] getWiiUseApiListeners() {
return listeners.getListeners(WiiUseApiListener.class); return listeners.getListeners(WiiUseApiListener.class);
} }

View File

@@ -22,36 +22,37 @@ import wiiusej.WiiUseApiManager;
/** /**
* This class is used to close wiiusej cleanly. * This class is used to close wiiusej cleanly.
*
* @author guiguito * @author guiguito
*/ */
public class CloseGuiTestCleanly implements WindowListener{ public class CloseGuiTestCleanly implements WindowListener {
public void windowOpened(WindowEvent e) { public void windowOpened(WindowEvent e) {
//nothing // nothing
} }
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
WiiUseApiManager.getInstance().shutdown(); WiiUseApiManager.definitiveShutdown();
} }
public void windowClosed(WindowEvent e) { public void windowClosed(WindowEvent e) {
//nothing // nothing
} }
public void windowIconified(WindowEvent e) { public void windowIconified(WindowEvent e) {
//nothing // nothing
} }
public void windowDeiconified(WindowEvent e) { public void windowDeiconified(WindowEvent e) {
//nothing // nothing
} }
public void windowActivated(WindowEvent e) { public void windowActivated(WindowEvent e) {
//nothing // nothing
} }
public void windowDeactivated(WindowEvent e) {
// nothing
}
public void windowDeactivated(WindowEvent e) {
//nothing
}
} }

View File

@@ -21,23 +21,25 @@ import wiiusej.Wiimote;
/** /**
* Main Class to launch WiiuseJ GUI Test. * Main Class to launch WiiuseJ GUI Test.
*
* @author guiguito * @author guiguito
*/ */
public class Main { public class Main {
/** /**
* @param args the command line arguments * @param args
*/ * the command line arguments
public static void main(String[] args) { */
Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true); public static void main(String[] args) {
Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true);
WiiuseJGuiTest gui = null; WiiuseJGuiTest gui = null;
if (wiimotes.length > 0) { if (wiimotes.length > 0) {
gui = new WiiuseJGuiTest(wiimotes[0]); gui = new WiiuseJGuiTest(wiimotes[0]);
} else { } else {
gui = new WiiuseJGuiTest(); gui = new WiiuseJGuiTest();
} }
gui.setDefaultCloseOperation(gui.EXIT_ON_CLOSE); gui.setDefaultCloseOperation(WiiuseJGuiTest.EXIT_ON_CLOSE);
gui.setVisible(true); gui.setVisible(true);
} }
} }

View File

@@ -37,324 +37,387 @@ import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
/** /**
* * This frame is used to display events from a nunchuk.
* @author guiguito *
* @author guiguito
*/ */
public class NunchukGuiTest extends javax.swing.JFrame implements WiimoteListener { public class NunchukGuiTest extends javax.swing.JFrame implements
WiimoteListener {
private Wiimote wiimote; private Wiimote wiimote;
private boolean isThresholdsRequested = true; private boolean isThresholdsRequested = true;
/** Creates new form NunchukGuiTest */ /** Creates new form NunchukGuiTest */
public NunchukGuiTest(Wiimote wiimote) { public NunchukGuiTest(Wiimote wiimote) {
initComponents(); initComponents();
this.wiimote = wiimote; this.wiimote = wiimote;
registerListeners(); registerListeners();
} }
private void registerListeners() { private void registerListeners() {
wiimote.addWiiMoteEventListeners(this); wiimote.addWiiMoteEventListeners(this);
wiimote.addWiiMoteEventListeners((OrientationPanel) orientationPanel); wiimote.addWiiMoteEventListeners((OrientationPanel) orientationPanel);
wiimote.addWiiMoteEventListeners((GForcePanel) gForcePanel); wiimote.addWiiMoteEventListeners((GForcePanel) gForcePanel);
wiimote.addWiiMoteEventListeners((AccelerationPanel) rawAccelerationPanel); wiimote
wiimote.addWiiMoteEventListeners((NunchukJoystickEventPanel)joystickEventsPanel); .addWiiMoteEventListeners((AccelerationPanel) rawAccelerationPanel);
} wiimote
.addWiiMoteEventListeners((NunchukJoystickEventPanel) joystickEventsPanel);
}
public void unRegisterListeners() { public void unRegisterListeners() {
wiimote.removeWiiMoteEventListeners((OrientationPanel) orientationPanel); wiimote
wiimote.removeWiiMoteEventListeners((GForcePanel) gForcePanel); .removeWiiMoteEventListeners((OrientationPanel) orientationPanel);
wiimote.removeWiiMoteEventListeners((AccelerationPanel) rawAccelerationPanel); wiimote.removeWiiMoteEventListeners((GForcePanel) gForcePanel);
wiimote.removeWiiMoteEventListeners((NunchukJoystickEventPanel)joystickEventsPanel); wiimote
wiimote.removeWiiMoteEventListeners(this); .removeWiiMoteEventListeners((AccelerationPanel) rawAccelerationPanel);
} wiimote
.removeWiiMoteEventListeners((NunchukJoystickEventPanel) joystickEventsPanel);
public void requestThresholdsUpdate(){ wiimote.removeWiiMoteEventListeners(this);
isThresholdsRequested = true; }
}
/** This method is called from within the constructor to public void requestThresholdsUpdate() {
* initialize the form. isThresholdsRequested = true;
* WARNING: Do NOT modify this code. The content of this method is }
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
topPanels = new javax.swing.JPanel(); /**
joystickEventsPanel = joystickEventsPanel = new NunchukJoystickEventPanel(); * This method is called from within the constructor to initialize the form.
motionSensingEventsPanel = new javax.swing.JPanel(); * WARNING: Do NOT modify this code. The content of this method is always
motionSensingEventsTabbedPanels = new javax.swing.JTabbedPane(); * regenerated by the Form Editor.
rawAccelerationPanel = new AccelerationExpansionEventPanel(); */
orientationPanel = new OrientationExpansionEventPanel(); // <editor-fold defaultstate="collapsed" desc="Generated
gForcePanel = new GForceExpansionEventPanel(); // Code">//GEN-BEGIN:initComponents
setNunchukValuesPanel = new javax.swing.JPanel(); private void initComponents() {
nunchukButtonsEventPanel = new javax.swing.JPanel();
cButton = new javax.swing.JButton();
zButton = new javax.swing.JButton();
nunchukOrientationPanel = new javax.swing.JPanel();
nunchukOrientationTextField = new javax.swing.JTextField();
nunchukOrientationButton = new javax.swing.JButton();
nunchukAccelerationPanel = new javax.swing.JPanel();
nunchukAccelerationTextField = new javax.swing.JTextField();
nunchukAccelerationButton = new javax.swing.JButton();
messagePanel = new javax.swing.JPanel();
messageText = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); topPanels = new javax.swing.JPanel();
setMinimumSize(new java.awt.Dimension(400, 400)); joystickEventsPanel = new NunchukJoystickEventPanel();
getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS)); motionSensingEventsPanel = new javax.swing.JPanel();
motionSensingEventsTabbedPanels = new javax.swing.JTabbedPane();
rawAccelerationPanel = new AccelerationExpansionEventPanel();
orientationPanel = new OrientationExpansionEventPanel();
gForcePanel = new GForceExpansionEventPanel();
setNunchukValuesPanel = new javax.swing.JPanel();
nunchukButtonsEventPanel = new javax.swing.JPanel();
cButton = new javax.swing.JButton();
zButton = new javax.swing.JButton();
nunchukOrientationPanel = new javax.swing.JPanel();
nunchukOrientationTextField = new javax.swing.JTextField();
nunchukOrientationButton = new javax.swing.JButton();
nunchukAccelerationPanel = new javax.swing.JPanel();
nunchukAccelerationTextField = new javax.swing.JTextField();
nunchukAccelerationButton = new javax.swing.JButton();
messagePanel = new javax.swing.JPanel();
messageText = new javax.swing.JLabel();
topPanels.setMinimumSize(new java.awt.Dimension(400, 200)); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
topPanels.setPreferredSize(new java.awt.Dimension(400, 200)); setMinimumSize(new java.awt.Dimension(400, 400));
topPanels.setLayout(new javax.swing.BoxLayout(topPanels, javax.swing.BoxLayout.LINE_AXIS)); getContentPane().setLayout(
new javax.swing.BoxLayout(getContentPane(),
javax.swing.BoxLayout.Y_AXIS));
joystickEventsPanel.setBackground(new java.awt.Color(0, 0, 0)); topPanels.setMinimumSize(new java.awt.Dimension(400, 200));
joystickEventsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(51, 153, 0), 2, true), "Joystick View", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(204, 102, 0))); topPanels.setPreferredSize(new java.awt.Dimension(400, 200));
joystickEventsPanel.setToolTipText("JoystickEvent"); topPanels.setLayout(new javax.swing.BoxLayout(topPanels,
joystickEventsPanel.setMinimumSize(new java.awt.Dimension(200, 200)); javax.swing.BoxLayout.LINE_AXIS));
javax.swing.GroupLayout joystickEventsPanelLayout = new javax.swing.GroupLayout(joystickEventsPanel); joystickEventsPanel.setBackground(new java.awt.Color(0, 0, 0));
joystickEventsPanel.setLayout(joystickEventsPanelLayout); joystickEventsPanel.setBorder(javax.swing.BorderFactory
joystickEventsPanelLayout.setHorizontalGroup( .createTitledBorder(new javax.swing.border.LineBorder(
joystickEventsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) new java.awt.Color(51, 153, 0), 2, true),
.addGap(0, 601, Short.MAX_VALUE) "Joystick View",
); javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
joystickEventsPanelLayout.setVerticalGroup( javax.swing.border.TitledBorder.DEFAULT_POSITION,
joystickEventsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(
.addGap(0, 174, Short.MAX_VALUE) 204, 102, 0)));
); joystickEventsPanel.setToolTipText("JoystickEvent");
joystickEventsPanel.setMinimumSize(new java.awt.Dimension(200, 200));
topPanels.add(joystickEventsPanel); javax.swing.GroupLayout joystickEventsPanelLayout = new javax.swing.GroupLayout(
joystickEventsPanel.getAccessibleContext().setAccessibleName("Joystick"); joystickEventsPanel);
joystickEventsPanel.setLayout(joystickEventsPanelLayout);
joystickEventsPanelLayout.setHorizontalGroup(joystickEventsPanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 601, Short.MAX_VALUE));
joystickEventsPanelLayout.setVerticalGroup(joystickEventsPanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 174, Short.MAX_VALUE));
motionSensingEventsPanel.setMinimumSize(new java.awt.Dimension(200, 200)); topPanels.add(joystickEventsPanel);
joystickEventsPanel.getAccessibleContext()
.setAccessibleName("Joystick");
rawAccelerationPanel.setToolTipText("Nunchuk MotionSensingEvent"); motionSensingEventsPanel
.setMinimumSize(new java.awt.Dimension(200, 200));
javax.swing.GroupLayout rawAccelerationPanelLayout = new javax.swing.GroupLayout(rawAccelerationPanel); rawAccelerationPanel.setToolTipText("Nunchuk MotionSensingEvent");
rawAccelerationPanel.setLayout(rawAccelerationPanelLayout);
rawAccelerationPanelLayout.setHorizontalGroup(
rawAccelerationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 597, Short.MAX_VALUE)
);
rawAccelerationPanelLayout.setVerticalGroup(
rawAccelerationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 175, Short.MAX_VALUE)
);
motionSensingEventsTabbedPanels.addTab("RawAcceleration", rawAccelerationPanel); javax.swing.GroupLayout rawAccelerationPanelLayout = new javax.swing.GroupLayout(
rawAccelerationPanel);
rawAccelerationPanel.setLayout(rawAccelerationPanelLayout);
rawAccelerationPanelLayout
.setHorizontalGroup(rawAccelerationPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 597, Short.MAX_VALUE));
rawAccelerationPanelLayout.setVerticalGroup(rawAccelerationPanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 175, Short.MAX_VALUE));
javax.swing.GroupLayout orientationPanelLayout = new javax.swing.GroupLayout(orientationPanel); motionSensingEventsTabbedPanels.addTab("RawAcceleration",
orientationPanel.setLayout(orientationPanelLayout); rawAccelerationPanel);
orientationPanelLayout.setHorizontalGroup(
orientationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 597, Short.MAX_VALUE)
);
orientationPanelLayout.setVerticalGroup(
orientationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 175, Short.MAX_VALUE)
);
motionSensingEventsTabbedPanels.addTab("Orientation", orientationPanel); javax.swing.GroupLayout orientationPanelLayout = new javax.swing.GroupLayout(
orientationPanel);
orientationPanel.setLayout(orientationPanelLayout);
orientationPanelLayout.setHorizontalGroup(orientationPanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 597, Short.MAX_VALUE));
orientationPanelLayout.setVerticalGroup(orientationPanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 175, Short.MAX_VALUE));
javax.swing.GroupLayout gForcePanelLayout = new javax.swing.GroupLayout(gForcePanel); motionSensingEventsTabbedPanels.addTab("Orientation", orientationPanel);
gForcePanel.setLayout(gForcePanelLayout);
gForcePanelLayout.setHorizontalGroup(
gForcePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 597, Short.MAX_VALUE)
);
gForcePanelLayout.setVerticalGroup(
gForcePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 175, Short.MAX_VALUE)
);
motionSensingEventsTabbedPanels.addTab("GForce", gForcePanel); javax.swing.GroupLayout gForcePanelLayout = new javax.swing.GroupLayout(
gForcePanel);
gForcePanel.setLayout(gForcePanelLayout);
gForcePanelLayout.setHorizontalGroup(gForcePanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 597, Short.MAX_VALUE));
gForcePanelLayout.setVerticalGroup(gForcePanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 175, Short.MAX_VALUE));
javax.swing.GroupLayout motionSensingEventsPanelLayout = new javax.swing.GroupLayout(motionSensingEventsPanel); motionSensingEventsTabbedPanels.addTab("GForce", gForcePanel);
motionSensingEventsPanel.setLayout(motionSensingEventsPanelLayout);
motionSensingEventsPanelLayout.setHorizontalGroup(
motionSensingEventsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(motionSensingEventsTabbedPanels, javax.swing.GroupLayout.DEFAULT_SIZE, 602, Short.MAX_VALUE)
);
motionSensingEventsPanelLayout.setVerticalGroup(
motionSensingEventsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(motionSensingEventsTabbedPanels, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
);
topPanels.add(motionSensingEventsPanel); javax.swing.GroupLayout motionSensingEventsPanelLayout = new javax.swing.GroupLayout(
motionSensingEventsPanel);
motionSensingEventsPanel.setLayout(motionSensingEventsPanelLayout);
motionSensingEventsPanelLayout
.setHorizontalGroup(motionSensingEventsPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(motionSensingEventsTabbedPanels,
javax.swing.GroupLayout.DEFAULT_SIZE, 602,
Short.MAX_VALUE));
motionSensingEventsPanelLayout
.setVerticalGroup(motionSensingEventsPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(motionSensingEventsTabbedPanels,
javax.swing.GroupLayout.DEFAULT_SIZE, 200,
Short.MAX_VALUE));
getContentPane().add(topPanels); topPanels.add(motionSensingEventsPanel);
setNunchukValuesPanel.setMinimumSize(new java.awt.Dimension(400, 200)); getContentPane().add(topPanels);
setNunchukValuesPanel.setPreferredSize(new java.awt.Dimension(400, 200));
setNunchukValuesPanel.setLayout(new javax.swing.BoxLayout(setNunchukValuesPanel, javax.swing.BoxLayout.Y_AXIS));
nunchukButtonsEventPanel.setToolTipText("Nunchuk ButtonsEvent"); setNunchukValuesPanel.setMinimumSize(new java.awt.Dimension(400, 200));
nunchukButtonsEventPanel.setMinimumSize(new java.awt.Dimension(100, 100)); setNunchukValuesPanel
nunchukButtonsEventPanel.setPreferredSize(new java.awt.Dimension(100, 100)); .setPreferredSize(new java.awt.Dimension(400, 200));
nunchukButtonsEventPanel.setLayout(new javax.swing.BoxLayout(nunchukButtonsEventPanel, javax.swing.BoxLayout.LINE_AXIS)); setNunchukValuesPanel.setLayout(new javax.swing.BoxLayout(
setNunchukValuesPanel, javax.swing.BoxLayout.Y_AXIS));
cButton.setText("C"); nunchukButtonsEventPanel.setToolTipText("Nunchuk ButtonsEvent");
cButton.setMaximumSize(new java.awt.Dimension(50, 50)); nunchukButtonsEventPanel
cButton.setMinimumSize(new java.awt.Dimension(50, 50)); .setMinimumSize(new java.awt.Dimension(100, 100));
cButton.setPreferredSize(new java.awt.Dimension(50, 50)); nunchukButtonsEventPanel.setPreferredSize(new java.awt.Dimension(100,
nunchukButtonsEventPanel.add(cButton); 100));
nunchukButtonsEventPanel.setLayout(new javax.swing.BoxLayout(
nunchukButtonsEventPanel, javax.swing.BoxLayout.LINE_AXIS));
zButton.setText("Z"); cButton.setText("C");
zButton.setMaximumSize(new java.awt.Dimension(50, 50)); cButton.setMaximumSize(new java.awt.Dimension(50, 50));
zButton.setMinimumSize(new java.awt.Dimension(50, 50)); cButton.setMinimumSize(new java.awt.Dimension(50, 50));
zButton.setPreferredSize(new java.awt.Dimension(50, 50)); cButton.setPreferredSize(new java.awt.Dimension(50, 50));
nunchukButtonsEventPanel.add(zButton); nunchukButtonsEventPanel.add(cButton);
setNunchukValuesPanel.add(nunchukButtonsEventPanel); zButton.setText("Z");
zButton.setMaximumSize(new java.awt.Dimension(50, 50));
zButton.setMinimumSize(new java.awt.Dimension(50, 50));
zButton.setPreferredSize(new java.awt.Dimension(50, 50));
nunchukButtonsEventPanel.add(zButton);
nunchukOrientationTextField.setPreferredSize(new java.awt.Dimension(60, 20)); setNunchukValuesPanel.add(nunchukButtonsEventPanel);
nunchukOrientationPanel.add(nunchukOrientationTextField);
nunchukOrientationButton.setText("Set Orientation Threshold"); nunchukOrientationTextField.setPreferredSize(new java.awt.Dimension(60,
nunchukOrientationButton.addMouseListener(new java.awt.event.MouseAdapter() { 20));
public void mousePressed(java.awt.event.MouseEvent evt) { nunchukOrientationPanel.add(nunchukOrientationTextField);
nunchukOrientationButtonMousePressed(evt);
}
});
nunchukOrientationPanel.add(nunchukOrientationButton);
setNunchukValuesPanel.add(nunchukOrientationPanel); nunchukOrientationButton.setText("Set Orientation Threshold");
nunchukOrientationButton
.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
nunchukOrientationButtonMousePressed(evt);
}
});
nunchukOrientationPanel.add(nunchukOrientationButton);
nunchukAccelerationTextField.setPreferredSize(new java.awt.Dimension(60, 20)); setNunchukValuesPanel.add(nunchukOrientationPanel);
nunchukAccelerationPanel.add(nunchukAccelerationTextField);
nunchukAccelerationButton.setText("Set Acceleration Threshold"); nunchukAccelerationTextField.setPreferredSize(new java.awt.Dimension(
nunchukAccelerationButton.addMouseListener(new java.awt.event.MouseAdapter() { 60, 20));
public void mousePressed(java.awt.event.MouseEvent evt) { nunchukAccelerationPanel.add(nunchukAccelerationTextField);
nunchukAccelerationButtonMousePressed(evt);
}
});
nunchukAccelerationPanel.add(nunchukAccelerationButton);
setNunchukValuesPanel.add(nunchukAccelerationPanel); nunchukAccelerationButton.setText("Set Acceleration Threshold");
nunchukAccelerationButton
.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
nunchukAccelerationButtonMousePressed(evt);
}
});
nunchukAccelerationPanel.add(nunchukAccelerationButton);
messageText.setText("Message:"); setNunchukValuesPanel.add(nunchukAccelerationPanel);
javax.swing.GroupLayout messagePanelLayout = new javax.swing.GroupLayout(messagePanel); messageText.setText("Message:");
messagePanel.setLayout(messagePanelLayout);
messagePanelLayout.setHorizontalGroup(
messagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 1216, Short.MAX_VALUE)
.addGroup(messagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(messagePanelLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(messageText)
.addGap(0, 0, Short.MAX_VALUE)))
);
messagePanelLayout.setVerticalGroup(
messagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 34, Short.MAX_VALUE)
.addGroup(messagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(messagePanelLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(messageText)
.addGap(0, 0, Short.MAX_VALUE)))
);
setNunchukValuesPanel.add(messagePanel); javax.swing.GroupLayout messagePanelLayout = new javax.swing.GroupLayout(
messagePanel);
messagePanel.setLayout(messagePanelLayout);
messagePanelLayout
.setHorizontalGroup(messagePanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 1216, Short.MAX_VALUE)
.addGroup(
messagePanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
messagePanelLayout
.createSequentialGroup()
.addGap(0, 0,
Short.MAX_VALUE)
.addComponent(
messageText)
.addGap(0, 0,
Short.MAX_VALUE))));
messagePanelLayout
.setVerticalGroup(messagePanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 34, Short.MAX_VALUE)
.addGroup(
messagePanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
messagePanelLayout
.createSequentialGroup()
.addGap(0, 0,
Short.MAX_VALUE)
.addComponent(
messageText)
.addGap(0, 0,
Short.MAX_VALUE))));
getContentPane().add(setNunchukValuesPanel); setNunchukValuesPanel.add(messagePanel);
pack(); getContentPane().add(setNunchukValuesPanel);
}// </editor-fold>//GEN-END:initComponents
private void nunchukOrientationButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nunchukOrientationButtonMousePressed
try {
float nb = Float.parseFloat(nunchukOrientationTextField.getText());
wiimote.setNunchukOrientationThreshold(nb);
messageText.setText("Nunchuk orientation threshold set to " + nb);
} catch (NumberFormatException e) {
messageText.setText("Number is not an integer, nunchuk orientation threshold not set !");
}
}//GEN-LAST:event_nunchukOrientationButtonMousePressed
private void nunchukAccelerationButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nunchukAccelerationButtonMousePressed pack();
try { }// </editor-fold>//GEN-END:initComponents
int nb = Integer.parseInt(nunchukAccelerationTextField.getText());
wiimote.setNunchukAccelerationThreshold(nb);
messageText.setText("Nunchuk acceleration threshold set to " + nb);
} catch (NumberFormatException e) {
messageText.setText("Number is not an integer, nunchuk acceleration threshold not set !");
}
}//GEN-LAST:event_nunchukAccelerationButtonMousePressed
public void onButtonsEvent(WiimoteButtonsEvent arg0) { private void nunchukOrientationButtonMousePressed(
//nothing to do java.awt.event.MouseEvent evt) {// GEN-FIRST:event_nunchukOrientationButtonMousePressed
} try {
float nb = Float.parseFloat(nunchukOrientationTextField.getText());
wiimote.setNunchukOrientationThreshold(nb);
messageText.setText("Nunchuk orientation threshold set to " + nb);
} catch (NumberFormatException e) {
messageText
.setText("Number is not an integer, nunchuk orientation threshold not set !");
}
}// GEN-LAST:event_nunchukOrientationButtonMousePressed
public void onIrEvent(IREvent arg0) { private void nunchukAccelerationButtonMousePressed(
//nothing to do java.awt.event.MouseEvent evt) {// GEN-FIRST:event_nunchukAccelerationButtonMousePressed
} try {
int nb = Integer.parseInt(nunchukAccelerationTextField.getText());
wiimote.setNunchukAccelerationThreshold(nb);
messageText.setText("Nunchuk acceleration threshold set to " + nb);
} catch (NumberFormatException e) {
messageText
.setText("Number is not an integer, nunchuk acceleration threshold not set !");
}
}// GEN-LAST:event_nunchukAccelerationButtonMousePressed
public void onMotionSensingEvent(MotionSensingEvent arg0) { public void onButtonsEvent(WiimoteButtonsEvent arg0) {
//nothing to do // nothing to do
} }
public void onExpansionEvent(ExpansionEvent arg0) { public void onIrEvent(IREvent arg0) {
if (arg0 instanceof NunchukEvent) { // nothing to do
NunchukEvent nunchuk = (NunchukEvent) arg0; }
NunchukButtonsEvent buttons = nunchuk.getButtonsEvent();
if (buttons.isButtonCJustPressed()) {
cButton.setEnabled(false);
}
if (buttons.isButtonCJustReleased()) {
cButton.setEnabled(true);
}
if (buttons.isButtonZJustPressed()) {
zButton.setEnabled(false);
}
if (buttons.isButtonZJustReleased()) {
zButton.setEnabled(true);
}
if (isThresholdsRequested){
MotionSensingEvent evt = nunchuk.getNunchukMotionSensingEvent();
nunchukAccelerationTextField.setText(evt.getAccelerationThreshold()+"");
nunchukOrientationTextField.setText(evt.getOrientationThreshold()+"");
isThresholdsRequested = false;
}
}
}
public void onStatusEvent(StatusEvent arg0) { public void onMotionSensingEvent(MotionSensingEvent arg0) {
//nothing to do // nothing to do
} }
public void onDisconnectionEvent(DisconnectionEvent arg0) { public void onExpansionEvent(ExpansionEvent arg0) {
//nothing if (arg0 instanceof NunchukEvent) {
} NunchukEvent nunchuk = (NunchukEvent) arg0;
NunchukButtonsEvent buttons = nunchuk.getButtonsEvent();
if (buttons.isButtonCJustPressed()) {
cButton.setEnabled(false);
}
if (buttons.isButtonCJustReleased()) {
cButton.setEnabled(true);
}
if (buttons.isButtonZJustPressed()) {
zButton.setEnabled(false);
}
if (buttons.isButtonZJustReleased()) {
zButton.setEnabled(true);
}
if (isThresholdsRequested) {
MotionSensingEvent evt = nunchuk.getNunchukMotionSensingEvent();
nunchukAccelerationTextField.setText(evt
.getAccelerationThreshold()
+ "");
nunchukOrientationTextField.setText(evt
.getOrientationThreshold()
+ "");
isThresholdsRequested = false;
}
}
}
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) { public void onStatusEvent(StatusEvent arg0) {
//nothing // nothing to do
} }
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { public void onDisconnectionEvent(DisconnectionEvent arg0) {
//nothing // nothing
} }
// Variables declaration - do not modify//GEN-BEGIN:variables public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
private javax.swing.JButton cButton; // nothing
private javax.swing.JPanel gForcePanel; }
private javax.swing.JPanel joystickEventsPanel;
private javax.swing.JPanel messagePanel; public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
private javax.swing.JLabel messageText; // nothing
private javax.swing.JPanel motionSensingEventsPanel; }
private javax.swing.JTabbedPane motionSensingEventsTabbedPanels;
private javax.swing.JButton nunchukAccelerationButton; // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel nunchukAccelerationPanel; private javax.swing.JButton cButton;
private javax.swing.JTextField nunchukAccelerationTextField; private javax.swing.JPanel gForcePanel;
private javax.swing.JPanel nunchukButtonsEventPanel; private javax.swing.JPanel joystickEventsPanel;
private javax.swing.JButton nunchukOrientationButton; private javax.swing.JPanel messagePanel;
private javax.swing.JPanel nunchukOrientationPanel; private javax.swing.JLabel messageText;
private javax.swing.JTextField nunchukOrientationTextField; private javax.swing.JPanel motionSensingEventsPanel;
private javax.swing.JPanel orientationPanel; private javax.swing.JTabbedPane motionSensingEventsTabbedPanels;
private javax.swing.JPanel rawAccelerationPanel; private javax.swing.JButton nunchukAccelerationButton;
private javax.swing.JPanel setNunchukValuesPanel; private javax.swing.JPanel nunchukAccelerationPanel;
private javax.swing.JPanel topPanels; private javax.swing.JTextField nunchukAccelerationTextField;
private javax.swing.JButton zButton; private javax.swing.JPanel nunchukButtonsEventPanel;
// End of variables declaration//GEN-END:variables private javax.swing.JButton nunchukOrientationButton;
private javax.swing.JPanel nunchukOrientationPanel;
private javax.swing.JTextField nunchukOrientationTextField;
private javax.swing.JPanel orientationPanel;
private javax.swing.JPanel rawAccelerationPanel;
private javax.swing.JPanel setNunchukValuesPanel;
private javax.swing.JPanel topPanels;
private javax.swing.JButton zButton;
// End of variables declaration//GEN-END:variables
} }

View File

@@ -34,7 +34,7 @@ import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
/** /**
* This class used to test WiiuseJ. * This class used to test WiiuseJ in text mode.
* *
* @author guiguito * @author guiguito
*/ */
@@ -61,8 +61,6 @@ public class Tests implements WiimoteListener {
} }
} }
private static int nb = 0;
public void onButtonsEvent(WiimoteButtonsEvent e) { public void onButtonsEvent(WiimoteButtonsEvent e) {
if (dump == DISPLAY_EACH_VALUE) { if (dump == DISPLAY_EACH_VALUE) {
// System.out.println("*********** WIIMOTE ID : "+ // System.out.println("*********** WIIMOTE ID : "+
@@ -326,7 +324,7 @@ public class Tests implements WiimoteListener {
/* display motion sensing */ /* display motion sensing */
System.out.println(e); System.out.println(e);
} }
public void onExpansionEvent(ExpansionEvent e) { public void onExpansionEvent(ExpansionEvent e) {
System.out.println(e); System.out.println(e);
} }
@@ -340,23 +338,23 @@ public class Tests implements WiimoteListener {
System.out.println(" wiimote " + e.getWiimoteId() System.out.println(" wiimote " + e.getWiimoteId()
+ "has been disconnected !!"); + "has been disconnected !!");
} }
public void onNunchukInsertedEvent(NunchukInsertedEvent e) { public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
System.out.println(e); System.out.println(e);
} }
public void onNunchukRemovedEvent(NunchukRemovedEvent e) { public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
System.out.println(e); System.out.println(e);
} }
/** /**
* @param args * @param args
*/ */
public static void main(String[] args) { public static void main(String[] args) {
Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(4, true); Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true);
if (wiimotes.length > 0) { if (wiimotes.length > 0) {
System.out.println(wiimotes[0]); System.out.println(wiimotes[0]);
Tests tests = new Tests(wiimotes[0]); new Tests(wiimotes[0]);
} else { } else {
System.out.println("No wiimotes found !!!"); System.out.println("No wiimotes found !!!");
} }

View File

@@ -90,9 +90,9 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements
showExpansionWiimoteButton.setText("Show Nunchuk"); showExpansionWiimoteButton.setText("Show Nunchuk");
} }
}; };
/** /**
* default constructor * default constructor
*/ */
public WiiuseJGuiTest() { public WiiuseJGuiTest() {
initComponents(); initComponents();
@@ -231,7 +231,7 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements
showExpansionWiimoteButton.setText("Show Nunchuk"); showExpansionWiimoteButton.setText("Show Nunchuk");
expansionFrame = new NunchukGuiTest(wiimote); expansionFrame = new NunchukGuiTest(wiimote);
expansionFrame expansionFrame
.setDefaultCloseOperation(expansionFrame.HIDE_ON_CLOSE); .setDefaultCloseOperation(NunchukGuiTest.HIDE_ON_CLOSE);
expansionFrame.addWindowListener(buttonSetter); expansionFrame.addWindowListener(buttonSetter);
isFirstStatusGot = true; isFirstStatusGot = true;
} }
@@ -275,7 +275,7 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements
showExpansionWiimoteButton.setEnabled(true); showExpansionWiimoteButton.setEnabled(true);
showExpansionWiimoteButton.setText("Show nunchuk"); showExpansionWiimoteButton.setText("Show nunchuk");
expansionFrame = new NunchukGuiTest(wiimote); expansionFrame = new NunchukGuiTest(wiimote);
expansionFrame.setDefaultCloseOperation(expansionFrame.HIDE_ON_CLOSE); expansionFrame.setDefaultCloseOperation(NunchukGuiTest.HIDE_ON_CLOSE);
expansionFrame.addWindowListener(buttonSetter); expansionFrame.addWindowListener(buttonSetter);
} }
@@ -1188,8 +1188,7 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements
private void reconnectWiimotesButtonMousePressed( private void reconnectWiimotesButtonMousePressed(
java.awt.event.MouseEvent evt) {// GEN-FIRST:event_reconnectWiimotesButtonMousePressed java.awt.event.MouseEvent evt) {// GEN-FIRST:event_reconnectWiimotesButtonMousePressed
// stop manager // stop manager
WiiUseApiManager manager = WiiUseApiManager.getInstance(); WiiUseApiManager.shutdown();
manager.shutdown();
// unregister previous wiimote // unregister previous wiimote
if (wiimote != null) { if (wiimote != null) {
@@ -1228,7 +1227,7 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements
// get wiimote // get wiimote
Wiimote[] listWiimote = WiiUseApiManager.getWiimotes(1, true); Wiimote[] listWiimote = WiiUseApiManager.getWiimotes(1, true);
if (listWiimote!=null && listWiimote.length > 0) { if (listWiimote != null && listWiimote.length > 0) {
wiimote = listWiimote[0]; wiimote = listWiimote[0];
// registers listeners // registers listeners
@@ -1244,7 +1243,7 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements
java.awt.event.MouseEvent evt) {// GEN-FIRST:event_showExpansionWiimoteButtonMousePressed java.awt.event.MouseEvent evt) {// GEN-FIRST:event_showExpansionWiimoteButtonMousePressed
if (expansionFrame != null) { if (expansionFrame != null) {
if (showExpansionWiimoteButton.isEnabled()) {// expansion frame if (showExpansionWiimoteButton.isEnabled()) {// expansion frame
// not shown // not shown
// show it // show it
expansionFrame.setEnabled(true); expansionFrame.setEnabled(true);
expansionFrame.setVisible(true); expansionFrame.setVisible(true);

View File

@@ -21,17 +21,19 @@ import wiiusej.wiiusejevents.GenericEvent;
import wiiusej.wiiusejevents.physicalevents.NunchukEvent; import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
/** /**
* * Panel to display Acceleration in a MotionSensingEvent from an expansion.
*
* @author guiguito * @author guiguito
*/ */
public class AccelerationExpansionEventPanel extends AccelerationPanel{ public class AccelerationExpansionEventPanel extends AccelerationPanel {
@Override @Override
public RawAcceleration getRawAccelerationValue(GenericEvent e) { public RawAcceleration getRawAccelerationValue(GenericEvent e) {
if (e instanceof NunchukEvent){ if (e instanceof NunchukEvent) {
return ((NunchukEvent)e).getNunchukMotionSensingEvent().getRawAcceleration(); return ((NunchukEvent) e).getNunchukMotionSensingEvent()
} .getRawAcceleration();
return null; }
} return null;
}
} }

View File

@@ -58,8 +58,8 @@ public abstract class AccelerationPanel extends javax.swing.JPanel implements
public AccelerationPanel() { public AccelerationPanel() {
initComponents(); initComponents();
} }
/** /**
* Constructor used to choose the colors used by the AccelerationPanel. * Constructor used to choose the colors used by the AccelerationPanel.
* *
* @param bgColor * @param bgColor
@@ -150,18 +150,19 @@ public abstract class AccelerationPanel extends javax.swing.JPanel implements
// put offscreen image on the screen // put offscreen image on the screen
g.drawImage(mImage, 0, 0, null); g.drawImage(mImage, 0, 0, null);
} }
/** /**
* check if the mImage variable has been initialized. If it's not the case * check if the mImage variable has been initialized. If it's not the case
* it initializes it with the dimensions of the panel. mImage is for double * it initializes it with the dimensions of the panel. mImage is for double
* buffering. * buffering.
*/ */
private void checkOffScreenImage() { private void checkOffScreenImage() {
Dimension d = getSize(); Dimension d = getSize();
if (mImage == null || mImage.getWidth(null) != d.width || mImage.getHeight(null) != d.height) { if (mImage == null || mImage.getWidth(null) != d.width
mImage = createImage(d.width, d.height); || mImage.getHeight(null) != d.height) {
} mImage = createImage(d.width, d.height);
} }
}
public void onButtonsEvent(WiimoteButtonsEvent arg0) { public void onButtonsEvent(WiimoteButtonsEvent arg0) {
// nothing // nothing
@@ -196,65 +197,66 @@ public abstract class AccelerationPanel extends javax.swing.JPanel implements
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
// nothing // nothing
} }
private void draw(GenericEvent arg0){ private void draw(GenericEvent arg0) {
if (values.size() >= getWidth()) { if (values.size() >= getWidth()) {
// if there are as many values as pixels in the width // if there are as many values as pixels in the width
// clear points // clear points
values.clear(); values.clear();
} }
RawAcceleration rawAcceleration = getRawAccelerationValue(arg0); RawAcceleration rawAcceleration = getRawAccelerationValue(arg0);
if (rawAcceleration != null) values.add(rawAcceleration); if (rawAcceleration != null)
values.add(rawAcceleration);
repaint(); repaint();
} }
public abstract RawAcceleration getRawAccelerationValue(GenericEvent e);
public Color getBackgroundColor() { public abstract RawAcceleration getRawAccelerationValue(GenericEvent e);
return backgroundColor;
}
public Color getLineColor() { public Color getBackgroundColor() {
return lineColor; return backgroundColor;
} }
public Color getXColor() { public Color getLineColor() {
return xColor; return lineColor;
} }
public Color getYColor() { public Color getXColor() {
return yColor; return xColor;
} }
public Color getZColor() { public Color getYColor() {
return zColor; return yColor;
} }
public void setBackgroundColor(Color backgroundColor) { public Color getZColor() {
this.backgroundColor = backgroundColor; return zColor;
} }
public void setLineColor(Color lineColor) { public void setBackgroundColor(Color backgroundColor) {
this.lineColor = lineColor; this.backgroundColor = backgroundColor;
} }
public void setXColor(Color xColor) { public void setLineColor(Color lineColor) {
this.xColor = xColor; this.lineColor = lineColor;
} }
public void setYColor(Color yColor) { public void setXColor(Color xColor) {
this.yColor = yColor; this.xColor = xColor;
} }
public void setYColor(Color yColor) {
this.yColor = yColor;
}
public void setZColor(Color zColor) {
this.zColor = zColor;
}
public void clearView() {
values.clear();
repaint();
}
public void setZColor(Color zColor) {
this.zColor = zColor;
}
public void clearView(){
values.clear();
repaint();
}
/** /**
* This method is called from within the constructor to initialize the form. * This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always * WARNING: Do NOT modify this code. The content of this method is always

View File

@@ -21,17 +21,17 @@ import wiiusej.wiiusejevents.GenericEvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
/** /**
* * Panel to display Acceleration in a MotionSensingEvent from a wiimote.
* @author guiguito * @author guiguito
*/ */
public class AccelerationWiimoteEventPanel extends AccelerationPanel{ public class AccelerationWiimoteEventPanel extends AccelerationPanel {
@Override @Override
public RawAcceleration getRawAccelerationValue(GenericEvent e) { public RawAcceleration getRawAccelerationValue(GenericEvent e) {
if (e instanceof MotionSensingEvent){ if (e instanceof MotionSensingEvent) {
return ((MotionSensingEvent)e).getRawAcceleration(); return ((MotionSensingEvent) e).getRawAcceleration();
} }
return null; return null;
} }
} }

View File

@@ -37,8 +37,8 @@ import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
/** /**
* This panel is used to see what buttons are pressed. It displays the result of * This panel is used to see what buttons are pressed on the wiimote. It
* last ButtonsEvent. * displays the result of last ButtonsEvent.
* *
* @author guiguito * @author guiguito
*/ */
@@ -303,42 +303,42 @@ public class ButtonsEventPanel extends javax.swing.JPanel implements
// nothing // nothing
} }
public Color getHeldColor() { public Color getHeldColor() {
return heldColor; return heldColor;
} }
public Color getPressedColor() { public Color getPressedColor() {
return pressedColor; return pressedColor;
} }
public Color getReleasedColor() { public Color getReleasedColor() {
return releasedColor; return releasedColor;
} }
public Shape getShape() { public Shape getShape() {
return shape; return shape;
} }
public void setHeldColor(Color heldColor) { public void setHeldColor(Color heldColor) {
this.heldColor = heldColor; this.heldColor = heldColor;
} }
public void setPressedColor(Color pressedColor) { public void setPressedColor(Color pressedColor) {
this.pressedColor = pressedColor; this.pressedColor = pressedColor;
} }
public void setReleasedColor(Color releasedColor) { public void setReleasedColor(Color releasedColor) {
this.releasedColor = releasedColor; this.releasedColor = releasedColor;
} }
public void setShape(Shape shape) { public void setShape(Shape shape) {
this.shape = shape; this.shape = shape;
} }
public void clearView(){ public void clearView() {
buttons = null; buttons = null;
repaint(); repaint();
} }
/** /**
* This method is called from within the constructor to initialize the form. * This method is called from within the constructor to initialize the form.

View File

@@ -21,7 +21,8 @@ import wiiusej.wiiusejevents.GenericEvent;
import wiiusej.wiiusejevents.physicalevents.NunchukEvent; import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
/** /**
* * Panel to display GForce in a MotionSensingEvent from an expansion.
*
* @author guiguito * @author guiguito
*/ */
public class GForceExpansionEventPanel extends GForcePanel{ public class GForceExpansionEventPanel extends GForcePanel{

View File

@@ -42,7 +42,8 @@ import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
* *
* @author guiguito * @author guiguito
*/ */
public abstract class GForcePanel extends javax.swing.JPanel implements WiimoteListener { public abstract class GForcePanel extends javax.swing.JPanel implements
WiimoteListener {
private Image mImage;// image for double buffering private Image mImage;// image for double buffering
private Color xColor = Color.RED; private Color xColor = Color.RED;
@@ -195,68 +196,69 @@ public abstract class GForcePanel extends javax.swing.JPanel implements WiimoteL
// nothing // nothing
} }
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0){ public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
// nothing // nothing
} }
private void draw(GenericEvent arg0){ private void draw(GenericEvent arg0) {
if (values.size() >= getWidth()) { if (values.size() >= getWidth()) {
// if there are as many values as pixels in the width // if there are as many values as pixels in the width
// clear points // clear points
values.clear(); values.clear();
} }
GForce gforce = getGForceValue(arg0); GForce gforce = getGForceValue(arg0);
if (gforce != null) values.add(gforce); if (gforce != null)
values.add(gforce);
repaint(); repaint();
} }
public abstract GForce getGForceValue(GenericEvent e);
public Color getBackgroundColor() { public abstract GForce getGForceValue(GenericEvent e);
return backgroundColor;
}
public Color getLineColor() { public Color getBackgroundColor() {
return lineColor; return backgroundColor;
} }
public Color getXColor() { public Color getLineColor() {
return xColor; return lineColor;
} }
public Color getYColor() { public Color getXColor() {
return yColor; return xColor;
} }
public Color getZColor() { public Color getYColor() {
return zColor; return yColor;
} }
public void setBackgroundColor(Color backgroundColor) { public Color getZColor() {
this.backgroundColor = backgroundColor; return zColor;
} }
public void setLineColor(Color lineColor) { public void setBackgroundColor(Color backgroundColor) {
this.lineColor = lineColor; this.backgroundColor = backgroundColor;
} }
public void setXColor(Color xColor) { public void setLineColor(Color lineColor) {
this.xColor = xColor; this.lineColor = lineColor;
} }
public void setYColor(Color yColor) { public void setXColor(Color xColor) {
this.yColor = yColor; this.xColor = xColor;
} }
public void setZColor(Color zColor) { public void setYColor(Color yColor) {
this.zColor = zColor; this.yColor = yColor;
} }
public void setZColor(Color zColor) {
this.zColor = zColor;
}
public void clearView() {
values.clear();
repaint();
}
public void clearView(){
values.clear();
repaint();
}
/** /**
* This method is called from within the constructor to initialize the form. * This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always * WARNING: Do NOT modify this code. The content of this method is always

View File

@@ -21,16 +21,17 @@ import wiiusej.wiiusejevents.GenericEvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
/** /**
* * Panel to display GForce in a MotionSensingEvent from a wiimote.
*
* @author guiguito * @author guiguito
*/ */
public class GForceWiimoteEventPanel extends GForcePanel { public class GForceWiimoteEventPanel extends GForcePanel {
@Override @Override
public GForce getGForceValue(GenericEvent e) { public GForce getGForceValue(GenericEvent e) {
if (e instanceof MotionSensingEvent) { if (e instanceof MotionSensingEvent) {
return ((MotionSensingEvent) e).getGforce(); return ((MotionSensingEvent) e).getGforce();
} }
return null; return null;
} }
} }

View File

@@ -37,210 +37,217 @@ import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
/** /**
* This panel is used to see what the IR camera of the wiimote sees. * This panel is used to see what the IR camera of the wiimote sees.
* @author guiguito *
* @author guiguito
*/ */
public class IRPanel extends javax.swing.JPanel implements WiimoteListener { public class IRPanel extends javax.swing.JPanel implements WiimoteListener {
private static int MAX_NB_POINTS = 4; private static int MAX_NB_POINTS = 4;
private Color color = Color.YELLOW; private Color color = Color.YELLOW;
private Color backgroundColor = Color.BLACK; private Color backgroundColor = Color.BLACK;
private Color borderColor = Color.BLUE; private Color borderColor = Color.BLUE;
private Shape shape; private Shape shape;
private Image mImage;//image for double buffering private Image mImage;// image for double buffering
private int[] xCoordinates; private int[] xCoordinates;
private int[] yCoordinates; private int[] yCoordinates;
private int nbPoints = -1; private int nbPoints = -1;
/** /**
* Default constructor for IR Panel. * Default constructor for IR Panel. Background color : black. IR sources
* Background color : black. * color : yellow. Border color of IR sources : blue. Shape of the IR
* IR sources color : yellow. * sources : circle with a diameter of 10.
* Border color of IR sources : blue. */
* Shape of the IR sources : circle with a diameter of 10. public IRPanel() {
*/ shape = new java.awt.geom.Ellipse2D.Double(0, 0, 10, 10);
public IRPanel() { initArrays();
shape = new java.awt.geom.Ellipse2D.Double(0, 0, 10, 10); initComponents();
initArrays(); }
initComponents();
}
/** /**
* Constructor used to parameterize the IR panel. * Constructor used to parameterize the IR panel.
* @param bgColor color. *
* @param ptColor IR sources color. * @param bgColor
* @param bdColor border color of IR sources. * color.
* @param sh Shape of the IR sources. * @param ptColor
*/ * IR sources color.
public IRPanel(Color bgColor, Color ptColor, Color bdColor, Shape sh) { * @param bdColor
backgroundColor = bgColor; * border color of IR sources.
color = ptColor; * @param sh
borderColor = bdColor; * Shape of the IR sources.
shape = sh; */
initArrays(); public IRPanel(Color bgColor, Color ptColor, Color bdColor, Shape sh) {
initComponents(); backgroundColor = bgColor;
} color = ptColor;
borderColor = bdColor;
shape = sh;
initArrays();
initComponents();
}
private void initArrays() { private void initArrays() {
xCoordinates = new int[MAX_NB_POINTS]; xCoordinates = new int[MAX_NB_POINTS];
yCoordinates = new int[MAX_NB_POINTS]; yCoordinates = new int[MAX_NB_POINTS];
for (int i = 0; i < MAX_NB_POINTS; i++) { for (int i = 0; i < MAX_NB_POINTS; i++) {
xCoordinates[i] = -1; xCoordinates[i] = -1;
yCoordinates[i] = -1; yCoordinates[i] = -1;
} }
} }
@Override @Override
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);
Dimension d = getSize(); Dimension d = getSize();
checkOffScreenImage(); checkOffScreenImage();
Graphics offG = mImage.getGraphics(); Graphics offG = mImage.getGraphics();
offG.setColor(backgroundColor); offG.setColor(backgroundColor);
offG.fillRect(0, 0, d.width, d.height); offG.fillRect(0, 0, d.width, d.height);
Graphics2D g2 = (Graphics2D) mImage.getGraphics(); Graphics2D g2 = (Graphics2D) mImage.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
//draw points // draw points
int i = 0; int i = 0;
while (i < nbPoints) { while (i < nbPoints) {
double x = xCoordinates[i]; double x = xCoordinates[i];
double y = yCoordinates[i]; double y = yCoordinates[i];
long xx = getWidth() - Math.round((double) getWidth() * x / 1024.0); long xx = getWidth() - Math.round((double) getWidth() * x / 1024.0);
long yy = getHeight() - Math.round((double) getHeight() * y / 768.0); long yy = getHeight()
g2.translate(xx, yy); - Math.round((double) getHeight() * y / 768.0);
g2.translate(xx, yy);
g2.setPaint(borderColor); g2.setPaint(borderColor);
g2.draw(shape); g2.draw(shape);
g2.setPaint(color); g2.setPaint(color);
g2.fill(shape); g2.fill(shape);
g2.setTransform(new AffineTransform()); g2.setTransform(new AffineTransform());
i++; i++;
} }
//put offscreen image on the screen // put offscreen image on the screen
g.drawImage(mImage, 0, 0, null); g.drawImage(mImage, 0, 0, null);
} }
/** /**
* check if the mImage variable has been initialized. If it's not the case it initializes it * check if the mImage variable has been initialized. If it's not the case
* with the dimensions of the panel. mImage is for double buffering. * it initializes it with the dimensions of the panel. mImage is for double
*/ * buffering.
private void checkOffScreenImage() { */
Dimension d = getSize(); private void checkOffScreenImage() {
if (mImage == null || mImage.getWidth(null) != d.width || mImage.getHeight(null) != d.height) { Dimension d = getSize();
mImage = createImage(d.width, d.height); if (mImage == null || mImage.getWidth(null) != d.width
} || mImage.getHeight(null) != d.height) {
} mImage = createImage(d.width, d.height);
}
}
public void onButtonsEvent(WiimoteButtonsEvent arg0) { public void onButtonsEvent(WiimoteButtonsEvent arg0) {
//nothing // nothing
repaint(); repaint();
} }
public void onIrEvent(IREvent arg0) { public void onIrEvent(IREvent arg0) {
//transfer points // transfer points
wiiusej.values.IRSource[] points = arg0.getIRPoints(); wiiusej.values.IRSource[] points = arg0.getIRPoints();
nbPoints = points.length; nbPoints = points.length;
for (int i = 0; i < points.length; i++) { for (int i = 0; i < points.length; i++) {
xCoordinates[i] = (int) points[i].getRx(); xCoordinates[i] = (int) points[i].getRx();
yCoordinates[i] = (int) points[i].getRy(); yCoordinates[i] = (int) points[i].getRy();
} }
for (int i = points.length; i < MAX_NB_POINTS; i++) { for (int i = points.length; i < MAX_NB_POINTS; i++) {
xCoordinates[i] = -1; xCoordinates[i] = -1;
yCoordinates[i] = -1; yCoordinates[i] = -1;
} }
//redraw panel // redraw panel
repaint(); repaint();
} }
public void onMotionSensingEvent(MotionSensingEvent arg0) { public void onMotionSensingEvent(MotionSensingEvent arg0) {
//nothing // nothing
} }
public void onExpansionEvent(ExpansionEvent e) { public void onExpansionEvent(ExpansionEvent e) {
// nothing // nothing
} }
public void onStatusEvent(StatusEvent arg0) { public void onStatusEvent(StatusEvent arg0) {
//nothing // nothing
} }
public void onDisconnectionEvent(DisconnectionEvent arg0) { public void onDisconnectionEvent(DisconnectionEvent arg0) {
//clear previous points // clear previous points
for (int i = 0; i < MAX_NB_POINTS; i++) { for (int i = 0; i < MAX_NB_POINTS; i++) {
xCoordinates[i] = -1; xCoordinates[i] = -1;
yCoordinates[i] = -1; yCoordinates[i] = -1;
} }
//redraw panel // redraw panel
repaint(); repaint();
} }
public void onNunchukInsertedEvent(NunchukInsertedEvent e) { public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
// nothing // nothing
} }
public void onNunchukRemovedEvent(NunchukRemovedEvent e) { public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
// nothing // nothing
} }
public Color getBackgroundColor() { public Color getBackgroundColor() {
return backgroundColor; return backgroundColor;
} }
public Color getBorderColor() { public Color getBorderColor() {
return borderColor; return borderColor;
} }
public Color getColor() { public Color getColor() {
return color; return color;
} }
public Shape getShape() { public Shape getShape() {
return shape; return shape;
} }
public void setBackgroundColor(Color backgroundColor) { public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor; this.backgroundColor = backgroundColor;
} }
public void setBorderColor(Color borderColor) { public void setBorderColor(Color borderColor) {
this.borderColor = borderColor; this.borderColor = borderColor;
} }
public void setColor(Color color) { public void setColor(Color color) {
this.color = color; this.color = color;
} }
public void setShape(Shape shape) { public void setShape(Shape shape) {
this.shape = shape; this.shape = shape;
} }
public void clearView(){
initArrays();
repaint();
}
/** This method is called from within the constructor to public void clearView() {
* initialize the form. initArrays();
* WARNING: Do NOT modify this code. The content of this method is repaint();
* always regenerated by the Form Editor. }
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); /**
this.setLayout(layout); * This method is called from within the constructor to initialize the form.
layout.setHorizontalGroup( * WARNING: Do NOT modify this code. The content of this method is always
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) * regenerated by the Form Editor.
.addGap(0, 400, Short.MAX_VALUE) */
); // <editor-fold defaultstate="collapsed" desc="Generated
layout.setVerticalGroup( // Code">//GEN-BEGIN:initComponents
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) private void initComponents() {
.addGap(0, 300, Short.MAX_VALUE)
); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
}// </editor-fold>//GEN-END:initComponents this.setLayout(layout);
// Variables declaration - do not modify//GEN-BEGIN:variables layout.setHorizontalGroup(layout.createParallelGroup(
// End of variables declaration//GEN-END:variables javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
Short.MAX_VALUE));
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
} }

View File

@@ -37,188 +37,195 @@ import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
/** /**
* Panel to display joystick events. * Panel to display joystick events.
* @author guiguito *
* @author guiguito
*/ */
public abstract class JoystickEventPanel extends javax.swing.JPanel implements WiimoteListener { public abstract class JoystickEventPanel extends javax.swing.JPanel implements
WiimoteListener {
private Image mImage;// image for double buffering private Image mImage;// image for double buffering
private Color backgroundColor = Color.BLACK; private Color backgroundColor = Color.BLACK;
private Color borderColor = Color.RED; private Color borderColor = Color.RED;
private Color pointColor = Color.RED; private Color pointColor = Color.RED;
private Shape shape = new java.awt.geom.Ellipse2D.Double(0, 0, 30, 30); private Shape shape = new java.awt.geom.Ellipse2D.Double(0, 0, 30, 30);
private JoystickEvent lastJoystickEvent = null; private JoystickEvent lastJoystickEvent = null;
/** Creates new form JoystickPanel */ /** Creates new form JoystickPanel */
public JoystickEventPanel() { public JoystickEventPanel() {
initComponents(); initComponents();
} }
/** /**
* Constructor used to choose the colors used by the JoystickPanel. * Constructor used to choose the colors used by the JoystickPanel.
* *
* @param bgColor * @param bgColor
* background color. * background color.
* @param pColor * @param pColor
* point color. * point color.
* @param bdColor * @param bdColor
* border color for the shape. * border color for the shape.
* @param sh * @param sh
* shape of what is drawn. * shape of what is drawn.
*/ */
public JoystickEventPanel(Color bgColor, Color pColor, Color bdColor, Shape sh) { public JoystickEventPanel(Color bgColor, Color pColor, Color bdColor,
backgroundColor = bgColor; Shape sh) {
pointColor = pColor; backgroundColor = bgColor;
shape = sh; pointColor = pColor;
borderColor = bdColor; shape = sh;
initComponents(); borderColor = bdColor;
} initComponents();
}
@Override @Override
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);
Dimension d = getSize(); Dimension d = getSize();
checkOffScreenImage(); checkOffScreenImage();
Graphics offG = mImage.getGraphics(); Graphics offG = mImage.getGraphics();
offG.setColor(backgroundColor); offG.setColor(backgroundColor);
offG.fillRect(0, 0, d.width, d.height); offG.fillRect(0, 0, d.width, d.height);
Graphics2D g2 = (Graphics2D) mImage.getGraphics(); Graphics2D g2 = (Graphics2D) mImage.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
g2.setTransform(new AffineTransform()); g2.setTransform(new AffineTransform());
//compute center // compute center
int xCenter = (int) Math.round(d.getWidth() / 2.0); int xCenter = (int) Math.round(d.getWidth() / 2.0);
int yCenter = (int) Math.round(d.getHeight() / 2.0); int yCenter = (int) Math.round(d.getHeight() / 2.0);
//compute coordinates // compute coordinates
if (lastJoystickEvent != null) { if (lastJoystickEvent != null) {
double xAng = Math.sin(lastJoystickEvent.getAngle() * Math.PI / 180.0) * lastJoystickEvent.getMagnitude(); double xAng = Math.sin(lastJoystickEvent.getAngle() * Math.PI
double yAng = Math.cos(lastJoystickEvent.getAngle() * Math.PI / 180.0) * lastJoystickEvent.getMagnitude(); / 180.0)
int dx = (int) Math.round(shape.getBounds().getWidth() / 2); * lastJoystickEvent.getMagnitude();
int dy = (int) Math.round(shape.getBounds().getHeight() / 2); double yAng = Math.cos(lastJoystickEvent.getAngle() * Math.PI
double xTemp = xAng * (xCenter - dx * 2); / 180.0)
double yTemp = yAng * (yCenter - dy * 2); * lastJoystickEvent.getMagnitude();
int x = xCenter - dx + (int) xTemp; int dx = (int) Math.round(shape.getBounds().getWidth() / 2);
int y = yCenter - dy - (int) yTemp; int dy = (int) Math.round(shape.getBounds().getHeight() / 2);
// System.out.println("--------------------------------------------------------------------"); double xTemp = xAng * (xCenter - dx * 2);
// System.out.println(lastJoystickEvent); double yTemp = yAng * (yCenter - dy * 2);
// System.out.println("xCenter ,yCenter : "+xCenter+" , "+yCenter); int x = xCenter - dx + (int) xTemp;
// System.out.println("xAng, yAng : "+xAng+" , "+yAng); int y = yCenter - dy - (int) yTemp;
// System.out.println("dx, dy : "+dx+" , "+dy); // System.out.println("--------------------------------------------------------------------");
// System.out.println("xTemp, yTemp : "+xTemp+" , "+yTemp); // System.out.println(lastJoystickEvent);
// System.out.println("x, y : "+x+" , "+y); // System.out.println("xCenter ,yCenter : "+xCenter+" , "+yCenter);
//shape // System.out.println("xAng, yAng : "+xAng+" , "+yAng);
g2.translate(x, y); // System.out.println("dx, dy : "+dx+" , "+dy);
g2.setPaint(borderColor); // System.out.println("xTemp, yTemp : "+xTemp+" , "+yTemp);
g2.draw(shape); // System.out.println("x, y : "+x+" , "+y);
g2.setPaint(pointColor); // shape
g2.fill(shape); g2.translate(x, y);
} g2.setPaint(borderColor);
// put offscreen image on the screen g2.draw(shape);
g.drawImage(mImage, 0, 0, null); g2.setPaint(pointColor);
} g2.fill(shape);
}
// put offscreen image on the screen
g.drawImage(mImage, 0, 0, null);
}
/** /**
* check if the mImage variable has been initialized. If it's not the case * check if the mImage variable has been initialized. If it's not the case
* it initializes it with the dimensions of the panel. mImage is for double * it initializes it with the dimensions of the panel. mImage is for double
* buffering. * buffering.
*/ */
private void checkOffScreenImage() { private void checkOffScreenImage() {
Dimension d = getSize(); Dimension d = getSize();
if (mImage == null || mImage.getWidth(null) != d.width || mImage.getHeight(null) != d.height) { if (mImage == null || mImage.getWidth(null) != d.width
mImage = createImage(d.width, d.height); || mImage.getHeight(null) != d.height) {
} mImage = createImage(d.width, d.height);
} }
}
public void onButtonsEvent(WiimoteButtonsEvent arg0) { public void onButtonsEvent(WiimoteButtonsEvent arg0) {
//nothing // nothing
} }
public void onIrEvent(IREvent arg0) { public void onIrEvent(IREvent arg0) {
//nothing // nothing
} }
public void onMotionSensingEvent(MotionSensingEvent arg0) { public void onMotionSensingEvent(MotionSensingEvent arg0) {
//nothing // nothing
} }
public void onExpansionEvent(ExpansionEvent arg0) { public void onExpansionEvent(ExpansionEvent arg0) {
JoystickEvent joy = getJoystikEvent(arg0); JoystickEvent joy = getJoystikEvent(arg0);
if (joy != null) { if (joy != null) {
lastJoystickEvent = joy; lastJoystickEvent = joy;
} }
repaint(); repaint();
} }
public void onStatusEvent(StatusEvent arg0) { public void onStatusEvent(StatusEvent arg0) {
//nothing // nothing
} }
public void onDisconnectionEvent(DisconnectionEvent arg0) { public void onDisconnectionEvent(DisconnectionEvent arg0) {
//nothing // nothing
} }
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) { public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
//nothing // nothing
} }
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
//nothing // nothing
} }
public Color getBackgroundColor() { public Color getBackgroundColor() {
return backgroundColor; return backgroundColor;
} }
public Color getPointColor() { public Color getPointColor() {
return pointColor; return pointColor;
} }
public Color getBorderColor() { public Color getBorderColor() {
return borderColor; return borderColor;
} }
public Shape getShape() { public Shape getShape() {
return shape; return shape;
} }
public void setBackgroundColor(Color backgroundColor) { public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor; this.backgroundColor = backgroundColor;
} }
public void setPointColor(Color pointColor) { public void setPointColor(Color pointColor) {
this.pointColor = pointColor; this.pointColor = pointColor;
} }
public void setBorderColor(Color borderColor) { public void setBorderColor(Color borderColor) {
this.borderColor = borderColor; this.borderColor = borderColor;
} }
public void setShape(Shape shape) { public void setShape(Shape shape) {
this.shape = shape; this.shape = shape;
} }
public abstract JoystickEvent getJoystikEvent(ExpansionEvent e); public abstract JoystickEvent getJoystikEvent(ExpansionEvent e);
/** This method is called from within the constructor to /**
* initialize the form. * This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is * WARNING: Do NOT modify this code. The content of this method is always
* always regenerated by the Form Editor. * regenerated by the Form Editor.
*/ */
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated
private void initComponents() { // Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout); this.setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(layout.createParallelGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
.addGap(0, 400, Short.MAX_VALUE) Short.MAX_VALUE));
); layout.setVerticalGroup(layout.createParallelGroup(
layout.setVerticalGroup( javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) Short.MAX_VALUE));
.addGap(0, 300, Short.MAX_VALUE) }// </editor-fold>//GEN-END:initComponents
); // Variables declaration - do not modify//GEN-BEGIN:variables
}// </editor-fold>//GEN-END:initComponents // End of variables declaration//GEN-END:variables
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
} }

View File

@@ -22,15 +22,16 @@ import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
/** /**
* Panel to display nunchuk joystick events. * Panel to display nunchuk joystick events.
*
* @author guiguito * @author guiguito
*/ */
public class NunchukJoystickEventPanel extends JoystickEventPanel { public class NunchukJoystickEventPanel extends JoystickEventPanel {
@Override @Override
public JoystickEvent getJoystikEvent(ExpansionEvent e) { public JoystickEvent getJoystikEvent(ExpansionEvent e) {
if (e instanceof NunchukEvent) { if (e instanceof NunchukEvent) {
return ((NunchukEvent) e).getNunchukJoystickEvent(); return ((NunchukEvent) e).getNunchukJoystickEvent();
} }
return null; return null;
} }
} }

View File

@@ -21,16 +21,18 @@ import wiiusej.wiiusejevents.GenericEvent;
import wiiusej.wiiusejevents.physicalevents.NunchukEvent; import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
/** /**
* * Panel to display Orientation in a MotionSensingEvent from an expansion.
*
* @author guiguito * @author guiguito
*/ */
public class OrientationExpansionEventPanel extends OrientationPanel { public class OrientationExpansionEventPanel extends OrientationPanel {
@Override @Override
public Orientation getOrientationValue(GenericEvent e) { public Orientation getOrientationValue(GenericEvent e) {
if (e instanceof NunchukEvent) { if (e instanceof NunchukEvent) {
return ((NunchukEvent) e).getNunchukMotionSensingEvent().getOrientation(); return ((NunchukEvent) e).getNunchukMotionSensingEvent()
} .getOrientation();
return null; }
} return null;
}
} }

View File

@@ -200,65 +200,66 @@ public abstract class OrientationPanel extends javax.swing.JPanel implements
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
// nothing // nothing
} }
private void draw(GenericEvent arg0){ private void draw(GenericEvent arg0) {
if (values.size() >= getWidth()) { if (values.size() >= getWidth()) {
// if there are as many values as pixels in the width // if there are as many values as pixels in the width
// clear points // clear points
values.clear(); values.clear();
} }
Orientation orientation = getOrientationValue(arg0); Orientation orientation = getOrientationValue(arg0);
if (orientation != null) values.add(orientation); if (orientation != null)
values.add(orientation);
repaint(); repaint();
} }
public abstract Orientation getOrientationValue(GenericEvent e);
public Color getBackgroundColor() { public abstract Orientation getOrientationValue(GenericEvent e);
return backgroundColor;
}
public Color getLineColor() { public Color getBackgroundColor() {
return lineColor; return backgroundColor;
} }
public Color getPitchColor() { public Color getLineColor() {
return pitchColor; return lineColor;
} }
public Color getRollColor() { public Color getPitchColor() {
return rollColor; return pitchColor;
} }
public Color getYawColor() { public Color getRollColor() {
return yawColor; return rollColor;
} }
public void setBackgroundColor(Color backgroundColor) { public Color getYawColor() {
this.backgroundColor = backgroundColor; return yawColor;
} }
public void setLineColor(Color lineColor) { public void setBackgroundColor(Color backgroundColor) {
this.lineColor = lineColor; this.backgroundColor = backgroundColor;
} }
public void setPitchColor(Color pitchColor) { public void setLineColor(Color lineColor) {
this.pitchColor = pitchColor; this.lineColor = lineColor;
} }
public void setRollColor(Color rollColor) { public void setPitchColor(Color pitchColor) {
this.rollColor = rollColor; this.pitchColor = pitchColor;
} }
public void setYawColor(Color yawColor) { public void setRollColor(Color rollColor) {
this.yawColor = yawColor; this.rollColor = rollColor;
} }
public void setYawColor(Color yawColor) {
this.yawColor = yawColor;
}
public void clearView() {
values.clear();
repaint();
}
public void clearView(){
values.clear();
repaint();
}
/** /**
* This method is called from within the constructor to initialize the form. * This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always * WARNING: Do NOT modify this code. The content of this method is always

View File

@@ -21,17 +21,18 @@ import wiiusej.wiiusejevents.GenericEvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
/** /**
* * Panel to display Orientation in a MotionSensingEvent from a wiimote.
*
* @author guiguito * @author guiguito
*/ */
public class OrientationWiimoteEventPanel extends OrientationPanel{ public class OrientationWiimoteEventPanel extends OrientationPanel {
@Override @Override
public Orientation getOrientationValue(GenericEvent e) { public Orientation getOrientationValue(GenericEvent e) {
if (e instanceof MotionSensingEvent){ if (e instanceof MotionSensingEvent) {
return ((MotionSensingEvent)e).getOrientation(); return ((MotionSensingEvent) e).getOrientation();
} }
return null; return null;
} }
} }

View File

@@ -18,6 +18,7 @@ package wiiusej.values;
/** /**
* Represents gravity force on each axis. * Represents gravity force on each axis.
*
* @author guiguito * @author guiguito
*/ */
public class GForce { public class GForce {
@@ -25,23 +26,27 @@ public class GForce {
private float x; private float x;
private float y; private float y;
private float z; private float z;
/** /**
* Default constructor; * Default constructor;
*/ */
public GForce(){ public GForce() {
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
} }
/** /**
* Constructor with gravity force on each axis. * Constructor with gravity force on each axis.
* @param xx x value *
* @param yy x value * @param xx
* @param zz x value * x value
* @param yy
* x value
* @param zz
* x value
*/ */
public GForce(float xx, float yy, float zz){ public GForce(float xx, float yy, float zz) {
x = xx; x = xx;
y = yy; y = yy;
z = zz; z = zz;
@@ -67,9 +72,9 @@ public class GForce {
public float getZ() { public float getZ() {
return z; return z;
} }
@Override @Override
public String toString() { public String toString() {
return "Gravity force : ("+x+", "+y+","+z+")"; return "Gravity force : (" + x + ", " + y + "," + z + ")";
} }
} }

View File

@@ -18,16 +18,17 @@ package wiiusej.values;
/** /**
* Class used for IR sources. * Class used for IR sources.
*
* @author guiguito * @author guiguito
*/ */
public class IRSource{ public class IRSource {
private int x; private int x;
private int y; private int y;
private short rx; private short rx;
private short ry; private short ry;
private short size; private short size;
/** /**
* Build an IR source with all details. * Build an IR source with all details.
* *
@@ -42,68 +43,64 @@ public class IRSource{
* @param si * @param si
* size of the IR dot (0-15). * size of the IR dot (0-15).
*/ */
public IRSource(int xx, int yy, short rxx, short ryy, short si) { public IRSource(int xx, int yy, short rxx, short ryy, short si) {
x = xx; x = xx;
y = yy; y = yy;
rx = rxx; rx = rxx;
ry = ryy; ry = ryy;
size = si; size = si;
} }
/** /**
* Return x interpolated coordinates. * Return x interpolated coordinates.
*
* @return the x * @return the x
*/ */
public int getX() { public int getX() {
return x; return x;
} }
/** /**
* Return y interpolated coordinates. * Return y interpolated coordinates.
*
* @return the y * @return the y
*/ */
public int getY() { public int getY() {
return y; return y;
} }
/** /**
* Return raw X coordinate (0-1023). * Return raw X coordinate (0-1023).
*
* @return the rx * @return the rx
*/ */
public short getRx() { public short getRx() {
return rx; return rx;
} }
/** /**
* Return raw Y coordinate (0-1023). * Return raw Y coordinate (0-1023).
*
* @return the ry * @return the ry
*/ */
public short getRy() { public short getRy() {
return ry; return ry;
} }
/** /**
* Return size of the IR dot (0-15). * Return size of the IR dot (0-15).
*
* @return the size * @return the size
*/ */
public short getSize() { public short getSize() {
return size; return size;
} }
@Override @Override
public String toString() { public String toString() {
return "Interpolated coordinates ("+x+","+y+"), Raw coordinates("+rx+","+ry+"), source size : "+size+")"; return "Interpolated coordinates (" + x + "," + y
+ "), Raw coordinates(" + rx + "," + ry + "), source size : "
+ size + ")";
} }
} }

View File

@@ -18,14 +18,15 @@ package wiiusej.values;
/** /**
* Represents raw acceleration on each axis. * Represents raw acceleration on each axis.
*
* @author guiguito * @author guiguito
*/ */
public class RawAcceleration { public class RawAcceleration {
private short x; private short x;
private short y; private short y;
private short z; private short z;
/** /**
* Default constructor; * Default constructor;
*/ */
@@ -34,12 +35,16 @@ public class RawAcceleration {
y = 0; y = 0;
z = 0; z = 0;
} }
/** /**
* Constructor with raw acceleration on each axis. * Constructor with raw acceleration on each axis.
* @param xx x value *
* @param yy x value * @param xx
* @param zz x value * x value
* @param yy
* x value
* @param zz
* x value
*/ */
public RawAcceleration(short xx, short yy, short zz) { public RawAcceleration(short xx, short yy, short zz) {
x = xx; x = xx;
@@ -53,6 +58,7 @@ public class RawAcceleration {
public short getX() { public short getX() {
return x; return x;
} }
/** /**
* @return the y * @return the y
*/ */
@@ -66,10 +72,10 @@ public class RawAcceleration {
public short getZ() { public short getZ() {
return z; return z;
} }
@Override @Override
public String toString() { public String toString() {
return "Raw acceleration : ("+x+", "+y+","+z+")"; return "Raw acceleration : (" + x + ", " + y + "," + z + ")";
} }
} }

View File

@@ -20,28 +20,34 @@ import wiiusej.wiiusejevents.GenericEvent;
/** /**
* Class which represents a buttons event. * Class which represents a buttons event.
*
* @author guiguito * @author guiguito
*/ */
public abstract class ButtonsEvent extends GenericEvent{ public abstract class ButtonsEvent extends GenericEvent {
/* Buttons */ /* Buttons */
private short buttonsJustPressed = 0; private short buttonsJustPressed = 0;
private short buttonsJustReleased = 0; private short buttonsJustReleased = 0;
private short buttonsHeld = 0; private short buttonsHeld = 0;
/** /**
* Constructor of the button Event. * Constructor of the button Event.
* @param id id of the wiimote concerned. *
* @param buttonsJustPressed buttons just pressed. * @param id
* @param buttonsJustReleased buttons just released. * id of the wiimote concerned.
* @param buttonsHeld buttons just held. * @param buttonsJustPressed
* buttons just pressed.
* @param buttonsJustReleased
* buttons just released.
* @param buttonsHeld
* buttons just held.
*/ */
public ButtonsEvent(int id, short buttonsJustPressed, public ButtonsEvent(int id, short buttonsJustPressed,
short buttonsJustReleased, short buttonsHeld){ short buttonsJustReleased, short buttonsHeld) {
super(id); super(id);
setAllButtons(buttonsJustPressed, buttonsJustReleased, buttonsHeld); setAllButtons(buttonsJustPressed, buttonsJustReleased, buttonsHeld);
} }
/** /**
* Set all buttons in one method. * Set all buttons in one method.
* *
@@ -55,7 +61,7 @@ public abstract class ButtonsEvent extends GenericEvent{
this.buttonsJustReleased = buttonsJustReleased; this.buttonsJustReleased = buttonsJustReleased;
this.buttonsHeld = buttonsHeld; this.buttonsHeld = buttonsHeld;
} }
/** /**
* Get the short storing the buttons just pressed * Get the short storing the buttons just pressed
* *
@@ -82,7 +88,7 @@ public abstract class ButtonsEvent extends GenericEvent{
public short getButtonsHeld() { public short getButtonsHeld() {
return buttonsHeld; return buttonsHeld;
} }
/** **************** BUTTONS Methods ***************** */ /** **************** BUTTONS Methods ***************** */
/* generic button functions */ /* generic button functions */
@@ -102,11 +108,12 @@ public abstract class ButtonsEvent extends GenericEvent{
protected boolean isButtonHeld(short buttonBitsDefinition) { protected boolean isButtonHeld(short buttonBitsDefinition) {
return buttonTest(buttonBitsDefinition, buttonsHeld); return buttonTest(buttonBitsDefinition, buttonsHeld);
} }
protected boolean isButtonPressed(short buttonBitsDefinition) { protected boolean isButtonPressed(short buttonBitsDefinition) {
return isButtonHeld(buttonBitsDefinition)||isButtonJustPressed(buttonBitsDefinition); return isButtonHeld(buttonBitsDefinition)
} || isButtonJustPressed(buttonBitsDefinition);
}
@Override @Override
public String toString() { public String toString() {
String out = ""; String out = "";

View File

@@ -18,19 +18,20 @@ package wiiusej.wiiusejevents.physicalevents;
import wiiusej.wiiusejevents.GenericEvent; import wiiusej.wiiusejevents.GenericEvent;
/** /**
* Mother Class of all expansions. * Mother Class of all expansions event.
*
* @author guiguito * @author guiguito
*/ */
public abstract class ExpansionEvent extends GenericEvent { public abstract class ExpansionEvent extends GenericEvent {
/** /**
* Constructor of an ExpansionEvent. * Constructor of an ExpansionEvent.
* @param id id of the wiimote to which the expansion is connected. *
* @param id
* id of the wiimote to which the expansion is connected.
*/ */
public ExpansionEvent(int id){ public ExpansionEvent(int id) {
super(id); super(id);
} }

View File

@@ -27,19 +27,24 @@ public class NunchukButtonsEvent extends ButtonsEvent {
private static short NUNCHUK_BUTTON_Z = 0x01; private static short NUNCHUK_BUTTON_Z = 0x01;
private static short NUNCHUK_BUTTON_C = 0x02; private static short NUNCHUK_BUTTON_C = 0x02;
private static short NUNCHUK_BUTTON_ALL = 0x03; private static short NUNCHUK_BUTTON_ALL = 0x03;
/** /**
* Constructor of the nunchuk button Event. * Constructor of the nunchuk button Event.
* @param id id of the wiimote. *
* @param buttonsJustPressed buttons just pressed. * @param id
* @param buttonsJustReleased buttons just released. * id of the wiimote.
* @param buttonsHeld buttons just pressed. * @param buttonsJustPressed
* buttons just pressed.
* @param buttonsJustReleased
* buttons just released.
* @param buttonsHeld
* buttons just pressed.
*/ */
public NunchukButtonsEvent(int id, short buttonsJustPressed, public NunchukButtonsEvent(int id, short buttonsJustPressed,
short buttonsJustReleased, short buttonsHeld) { short buttonsJustReleased, short buttonsHeld) {
super(id, buttonsJustPressed, buttonsJustReleased, buttonsHeld); super(id, buttonsJustPressed, buttonsJustReleased, buttonsHeld);
} }
/* Button Z */ /* Button Z */
public boolean isButtonZJustPressed() { public boolean isButtonZJustPressed() {
@@ -57,7 +62,7 @@ public class NunchukButtonsEvent extends ButtonsEvent {
public boolean isButtonZPressed() { public boolean isButtonZPressed() {
return isButtonPressed(NUNCHUK_BUTTON_Z); return isButtonPressed(NUNCHUK_BUTTON_Z);
} }
/* Button Z */ /* Button Z */
public boolean isButtonCJustPressed() { public boolean isButtonCJustPressed() {
@@ -82,5 +87,4 @@ public class NunchukButtonsEvent extends ButtonsEvent {
+ super.toString(); + super.toString();
} }
} }

View File

@@ -103,9 +103,7 @@ public class NunchukEvent extends ExpansionEvent {
nunchukJoystickEvent = new JoystickEvent(id, angle, magnitude, max1, nunchukJoystickEvent = new JoystickEvent(id, angle, magnitude, max1,
max2, min1, min2, center1, center2); max2, min1, min2, center1, center2);
} }
/** /**
* Tell if there is a nunchuk motion sensing Event. * Tell if there is a nunchuk motion sensing Event.
* *
@@ -114,7 +112,7 @@ public class NunchukEvent extends ExpansionEvent {
public boolean isThereMotionSensingEvent() { public boolean isThereMotionSensingEvent() {
return nunchukMotionSensingEvent != null; return nunchukMotionSensingEvent != null;
} }
/** /**
* Tell if there is a nunchuk joystick event. * Tell if there is a nunchuk joystick event.
* *

View File

@@ -45,10 +45,15 @@ public class WiimoteButtonsEvent extends ButtonsEvent {
/** /**
* Constructor of the wiimote button Event. * Constructor of the wiimote button Event.
* @param id id of the wiimote. *
* @param buttonsJustPressed buttons just pressed. * @param id
* @param buttonsJustReleased buttons just released. * id of the wiimote.
* @param buttonsHeld buttons held. * @param buttonsJustPressed
* buttons just pressed.
* @param buttonsJustReleased
* buttons just released.
* @param buttonsHeld
* buttons held.
*/ */
public WiimoteButtonsEvent(int id, short buttonsJustPressed, public WiimoteButtonsEvent(int id, short buttonsJustPressed,
short buttonsJustReleased, short buttonsHeld) { short buttonsJustReleased, short buttonsHeld) {

View File

@@ -103,9 +103,10 @@ public class EventsGatherer {
* @param distance * @param distance
* Pixel Distance between first two dots. * Pixel Distance between first two dots.
*/ */
public void prepareIRevent(int x, int y, float z, int ax, int ay, int xVRes, public void prepareIRevent(int x, int y, float z, int ax, int ay,
int yVRes, int xOffset, int yOffset, short sensorBarPostion, int xVRes, int yVRes, int xOffset, int yOffset,
short screenAsPectRatio, short irSensitivity, float distance) { short sensorBarPostion, short screenAsPectRatio,
short irSensitivity, float distance) {
genericEvent.prepareIRevent(x, y, z, ax, ay, xVRes, yVRes, xOffset, genericEvent.prepareIRevent(x, y, z, ax, ay, xVRes, yVRes, xOffset,
yOffset, sensorBarPostion, screenAsPectRatio, irSensitivity, yOffset, sensorBarPostion, screenAsPectRatio, irSensitivity,
distance); distance);
@@ -179,7 +180,7 @@ public class EventsGatherer {
ya, ar, ap, x, y, z, xx, yy, zz); ya, ar, ap, x, y, z, xx, yy, zz);
} }
} }
/** /**
* Set a NunchukEvent to the prepared . * Set a NunchukEvent to the prepared .
* *
@@ -238,19 +239,20 @@ public class EventsGatherer {
* @param center2 * @param center2
* center joystick value 2. * center joystick value 2.
*/ */
public void addNunchunkEventToPreparedWiimoteEvent(short buttonsJustPressed, public void addNunchunkEventToPreparedWiimoteEvent(
short buttonsJustReleased, short buttonsHeld, short buttonsJustPressed, short buttonsJustReleased,
float orientationThreshold, int accelerationThreshold, short buttonsHeld, float orientationThreshold,
boolean smoothingState, float alphaSmooth, float r, float p, int accelerationThreshold, boolean smoothingState,
float ya, float ar, float ap, float x, float y, float z, short xx, float alphaSmooth, float r, float p, float ya, float ar, float ap,
short yy, short zz, float angle, float magnitude, short max1, float x, float y, float z, short xx, short yy, short zz,
short max2, short min1, short min2, short center1, short center2){ float angle, float magnitude, short max1, short max2, short min1,
short min2, short center1, short center2) {
if (genericEvent != null) { if (genericEvent != null) {
genericEvent.setNunchukEvent(buttonsJustPressed, genericEvent.setNunchukEvent(buttonsJustPressed,
buttonsJustReleased, buttonsHeld, orientationThreshold, buttonsJustReleased, buttonsHeld, orientationThreshold,
accelerationThreshold, smoothingState, alphaSmooth, r, p, ya, accelerationThreshold, smoothingState, alphaSmooth, r, p,
ar, ap, x, y, z, xx, yy, zz, angle, magnitude, max1, max2, ya, ar, ap, x, y, z, xx, yy, zz, angle, magnitude, max1,
min1, min2, center1, center2); max2, min1, min2, center1, center2);
} }
} }
@@ -307,7 +309,7 @@ public class EventsGatherer {
DisconnectionEvent evt = new DisconnectionEvent(id); DisconnectionEvent evt = new DisconnectionEvent(id);
addEvent(evt); addEvent(evt);
} }
/** /**
* Add a NunchukInsertedEvent to the gatherer. * Add a NunchukInsertedEvent to the gatherer.
* *
@@ -318,7 +320,7 @@ public class EventsGatherer {
NunchukInsertedEvent evt = new NunchukInsertedEvent(id); NunchukInsertedEvent evt = new NunchukInsertedEvent(id);
addEvent(evt); addEvent(evt);
} }
/** /**
* Add a NunchukRemovedEvent to the gatherer. * Add a NunchukRemovedEvent to the gatherer.
* *

View File

@@ -18,24 +18,20 @@ package wiiusej.wiiusejevents.utils;
import wiiusej.wiiusejevents.wiiuseapievents.WiiUseApiEvent; import wiiusej.wiiusejevents.wiiuseapievents.WiiUseApiEvent;
/** /**
* This is the interface to implement to listen to events from the wiiuse API. * This is the interface to implement to listen to events from the wiiuse API.
* *
* @author guiguito * @author guiguito
*/ */
public interface WiiUseApiListener extends java.util.EventListener { public interface WiiUseApiListener extends java.util.EventListener {
/** /**
* Method called when a WiiUseApiEvent occurs. * Method called when a WiiUseApiEvent occurs. A WiiUseApiEvent can be : -
* A WiiUseApiEvent can be : * WiimoteEvent (Storing ButtonsEvent and eventually IREvent and
* - WiimoteEvent (Storing ButtonsEvent and * MotionSensingEvent) - StatusEvent - DisconnectionEvent
* eventually IREvent and MotionSensingEvent) *
* - StatusEvent
* - DisconnectionEvent
* @param e * @param e
*/ */
void onWiiUseApiEvent(WiiUseApiEvent e); void onWiiUseApiEvent(WiiUseApiEvent e);
} }

View File

@@ -26,9 +26,10 @@ import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
/** /**
* This is the interface to implement to listen to events from wiimotes. * This is the interface to implement to listen to events from wiimotes. The
* The differents methods are called in this order : * differents methods are called in this order : onButtonsEvent, onIrEvent,
* onButtonsEvent, onIrEvent, onMotionSensingEvent, onStatusEvent, onDisconnectionEvent. * onMotionSensingEvent, onExpansionEvent, onStatusEvent, onDisconnectionEvent
* onNunchukInsertedEvent, onNunchukRemovedEvent.
* *
* @author guiguito * @author guiguito
*/ */
@@ -36,60 +37,71 @@ public interface WiimoteListener extends java.util.EventListener {
/** /**
* Method called on a button Event. * Method called on a button Event.
* @param e the buttonEvent with the last informations *
* about the buttons of the wiimote. * @param e
* the buttonEvent with the last informations about the buttons
* of the wiimote.
*/ */
void onButtonsEvent(WiimoteButtonsEvent e); void onButtonsEvent(WiimoteButtonsEvent e);
/** /**
* Method called when an IR event occurs. * Method called when an IR event occurs.
* @param e the IREvent with the IR points seen. *
* @param e
* the IREvent with the IR points seen.
*/ */
void onIrEvent(IREvent e); void onIrEvent(IREvent e);
/** /**
* Method called when a motion sensing event occurs. * Method called when a motion sensing event occurs.
* @param e the motion sensing event with orientation and acceleration. *
* @param e
* the motion sensing event with orientation and acceleration.
*/ */
void onMotionSensingEvent(MotionSensingEvent e); void onMotionSensingEvent(MotionSensingEvent e);
/** /**
* Method called when an expansion event occurs. * Method called when an expansion event occurs.
* @param e the expansion event occured. *
* @param e
* the expansion event occured.
*/ */
void onExpansionEvent(ExpansionEvent e); void onExpansionEvent(ExpansionEvent e);
/** /**
* Method called on a status event. * Method called on a status event. A status event occurs when : - we ask it -
* A status event occurs when : * an expansion controller has been plugged - an expansion controller has
* - we ask it * been unplugged This is where you can get the different values of the
* - an expansion controller has been plugged * parameters setup on your wiimote.
* - an expansion controller has been unplugged *
* This is where you can get the different values of * @param e
* the parameters setup on your wiimote. * the status event.
* @param e the status event.
*/ */
void onStatusEvent(StatusEvent e); void onStatusEvent(StatusEvent e);
/** /**
* This is the method called when a disconnection event occurs. * This is the method called when a disconnection event occurs. A
* A disconnection event happens when : * disconnection event happens when : - there are no battery left - the
* - there are no battery left * wiimote has just been turned off - the connection is dropped
* - the wiimote has just been turned off *
* - the connection is dropped * @param e
* @param e the disconnection event. * the disconnection event.
*/ */
void onDisconnectionEvent(DisconnectionEvent e); void onDisconnectionEvent(DisconnectionEvent e);
/** /**
* This is the method called when a NunchukInsertedEvent occurs. * This is the method called when a NunchukInsertedEvent occurs.
* @param e the NunchukInsertedEvent. *
* @param e
* the NunchukInsertedEvent.
*/ */
void onNunchukInsertedEvent(NunchukInsertedEvent e); void onNunchukInsertedEvent(NunchukInsertedEvent e);
/** /**
* This is the method called when a NunchukRemovedEvent occurs. * This is the method called when a NunchukRemovedEvent occurs.
* @param e the NunchukRemovedEvent. *
* @param e
* the NunchukRemovedEvent.
*/ */
void onNunchukRemovedEvent(NunchukRemovedEvent e); void onNunchukRemovedEvent(NunchukRemovedEvent e);
} }

View File

@@ -16,9 +16,9 @@
*/ */
package wiiusej.wiiusejevents.wiiuseapievents; package wiiusej.wiiusejevents.wiiuseapievents;
/** /**
* Class representing a disconnection event. * Class representing a disconnection event.
*
* @author guiguito * @author guiguito
*/ */
public class DisconnectionEvent extends WiiUseApiEvent { public class DisconnectionEvent extends WiiUseApiEvent {
@@ -30,14 +30,15 @@ public class DisconnectionEvent extends WiiUseApiEvent {
* the Wiimote id * the Wiimote id
*/ */
public DisconnectionEvent(int id) { public DisconnectionEvent(int id) {
super(id,WiiUseApiEvent.DISCONNECTION_EVENT); super(id, WiiUseApiEvent.DISCONNECTION_EVENT);
} }
@Override @Override
public String toString() { public String toString() {
String out = ""; String out = "";
/* Status */ /* Status */
out += "/*********** DISCONNECTION EVENT : WIIMOTE ID :" + super.getWiimoteId() + " ********/\n"; out += "/*********** DISCONNECTION EVENT : WIIMOTE ID :"
+ super.getWiimoteId() + " ********/\n";
return out; return out;
} }

View File

@@ -16,30 +16,35 @@
*/ */
package wiiusej.wiiusejevents.wiiuseapievents; package wiiusej.wiiusejevents.wiiuseapievents;
/** /**
* Event that represents the connection of a nunchuk to a wiimote. * Event that represents the connection of a nunchuk to a wiimote.
*
* @author guiguito * @author guiguito
* *
*/ */
public class NunchukInsertedEvent extends WiiUseApiEvent { public class NunchukInsertedEvent extends WiiUseApiEvent {
/** /**
* Construct the NunchukInsertedEvent setting up the id. * Construct the NunchukInsertedEvent setting up the id.
* @param id id of the wiimote. *
* @param id
* id of the wiimote.
*/ */
public NunchukInsertedEvent(int id) { public NunchukInsertedEvent(int id) {
super(id, WIIUSE_NUNCHUK_INSERTED); super(id, WIIUSE_NUNCHUK_INSERTED);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see wiiusej.wiiusejevents.WiiUseApiEvent#toString() * @see wiiusej.wiiusejevents.WiiUseApiEvent#toString()
*/ */
@Override @Override
public String toString() { public String toString() {
String out = ""; String out = "";
/* Status */ /* Status */
out += "/*********** NUNCHUK INSERTED EVENT : WIIMOTE ID :" + super.getWiimoteId() + " ********/\n"; out += "/*********** NUNCHUK INSERTED EVENT : WIIMOTE ID :"
+ super.getWiimoteId() + " ********/\n";
return out; return out;
} }

View File

@@ -16,29 +16,34 @@
*/ */
package wiiusej.wiiusejevents.wiiuseapievents; package wiiusej.wiiusejevents.wiiuseapievents;
/** /**
* Event that represents the connection of a nunchuk to a wiimote. * Event that represents the connection of a nunchuk to a wiimote.
*
* @author guiguito * @author guiguito
*/ */
public class NunchukRemovedEvent extends WiiUseApiEvent { public class NunchukRemovedEvent extends WiiUseApiEvent {
/** /**
* Construct the NunchukInsertedEvent setting up the id. * Construct the NunchukInsertedEvent setting up the id.
* @param id id of the wiimote. *
* @param id
* id of the wiimote.
*/ */
public NunchukRemovedEvent(int id) { public NunchukRemovedEvent(int id) {
super(id, WIIUSE_NUNCHUK_REMOVED); super(id, WIIUSE_NUNCHUK_REMOVED);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see wiiusej.wiiusejevents.WiiUseApiEvent#toString() * @see wiiusej.wiiusejevents.WiiUseApiEvent#toString()
*/ */
@Override @Override
public String toString() { public String toString() {
String out = ""; String out = "";
/* Status */ /* Status */
out += "/*********** NUNCHUK REMOVED EVENT : WIIMOTE ID :" + super.getWiimoteId() + " ********/\n"; out += "/*********** NUNCHUK REMOVED EVENT : WIIMOTE ID :"
+ super.getWiimoteId() + " ********/\n";
return out; return out;
} }

View File

@@ -157,9 +157,10 @@ public class WiimoteEvent extends WiiUseApiEvent {
* @param distance * @param distance
* Pixel Distance between first two dots * Pixel Distance between first two dots
*/ */
public void prepareIRevent(int x, int y, float z, int ax, int ay, int xVRes, public void prepareIRevent(int x, int y, float z, int ax, int ay,
int yVRes, int xOffset, int yOffset, short sensorBarPostion, int xVRes, int yVRes, int xOffset, int yOffset,
short screenAsPectRatio, short irSensitivity, float distance) { short sensorBarPostion, short screenAsPectRatio,
short irSensitivity, float distance) {
if (infraredEvent == null) { if (infraredEvent == null) {
infraredEvent = new IREvent(getWiimoteId(), x, y, z, ax, ay, xVRes, infraredEvent = new IREvent(getWiimoteId(), x, y, z, ax, ay, xVRes,
yVRes, xOffset, yOffset, sensorBarPostion, yVRes, xOffset, yOffset, sensorBarPostion,