diff --git a/WiiUseJ/src/wiiusej/WiiUseApi.java b/WiiUseJ/src/wiiusej/WiiUseApi.java index 5d5f06c..428f522 100644 --- a/WiiUseJ/src/wiiusej/WiiUseApi.java +++ b/WiiUseJ/src/wiiusej/WiiUseApi.java @@ -36,7 +36,7 @@ public class WiiUseApi { * * @return the only instace of WiiUseApi. */ - static WiiUseApi getInstance() { + protected static WiiUseApi getInstance() { return instance; } @@ -334,7 +334,8 @@ public class WiiUseApi { * Force the bluetooth stack type.(useful only for windows) * * @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. */ native void windowsSetBluetoothStack(int bluetoothStackType); diff --git a/WiiUseJ/src/wiiusej/WiiUseApiManager.java b/WiiUseJ/src/wiiusej/WiiUseApiManager.java index 9ee79ac..23ddc6f 100644 --- a/WiiUseJ/src/wiiusej/WiiUseApiManager.java +++ b/WiiUseJ/src/wiiusej/WiiUseApiManager.java @@ -23,7 +23,6 @@ import javax.swing.event.EventListenerList; import wiiusej.wiiusejevents.utils.EventsGatherer; import wiiusej.wiiusejevents.utils.WiiUseApiListener; -import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; import wiiusej.wiiusejevents.wiiuseapievents.WiiUseApiEvent; /** @@ -46,14 +45,14 @@ public class WiiUseApiManager extends Thread { private int connected = -1; private AtomicBoolean running = new AtomicBoolean(false); - + private boolean leave = false; public static int WIIUSE_STACK_UNKNOWN = 0; public static int WIIUSE_STACK_MS = 1; public static int WIIUSE_STACK_BLUESOLEIL = 2; - public static WiiUseApiManager getInstance() { + private static WiiUseApiManager getInstance() { return instance; } @@ -112,13 +111,14 @@ public class WiiUseApiManager extends Thread { * @return an array with connected wiimotes or NULL. */ private synchronized static Wiimote[] getWiimotesPrivate(int nb, - boolean rumble, boolean forceStackType, int stackType) { + boolean rumble, boolean forceStackType, int stackType) { 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()) { - //connect wiimotes. + // connect wiimotes. int nbWiimotes = manager.connectWiimotes(nb, rumble, forceStackType, stackType); manager.wiimotes = new Wiimote[nbWiimotes]; @@ -131,7 +131,6 @@ public class WiiUseApiManager extends Thread { // Set leds on wiimote for (Wiimote wiimote : manager.wiimotes) { int id = wiimote.getId(); - short leds = 0; if (id % 4 == 0) { wiimote.setLeds(true, true, true, true); } else if (id % 4 == 1) { @@ -156,13 +155,13 @@ public class WiiUseApiManager extends Thread { } } } - - if (manager.connected == 0) {//no wiimote connected - //return empty array + + if (manager.connected == 0) {// no wiimote connected + // return empty array return new Wiimote[0]; } - if (!manager.isAlive())//start wiiuseJ polling + if (!manager.isAlive())// start wiiuseJ polling manager.start(); manager.semaphore.release(1); @@ -208,7 +207,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote to disconnect. */ - public void closeConnection(int id) { + protected void closeConnection(int id) { int index = 0; boolean found = false; while (index < wiimotes.length && !found) { @@ -236,30 +235,32 @@ public class WiiUseApiManager extends Thread { * * @return the number of wiimotes connected. */ - public int getNbConnectedWiimotes() { - return connected; + public static int getNbConnectedWiimotes() { + return getInstance().connected; } /** * Stop thread and shutdown wiiuse Api. */ - public void shutdown() { - if (connected > 0) { - for (Wiimote wim : wiimotes) { + public static void shutdown() { + WiiUseApiManager manager = getInstance(); + if (manager.connected > 0) { + for (Wiimote wim : manager.wiimotes) { if (wim != null) wim.disconnect(); } } - running.set(false); - wiiuse.cleanUp(); + manager.running.set(false); + 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(){ - leave = true; - shutdown(); + public static void definitiveShutdown() { + getInstance().leave = true; + shutdown(); } /** @@ -268,7 +269,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void activateRumble(int id) { + protected void activateRumble(int id) { wiiuse.activateRumble(id); } @@ -278,7 +279,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void deactivateRumble(int id) { + protected void deactivateRumble(int id) { wiiuse.deactivateRumble(id); } @@ -288,7 +289,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void activateIRTRacking(int id) { + protected void activateIRTRacking(int id) { wiiuse.activateIRTracking(id); } @@ -298,7 +299,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void deactivateIRTRacking(int id) { + protected void deactivateIRTRacking(int id) { wiiuse.deactivateIRTracking(id); } @@ -308,7 +309,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void activateMotionSensing(int id) { + protected void activateMotionSensing(int id) { wiiuse.activateMotionSensing(id); } @@ -318,7 +319,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void deactivateMotionSensing(int id) { + protected void deactivateMotionSensing(int id) { wiiuse.deactivateMotionSensing(id); } @@ -328,7 +329,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void activateSmoothing(int id) { + protected void activateSmoothing(int id) { wiiuse.activateSmoothing(id); } @@ -338,7 +339,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void deactivateSmoothing(int id) { + protected void deactivateSmoothing(int id) { wiiuse.deactivateSmoothing(id); } @@ -348,7 +349,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void activateContinuous(int id) { + protected void activateContinuous(int id) { wiiuse.activateContinuous(id); } @@ -358,7 +359,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void deactivateContinuous(int id) { + protected void deactivateContinuous(int id) { wiiuse.deactivateContinuous(id); } @@ -376,7 +377,8 @@ public class WiiUseApiManager extends Thread { * @param l4 * 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); } @@ -389,7 +391,7 @@ public class WiiUseApiManager extends Thread { * @param th * threshold in degrees. */ - public void setOrientationThreshold(int id, float th) { + protected void setOrientationThreshold(int id, float th) { wiiuse.setOrientThreshold(id, th); } @@ -402,7 +404,7 @@ public class WiiUseApiManager extends Thread { * @param th * threshold. */ - public void setAccelerationThreshold(int id, int th) { + protected void setAccelerationThreshold(int id, int th) { wiiuse.setAccelThreshold(id, th); } @@ -414,7 +416,7 @@ public class WiiUseApiManager extends Thread { * @param th * threshold. */ - public void setAlphaSmoothing(int id, float th) { + protected void setAlphaSmoothing(int id, float th) { wiiuse.setAlphaSmoothing(id, th); } @@ -424,7 +426,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void reSync(int id) { + protected void reSync(int id) { wiiuse.reSync(id); } @@ -434,7 +436,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void setScreenAspectRatio43(int id) { + protected void setScreenAspectRatio43(int id) { wiiuse.setScreenRatio43(id); } @@ -444,7 +446,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void setScreenAspectRatio169(int id) { + protected void setScreenAspectRatio169(int id) { wiiuse.setScreenRatio169(id); } @@ -454,7 +456,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void setSensorBarAboveScreen(int id) { + protected void setSensorBarAboveScreen(int id) { wiiuse.setSensorBarAboveScreen(id); } @@ -464,7 +466,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void setSensorBarBelowScreen(int id) { + protected void setSensorBarBelowScreen(int id) { wiiuse.setSensorBarBelowScreen(id); } @@ -480,7 +482,7 @@ public class WiiUseApiManager extends Thread { * @param y * 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); } @@ -490,7 +492,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote. */ - public void getStatus(int id) { + protected void getStatus(int id) { wiiuse.getStatus(id); } @@ -505,7 +507,8 @@ public class WiiUseApiManager extends Thread { * The timeout in millisecondsd to wait for an expansion * handshake. */ - public void setTimeout(int id, short normalTimeout, short expansionTimeout) { + protected void setTimeout(int id, short normalTimeout, + short 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 * level will be set to 5. */ - public void setIrSensitivity(int id, int level) { + protected void setIrSensitivity(int id, int level) { wiiuse.setIrSensitivity(id, level); } @@ -532,7 +535,7 @@ public class WiiUseApiManager extends Thread { * @param th * threshold in degrees. */ - public void setNunchukOrientationThreshold(int id, float th) { + protected void setNunchukOrientationThreshold(int id, float th) { wiiuse.setNunchukOrientationThreshold(id, th); } @@ -545,7 +548,7 @@ public class WiiUseApiManager extends Thread { * @param th * threshold. */ - public void setNunchukAccelerationThreshold(int id, int th) { + protected void setNunchukAccelerationThreshold(int id, int th) { wiiuse.setNunchukAccelerationThreshold(id, th); } @@ -606,7 +609,7 @@ public class WiiUseApiManager extends Thread { System.out.println("No wiimotes connected !"); } } - }//end while true + }// end while true } @@ -616,7 +619,7 @@ public class WiiUseApiManager extends Thread { * @param listener * a WiiUseApiListener */ - public void addWiiUseApiListener(WiiUseApiListener listener) { + protected void addWiiUseApiListener(WiiUseApiListener listener) { listeners.add(WiiUseApiListener.class, listener); } @@ -626,7 +629,7 @@ public class WiiUseApiManager extends Thread { * @param listener * a WiiUseApiListener */ - public void removeWiiUseApiListener(WiiUseApiListener listener) { + protected void removeWiiUseApiListener(WiiUseApiListener listener) { listeners.remove(WiiUseApiListener.class, listener); } @@ -635,7 +638,7 @@ public class WiiUseApiManager extends Thread { * * @return the list of WiiUseApiListeners. */ - public WiiUseApiListener[] getWiiUseApiListeners() { + protected WiiUseApiListener[] getWiiUseApiListeners() { return listeners.getListeners(WiiUseApiListener.class); } diff --git a/WiiUseJ/src/wiiusej/test/CloseGuiTestCleanly.java b/WiiUseJ/src/wiiusej/test/CloseGuiTestCleanly.java index e48f7a7..584f2d9 100644 --- a/WiiUseJ/src/wiiusej/test/CloseGuiTestCleanly.java +++ b/WiiUseJ/src/wiiusej/test/CloseGuiTestCleanly.java @@ -22,36 +22,37 @@ import wiiusej.WiiUseApiManager; /** * This class is used to close wiiusej cleanly. + * * @author guiguito */ -public class CloseGuiTestCleanly implements WindowListener{ +public class CloseGuiTestCleanly implements WindowListener { - public void windowOpened(WindowEvent e) { - //nothing - } + public void windowOpened(WindowEvent e) { + // nothing + } - public void windowClosing(WindowEvent e) { - WiiUseApiManager.getInstance().shutdown(); - } + public void windowClosing(WindowEvent e) { + WiiUseApiManager.definitiveShutdown(); + } - public void windowClosed(WindowEvent e) { - //nothing - } + public void windowClosed(WindowEvent e) { + // nothing + } - public void windowIconified(WindowEvent e) { - //nothing - } + public void windowIconified(WindowEvent e) { + // nothing + } - public void windowDeiconified(WindowEvent e) { - //nothing - } + public void windowDeiconified(WindowEvent e) { + // nothing + } - public void windowActivated(WindowEvent e) { - //nothing - } + public void windowActivated(WindowEvent e) { + // nothing + } + + public void windowDeactivated(WindowEvent e) { + // nothing + } - public void windowDeactivated(WindowEvent e) { - //nothing - } - } diff --git a/WiiUseJ/src/wiiusej/test/Main.java b/WiiUseJ/src/wiiusej/test/Main.java index be449c4..67ef279 100644 --- a/WiiUseJ/src/wiiusej/test/Main.java +++ b/WiiUseJ/src/wiiusej/test/Main.java @@ -21,23 +21,25 @@ import wiiusej.Wiimote; /** * Main Class to launch WiiuseJ GUI Test. + * * @author guiguito */ public class Main { - /** - * @param args the command line arguments - */ - public static void main(String[] args) { - Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true); + /** + * @param args + * the command line arguments + */ + public static void main(String[] args) { + Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true); WiiuseJGuiTest gui = null; if (wiimotes.length > 0) { gui = new WiiuseJGuiTest(wiimotes[0]); } else { gui = new WiiuseJGuiTest(); } - gui.setDefaultCloseOperation(gui.EXIT_ON_CLOSE); + gui.setDefaultCloseOperation(WiiuseJGuiTest.EXIT_ON_CLOSE); gui.setVisible(true); - } + } } diff --git a/WiiUseJ/src/wiiusej/test/NunchukGuiTest.java b/WiiUseJ/src/wiiusej/test/NunchukGuiTest.java index be6a495..bc42a51 100644 --- a/WiiUseJ/src/wiiusej/test/NunchukGuiTest.java +++ b/WiiUseJ/src/wiiusej/test/NunchukGuiTest.java @@ -37,324 +37,387 @@ import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent; import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; /** - * - * @author guiguito + * This frame is used to display events from a nunchuk. + * + * @author guiguito */ -public class NunchukGuiTest extends javax.swing.JFrame implements WiimoteListener { +public class NunchukGuiTest extends javax.swing.JFrame implements + WiimoteListener { - private Wiimote wiimote; - private boolean isThresholdsRequested = true; + private Wiimote wiimote; + private boolean isThresholdsRequested = true; - /** Creates new form NunchukGuiTest */ - public NunchukGuiTest(Wiimote wiimote) { - initComponents(); - this.wiimote = wiimote; - registerListeners(); - } + /** Creates new form NunchukGuiTest */ + public NunchukGuiTest(Wiimote wiimote) { + initComponents(); + this.wiimote = wiimote; + registerListeners(); + } - private void registerListeners() { - wiimote.addWiiMoteEventListeners(this); - wiimote.addWiiMoteEventListeners((OrientationPanel) orientationPanel); - wiimote.addWiiMoteEventListeners((GForcePanel) gForcePanel); - wiimote.addWiiMoteEventListeners((AccelerationPanel) rawAccelerationPanel); - wiimote.addWiiMoteEventListeners((NunchukJoystickEventPanel)joystickEventsPanel); - } + private void registerListeners() { + wiimote.addWiiMoteEventListeners(this); + wiimote.addWiiMoteEventListeners((OrientationPanel) orientationPanel); + wiimote.addWiiMoteEventListeners((GForcePanel) gForcePanel); + wiimote + .addWiiMoteEventListeners((AccelerationPanel) rawAccelerationPanel); + wiimote + .addWiiMoteEventListeners((NunchukJoystickEventPanel) joystickEventsPanel); + } - public void unRegisterListeners() { - wiimote.removeWiiMoteEventListeners((OrientationPanel) orientationPanel); - wiimote.removeWiiMoteEventListeners((GForcePanel) gForcePanel); - wiimote.removeWiiMoteEventListeners((AccelerationPanel) rawAccelerationPanel); - wiimote.removeWiiMoteEventListeners((NunchukJoystickEventPanel)joystickEventsPanel); - wiimote.removeWiiMoteEventListeners(this); - } - - public void requestThresholdsUpdate(){ - isThresholdsRequested = true; - } + public void unRegisterListeners() { + wiimote + .removeWiiMoteEventListeners((OrientationPanel) orientationPanel); + wiimote.removeWiiMoteEventListeners((GForcePanel) gForcePanel); + wiimote + .removeWiiMoteEventListeners((AccelerationPanel) rawAccelerationPanel); + wiimote + .removeWiiMoteEventListeners((NunchukJoystickEventPanel) joystickEventsPanel); + wiimote.removeWiiMoteEventListeners(this); + } - /** 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 regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { + public void requestThresholdsUpdate() { + isThresholdsRequested = true; + } - topPanels = new javax.swing.JPanel(); - joystickEventsPanel = joystickEventsPanel = new NunchukJoystickEventPanel(); - 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(); + /** + * 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 + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - setMinimumSize(new java.awt.Dimension(400, 400)); - getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS)); + topPanels = new javax.swing.JPanel(); + joystickEventsPanel = new NunchukJoystickEventPanel(); + 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)); - topPanels.setPreferredSize(new java.awt.Dimension(400, 200)); - topPanels.setLayout(new javax.swing.BoxLayout(topPanels, javax.swing.BoxLayout.LINE_AXIS)); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setMinimumSize(new java.awt.Dimension(400, 400)); + getContentPane().setLayout( + new javax.swing.BoxLayout(getContentPane(), + javax.swing.BoxLayout.Y_AXIS)); - joystickEventsPanel.setBackground(new java.awt.Color(0, 0, 0)); - 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))); - joystickEventsPanel.setToolTipText("JoystickEvent"); - joystickEventsPanel.setMinimumSize(new java.awt.Dimension(200, 200)); + topPanels.setMinimumSize(new java.awt.Dimension(400, 200)); + topPanels.setPreferredSize(new java.awt.Dimension(400, 200)); + topPanels.setLayout(new javax.swing.BoxLayout(topPanels, + javax.swing.BoxLayout.LINE_AXIS)); - javax.swing.GroupLayout joystickEventsPanelLayout = new javax.swing.GroupLayout(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) - ); + joystickEventsPanel.setBackground(new java.awt.Color(0, 0, 0)); + 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))); + joystickEventsPanel.setToolTipText("JoystickEvent"); + joystickEventsPanel.setMinimumSize(new java.awt.Dimension(200, 200)); - topPanels.add(joystickEventsPanel); - joystickEventsPanel.getAccessibleContext().setAccessibleName("Joystick"); + javax.swing.GroupLayout joystickEventsPanelLayout = new javax.swing.GroupLayout( + 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.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) - ); + rawAccelerationPanel.setToolTipText("Nunchuk MotionSensingEvent"); - 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); - 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) - ); + motionSensingEventsTabbedPanels.addTab("RawAcceleration", + rawAccelerationPanel); - 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); - 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("Orientation", orientationPanel); - 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); - 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) - ); + motionSensingEventsTabbedPanels.addTab("GForce", gForcePanel); - 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)); - setNunchukValuesPanel.setPreferredSize(new java.awt.Dimension(400, 200)); - setNunchukValuesPanel.setLayout(new javax.swing.BoxLayout(setNunchukValuesPanel, javax.swing.BoxLayout.Y_AXIS)); + getContentPane().add(topPanels); - nunchukButtonsEventPanel.setToolTipText("Nunchuk ButtonsEvent"); - nunchukButtonsEventPanel.setMinimumSize(new java.awt.Dimension(100, 100)); - nunchukButtonsEventPanel.setPreferredSize(new java.awt.Dimension(100, 100)); - nunchukButtonsEventPanel.setLayout(new javax.swing.BoxLayout(nunchukButtonsEventPanel, javax.swing.BoxLayout.LINE_AXIS)); + setNunchukValuesPanel.setMinimumSize(new java.awt.Dimension(400, 200)); + setNunchukValuesPanel + .setPreferredSize(new java.awt.Dimension(400, 200)); + setNunchukValuesPanel.setLayout(new javax.swing.BoxLayout( + setNunchukValuesPanel, javax.swing.BoxLayout.Y_AXIS)); - cButton.setText("C"); - cButton.setMaximumSize(new java.awt.Dimension(50, 50)); - cButton.setMinimumSize(new java.awt.Dimension(50, 50)); - cButton.setPreferredSize(new java.awt.Dimension(50, 50)); - nunchukButtonsEventPanel.add(cButton); + nunchukButtonsEventPanel.setToolTipText("Nunchuk ButtonsEvent"); + nunchukButtonsEventPanel + .setMinimumSize(new java.awt.Dimension(100, 100)); + nunchukButtonsEventPanel.setPreferredSize(new java.awt.Dimension(100, + 100)); + nunchukButtonsEventPanel.setLayout(new javax.swing.BoxLayout( + nunchukButtonsEventPanel, javax.swing.BoxLayout.LINE_AXIS)); - 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); + cButton.setText("C"); + cButton.setMaximumSize(new java.awt.Dimension(50, 50)); + cButton.setMinimumSize(new java.awt.Dimension(50, 50)); + cButton.setPreferredSize(new java.awt.Dimension(50, 50)); + 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)); - nunchukOrientationPanel.add(nunchukOrientationTextField); + setNunchukValuesPanel.add(nunchukButtonsEventPanel); - 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); + nunchukOrientationTextField.setPreferredSize(new java.awt.Dimension(60, + 20)); + nunchukOrientationPanel.add(nunchukOrientationTextField); - 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)); - nunchukAccelerationPanel.add(nunchukAccelerationTextField); + setNunchukValuesPanel.add(nunchukOrientationPanel); - 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); + nunchukAccelerationTextField.setPreferredSize(new java.awt.Dimension( + 60, 20)); + nunchukAccelerationPanel.add(nunchukAccelerationTextField); - 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); - 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))) - ); + messageText.setText("Message:"); - 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(); - }// //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 + getContentPane().add(setNunchukValuesPanel); - private void nunchukAccelerationButtonMousePressed(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 + pack(); + }// //GEN-END:initComponents - public void onButtonsEvent(WiimoteButtonsEvent arg0) { - //nothing to do - } + 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 - public void onIrEvent(IREvent arg0) { - //nothing to do - } + private void nunchukAccelerationButtonMousePressed( + 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) { - //nothing to do - } + public void onButtonsEvent(WiimoteButtonsEvent arg0) { + // nothing to do + } - public void onExpansionEvent(ExpansionEvent arg0) { - 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 onIrEvent(IREvent arg0) { + // nothing to do + } - public void onStatusEvent(StatusEvent arg0) { - //nothing to do - } + public void onMotionSensingEvent(MotionSensingEvent arg0) { + // nothing to do + } - public void onDisconnectionEvent(DisconnectionEvent arg0) { - //nothing - } + public void onExpansionEvent(ExpansionEvent arg0) { + 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) { - //nothing - } + public void onStatusEvent(StatusEvent arg0) { + // nothing to do + } - public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { - //nothing - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton cButton; - private javax.swing.JPanel gForcePanel; - private javax.swing.JPanel joystickEventsPanel; - private javax.swing.JPanel messagePanel; - private javax.swing.JLabel messageText; - private javax.swing.JPanel motionSensingEventsPanel; - private javax.swing.JTabbedPane motionSensingEventsTabbedPanels; - private javax.swing.JButton nunchukAccelerationButton; - private javax.swing.JPanel nunchukAccelerationPanel; - private javax.swing.JTextField nunchukAccelerationTextField; - private javax.swing.JPanel nunchukButtonsEventPanel; - 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 + public void onDisconnectionEvent(DisconnectionEvent arg0) { + // nothing + } + + public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) { + // nothing + } + + public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { + // nothing + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton cButton; + private javax.swing.JPanel gForcePanel; + private javax.swing.JPanel joystickEventsPanel; + private javax.swing.JPanel messagePanel; + private javax.swing.JLabel messageText; + private javax.swing.JPanel motionSensingEventsPanel; + private javax.swing.JTabbedPane motionSensingEventsTabbedPanels; + private javax.swing.JButton nunchukAccelerationButton; + private javax.swing.JPanel nunchukAccelerationPanel; + private javax.swing.JTextField nunchukAccelerationTextField; + private javax.swing.JPanel nunchukButtonsEventPanel; + 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 } diff --git a/WiiUseJ/src/wiiusej/test/Tests.java b/WiiUseJ/src/wiiusej/test/Tests.java index 55f32c2..6a3cdb7 100644 --- a/WiiUseJ/src/wiiusej/test/Tests.java +++ b/WiiUseJ/src/wiiusej/test/Tests.java @@ -34,7 +34,7 @@ import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent; import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; /** - * This class used to test WiiuseJ. + * This class used to test WiiuseJ in text mode. * * @author guiguito */ @@ -61,8 +61,6 @@ public class Tests implements WiimoteListener { } } - private static int nb = 0; - public void onButtonsEvent(WiimoteButtonsEvent e) { if (dump == DISPLAY_EACH_VALUE) { // System.out.println("*********** WIIMOTE ID : "+ @@ -326,7 +324,7 @@ public class Tests implements WiimoteListener { /* display motion sensing */ System.out.println(e); } - + public void onExpansionEvent(ExpansionEvent e) { System.out.println(e); } @@ -340,23 +338,23 @@ public class Tests implements WiimoteListener { System.out.println(" wiimote " + e.getWiimoteId() + "has been disconnected !!"); } - + public void onNunchukInsertedEvent(NunchukInsertedEvent e) { - System.out.println(e); + System.out.println(e); } public void onNunchukRemovedEvent(NunchukRemovedEvent e) { - System.out.println(e); + System.out.println(e); } /** * @param args */ public static void main(String[] args) { - Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(4, true); + Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true); if (wiimotes.length > 0) { System.out.println(wiimotes[0]); - Tests tests = new Tests(wiimotes[0]); + new Tests(wiimotes[0]); } else { System.out.println("No wiimotes found !!!"); } diff --git a/WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java b/WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java index 32ad9f5..2a8f229 100644 --- a/WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java +++ b/WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java @@ -90,9 +90,9 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements showExpansionWiimoteButton.setText("Show Nunchuk"); } }; - + /** - * default constructor + * default constructor */ public WiiuseJGuiTest() { initComponents(); @@ -231,7 +231,7 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements showExpansionWiimoteButton.setText("Show Nunchuk"); expansionFrame = new NunchukGuiTest(wiimote); expansionFrame - .setDefaultCloseOperation(expansionFrame.HIDE_ON_CLOSE); + .setDefaultCloseOperation(NunchukGuiTest.HIDE_ON_CLOSE); expansionFrame.addWindowListener(buttonSetter); isFirstStatusGot = true; } @@ -275,7 +275,7 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements showExpansionWiimoteButton.setEnabled(true); showExpansionWiimoteButton.setText("Show nunchuk"); expansionFrame = new NunchukGuiTest(wiimote); - expansionFrame.setDefaultCloseOperation(expansionFrame.HIDE_ON_CLOSE); + expansionFrame.setDefaultCloseOperation(NunchukGuiTest.HIDE_ON_CLOSE); expansionFrame.addWindowListener(buttonSetter); } @@ -1188,8 +1188,7 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements private void reconnectWiimotesButtonMousePressed( java.awt.event.MouseEvent evt) {// GEN-FIRST:event_reconnectWiimotesButtonMousePressed // stop manager - WiiUseApiManager manager = WiiUseApiManager.getInstance(); - manager.shutdown(); + WiiUseApiManager.shutdown(); // unregister previous wiimote if (wiimote != null) { @@ -1228,7 +1227,7 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements // get wiimote Wiimote[] listWiimote = WiiUseApiManager.getWiimotes(1, true); - if (listWiimote!=null && listWiimote.length > 0) { + if (listWiimote != null && listWiimote.length > 0) { wiimote = listWiimote[0]; // registers listeners @@ -1244,7 +1243,7 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements java.awt.event.MouseEvent evt) {// GEN-FIRST:event_showExpansionWiimoteButtonMousePressed if (expansionFrame != null) { if (showExpansionWiimoteButton.isEnabled()) {// expansion frame - // not shown + // not shown // show it expansionFrame.setEnabled(true); expansionFrame.setVisible(true); diff --git a/WiiUseJ/src/wiiusej/utils/AccelerationExpansionEventPanel.java b/WiiUseJ/src/wiiusej/utils/AccelerationExpansionEventPanel.java index ebc3dbe..cb3021f 100644 --- a/WiiUseJ/src/wiiusej/utils/AccelerationExpansionEventPanel.java +++ b/WiiUseJ/src/wiiusej/utils/AccelerationExpansionEventPanel.java @@ -21,17 +21,19 @@ import wiiusej.wiiusejevents.GenericEvent; import wiiusej.wiiusejevents.physicalevents.NunchukEvent; /** - * + * Panel to display Acceleration in a MotionSensingEvent from an expansion. + * * @author guiguito */ -public class AccelerationExpansionEventPanel extends AccelerationPanel{ +public class AccelerationExpansionEventPanel extends AccelerationPanel { - @Override - public RawAcceleration getRawAccelerationValue(GenericEvent e) { - if (e instanceof NunchukEvent){ - return ((NunchukEvent)e).getNunchukMotionSensingEvent().getRawAcceleration(); - } - return null; - } + @Override + public RawAcceleration getRawAccelerationValue(GenericEvent e) { + if (e instanceof NunchukEvent) { + return ((NunchukEvent) e).getNunchukMotionSensingEvent() + .getRawAcceleration(); + } + return null; + } } diff --git a/WiiUseJ/src/wiiusej/utils/AccelerationPanel.java b/WiiUseJ/src/wiiusej/utils/AccelerationPanel.java index 58659f6..6caa3b6 100644 --- a/WiiUseJ/src/wiiusej/utils/AccelerationPanel.java +++ b/WiiUseJ/src/wiiusej/utils/AccelerationPanel.java @@ -58,8 +58,8 @@ public abstract class AccelerationPanel extends javax.swing.JPanel implements public AccelerationPanel() { initComponents(); } - - /** + + /** * Constructor used to choose the colors used by the AccelerationPanel. * * @param bgColor @@ -150,18 +150,19 @@ public abstract class AccelerationPanel extends javax.swing.JPanel implements // 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 - * it initializes it with the dimensions of the panel. mImage is for double - * buffering. - */ - private void checkOffScreenImage() { - Dimension d = getSize(); - if (mImage == null || mImage.getWidth(null) != d.width || mImage.getHeight(null) != d.height) { - mImage = createImage(d.width, d.height); - } - } + + /** + * 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 + * buffering. + */ + private void checkOffScreenImage() { + Dimension d = getSize(); + if (mImage == null || mImage.getWidth(null) != d.width + || mImage.getHeight(null) != d.height) { + mImage = createImage(d.width, d.height); + } + } public void onButtonsEvent(WiimoteButtonsEvent arg0) { // nothing @@ -196,65 +197,66 @@ public abstract class AccelerationPanel extends javax.swing.JPanel implements public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { // nothing } - - private void draw(GenericEvent arg0){ - if (values.size() >= getWidth()) { + + private void draw(GenericEvent arg0) { + if (values.size() >= getWidth()) { // if there are as many values as pixels in the width // clear points values.clear(); } - RawAcceleration rawAcceleration = getRawAccelerationValue(arg0); - if (rawAcceleration != null) values.add(rawAcceleration); + RawAcceleration rawAcceleration = getRawAccelerationValue(arg0); + if (rawAcceleration != null) + values.add(rawAcceleration); repaint(); - } - - public abstract RawAcceleration getRawAccelerationValue(GenericEvent e); + } - public Color getBackgroundColor() { - return backgroundColor; - } + public abstract RawAcceleration getRawAccelerationValue(GenericEvent e); - public Color getLineColor() { - return lineColor; - } + public Color getBackgroundColor() { + return backgroundColor; + } - public Color getXColor() { - return xColor; - } + public Color getLineColor() { + return lineColor; + } - public Color getYColor() { - return yColor; - } + public Color getXColor() { + return xColor; + } - public Color getZColor() { - return zColor; - } + public Color getYColor() { + return yColor; + } - public void setBackgroundColor(Color backgroundColor) { - this.backgroundColor = backgroundColor; - } + public Color getZColor() { + return zColor; + } - public void setLineColor(Color lineColor) { - this.lineColor = lineColor; - } + public void setBackgroundColor(Color backgroundColor) { + this.backgroundColor = backgroundColor; + } - public void setXColor(Color xColor) { - this.xColor = xColor; - } + public void setLineColor(Color lineColor) { + this.lineColor = lineColor; + } - public void setYColor(Color yColor) { - this.yColor = yColor; - } + public void setXColor(Color xColor) { + 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. * WARNING: Do NOT modify this code. The content of this method is always diff --git a/WiiUseJ/src/wiiusej/utils/AccelerationWiimoteEventPanel.java b/WiiUseJ/src/wiiusej/utils/AccelerationWiimoteEventPanel.java index 25883f1..4e716de 100644 --- a/WiiUseJ/src/wiiusej/utils/AccelerationWiimoteEventPanel.java +++ b/WiiUseJ/src/wiiusej/utils/AccelerationWiimoteEventPanel.java @@ -21,17 +21,17 @@ import wiiusej.wiiusejevents.GenericEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; /** - * + * Panel to display Acceleration in a MotionSensingEvent from a wiimote. * @author guiguito */ -public class AccelerationWiimoteEventPanel extends AccelerationPanel{ +public class AccelerationWiimoteEventPanel extends AccelerationPanel { - @Override - public RawAcceleration getRawAccelerationValue(GenericEvent e) { - if (e instanceof MotionSensingEvent){ - return ((MotionSensingEvent)e).getRawAcceleration(); - } - return null; - } + @Override + public RawAcceleration getRawAccelerationValue(GenericEvent e) { + if (e instanceof MotionSensingEvent) { + return ((MotionSensingEvent) e).getRawAcceleration(); + } + return null; + } } diff --git a/WiiUseJ/src/wiiusej/utils/ButtonsEventPanel.java b/WiiUseJ/src/wiiusej/utils/ButtonsEventPanel.java index 58a1e44..ba01ef4 100644 --- a/WiiUseJ/src/wiiusej/utils/ButtonsEventPanel.java +++ b/WiiUseJ/src/wiiusej/utils/ButtonsEventPanel.java @@ -37,8 +37,8 @@ import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent; import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; /** - * This panel is used to see what buttons are pressed. It displays the result of - * last ButtonsEvent. + * This panel is used to see what buttons are pressed on the wiimote. It + * displays the result of last ButtonsEvent. * * @author guiguito */ @@ -303,42 +303,42 @@ public class ButtonsEventPanel extends javax.swing.JPanel implements // nothing } - public Color getHeldColor() { - return heldColor; - } + public Color getHeldColor() { + return heldColor; + } - public Color getPressedColor() { - return pressedColor; - } + public Color getPressedColor() { + return pressedColor; + } - public Color getReleasedColor() { - return releasedColor; - } + public Color getReleasedColor() { + return releasedColor; + } - public Shape getShape() { - return shape; - } + public Shape getShape() { + return shape; + } - public void setHeldColor(Color heldColor) { - this.heldColor = heldColor; - } + public void setHeldColor(Color heldColor) { + this.heldColor = heldColor; + } - public void setPressedColor(Color pressedColor) { - this.pressedColor = pressedColor; - } + public void setPressedColor(Color pressedColor) { + this.pressedColor = pressedColor; + } - public void setReleasedColor(Color releasedColor) { - this.releasedColor = releasedColor; - } + public void setReleasedColor(Color releasedColor) { + this.releasedColor = releasedColor; + } - public void setShape(Shape shape) { - this.shape = shape; - } - - public void clearView(){ - buttons = null; - repaint(); - } + public void setShape(Shape shape) { + this.shape = shape; + } + + public void clearView() { + buttons = null; + repaint(); + } /** * This method is called from within the constructor to initialize the form. diff --git a/WiiUseJ/src/wiiusej/utils/GForceExpansionEventPanel.java b/WiiUseJ/src/wiiusej/utils/GForceExpansionEventPanel.java index 5493520..d5852b0 100644 --- a/WiiUseJ/src/wiiusej/utils/GForceExpansionEventPanel.java +++ b/WiiUseJ/src/wiiusej/utils/GForceExpansionEventPanel.java @@ -21,7 +21,8 @@ import wiiusej.wiiusejevents.GenericEvent; import wiiusej.wiiusejevents.physicalevents.NunchukEvent; /** - * + * Panel to display GForce in a MotionSensingEvent from an expansion. + * * @author guiguito */ public class GForceExpansionEventPanel extends GForcePanel{ diff --git a/WiiUseJ/src/wiiusej/utils/GForcePanel.java b/WiiUseJ/src/wiiusej/utils/GForcePanel.java index ce002b8..14de5f2 100644 --- a/WiiUseJ/src/wiiusej/utils/GForcePanel.java +++ b/WiiUseJ/src/wiiusej/utils/GForcePanel.java @@ -42,7 +42,8 @@ import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; * * @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 Color xColor = Color.RED; @@ -195,68 +196,69 @@ public abstract class GForcePanel extends javax.swing.JPanel implements WiimoteL // nothing } - public void onNunchukRemovedEvent(NunchukRemovedEvent arg0){ + public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { // nothing } - - private void draw(GenericEvent arg0){ - if (values.size() >= getWidth()) { + + private void draw(GenericEvent arg0) { + if (values.size() >= getWidth()) { // if there are as many values as pixels in the width // clear points values.clear(); } - GForce gforce = getGForceValue(arg0); - if (gforce != null) values.add(gforce); + GForce gforce = getGForceValue(arg0); + if (gforce != null) + values.add(gforce); repaint(); - } - - public abstract GForce getGForceValue(GenericEvent e); + } - public Color getBackgroundColor() { - return backgroundColor; - } + public abstract GForce getGForceValue(GenericEvent e); - public Color getLineColor() { - return lineColor; - } + public Color getBackgroundColor() { + return backgroundColor; + } - public Color getXColor() { - return xColor; - } + public Color getLineColor() { + return lineColor; + } - public Color getYColor() { - return yColor; - } + public Color getXColor() { + return xColor; + } - public Color getZColor() { - return zColor; - } + public Color getYColor() { + return yColor; + } - public void setBackgroundColor(Color backgroundColor) { - this.backgroundColor = backgroundColor; - } + public Color getZColor() { + return zColor; + } - public void setLineColor(Color lineColor) { - this.lineColor = lineColor; - } + public void setBackgroundColor(Color backgroundColor) { + this.backgroundColor = backgroundColor; + } - public void setXColor(Color xColor) { - this.xColor = xColor; - } + public void setLineColor(Color lineColor) { + this.lineColor = lineColor; + } - public void setYColor(Color yColor) { - this.yColor = yColor; - } + public void setXColor(Color xColor) { + this.xColor = xColor; + } - public void setZColor(Color zColor) { - this.zColor = zColor; - } + public void setYColor(Color yColor) { + 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. * WARNING: Do NOT modify this code. The content of this method is always diff --git a/WiiUseJ/src/wiiusej/utils/GForceWiimoteEventPanel.java b/WiiUseJ/src/wiiusej/utils/GForceWiimoteEventPanel.java index 7b87ee4..1ae710e 100644 --- a/WiiUseJ/src/wiiusej/utils/GForceWiimoteEventPanel.java +++ b/WiiUseJ/src/wiiusej/utils/GForceWiimoteEventPanel.java @@ -21,16 +21,17 @@ import wiiusej.wiiusejevents.GenericEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; /** - * + * Panel to display GForce in a MotionSensingEvent from a wiimote. + * * @author guiguito */ public class GForceWiimoteEventPanel extends GForcePanel { - @Override - public GForce getGForceValue(GenericEvent e) { - if (e instanceof MotionSensingEvent) { - return ((MotionSensingEvent) e).getGforce(); - } - return null; - } + @Override + public GForce getGForceValue(GenericEvent e) { + if (e instanceof MotionSensingEvent) { + return ((MotionSensingEvent) e).getGforce(); + } + return null; + } } diff --git a/WiiUseJ/src/wiiusej/utils/IRPanel.java b/WiiUseJ/src/wiiusej/utils/IRPanel.java index 9b61852..c826fee 100644 --- a/WiiUseJ/src/wiiusej/utils/IRPanel.java +++ b/WiiUseJ/src/wiiusej/utils/IRPanel.java @@ -37,210 +37,217 @@ import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; /** * 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 { - private static int MAX_NB_POINTS = 4; - private Color color = Color.YELLOW; - private Color backgroundColor = Color.BLACK; - private Color borderColor = Color.BLUE; - private Shape shape; - private Image mImage;//image for double buffering - private int[] xCoordinates; - private int[] yCoordinates; - private int nbPoints = -1; + private static int MAX_NB_POINTS = 4; + private Color color = Color.YELLOW; + private Color backgroundColor = Color.BLACK; + private Color borderColor = Color.BLUE; + private Shape shape; + private Image mImage;// image for double buffering + private int[] xCoordinates; + private int[] yCoordinates; + private int nbPoints = -1; - /** - * Default constructor for IR Panel. - * Background color : black. - * IR sources color : yellow. - * 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); - initArrays(); - initComponents(); - } + /** + * Default constructor for IR Panel. Background color : black. IR sources + * color : yellow. 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); + initArrays(); + initComponents(); + } - /** - * Constructor used to parameterize the IR panel. - * @param bgColor color. - * @param ptColor IR sources color. - * @param bdColor border color of IR sources. - * @param sh Shape of the IR sources. - */ - public IRPanel(Color bgColor, Color ptColor, Color bdColor, Shape sh) { - backgroundColor = bgColor; - color = ptColor; - borderColor = bdColor; - shape = sh; - initArrays(); - initComponents(); - } + /** + * Constructor used to parameterize the IR panel. + * + * @param bgColor + * color. + * @param ptColor + * IR sources color. + * @param bdColor + * border color of IR sources. + * @param sh + * Shape of the IR sources. + */ + public IRPanel(Color bgColor, Color ptColor, Color bdColor, Shape sh) { + backgroundColor = bgColor; + color = ptColor; + borderColor = bdColor; + shape = sh; + initArrays(); + initComponents(); + } - private void initArrays() { - xCoordinates = new int[MAX_NB_POINTS]; - yCoordinates = new int[MAX_NB_POINTS]; - for (int i = 0; i < MAX_NB_POINTS; i++) { - xCoordinates[i] = -1; - yCoordinates[i] = -1; - } - } + private void initArrays() { + xCoordinates = new int[MAX_NB_POINTS]; + yCoordinates = new int[MAX_NB_POINTS]; + for (int i = 0; i < MAX_NB_POINTS; i++) { + xCoordinates[i] = -1; + yCoordinates[i] = -1; + } + } - @Override - public void paintComponent(Graphics g) { - super.paintComponent(g); - Dimension d = getSize(); - checkOffScreenImage(); - Graphics offG = mImage.getGraphics(); - offG.setColor(backgroundColor); - offG.fillRect(0, 0, d.width, d.height); - Graphics2D g2 = (Graphics2D) mImage.getGraphics(); - g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + @Override + public void paintComponent(Graphics g) { + super.paintComponent(g); + Dimension d = getSize(); + checkOffScreenImage(); + Graphics offG = mImage.getGraphics(); + offG.setColor(backgroundColor); + offG.fillRect(0, 0, d.width, d.height); + Graphics2D g2 = (Graphics2D) mImage.getGraphics(); + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); - //draw points - int i = 0; - while (i < nbPoints) { - double x = xCoordinates[i]; - double y = yCoordinates[i]; + // draw points + int i = 0; + while (i < nbPoints) { + double x = xCoordinates[i]; + double y = yCoordinates[i]; - long xx = getWidth() - Math.round((double) getWidth() * x / 1024.0); - long yy = getHeight() - Math.round((double) getHeight() * y / 768.0); - g2.translate(xx, yy); + long xx = getWidth() - Math.round((double) getWidth() * x / 1024.0); + long yy = getHeight() + - Math.round((double) getHeight() * y / 768.0); + g2.translate(xx, yy); - g2.setPaint(borderColor); - g2.draw(shape); - g2.setPaint(color); - g2.fill(shape); + g2.setPaint(borderColor); + g2.draw(shape); + g2.setPaint(color); + g2.fill(shape); - g2.setTransform(new AffineTransform()); - i++; - } - //put offscreen image on the screen - g.drawImage(mImage, 0, 0, null); - } + g2.setTransform(new AffineTransform()); + i++; + } + // 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 it initializes it - * with the dimensions of the panel. mImage is for double buffering. - */ - private void checkOffScreenImage() { - Dimension d = getSize(); - if (mImage == null || mImage.getWidth(null) != d.width || mImage.getHeight(null) != d.height) { - mImage = createImage(d.width, d.height); - } - } + /** + * 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 + * buffering. + */ + private void checkOffScreenImage() { + Dimension d = getSize(); + if (mImage == null || mImage.getWidth(null) != d.width + || mImage.getHeight(null) != d.height) { + mImage = createImage(d.width, d.height); + } + } - public void onButtonsEvent(WiimoteButtonsEvent arg0) { - //nothing - repaint(); - } + public void onButtonsEvent(WiimoteButtonsEvent arg0) { + // nothing + repaint(); + } - public void onIrEvent(IREvent arg0) { - //transfer points - wiiusej.values.IRSource[] points = arg0.getIRPoints(); - nbPoints = points.length; - for (int i = 0; i < points.length; i++) { - xCoordinates[i] = (int) points[i].getRx(); - yCoordinates[i] = (int) points[i].getRy(); - } - for (int i = points.length; i < MAX_NB_POINTS; i++) { - xCoordinates[i] = -1; - yCoordinates[i] = -1; - } + public void onIrEvent(IREvent arg0) { + // transfer points + wiiusej.values.IRSource[] points = arg0.getIRPoints(); + nbPoints = points.length; + for (int i = 0; i < points.length; i++) { + xCoordinates[i] = (int) points[i].getRx(); + yCoordinates[i] = (int) points[i].getRy(); + } + for (int i = points.length; i < MAX_NB_POINTS; i++) { + xCoordinates[i] = -1; + yCoordinates[i] = -1; + } - //redraw panel - repaint(); - } + // redraw panel + repaint(); + } - public void onMotionSensingEvent(MotionSensingEvent arg0) { - //nothing - } + public void onMotionSensingEvent(MotionSensingEvent arg0) { + // nothing + } - public void onExpansionEvent(ExpansionEvent e) { - // nothing - } + public void onExpansionEvent(ExpansionEvent e) { + // nothing + } - public void onStatusEvent(StatusEvent arg0) { - //nothing - } + public void onStatusEvent(StatusEvent arg0) { + // nothing + } - public void onDisconnectionEvent(DisconnectionEvent arg0) { - //clear previous points - for (int i = 0; i < MAX_NB_POINTS; i++) { - xCoordinates[i] = -1; - yCoordinates[i] = -1; - } - //redraw panel - repaint(); - } + public void onDisconnectionEvent(DisconnectionEvent arg0) { + // clear previous points + for (int i = 0; i < MAX_NB_POINTS; i++) { + xCoordinates[i] = -1; + yCoordinates[i] = -1; + } + // redraw panel + repaint(); + } - public void onNunchukInsertedEvent(NunchukInsertedEvent e) { - // nothing - } + public void onNunchukInsertedEvent(NunchukInsertedEvent e) { + // nothing + } - public void onNunchukRemovedEvent(NunchukRemovedEvent e) { - // nothing - } + public void onNunchukRemovedEvent(NunchukRemovedEvent e) { + // nothing + } - public Color getBackgroundColor() { - return backgroundColor; - } + public Color getBackgroundColor() { + return backgroundColor; + } - public Color getBorderColor() { - return borderColor; - } + public Color getBorderColor() { + return borderColor; + } - public Color getColor() { - return color; - } + public Color getColor() { + return color; + } - public Shape getShape() { - return shape; - } + public Shape getShape() { + return shape; + } - public void setBackgroundColor(Color backgroundColor) { - this.backgroundColor = backgroundColor; - } + public void setBackgroundColor(Color backgroundColor) { + this.backgroundColor = backgroundColor; + } - public void setBorderColor(Color borderColor) { - this.borderColor = borderColor; - } + public void setBorderColor(Color borderColor) { + this.borderColor = borderColor; + } - public void setColor(Color color) { - this.color = color; - } + public void setColor(Color color) { + this.color = color; + } - public void setShape(Shape shape) { - this.shape = shape; - } - - public void clearView(){ - initArrays(); - repaint(); - } + public void setShape(Shape shape) { + this.shape = shape; + } - /** 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 regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { + public void clearView() { + initArrays(); + repaint(); + } - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(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) - ); - }// //GEN-END:initComponents - // Variables declaration - do not modify//GEN-BEGIN:variables - // End of variables declaration//GEN-END:variables + /** + * 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 + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup(layout.createParallelGroup( + 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)); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables } diff --git a/WiiUseJ/src/wiiusej/utils/JoystickEventPanel.java b/WiiUseJ/src/wiiusej/utils/JoystickEventPanel.java index 62b7a2a..6f04ce6 100644 --- a/WiiUseJ/src/wiiusej/utils/JoystickEventPanel.java +++ b/WiiUseJ/src/wiiusej/utils/JoystickEventPanel.java @@ -37,188 +37,195 @@ import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; /** * 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 Color backgroundColor = Color.BLACK; - private Color borderColor = Color.RED; - private Color pointColor = Color.RED; - private Shape shape = new java.awt.geom.Ellipse2D.Double(0, 0, 30, 30); - private JoystickEvent lastJoystickEvent = null; + private Image mImage;// image for double buffering + private Color backgroundColor = Color.BLACK; + private Color borderColor = Color.RED; + private Color pointColor = Color.RED; + private Shape shape = new java.awt.geom.Ellipse2D.Double(0, 0, 30, 30); + private JoystickEvent lastJoystickEvent = null; - /** Creates new form JoystickPanel */ - public JoystickEventPanel() { - initComponents(); - } + /** Creates new form JoystickPanel */ + public JoystickEventPanel() { + initComponents(); + } - /** - * Constructor used to choose the colors used by the JoystickPanel. - * - * @param bgColor - * background color. - * @param pColor - * point color. - * @param bdColor - * border color for the shape. - * @param sh - * shape of what is drawn. - */ - public JoystickEventPanel(Color bgColor, Color pColor, Color bdColor, Shape sh) { - backgroundColor = bgColor; - pointColor = pColor; - shape = sh; - borderColor = bdColor; - initComponents(); - } + /** + * Constructor used to choose the colors used by the JoystickPanel. + * + * @param bgColor + * background color. + * @param pColor + * point color. + * @param bdColor + * border color for the shape. + * @param sh + * shape of what is drawn. + */ + public JoystickEventPanel(Color bgColor, Color pColor, Color bdColor, + Shape sh) { + backgroundColor = bgColor; + pointColor = pColor; + shape = sh; + borderColor = bdColor; + initComponents(); + } - @Override - public void paintComponent(Graphics g) { - super.paintComponent(g); - Dimension d = getSize(); - checkOffScreenImage(); - Graphics offG = mImage.getGraphics(); - offG.setColor(backgroundColor); - offG.fillRect(0, 0, d.width, d.height); - Graphics2D g2 = (Graphics2D) mImage.getGraphics(); - g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - g2.setTransform(new AffineTransform()); + @Override + public void paintComponent(Graphics g) { + super.paintComponent(g); + Dimension d = getSize(); + checkOffScreenImage(); + Graphics offG = mImage.getGraphics(); + offG.setColor(backgroundColor); + offG.fillRect(0, 0, d.width, d.height); + Graphics2D g2 = (Graphics2D) mImage.getGraphics(); + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + g2.setTransform(new AffineTransform()); - //compute center - int xCenter = (int) Math.round(d.getWidth() / 2.0); - int yCenter = (int) Math.round(d.getHeight() / 2.0); + // compute center + int xCenter = (int) Math.round(d.getWidth() / 2.0); + int yCenter = (int) Math.round(d.getHeight() / 2.0); - //compute coordinates - if (lastJoystickEvent != null) { - double xAng = Math.sin(lastJoystickEvent.getAngle() * Math.PI / 180.0) * lastJoystickEvent.getMagnitude(); - double yAng = Math.cos(lastJoystickEvent.getAngle() * Math.PI / 180.0) * lastJoystickEvent.getMagnitude(); - int dx = (int) Math.round(shape.getBounds().getWidth() / 2); - int dy = (int) Math.round(shape.getBounds().getHeight() / 2); - double xTemp = xAng * (xCenter - dx * 2); - double yTemp = yAng * (yCenter - dy * 2); - int x = xCenter - dx + (int) xTemp; - int y = yCenter - dy - (int) yTemp; -// System.out.println("--------------------------------------------------------------------"); -// System.out.println(lastJoystickEvent); -// System.out.println("xCenter ,yCenter : "+xCenter+" , "+yCenter); -// System.out.println("xAng, yAng : "+xAng+" , "+yAng); -// System.out.println("dx, dy : "+dx+" , "+dy); -// System.out.println("xTemp, yTemp : "+xTemp+" , "+yTemp); -// System.out.println("x, y : "+x+" , "+y); - //shape - g2.translate(x, y); - g2.setPaint(borderColor); - g2.draw(shape); - g2.setPaint(pointColor); - g2.fill(shape); - } - // put offscreen image on the screen - g.drawImage(mImage, 0, 0, null); - } + // compute coordinates + if (lastJoystickEvent != null) { + double xAng = Math.sin(lastJoystickEvent.getAngle() * Math.PI + / 180.0) + * lastJoystickEvent.getMagnitude(); + double yAng = Math.cos(lastJoystickEvent.getAngle() * Math.PI + / 180.0) + * lastJoystickEvent.getMagnitude(); + int dx = (int) Math.round(shape.getBounds().getWidth() / 2); + int dy = (int) Math.round(shape.getBounds().getHeight() / 2); + double xTemp = xAng * (xCenter - dx * 2); + double yTemp = yAng * (yCenter - dy * 2); + int x = xCenter - dx + (int) xTemp; + int y = yCenter - dy - (int) yTemp; + // System.out.println("--------------------------------------------------------------------"); + // System.out.println(lastJoystickEvent); + // System.out.println("xCenter ,yCenter : "+xCenter+" , "+yCenter); + // System.out.println("xAng, yAng : "+xAng+" , "+yAng); + // System.out.println("dx, dy : "+dx+" , "+dy); + // System.out.println("xTemp, yTemp : "+xTemp+" , "+yTemp); + // System.out.println("x, y : "+x+" , "+y); + // shape + g2.translate(x, y); + g2.setPaint(borderColor); + g2.draw(shape); + 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 - * it initializes it with the dimensions of the panel. mImage is for double - * buffering. - */ - private void checkOffScreenImage() { - Dimension d = getSize(); - if (mImage == null || mImage.getWidth(null) != d.width || mImage.getHeight(null) != d.height) { - mImage = createImage(d.width, d.height); - } - } + /** + * 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 + * buffering. + */ + private void checkOffScreenImage() { + Dimension d = getSize(); + if (mImage == null || mImage.getWidth(null) != d.width + || mImage.getHeight(null) != d.height) { + mImage = createImage(d.width, d.height); + } + } - public void onButtonsEvent(WiimoteButtonsEvent arg0) { - //nothing - } + public void onButtonsEvent(WiimoteButtonsEvent arg0) { + // nothing + } - public void onIrEvent(IREvent arg0) { - //nothing - } + public void onIrEvent(IREvent arg0) { + // nothing + } - public void onMotionSensingEvent(MotionSensingEvent arg0) { - //nothing - } + public void onMotionSensingEvent(MotionSensingEvent arg0) { + // nothing + } - public void onExpansionEvent(ExpansionEvent arg0) { - JoystickEvent joy = getJoystikEvent(arg0); - if (joy != null) { - lastJoystickEvent = joy; - } - repaint(); - } + public void onExpansionEvent(ExpansionEvent arg0) { + JoystickEvent joy = getJoystikEvent(arg0); + if (joy != null) { + lastJoystickEvent = joy; + } + repaint(); + } - public void onStatusEvent(StatusEvent arg0) { - //nothing - } + public void onStatusEvent(StatusEvent arg0) { + // nothing + } - public void onDisconnectionEvent(DisconnectionEvent arg0) { - //nothing - } + public void onDisconnectionEvent(DisconnectionEvent arg0) { + // nothing + } - public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) { - //nothing - } + public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) { + // nothing + } - public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { - //nothing - } + public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { + // nothing + } - public Color getBackgroundColor() { - return backgroundColor; - } + public Color getBackgroundColor() { + return backgroundColor; + } - public Color getPointColor() { - return pointColor; - } + public Color getPointColor() { + return pointColor; + } - public Color getBorderColor() { - return borderColor; - } + public Color getBorderColor() { + return borderColor; + } - public Shape getShape() { - return shape; - } + public Shape getShape() { + return shape; + } - public void setBackgroundColor(Color backgroundColor) { - this.backgroundColor = backgroundColor; - } + public void setBackgroundColor(Color backgroundColor) { + this.backgroundColor = backgroundColor; + } - public void setPointColor(Color pointColor) { - this.pointColor = pointColor; - } + public void setPointColor(Color pointColor) { + this.pointColor = pointColor; + } - public void setBorderColor(Color borderColor) { - this.borderColor = borderColor; - } + public void setBorderColor(Color borderColor) { + this.borderColor = borderColor; + } - public void setShape(Shape shape) { - this.shape = shape; - } + public void setShape(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. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { + /** + * 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 + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(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) - ); - }// //GEN-END:initComponents - // Variables declaration - do not modify//GEN-BEGIN:variables - // End of variables declaration//GEN-END:variables + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup(layout.createParallelGroup( + 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)); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables } diff --git a/WiiUseJ/src/wiiusej/utils/NunchukJoystickEventPanel.java b/WiiUseJ/src/wiiusej/utils/NunchukJoystickEventPanel.java index b2fbba4..a534751 100644 --- a/WiiUseJ/src/wiiusej/utils/NunchukJoystickEventPanel.java +++ b/WiiUseJ/src/wiiusej/utils/NunchukJoystickEventPanel.java @@ -22,15 +22,16 @@ import wiiusej.wiiusejevents.physicalevents.NunchukEvent; /** * Panel to display nunchuk joystick events. + * * @author guiguito */ public class NunchukJoystickEventPanel extends JoystickEventPanel { - @Override - public JoystickEvent getJoystikEvent(ExpansionEvent e) { - if (e instanceof NunchukEvent) { - return ((NunchukEvent) e).getNunchukJoystickEvent(); - } - return null; - } + @Override + public JoystickEvent getJoystikEvent(ExpansionEvent e) { + if (e instanceof NunchukEvent) { + return ((NunchukEvent) e).getNunchukJoystickEvent(); + } + return null; + } } diff --git a/WiiUseJ/src/wiiusej/utils/OrientationExpansionEventPanel.java b/WiiUseJ/src/wiiusej/utils/OrientationExpansionEventPanel.java index e1ed7ce..f5e3856 100644 --- a/WiiUseJ/src/wiiusej/utils/OrientationExpansionEventPanel.java +++ b/WiiUseJ/src/wiiusej/utils/OrientationExpansionEventPanel.java @@ -21,16 +21,18 @@ import wiiusej.wiiusejevents.GenericEvent; import wiiusej.wiiusejevents.physicalevents.NunchukEvent; /** - * + * Panel to display Orientation in a MotionSensingEvent from an expansion. + * * @author guiguito */ public class OrientationExpansionEventPanel extends OrientationPanel { - @Override - public Orientation getOrientationValue(GenericEvent e) { - if (e instanceof NunchukEvent) { - return ((NunchukEvent) e).getNunchukMotionSensingEvent().getOrientation(); - } - return null; - } + @Override + public Orientation getOrientationValue(GenericEvent e) { + if (e instanceof NunchukEvent) { + return ((NunchukEvent) e).getNunchukMotionSensingEvent() + .getOrientation(); + } + return null; + } } diff --git a/WiiUseJ/src/wiiusej/utils/OrientationPanel.java b/WiiUseJ/src/wiiusej/utils/OrientationPanel.java index b9b63a8..b298911 100644 --- a/WiiUseJ/src/wiiusej/utils/OrientationPanel.java +++ b/WiiUseJ/src/wiiusej/utils/OrientationPanel.java @@ -200,65 +200,66 @@ public abstract class OrientationPanel extends javax.swing.JPanel implements public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { // nothing } - - private void draw(GenericEvent arg0){ - if (values.size() >= getWidth()) { + + private void draw(GenericEvent arg0) { + if (values.size() >= getWidth()) { // if there are as many values as pixels in the width // clear points values.clear(); } - Orientation orientation = getOrientationValue(arg0); - if (orientation != null) values.add(orientation); + Orientation orientation = getOrientationValue(arg0); + if (orientation != null) + values.add(orientation); repaint(); - } - - public abstract Orientation getOrientationValue(GenericEvent e); + } - public Color getBackgroundColor() { - return backgroundColor; - } + public abstract Orientation getOrientationValue(GenericEvent e); - public Color getLineColor() { - return lineColor; - } + public Color getBackgroundColor() { + return backgroundColor; + } - public Color getPitchColor() { - return pitchColor; - } + public Color getLineColor() { + return lineColor; + } - public Color getRollColor() { - return rollColor; - } + public Color getPitchColor() { + return pitchColor; + } - public Color getYawColor() { - return yawColor; - } + public Color getRollColor() { + return rollColor; + } - public void setBackgroundColor(Color backgroundColor) { - this.backgroundColor = backgroundColor; - } + public Color getYawColor() { + return yawColor; + } - public void setLineColor(Color lineColor) { - this.lineColor = lineColor; - } + public void setBackgroundColor(Color backgroundColor) { + this.backgroundColor = backgroundColor; + } - public void setPitchColor(Color pitchColor) { - this.pitchColor = pitchColor; - } + public void setLineColor(Color lineColor) { + this.lineColor = lineColor; + } - public void setRollColor(Color rollColor) { - this.rollColor = rollColor; - } + public void setPitchColor(Color pitchColor) { + this.pitchColor = pitchColor; + } - public void setYawColor(Color yawColor) { - this.yawColor = yawColor; - } + public void setRollColor(Color rollColor) { + 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. * WARNING: Do NOT modify this code. The content of this method is always diff --git a/WiiUseJ/src/wiiusej/utils/OrientationWiimoteEventPanel.java b/WiiUseJ/src/wiiusej/utils/OrientationWiimoteEventPanel.java index 5aebd8f..e38f3c9 100644 --- a/WiiUseJ/src/wiiusej/utils/OrientationWiimoteEventPanel.java +++ b/WiiUseJ/src/wiiusej/utils/OrientationWiimoteEventPanel.java @@ -21,17 +21,18 @@ import wiiusej.wiiusejevents.GenericEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; /** - * + * Panel to display Orientation in a MotionSensingEvent from a wiimote. + * * @author guiguito */ -public class OrientationWiimoteEventPanel extends OrientationPanel{ +public class OrientationWiimoteEventPanel extends OrientationPanel { - @Override - public Orientation getOrientationValue(GenericEvent e) { - if (e instanceof MotionSensingEvent){ - return ((MotionSensingEvent)e).getOrientation(); - } - return null; - } + @Override + public Orientation getOrientationValue(GenericEvent e) { + if (e instanceof MotionSensingEvent) { + return ((MotionSensingEvent) e).getOrientation(); + } + return null; + } } diff --git a/WiiUseJ/src/wiiusej/values/GForce.java b/WiiUseJ/src/wiiusej/values/GForce.java index 9732121..da79ed2 100644 --- a/WiiUseJ/src/wiiusej/values/GForce.java +++ b/WiiUseJ/src/wiiusej/values/GForce.java @@ -18,6 +18,7 @@ package wiiusej.values; /** * Represents gravity force on each axis. + * * @author guiguito */ public class GForce { @@ -25,23 +26,27 @@ public class GForce { private float x; private float y; private float z; - + /** * Default constructor; */ - public GForce(){ + public GForce() { x = 0; y = 0; z = 0; } - + /** * Constructor with gravity force on each axis. - * @param xx x value - * @param yy x value - * @param zz x value + * + * @param xx + * 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; y = yy; z = zz; @@ -67,9 +72,9 @@ public class GForce { public float getZ() { return z; } - + @Override public String toString() { - return "Gravity force : ("+x+", "+y+","+z+")"; + return "Gravity force : (" + x + ", " + y + "," + z + ")"; } } diff --git a/WiiUseJ/src/wiiusej/values/IRSource.java b/WiiUseJ/src/wiiusej/values/IRSource.java index 7caef55..a738c05 100644 --- a/WiiUseJ/src/wiiusej/values/IRSource.java +++ b/WiiUseJ/src/wiiusej/values/IRSource.java @@ -18,16 +18,17 @@ package wiiusej.values; /** * Class used for IR sources. + * * @author guiguito */ -public class IRSource{ - +public class IRSource { + private int x; private int y; private short rx; private short ry; private short size; - + /** * Build an IR source with all details. * @@ -42,68 +43,64 @@ public class IRSource{ * @param si * 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; y = yy; rx = rxx; ry = ryy; size = si; } - - + /** * Return x interpolated coordinates. + * * @return the x */ public int getX() { return x; } - - /** * Return y interpolated coordinates. + * * @return the y */ public int getY() { return y; } - - /** * Return raw X coordinate (0-1023). + * * @return the rx */ public short getRx() { return rx; } - - /** * Return raw Y coordinate (0-1023). + * * @return the ry */ public short getRy() { return ry; } - - /** * Return size of the IR dot (0-15). + * * @return the size */ public short getSize() { return size; } - - @Override 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 + ")"; } } diff --git a/WiiUseJ/src/wiiusej/values/RawAcceleration.java b/WiiUseJ/src/wiiusej/values/RawAcceleration.java index 903a51c..83f9578 100644 --- a/WiiUseJ/src/wiiusej/values/RawAcceleration.java +++ b/WiiUseJ/src/wiiusej/values/RawAcceleration.java @@ -18,14 +18,15 @@ package wiiusej.values; /** * Represents raw acceleration on each axis. + * * @author guiguito */ public class RawAcceleration { - + private short x; private short y; private short z; - + /** * Default constructor; */ @@ -34,12 +35,16 @@ public class RawAcceleration { y = 0; z = 0; } - + /** * Constructor with raw acceleration on each axis. - * @param xx x value - * @param yy x value - * @param zz x value + * + * @param xx + * x value + * @param yy + * x value + * @param zz + * x value */ public RawAcceleration(short xx, short yy, short zz) { x = xx; @@ -53,6 +58,7 @@ public class RawAcceleration { public short getX() { return x; } + /** * @return the y */ @@ -66,10 +72,10 @@ public class RawAcceleration { public short getZ() { return z; } - + @Override public String toString() { - return "Raw acceleration : ("+x+", "+y+","+z+")"; + return "Raw acceleration : (" + x + ", " + y + "," + z + ")"; } } diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/ButtonsEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/ButtonsEvent.java index a6a61bf..d9705fa 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/ButtonsEvent.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/ButtonsEvent.java @@ -20,28 +20,34 @@ import wiiusej.wiiusejevents.GenericEvent; /** * Class which represents a buttons event. + * * @author guiguito */ -public abstract class ButtonsEvent extends GenericEvent{ - +public abstract class ButtonsEvent extends GenericEvent { + /* Buttons */ private short buttonsJustPressed = 0; private short buttonsJustReleased = 0; private short buttonsHeld = 0; - + /** * Constructor of the button Event. - * @param id id of the wiimote concerned. - * @param buttonsJustPressed buttons just pressed. - * @param buttonsJustReleased buttons just released. - * @param buttonsHeld buttons just held. + * + * @param id + * id of the wiimote concerned. + * @param buttonsJustPressed + * buttons just pressed. + * @param buttonsJustReleased + * buttons just released. + * @param buttonsHeld + * buttons just held. */ public ButtonsEvent(int id, short buttonsJustPressed, - short buttonsJustReleased, short buttonsHeld){ + short buttonsJustReleased, short buttonsHeld) { super(id); setAllButtons(buttonsJustPressed, buttonsJustReleased, buttonsHeld); } - + /** * Set all buttons in one method. * @@ -55,7 +61,7 @@ public abstract class ButtonsEvent extends GenericEvent{ this.buttonsJustReleased = buttonsJustReleased; this.buttonsHeld = buttonsHeld; } - + /** * Get the short storing the buttons just pressed * @@ -82,7 +88,7 @@ public abstract class ButtonsEvent extends GenericEvent{ public short getButtonsHeld() { return buttonsHeld; } - + /** **************** BUTTONS Methods ***************** */ /* generic button functions */ @@ -102,11 +108,12 @@ public abstract class ButtonsEvent extends GenericEvent{ protected boolean isButtonHeld(short buttonBitsDefinition) { return buttonTest(buttonBitsDefinition, buttonsHeld); } - + protected boolean isButtonPressed(short buttonBitsDefinition) { - return isButtonHeld(buttonBitsDefinition)||isButtonJustPressed(buttonBitsDefinition); - } - + return isButtonHeld(buttonBitsDefinition) + || isButtonJustPressed(buttonBitsDefinition); + } + @Override public String toString() { String out = ""; diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/ExpansionEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/ExpansionEvent.java index bcd4425..868f33c 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/ExpansionEvent.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/ExpansionEvent.java @@ -18,19 +18,20 @@ package wiiusej.wiiusejevents.physicalevents; import wiiusej.wiiusejevents.GenericEvent; - /** - * Mother Class of all expansions. + * Mother Class of all expansions event. + * * @author guiguito */ public abstract class ExpansionEvent extends GenericEvent { - - + /** * 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); } diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/NunchukButtonsEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/NunchukButtonsEvent.java index 14866f2..b6584d6 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/NunchukButtonsEvent.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/NunchukButtonsEvent.java @@ -27,19 +27,24 @@ public class NunchukButtonsEvent extends ButtonsEvent { private static short NUNCHUK_BUTTON_Z = 0x01; private static short NUNCHUK_BUTTON_C = 0x02; private static short NUNCHUK_BUTTON_ALL = 0x03; - + /** * Constructor of the nunchuk button Event. - * @param id id of the wiimote. - * @param buttonsJustPressed buttons just pressed. - * @param buttonsJustReleased buttons just released. - * @param buttonsHeld buttons just pressed. + * + * @param id + * id of the wiimote. + * @param buttonsJustPressed + * buttons just pressed. + * @param buttonsJustReleased + * buttons just released. + * @param buttonsHeld + * buttons just pressed. */ public NunchukButtonsEvent(int id, short buttonsJustPressed, short buttonsJustReleased, short buttonsHeld) { super(id, buttonsJustPressed, buttonsJustReleased, buttonsHeld); } - + /* Button Z */ public boolean isButtonZJustPressed() { @@ -57,7 +62,7 @@ public class NunchukButtonsEvent extends ButtonsEvent { public boolean isButtonZPressed() { return isButtonPressed(NUNCHUK_BUTTON_Z); } - + /* Button Z */ public boolean isButtonCJustPressed() { @@ -82,5 +87,4 @@ public class NunchukButtonsEvent extends ButtonsEvent { + super.toString(); } - } diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/NunchukEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/NunchukEvent.java index e3fb076..eec7b97 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/NunchukEvent.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/NunchukEvent.java @@ -103,9 +103,7 @@ public class NunchukEvent extends ExpansionEvent { nunchukJoystickEvent = new JoystickEvent(id, angle, magnitude, max1, max2, min1, min2, center1, center2); } - - - + /** * Tell if there is a nunchuk motion sensing Event. * @@ -114,7 +112,7 @@ public class NunchukEvent extends ExpansionEvent { public boolean isThereMotionSensingEvent() { return nunchukMotionSensingEvent != null; } - + /** * Tell if there is a nunchuk joystick event. * diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/WiimoteButtonsEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/WiimoteButtonsEvent.java index 7ab19e7..106fc1c 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/WiimoteButtonsEvent.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/WiimoteButtonsEvent.java @@ -45,10 +45,15 @@ public class WiimoteButtonsEvent extends ButtonsEvent { /** * Constructor of the wiimote button Event. - * @param id id of the wiimote. - * @param buttonsJustPressed buttons just pressed. - * @param buttonsJustReleased buttons just released. - * @param buttonsHeld buttons held. + * + * @param id + * id of the wiimote. + * @param buttonsJustPressed + * buttons just pressed. + * @param buttonsJustReleased + * buttons just released. + * @param buttonsHeld + * buttons held. */ public WiimoteButtonsEvent(int id, short buttonsJustPressed, short buttonsJustReleased, short buttonsHeld) { diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/utils/EventsGatherer.java b/WiiUseJ/src/wiiusej/wiiusejevents/utils/EventsGatherer.java index 3e405bc..31ed13a 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/utils/EventsGatherer.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/utils/EventsGatherer.java @@ -103,9 +103,10 @@ public class EventsGatherer { * @param distance * Pixel Distance between first two dots. */ - public void prepareIRevent(int x, int y, float z, int ax, int ay, int xVRes, - int yVRes, int xOffset, int yOffset, short sensorBarPostion, - short screenAsPectRatio, short irSensitivity, float distance) { + public void prepareIRevent(int x, int y, float z, int ax, int ay, + int xVRes, int yVRes, int xOffset, int yOffset, + short sensorBarPostion, short screenAsPectRatio, + short irSensitivity, float distance) { genericEvent.prepareIRevent(x, y, z, ax, ay, xVRes, yVRes, xOffset, yOffset, sensorBarPostion, screenAsPectRatio, irSensitivity, distance); @@ -179,7 +180,7 @@ public class EventsGatherer { ya, ar, ap, x, y, z, xx, yy, zz); } } - + /** * Set a NunchukEvent to the prepared . * @@ -238,19 +239,20 @@ public class EventsGatherer { * @param center2 * center joystick value 2. */ - public void addNunchunkEventToPreparedWiimoteEvent(short buttonsJustPressed, - short buttonsJustReleased, short buttonsHeld, - float orientationThreshold, int accelerationThreshold, - boolean smoothingState, float alphaSmooth, float r, float p, - float ya, float ar, float ap, float x, float y, float z, short xx, - short yy, short zz, float angle, float magnitude, short max1, - short max2, short min1, short min2, short center1, short center2){ + public void addNunchunkEventToPreparedWiimoteEvent( + short buttonsJustPressed, short buttonsJustReleased, + short buttonsHeld, float orientationThreshold, + int accelerationThreshold, boolean smoothingState, + float alphaSmooth, float r, float p, float ya, float ar, float ap, + float x, float y, float z, short xx, short yy, short zz, + float angle, float magnitude, short max1, short max2, short min1, + short min2, short center1, short center2) { if (genericEvent != null) { genericEvent.setNunchukEvent(buttonsJustPressed, - buttonsJustReleased, buttonsHeld, orientationThreshold, - accelerationThreshold, smoothingState, alphaSmooth, r, p, ya, - ar, ap, x, y, z, xx, yy, zz, angle, magnitude, max1, max2, - min1, min2, center1, center2); + buttonsJustReleased, buttonsHeld, orientationThreshold, + accelerationThreshold, smoothingState, alphaSmooth, r, p, + ya, ar, ap, x, y, z, xx, yy, zz, angle, magnitude, max1, + max2, min1, min2, center1, center2); } } @@ -307,7 +309,7 @@ public class EventsGatherer { DisconnectionEvent evt = new DisconnectionEvent(id); addEvent(evt); } - + /** * Add a NunchukInsertedEvent to the gatherer. * @@ -318,7 +320,7 @@ public class EventsGatherer { NunchukInsertedEvent evt = new NunchukInsertedEvent(id); addEvent(evt); } - + /** * Add a NunchukRemovedEvent to the gatherer. * diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/utils/WiiUseApiListener.java b/WiiUseJ/src/wiiusej/wiiusejevents/utils/WiiUseApiListener.java index fb4b3b2..ee1ce80 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/utils/WiiUseApiListener.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/utils/WiiUseApiListener.java @@ -18,24 +18,20 @@ package wiiusej.wiiusejevents.utils; import wiiusej.wiiusejevents.wiiuseapievents.WiiUseApiEvent; - - /** * This is the interface to implement to listen to events from the wiiuse API. * * @author guiguito */ public interface WiiUseApiListener extends java.util.EventListener { - + /** - * Method called when a WiiUseApiEvent occurs. - * A WiiUseApiEvent can be : - * - WiimoteEvent (Storing ButtonsEvent and - * eventually IREvent and MotionSensingEvent) - * - StatusEvent - * - DisconnectionEvent + * Method called when a WiiUseApiEvent occurs. A WiiUseApiEvent can be : - + * WiimoteEvent (Storing ButtonsEvent and eventually IREvent and + * MotionSensingEvent) - StatusEvent - DisconnectionEvent + * * @param e */ void onWiiUseApiEvent(WiiUseApiEvent e); - + } diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/utils/WiimoteListener.java b/WiiUseJ/src/wiiusej/wiiusejevents/utils/WiimoteListener.java index 03d8837..d066516 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/utils/WiimoteListener.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/utils/WiimoteListener.java @@ -26,9 +26,10 @@ import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent; import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; /** - * This is the interface to implement to listen to events from wiimotes. - * The differents methods are called in this order : - * onButtonsEvent, onIrEvent, onMotionSensingEvent, onStatusEvent, onDisconnectionEvent. + * This is the interface to implement to listen to events from wiimotes. The + * differents methods are called in this order : onButtonsEvent, onIrEvent, + * onMotionSensingEvent, onExpansionEvent, onStatusEvent, onDisconnectionEvent + * onNunchukInsertedEvent, onNunchukRemovedEvent. * * @author guiguito */ @@ -36,60 +37,71 @@ public interface WiimoteListener extends java.util.EventListener { /** * 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); - + /** * 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); - + /** * 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); - + /** * Method called when an expansion event occurs. - * @param e the expansion event occured. + * + * @param e + * the expansion event occured. */ void onExpansionEvent(ExpansionEvent e); - + /** - * Method called on a status event. - * A status event occurs when : - * - we ask it - * - an expansion controller has been plugged - * - an expansion controller has been unplugged - * This is where you can get the different values of - * the parameters setup on your wiimote. - * @param e the status event. + * Method called on a status event. A status event occurs when : - we ask it - + * an expansion controller has been plugged - an expansion controller has + * been unplugged This is where you can get the different values of the + * parameters setup on your wiimote. + * + * @param e + * the status event. */ void onStatusEvent(StatusEvent e); /** - * This is the method called when a disconnection event occurs. - * A disconnection event happens when : - * - there are no battery left - * - the wiimote has just been turned off - * - the connection is dropped - * @param e the disconnection event. + * This is the method called when a disconnection event occurs. A + * disconnection event happens when : - there are no battery left - the + * wiimote has just been turned off - the connection is dropped + * + * @param e + * the disconnection event. */ void onDisconnectionEvent(DisconnectionEvent e); - + /** * This is the method called when a NunchukInsertedEvent occurs. - * @param e the NunchukInsertedEvent. + * + * @param e + * the NunchukInsertedEvent. */ void onNunchukInsertedEvent(NunchukInsertedEvent e); - + /** * This is the method called when a NunchukRemovedEvent occurs. - * @param e the NunchukRemovedEvent. + * + * @param e + * the NunchukRemovedEvent. */ void onNunchukRemovedEvent(NunchukRemovedEvent e); } diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/DisconnectionEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/DisconnectionEvent.java index 4662d61..1c844c7 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/DisconnectionEvent.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/DisconnectionEvent.java @@ -16,9 +16,9 @@ */ package wiiusej.wiiusejevents.wiiuseapievents; - /** * Class representing a disconnection event. + * * @author guiguito */ public class DisconnectionEvent extends WiiUseApiEvent { @@ -30,14 +30,15 @@ public class DisconnectionEvent extends WiiUseApiEvent { * the Wiimote id */ public DisconnectionEvent(int id) { - super(id,WiiUseApiEvent.DISCONNECTION_EVENT); + super(id, WiiUseApiEvent.DISCONNECTION_EVENT); } - + @Override public String toString() { String out = ""; /* Status */ - out += "/*********** DISCONNECTION EVENT : WIIMOTE ID :" + super.getWiimoteId() + " ********/\n"; + out += "/*********** DISCONNECTION EVENT : WIIMOTE ID :" + + super.getWiimoteId() + " ********/\n"; return out; } diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukInsertedEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukInsertedEvent.java index ce53fe7..6aff636 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukInsertedEvent.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukInsertedEvent.java @@ -16,30 +16,35 @@ */ package wiiusej.wiiusejevents.wiiuseapievents; - /** * Event that represents the connection of a nunchuk to a wiimote. + * * @author guiguito - * + * */ public class NunchukInsertedEvent extends WiiUseApiEvent { /** * Construct the NunchukInsertedEvent setting up the id. - * @param id id of the wiimote. + * + * @param id + * id of the wiimote. */ public NunchukInsertedEvent(int id) { super(id, WIIUSE_NUNCHUK_INSERTED); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see wiiusej.wiiusejevents.WiiUseApiEvent#toString() */ @Override public String toString() { String out = ""; /* Status */ - out += "/*********** NUNCHUK INSERTED EVENT : WIIMOTE ID :" + super.getWiimoteId() + " ********/\n"; + out += "/*********** NUNCHUK INSERTED EVENT : WIIMOTE ID :" + + super.getWiimoteId() + " ********/\n"; return out; } diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukRemovedEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukRemovedEvent.java index 50306bf..c9c585d 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukRemovedEvent.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukRemovedEvent.java @@ -16,29 +16,34 @@ */ package wiiusej.wiiusejevents.wiiuseapievents; - /** * Event that represents the connection of a nunchuk to a wiimote. + * * @author guiguito */ public class NunchukRemovedEvent extends WiiUseApiEvent { /** * Construct the NunchukInsertedEvent setting up the id. - * @param id id of the wiimote. + * + * @param id + * id of the wiimote. */ public NunchukRemovedEvent(int id) { super(id, WIIUSE_NUNCHUK_REMOVED); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see wiiusej.wiiusejevents.WiiUseApiEvent#toString() */ @Override public String toString() { String out = ""; /* Status */ - out += "/*********** NUNCHUK REMOVED EVENT : WIIMOTE ID :" + super.getWiimoteId() + " ********/\n"; + out += "/*********** NUNCHUK REMOVED EVENT : WIIMOTE ID :" + + super.getWiimoteId() + " ********/\n"; return out; } diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java index 3cdd204..04c1840 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java @@ -157,9 +157,10 @@ public class WiimoteEvent extends WiiUseApiEvent { * @param distance * Pixel Distance between first two dots */ - public void prepareIRevent(int x, int y, float z, int ax, int ay, int xVRes, - int yVRes, int xOffset, int yOffset, short sensorBarPostion, - short screenAsPectRatio, short irSensitivity, float distance) { + public void prepareIRevent(int x, int y, float z, int ax, int ay, + int xVRes, int yVRes, int xOffset, int yOffset, + short sensorBarPostion, short screenAsPectRatio, + short irSensitivity, float distance) { if (infraredEvent == null) { infraredEvent = new IREvent(getWiimoteId(), x, y, z, ax, ay, xVRes, yVRes, xOffset, yOffset, sensorBarPostion,