diff --git a/WiiUseJ/src/wiiusej/WiiUseApiManager.java b/WiiUseJ/src/wiiusej/WiiUseApiManager.java index 35549cb..aab1409 100644 --- a/WiiUseJ/src/wiiusej/WiiUseApiManager.java +++ b/WiiUseJ/src/wiiusej/WiiUseApiManager.java @@ -306,11 +306,11 @@ public class WiiUseApiManager extends Thread { requests.add(new FloatValueRequest(id, WiiUseApiRequest.WIIUSE_ALPHA_SMOOTHING_REQUEST, th)); } - + + //@TODO not used yet !! /** * Try to resync with the wiimote by starting a new handshake. * - * @TODO not used yet !! * @param id * id of the wiimote */ diff --git a/WiiUseJ/src/wiiusej/test/Main.java b/WiiUseJ/src/wiiusej/test/Main.java new file mode 100644 index 0000000..0f873bb --- /dev/null +++ b/WiiUseJ/src/wiiusej/test/Main.java @@ -0,0 +1,40 @@ +/** + * This file is part of WiiuseJ. + * + * WiiuseJ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * WiiuseJ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WiiuseJ. If not, see . + */ +package wiiusej.test; + +import wiiusej.WiiUseApiManager; +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); + if (wiimotes.length>0){ + WiiuseJGuiTest gui = new WiiuseJGuiTest(wiimotes[0]); + gui.setDefaultCloseOperation(gui.EXIT_ON_CLOSE); + gui.setVisible(true); + } + } + +} diff --git a/WiiUseJ/src/wiiusej/test/Tests.java b/WiiUseJ/src/wiiusej/test/Tests.java index c24ce9d..f9e20f9 100644 --- a/WiiUseJ/src/wiiusej/test/Tests.java +++ b/WiiUseJ/src/wiiusej/test/Tests.java @@ -47,7 +47,7 @@ public class Tests implements WiimoteListener { private Wiimote wiimote; - int dump = DUMP; + int dump = DISPLAY_EACH_VALUE; public Tests(Wiimote wim) { wiimote = wim; diff --git a/WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java b/WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java new file mode 100644 index 0000000..014f306 --- /dev/null +++ b/WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java @@ -0,0 +1,833 @@ +/** + * This file is part of WiiuseJ. + * + * WiiuseJ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * WiiuseJ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WiiuseJ. If not, see . + */ +package wiiusej.test; + +import java.awt.AWTException; +import java.awt.Robot; +import java.awt.event.InputEvent; +import java.util.logging.Level; +import java.util.logging.Logger; +import wiiusej.utils.IRPanel; +import wiiusej.Wiimote; +import wiiusej.utils.AccelerationPanel; +import wiiusej.utils.GForcePanel; +import wiiusej.utils.ButtonsEventPanel; +import wiiusej.utils.OrientationPanel; +import wiiusej.wiiuseapievents.ButtonsEvent; +import wiiusej.wiiuseapievents.DisconnectionEvent; +import wiiusej.wiiuseapievents.IREvent; +import wiiusej.wiiuseapievents.MotionSensingEvent; +import wiiusej.wiiuseapievents.StatusEvent; +import wiiusej.wiiuseapievents.WiimoteListener; + +/** + * Gui class to test WiiuseJ. + * @author guiguito + */ +public class WiiuseJGuiTest extends javax.swing.JFrame implements WiimoteListener { + + private Wiimote wiimote; + private Robot robot = null; + private boolean statusMotionRequested = false; + private boolean statusIRRequested = false; + + /** Creates new form WiiuseJGuiTest */ + public WiiuseJGuiTest(Wiimote wiimote) { + initComponents(); + this.wiimote = wiimote; + wiimote.addWiiMoteEventListeners((IRPanel) irViewPanel); + wiimote.addWiiMoteEventListeners((ButtonsEventPanel) buttonsPanel); + wiimote.addWiiMoteEventListeners((OrientationPanel) motionSensingPanel); + wiimote.addWiiMoteEventListeners((GForcePanel) gForcePanel); + wiimote.addWiiMoteEventListeners((AccelerationPanel) accelerationPanel); + wiimote.addWiiMoteEventListeners(this); + wiimote.deactivateContinuous(); + wiimote.deactivateSmoothing(); + wiimote.setScreenAspectRatio169(); + wiimote.setSensorBarBelowScreen(); + getStatusButtonMousePressed(null); + } + + public void onButtonsEvent(ButtonsEvent arg0) { + if (robot != null) { + if (arg0.isButtonAPressed()) { + robot.mousePress(InputEvent.BUTTON1_MASK); + + } + if (arg0.isButtonBPressed()) { + robot.mousePress(InputEvent.BUTTON2_MASK); + + } + if (arg0.isButtonOnePressed()) { + robot.mousePress(InputEvent.BUTTON3_MASK); + + } + if (arg0.isButtonAJustReleased()) { + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + } + if (arg0.isButtonBJustReleased()) { + robot.mouseRelease(InputEvent.BUTTON2_MASK); + + } + if (arg0.isButtonOneJustReleased()) { + robot.mouseRelease(InputEvent.BUTTON3_MASK); + + } + if (arg0.isButtonUpPressed()) {//mouse wheel up + robot.mouseWheel(-1); + } + if (arg0.isButtonDownPressed()) {//mouse wheel down + robot.mouseWheel(1); + } + + if (arg0.isButtonTwoPressed()) {//stop mouse control + mouseIRControlButtonMousePressed(null); + } + } + } + + public void onIrEvent(IREvent arg0) { + if (robot != null) {//if mouse control activated + robot.mouseMove(arg0.getX(), arg0.getY()); + } + if (statusIRRequested){ + xResolutionTextField.setText(""+arg0.getXVRes()); + yResolutionTextField.setText(""+arg0.getYVRes()); + statusIRRequested = false; + } + } + + public void onMotionSensingEvent(MotionSensingEvent arg0) { + if (statusMotionRequested){//Status requested + accelerationThresholdTextField.setText(""+arg0.getAccelerationThreshold()); + orientationThresholdTextField.setText(""+arg0.getOrientationThreshold()); + alphaSmoothingTextField.setText(""+arg0.getAlphaSmoothing()); + statusMotionRequested = false; + } + } + + public void onStatusEvent(StatusEvent arg0) { + messageText.setText("Status received !"); + batteryLevelText.setText(arg0.getBatteryLevel() + " %"); + led1Button.setEnabled(arg0.isLed1Set()); + led2Button.setEnabled(arg0.isLed2Set()); + led3Button.setEnabled(arg0.isLed3Set()); + led4Button.setEnabled(arg0.isLed4Set()); + //attachments + int eventType = arg0.getEventType(); + if (eventType == StatusEvent.WIIUSE_CLASSIC_CTRL_INSERTED){ + expansionText.setText("Classic control connected."); + }else + if (eventType == StatusEvent.WIIUSE_CLASSIC_CTRL_REMOVED){ + expansionText.setText("Classic control removed."); + }else + if (eventType == StatusEvent.WIIUSE_NUNCHUK_INSERTED){ + expansionText.setText("Nunchuk connected."); + }else + if (eventType == StatusEvent.WIIUSE_NUNCHUK_REMOVED){ + expansionText.setText("Nunchuk removed."); + }else + if (eventType == StatusEvent.WIIUSE_GUITAR_HERO_3_CTRL_INSERTED){ + expansionText.setText("Guitar Hero 3 control connected."); + }else + if (eventType == StatusEvent.WIIUSE_GUITAR_HERO_3_CTRL_REMOVED){ + expansionText.setText("Guitar Hero 3 control removed."); + } + } + + public void onDisconnectionEvent(DisconnectionEvent arg0) { + messageText.setText("Wiimote Disconnected !"); + } + + /** 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() { + + leftPanel = new javax.swing.JPanel(); + irViewPanel = new IRPanel(); + jTabbedPane1 = new javax.swing.JTabbedPane(); + motionSensingPanel = new OrientationPanel(); + gForcePanel = new wiiusej.utils.GForcePanel(); + accelerationPanel = new AccelerationPanel(); + rightPanel = new javax.swing.JPanel(); + fixedWiimotePanel = new javax.swing.JPanel(); + buttonsPanel = new ButtonsEventPanel(); + controlsPanel = new javax.swing.JPanel(); + activateRumblePanel = new javax.swing.JPanel(); + toggleRumbleButton = new javax.swing.JButton(); + deactivateRumblePanel = new javax.swing.JPanel(); + toggleIRTrackingButton = new javax.swing.JButton(); + activateIRtrackingPanel = new javax.swing.JPanel(); + toggleMotionSensingTrackingButton = new javax.swing.JButton(); + deactivateIRTrackingPanel = new javax.swing.JPanel(); + toggleSmoothingButton = new javax.swing.JButton(); + activateMotionSensingTrackingPanel = new javax.swing.JPanel(); + toggleContinuousButton = new javax.swing.JButton(); + deactivateMotionSensingTrackingPanel = new javax.swing.JPanel(); + led1Button = new javax.swing.JButton(); + led2Button = new javax.swing.JButton(); + led3Button = new javax.swing.JButton(); + led4Button = new javax.swing.JButton(); + setLedsButton = new javax.swing.JButton(); + activateSmoothingPanel = new javax.swing.JPanel(); + alphaSmoothingTextField = new javax.swing.JTextField(); + alphaSmoothingButton = new javax.swing.JButton(); + deactivateSmoothingPanel = new javax.swing.JPanel(); + orientationThresholdTextField = new javax.swing.JTextField(); + orientationThresholdButton = new javax.swing.JButton(); + activateContinuousPanel = new javax.swing.JPanel(); + accelerationThresholdTextField = new javax.swing.JTextField(); + accelerationThresholdButton = new javax.swing.JButton(); + deactivateContinuousPanel = new javax.swing.JPanel(); + getStatusButton = new javax.swing.JButton(); + batteryText = new javax.swing.JLabel(); + batteryLevelText = new javax.swing.JLabel(); + ledsPanel = new javax.swing.JPanel(); + toggleSensorBarPositionButton = new javax.swing.JButton(); + alphaSmoothingPanel = new javax.swing.JPanel(); + toggleScreenAspectRatioButton = new javax.swing.JButton(); + orientationThresholdPanel = new javax.swing.JPanel(); + xLabel = new javax.swing.JLabel(); + xResolutionTextField = new javax.swing.JTextField(); + yLabel = new javax.swing.JLabel(); + yResolutionTextField = new javax.swing.JTextField(); + setVirtualResolutionButton = new javax.swing.JButton(); + accelerationThresholdPanel = new javax.swing.JPanel(); + mouseIRControlButton = new javax.swing.JButton(); + batteryPanel = new javax.swing.JPanel(); + expansionText = new javax.swing.JLabel(); + messagesPanel = new javax.swing.JPanel(); + messageLabelText = new javax.swing.JLabel(); + messageText = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + leftPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); + + irViewPanel.setBackground(new java.awt.Color(0, 0, 0)); + irViewPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 153, 153), 2, true), "IR View", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 0, 51))); + + javax.swing.GroupLayout irViewPanelLayout = new javax.swing.GroupLayout(irViewPanel); + irViewPanel.setLayout(irViewPanelLayout); + irViewPanelLayout.setHorizontalGroup( + irViewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 272, Short.MAX_VALUE) + ); + irViewPanelLayout.setVerticalGroup( + irViewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 299, Short.MAX_VALUE) + ); + + javax.swing.GroupLayout motionSensingPanelLayout = new javax.swing.GroupLayout(motionSensingPanel); + motionSensingPanel.setLayout(motionSensingPanelLayout); + motionSensingPanelLayout.setHorizontalGroup( + motionSensingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 279, Short.MAX_VALUE) + ); + motionSensingPanelLayout.setVerticalGroup( + motionSensingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 213, Short.MAX_VALUE) + ); + + jTabbedPane1.addTab("Orientation", motionSensingPanel); + + javax.swing.GroupLayout gForcePanelLayout = new javax.swing.GroupLayout(gForcePanel); + gForcePanel.setLayout(gForcePanelLayout); + gForcePanelLayout.setHorizontalGroup( + gForcePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 279, Short.MAX_VALUE) + ); + gForcePanelLayout.setVerticalGroup( + gForcePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 213, Short.MAX_VALUE) + ); + + jTabbedPane1.addTab("GForce", gForcePanel); + + javax.swing.GroupLayout accelerationPanelLayout = new javax.swing.GroupLayout(accelerationPanel); + accelerationPanel.setLayout(accelerationPanelLayout); + accelerationPanelLayout.setHorizontalGroup( + accelerationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 279, Short.MAX_VALUE) + ); + accelerationPanelLayout.setVerticalGroup( + accelerationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 213, Short.MAX_VALUE) + ); + + jTabbedPane1.addTab("Raw Acceleration", accelerationPanel); + + javax.swing.GroupLayout leftPanelLayout = new javax.swing.GroupLayout(leftPanel); + leftPanel.setLayout(leftPanelLayout); + leftPanelLayout.setHorizontalGroup( + leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(irViewPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE) + ); + leftPanelLayout.setVerticalGroup( + leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, leftPanelLayout.createSequentialGroup() + .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(irViewPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + jTabbedPane1.getAccessibleContext().setAccessibleName("Orientation"); + + rightPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); + rightPanel.setLayout(new javax.swing.BoxLayout(rightPanel, javax.swing.BoxLayout.LINE_AXIS)); + + fixedWiimotePanel.setMaximumSize(new java.awt.Dimension(120, 32767)); + fixedWiimotePanel.setMinimumSize(new java.awt.Dimension(120, 100)); + fixedWiimotePanel.setPreferredSize(new java.awt.Dimension(120, 100)); + fixedWiimotePanel.setRequestFocusEnabled(false); + fixedWiimotePanel.setLayout(null); + + buttonsPanel.setMaximumSize(new java.awt.Dimension(120, 484)); + buttonsPanel.setMinimumSize(new java.awt.Dimension(120, 484)); + buttonsPanel.setOpaque(false); + buttonsPanel.setPreferredSize(new java.awt.Dimension(120, 484)); + + javax.swing.GroupLayout buttonsPanelLayout = new javax.swing.GroupLayout(buttonsPanel); + buttonsPanel.setLayout(buttonsPanelLayout); + buttonsPanelLayout.setHorizontalGroup( + buttonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 120, Short.MAX_VALUE) + ); + buttonsPanelLayout.setVerticalGroup( + buttonsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 484, Short.MAX_VALUE) + ); + + fixedWiimotePanel.add(buttonsPanel); + buttonsPanel.setBounds(0, 0, 120, 484); + + rightPanel.add(fixedWiimotePanel); + + controlsPanel.setMinimumSize(new java.awt.Dimension(100, 264)); + controlsPanel.setPreferredSize(new java.awt.Dimension(190, 264)); + controlsPanel.setLayout(new java.awt.GridLayout(16, 1)); + + toggleRumbleButton.setText("Activate Rumble"); + toggleRumbleButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + toggleRumbleButtonMousePressed(evt); + } + }); + activateRumblePanel.add(toggleRumbleButton); + + controlsPanel.add(activateRumblePanel); + + toggleIRTrackingButton.setText("Activate IR Tracking"); + toggleIRTrackingButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + toggleIRTrackingButtonMousePressed(evt); + } + }); + deactivateRumblePanel.add(toggleIRTrackingButton); + + controlsPanel.add(deactivateRumblePanel); + + toggleMotionSensingTrackingButton.setText("Activate motion sensing Tracking"); + toggleMotionSensingTrackingButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + toggleMotionSensingTrackingButtonMousePressed(evt); + } + }); + activateIRtrackingPanel.add(toggleMotionSensingTrackingButton); + + controlsPanel.add(activateIRtrackingPanel); + + toggleSmoothingButton.setText("Activate Smoothing"); + toggleSmoothingButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + toggleSmoothingButtonMousePressed(evt); + } + }); + deactivateIRTrackingPanel.add(toggleSmoothingButton); + + controlsPanel.add(deactivateIRTrackingPanel); + + toggleContinuousButton.setText("Activate Continuous"); + toggleContinuousButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + toggleContinuousButtonMousePressed(evt); + } + }); + activateMotionSensingTrackingPanel.add(toggleContinuousButton); + + controlsPanel.add(activateMotionSensingTrackingPanel); + + led1Button.setText("Led1"); + led1Button.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + led1ButtonMousePressed(evt); + } + }); + deactivateMotionSensingTrackingPanel.add(led1Button); + + led2Button.setText("Led2"); + led2Button.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + led2ButtonMousePressed(evt); + } + }); + deactivateMotionSensingTrackingPanel.add(led2Button); + + led3Button.setText("Led3"); + led3Button.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + led3ButtonMousePressed(evt); + } + }); + deactivateMotionSensingTrackingPanel.add(led3Button); + + led4Button.setText("Led4"); + led4Button.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + led4ButtonMousePressed(evt); + } + }); + deactivateMotionSensingTrackingPanel.add(led4Button); + + setLedsButton.setText("Set leds"); + setLedsButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + setLedsButtonMousePressed(evt); + } + }); + deactivateMotionSensingTrackingPanel.add(setLedsButton); + + controlsPanel.add(deactivateMotionSensingTrackingPanel); + + alphaSmoothingTextField.setMinimumSize(new java.awt.Dimension(100, 20)); + alphaSmoothingTextField.setPreferredSize(new java.awt.Dimension(100, 20)); + activateSmoothingPanel.add(alphaSmoothingTextField); + + alphaSmoothingButton.setText("Set alpha smoothing"); + alphaSmoothingButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + alphaSmoothingButtonMousePressed(evt); + } + }); + activateSmoothingPanel.add(alphaSmoothingButton); + + controlsPanel.add(activateSmoothingPanel); + + orientationThresholdTextField.setMinimumSize(new java.awt.Dimension(100, 20)); + orientationThresholdTextField.setPreferredSize(new java.awt.Dimension(100, 20)); + deactivateSmoothingPanel.add(orientationThresholdTextField); + + orientationThresholdButton.setText("Set orientation threshold"); + orientationThresholdButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + orientationThresholdButtonMousePressed(evt); + } + }); + deactivateSmoothingPanel.add(orientationThresholdButton); + + controlsPanel.add(deactivateSmoothingPanel); + + accelerationThresholdTextField.setPreferredSize(new java.awt.Dimension(100, 20)); + activateContinuousPanel.add(accelerationThresholdTextField); + + accelerationThresholdButton.setText("Set acceleration threshold"); + accelerationThresholdButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + accelerationThresholdButtonMousePressed(evt); + } + }); + activateContinuousPanel.add(accelerationThresholdButton); + + controlsPanel.add(activateContinuousPanel); + + getStatusButton.setText("Get status"); + getStatusButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + getStatusButtonMousePressed(evt); + } + }); + deactivateContinuousPanel.add(getStatusButton); + + batteryText.setFont(new java.awt.Font("Tahoma", 0, 14)); + batteryText.setText("Battery level :"); + deactivateContinuousPanel.add(batteryText); + + batteryLevelText.setFont(new java.awt.Font("Arial", 0, 14)); + batteryLevelText.setText(" %"); + deactivateContinuousPanel.add(batteryLevelText); + + controlsPanel.add(deactivateContinuousPanel); + + toggleSensorBarPositionButton.setText("Set sensor bar above"); + toggleSensorBarPositionButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + toggleSensorBarPositionButtonMousePressed(evt); + } + }); + ledsPanel.add(toggleSensorBarPositionButton); + + controlsPanel.add(ledsPanel); + + toggleScreenAspectRatioButton.setText("Set screen aspect ratio 4/3"); + toggleScreenAspectRatioButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + toggleScreenAspectRatioButtonMousePressed(evt); + } + }); + alphaSmoothingPanel.add(toggleScreenAspectRatioButton); + + controlsPanel.add(alphaSmoothingPanel); + + xLabel.setText("X"); + orientationThresholdPanel.add(xLabel); + + xResolutionTextField.setMinimumSize(new java.awt.Dimension(40, 20)); + xResolutionTextField.setPreferredSize(new java.awt.Dimension(40, 20)); + orientationThresholdPanel.add(xResolutionTextField); + + yLabel.setText("Y"); + orientationThresholdPanel.add(yLabel); + + yResolutionTextField.setFocusTraversalPolicyProvider(true); + yResolutionTextField.setMinimumSize(new java.awt.Dimension(40, 20)); + yResolutionTextField.setPreferredSize(new java.awt.Dimension(40, 20)); + orientationThresholdPanel.add(yResolutionTextField); + + setVirtualResolutionButton.setText("Set virtual resolution"); + setVirtualResolutionButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + setVirtualResolutionButtonMousePressed(evt); + } + }); + orientationThresholdPanel.add(setVirtualResolutionButton); + + controlsPanel.add(orientationThresholdPanel); + + mouseIRControlButton.setText("Start infrared mouse control"); + mouseIRControlButton.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + mouseIRControlButtonMousePressed(evt); + } + }); + accelerationThresholdPanel.add(mouseIRControlButton); + + controlsPanel.add(accelerationThresholdPanel); + + expansionText.setText("No expansion connected"); + batteryPanel.add(expansionText); + + controlsPanel.add(batteryPanel); + + messageLabelText.setFont(new java.awt.Font("Tahoma", 0, 14)); + messageLabelText.setText("Message : "); + messagesPanel.add(messageLabelText); + + messageText.setFont(new java.awt.Font("Arial", 0, 14)); + messageText.setText("None"); + messagesPanel.add(messageText); + + controlsPanel.add(messagesPanel); + + rightPanel.add(controlsPanel); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(leftPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(rightPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 498, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(leftPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(rightPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 573, Short.MAX_VALUE) + ); + + java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); + setBounds((screenSize.width-800)/2, (screenSize.height-600)/2, 800, 600); + }// //GEN-END:initComponents + private void toggleRumbleButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_toggleRumbleButtonMousePressed + if (toggleRumbleButton.isEnabled()) { + wiimote.activateRumble(); + toggleRumbleButton.setEnabled(false); + toggleRumbleButton.setText("Deactivate Rumble"); + messageText.setText("Rumble activated"); + } else { + wiimote.deactivateRumble(); + toggleRumbleButton.setEnabled(true); + toggleRumbleButton.setText("Activate Rumble"); + messageText.setText("Rumble deactivated"); + } + }//GEN-LAST:event_toggleRumbleButtonMousePressed + + private void toggleIRTrackingButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_toggleIRTrackingButtonMousePressed + if (toggleIRTrackingButton.isEnabled()) { + wiimote.activateIRTRacking(); + toggleIRTrackingButton.setEnabled(false); + toggleIRTrackingButton.setText("Deactivate IR Tracking"); + messageText.setText("IR Tracking activated"); + } else { + wiimote.deactivateIRTRacking(); + toggleIRTrackingButton.setEnabled(true); + toggleIRTrackingButton.setText("Activate IR Tracking"); + ((IRPanel) irViewPanel).onDisconnectionEvent(null); + messageText.setText("IR Tracking deactivated"); + } + }//GEN-LAST:event_toggleIRTrackingButtonMousePressed + + private void toggleMotionSensingTrackingButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_toggleMotionSensingTrackingButtonMousePressed + if (toggleMotionSensingTrackingButton.isEnabled()) { + wiimote.activateMotionSensing(); + toggleMotionSensingTrackingButton.setEnabled(false); + toggleMotionSensingTrackingButton.setText("Deactivate Motion Sensing"); + messageText.setText("Motion Sensing activated"); + } else { + wiimote.deactivateMotionSensing(); + toggleMotionSensingTrackingButton.setEnabled(true); + toggleMotionSensingTrackingButton.setText("Activate Motion Sensing"); + ((OrientationPanel) motionSensingPanel).onDisconnectionEvent(null); + ((GForcePanel) gForcePanel).onDisconnectionEvent(null); + messageText.setText("Motion Sensing deactivated"); + } + }//GEN-LAST:event_toggleMotionSensingTrackingButtonMousePressed + + private void toggleSmoothingButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_toggleSmoothingButtonMousePressed + if (toggleSmoothingButton.isEnabled()) { + wiimote.activateSmoothing(); + toggleSmoothingButton.setEnabled(false); + toggleSmoothingButton.setText("Deactivate Alpha Smoothing"); + messageText.setText("Alpha Smoothing activated"); + } else { + wiimote.deactivateSmoothing(); + toggleSmoothingButton.setEnabled(true); + toggleSmoothingButton.setText("Activate Alpha Smoothing"); + messageText.setText("Alpha Smoothing deactivated"); + } + }//GEN-LAST:event_toggleSmoothingButtonMousePressed + + private void toggleContinuousButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_toggleContinuousButtonMousePressed + if (toggleContinuousButton.isEnabled()) { + wiimote.activateContinuous(); + toggleContinuousButton.setEnabled(false); + toggleContinuousButton.setText("Deactivate Continuous"); + messageText.setText("Continuous activated"); + } else { + wiimote.deactivateContinuous(); + toggleContinuousButton.setEnabled(true); + toggleContinuousButton.setText("Activate Continuous"); + messageText.setText("Continuous deactivated"); + } + }//GEN-LAST:event_toggleContinuousButtonMousePressed + + private void led1ButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_led1ButtonMousePressed + if (led1Button.isEnabled()) { + led1Button.setEnabled(false); + } else { + led1Button.setEnabled(true); + } + }//GEN-LAST:event_led1ButtonMousePressed + + private void led2ButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_led2ButtonMousePressed + if (led2Button.isEnabled()) { + led2Button.setEnabled(false); + } else { + led2Button.setEnabled(true); + } + }//GEN-LAST:event_led2ButtonMousePressed + + private void led3ButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_led3ButtonMousePressed + if (led3Button.isEnabled()) { + led3Button.setEnabled(false); + } else { + led3Button.setEnabled(true); + } + }//GEN-LAST:event_led3ButtonMousePressed + + private void led4ButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_led4ButtonMousePressed + if (led4Button.isEnabled()) { + led4Button.setEnabled(false); + } else { + led4Button.setEnabled(true); + } + }//GEN-LAST:event_led4ButtonMousePressed + + private void setLedsButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_setLedsButtonMousePressed + wiimote.setLeds(led1Button.isEnabled(), led2Button.isEnabled(), + led3Button.isEnabled(), led4Button.isEnabled()); + messageText.setText("Leds set"); + }//GEN-LAST:event_setLedsButtonMousePressed + + private void alphaSmoothingButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_alphaSmoothingButtonMousePressed + try { + float nb = Float.parseFloat(alphaSmoothingTextField.getText()); + wiimote.setAlphaSmoothingValue(nb); + messageText.setText("Alpha smoothing set to " + nb); + } catch (NumberFormatException e) { + messageText.setText("Number is not a float, alpha smoothing not set !"); + } + }//GEN-LAST:event_alphaSmoothingButtonMousePressed + + private void orientationThresholdButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_orientationThresholdButtonMousePressed + try { + float nb = Float.parseFloat(orientationThresholdTextField.getText()); + wiimote.setOrientationThreshold(nb); + messageText.setText("Orientation threshold set to " + nb); + } catch (NumberFormatException e) { + messageText.setText("Number is not a float, orientation threshold not set !"); + } + }//GEN-LAST:event_orientationThresholdButtonMousePressed + + private void accelerationThresholdButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_accelerationThresholdButtonMousePressed + try { + int nb = Integer.parseInt(accelerationThresholdTextField.getText()); + wiimote.setAccelerationThreshold(nb); + messageText.setText("Acceleration threshold set to " + nb); + } catch (NumberFormatException e) { + messageText.setText("Number is not an integer, acceleration threshold not set !"); + } + }//GEN-LAST:event_accelerationThresholdButtonMousePressed + + private void getStatusButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_getStatusButtonMousePressed + wiimote.getStatus(); + statusMotionRequested = true; + statusIRRequested = true; + }//GEN-LAST:event_getStatusButtonMousePressed + + private void toggleSensorBarPositionButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_toggleSensorBarPositionButtonMousePressed + if (toggleSensorBarPositionButton.isEnabled()) { + wiimote.setSensorBarBelowScreen(); + toggleSensorBarPositionButton.setEnabled(false); + toggleSensorBarPositionButton.setText("Set sensor bar below"); + messageText.setText("Sensor bar set above"); + } else { + wiimote.setSensorBarAboveScreen(); + toggleSensorBarPositionButton.setEnabled(true); + toggleSensorBarPositionButton.setText("Set sensor bar above"); + messageText.setText("Sensor bar set below"); + } + }//GEN-LAST:event_toggleSensorBarPositionButtonMousePressed + + private void toggleScreenAspectRatioButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_toggleScreenAspectRatioButtonMousePressed + if (toggleScreenAspectRatioButton.isEnabled()) { + wiimote.setScreenAspectRatio43(); + toggleScreenAspectRatioButton.setEnabled(false); + toggleScreenAspectRatioButton.setText("Set screen aspect ratio 16/9"); + messageText.setText("creen aspect ratio to 4/3"); + } else { + wiimote.setScreenAspectRatio169(); + toggleScreenAspectRatioButton.setEnabled(true); + toggleScreenAspectRatioButton.setText("Set screen aspect ratio 4/3"); + messageText.setText("Screen aspect ratio to 16/9"); + } + }//GEN-LAST:event_toggleScreenAspectRatioButtonMousePressed + + private void setVirtualResolutionButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_setVirtualResolutionButtonMousePressed + try { + int xres = Integer.parseInt(xResolutionTextField.getText()); + int yres = Integer.parseInt(yResolutionTextField.getText()); + wiimote.setVirtualResolution(xres, yres); + messageText.setText("Virtual resolution set to " + xres + "X" + yres); + } catch (NumberFormatException e) { + messageText.setText("A number in the virtual resolution is not an integer. Virtual resolution not set!"); + } + }//GEN-LAST:event_setVirtualResolutionButtonMousePressed + + private void mouseIRControlButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mouseIRControlButtonMousePressed + if (mouseIRControlButton.isEnabled()) { + try { + mouseIRControlButton.setEnabled(false); + mouseIRControlButton.setText("Stop infrared mouse control"); + robot = new Robot(); + messageText.setText("Infrared mouse control started"); + } catch (AWTException ex) { + Logger.getLogger(WiiuseJGuiTest.class.getName()).log(Level.SEVERE, null, ex); + } + } else { + mouseIRControlButton.setEnabled(true); + mouseIRControlButton.setText("Start infrared mouse control"); + robot = null; + messageText.setText("Infrared mouse control stopped"); + } + }//GEN-LAST:event_mouseIRControlButtonMousePressed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel accelerationPanel; + private javax.swing.JButton accelerationThresholdButton; + private javax.swing.JPanel accelerationThresholdPanel; + private javax.swing.JTextField accelerationThresholdTextField; + private javax.swing.JPanel activateContinuousPanel; + private javax.swing.JPanel activateIRtrackingPanel; + private javax.swing.JPanel activateMotionSensingTrackingPanel; + private javax.swing.JPanel activateRumblePanel; + private javax.swing.JPanel activateSmoothingPanel; + private javax.swing.JButton alphaSmoothingButton; + private javax.swing.JPanel alphaSmoothingPanel; + private javax.swing.JTextField alphaSmoothingTextField; + private javax.swing.JLabel batteryLevelText; + private javax.swing.JPanel batteryPanel; + private javax.swing.JLabel batteryText; + private javax.swing.JPanel buttonsPanel; + private javax.swing.JPanel controlsPanel; + private javax.swing.JPanel deactivateContinuousPanel; + private javax.swing.JPanel deactivateIRTrackingPanel; + private javax.swing.JPanel deactivateMotionSensingTrackingPanel; + private javax.swing.JPanel deactivateRumblePanel; + private javax.swing.JPanel deactivateSmoothingPanel; + private javax.swing.JLabel expansionText; + private javax.swing.JPanel fixedWiimotePanel; + private javax.swing.JPanel gForcePanel; + private javax.swing.JButton getStatusButton; + private javax.swing.JPanel irViewPanel; + private javax.swing.JTabbedPane jTabbedPane1; + private javax.swing.JButton led1Button; + private javax.swing.JButton led2Button; + private javax.swing.JButton led3Button; + private javax.swing.JButton led4Button; + private javax.swing.JPanel ledsPanel; + private javax.swing.JPanel leftPanel; + private javax.swing.JLabel messageLabelText; + private javax.swing.JLabel messageText; + private javax.swing.JPanel messagesPanel; + private javax.swing.JPanel motionSensingPanel; + private javax.swing.JButton mouseIRControlButton; + private javax.swing.JButton orientationThresholdButton; + private javax.swing.JPanel orientationThresholdPanel; + private javax.swing.JTextField orientationThresholdTextField; + private javax.swing.JPanel rightPanel; + private javax.swing.JButton setLedsButton; + private javax.swing.JButton setVirtualResolutionButton; + private javax.swing.JButton toggleContinuousButton; + private javax.swing.JButton toggleIRTrackingButton; + private javax.swing.JButton toggleMotionSensingTrackingButton; + private javax.swing.JButton toggleRumbleButton; + private javax.swing.JButton toggleScreenAspectRatioButton; + private javax.swing.JButton toggleSensorBarPositionButton; + private javax.swing.JButton toggleSmoothingButton; + private javax.swing.JLabel xLabel; + private javax.swing.JTextField xResolutionTextField; + private javax.swing.JLabel yLabel; + private javax.swing.JTextField yResolutionTextField; + // End of variables declaration//GEN-END:variables +} diff --git a/WiiUseJ/src/wiiusej/utils/AccelerationPanel.java b/WiiUseJ/src/wiiusej/utils/AccelerationPanel.java new file mode 100644 index 0000000..0403255 --- /dev/null +++ b/WiiUseJ/src/wiiusej/utils/AccelerationPanel.java @@ -0,0 +1,182 @@ +/** + * This file is part of WiiuseJ. + * + * WiiuseJ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * WiiuseJ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WiiuseJ. If not, see . + */ +package wiiusej.utils; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.RenderingHints; +import java.awt.geom.AffineTransform; +import java.util.ArrayList; +import wiiusej.values.RawAcceleration; +import wiiusej.wiiuseapievents.ButtonsEvent; +import wiiusej.wiiuseapievents.DisconnectionEvent; +import wiiusej.wiiuseapievents.IREvent; +import wiiusej.wiiuseapievents.MotionSensingEvent; +import wiiusej.wiiuseapievents.StatusEvent; +import wiiusej.wiiuseapievents.WiimoteListener; + +/** + * This panel is used to watch raw acceleration values from a MotionSensingEvent. + * @author guiguito + */ +public class AccelerationPanel extends javax.swing.JPanel implements WiimoteListener { + + private Image mImage;//image for double buffering + private Color xColor = Color.RED; + private Color yColor = Color.GREEN; + private Color zColor = Color.BLUE; + private Color backgroundColor = Color.WHITE; + private Color lineColor = Color.BLACK; + private ArrayList values = new ArrayList(); + + /** Creates new form AccelerationPanel */ + public AccelerationPanel() { + 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); + + //draw medium line + int yLine = getHeight() - 25; + + g2.setPaint(lineColor); + g2.drawLine(0, yLine, getWidth(), yLine); + + RawAcceleration[] valuesArray = values.toArray(new RawAcceleration[0]); + + double unit = yLine / 255.0; + int previousX = 0; + int previousY = 0; + int previousZ = 0; + //draw curves + for (int i = 0; i < valuesArray.length && i < getWidth(); i++) { + RawAcceleration acceleration = valuesArray[i]; + //draw X + g2.setPaint(xColor); + int yDelta = (int) Math.round(unit * acceleration.getX()); + int y = -1 * yDelta + yLine; + g2.drawLine(i - 1, previousX, i, y); + g2.setTransform(new AffineTransform()); + previousX = y; + //draw Y + g2.setPaint(yColor); + yDelta = (int) Math.round(unit * acceleration.getY()); + y = -1 * yDelta + yLine; + g2.drawLine(i - 1, previousY, i, y); + g2.setTransform(new AffineTransform()); + previousY = y; + //draw Z + g2.setPaint(zColor); + yDelta = (int) Math.round(unit * acceleration.getZ()); + y = -1 * yDelta + yLine; + g2.drawLine(i - 1, previousZ, i, y); + g2.setTransform(new AffineTransform()); + previousZ = y; + } + + //draw legend + g2.setPaint(xColor); + g2.drawLine(5, getHeight() - 10, 25, getHeight() - 10); + g2.setPaint(yColor); + g2.drawLine(60, getHeight() - 10, 80, getHeight() - 10); + g2.setPaint(zColor); + g2.drawLine(120, getHeight() - 10, 140, getHeight() - 10); + + g2.setPaint(lineColor); + g2.drawString("X", 30, getHeight() - 5); + g2.drawString("Y", 85, getHeight() - 5); + g2.drawString("Z", 145, getHeight() - 5); + g2.drawString("0", 2, yLine - 5); + g2.drawString("255", 2, 15); + //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); + } + } + + public void onButtonsEvent(ButtonsEvent arg0) { + //nothing + } + + public void onIrEvent(IREvent arg0) { + //nothing + } + + public void onMotionSensingEvent(MotionSensingEvent arg0) { + if (values.size() >= getWidth()) { + //if there are as many values as pixels in the width + //clear points + values.clear(); + } + values.add(arg0.getRawAcceleration()); + repaint(); + } + + public void onStatusEvent(StatusEvent arg0) { + //nothing + } + + public void onDisconnectionEvent(DisconnectionEvent arg0) { + //Clear points. + 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 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/ButtonsEventPanel.java b/WiiUseJ/src/wiiusej/utils/ButtonsEventPanel.java new file mode 100644 index 0000000..3ccb422 --- /dev/null +++ b/WiiUseJ/src/wiiusej/utils/ButtonsEventPanel.java @@ -0,0 +1,296 @@ +/** + * This file is part of WiiuseJ. + * + * WiiuseJ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * WiiuseJ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WiiuseJ. If not, see . + */ +package wiiusej.utils; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.RenderingHints; +import java.awt.Shape; +import java.awt.Toolkit; +import java.awt.geom.AffineTransform; +import wiiusej.wiiuseapievents.ButtonsEvent; +import wiiusej.wiiuseapievents.DisconnectionEvent; +import wiiusej.wiiuseapievents.IREvent; +import wiiusej.wiiuseapievents.MotionSensingEvent; +import wiiusej.wiiuseapievents.StatusEvent; +import wiiusej.wiiuseapievents.WiimoteListener; + +/** + * This panel is used to see what buttons are pressed. + * It displays the result of last ButtonsEvent. + * @author guiguito + */ +public class ButtonsEventPanel extends javax.swing.JPanel implements WiimoteListener { + + private Image mImage;//image for double buffering + private Image wiimoteImage;//image for double buffering + private ButtonsEvent buttons; + private Color pressedColor = Color.RED; + private Color heldColor = Color.ORANGE; + private Color releasedColor = Color.YELLOW; + private Shape shape; + + /** + * Default constructor. + * Red : button just pressed. + * Orange : button held. + * Yellow : button just released. + */ + public ButtonsEventPanel() { + Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit(); + wiimoteImage = toolkit.createImage("img\\wiimote.png"); + shape = new java.awt.geom.Ellipse2D.Double(0, 0, 13, 13); + initComponents(); + } + + /** + * Constructor used to set colors and shape used. + * @param pressColor color of a button just pressed. + * @param hColor color of a button held. + * @param relColor color of a button just released. + * @param sh shape draw on the buttons. + */ + public ButtonsEventPanel(Color pressColor, Color hColor, Color relColor, Shape sh) { + pressedColor = pressColor; + heldColor = hColor; + releasedColor = relColor; + shape = sh; + Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit(); + wiimoteImage = toolkit.createImage("img\\wiimote.png"); + shape = new java.awt.geom.Ellipse2D.Double(0, 0, 13, 13); + 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); + + //draw buttons pushed + g2.drawImage(wiimoteImage, 0, 0, this); + g2.setTransform(new AffineTransform()); + + if (buttons != null) { + /* button ONE */ + if (buttons.isButtonOneJustPressed()) { + drawFunction(g2,pressedColor,53,353); + } + if (buttons.isButtonOneHeld()) { + drawFunction(g2,heldColor,53,353); + } + if (buttons.isButtonOneJustReleased()) { + drawFunction(g2, releasedColor, 53, 353); + } + + /* button TWO */ + if (buttons.isButtonTwoJustPressed()) { + drawFunction(g2,pressedColor,53,395); + } + if (buttons.isButtonTwoHeld()) { + drawFunction(g2,heldColor,53,395); + } + if (buttons.isButtonTwoJustReleased()) { + drawFunction(g2,releasedColor,53,395); + } + + /* button A */ + if (buttons.isButtonAJustPressed()) { + drawFunction(g2,pressedColor,53,150); + } + if (buttons.isButtonAHeld()) { + drawFunction(g2,heldColor,53,150); + } + if (buttons.isButtonAJustReleased()) { + drawFunction(g2,releasedColor,53,150); + } + + /* button B */ + if (buttons.isButtonBJustPressed()) { + drawFunction(g2,pressedColor,16,149); + } + if (buttons.isButtonBHeld()) { + drawFunction(g2,heldColor,16,149); + } + if (buttons.isButtonBJustReleased()) { + drawFunction(g2,releasedColor,16,149); + } + + /* button LEFT */ + if (buttons.isButtonLeftJustPressed()) { + drawFunction(g2,pressedColor,33,77); + } + if (buttons.isButtonLeftHeld()) { + drawFunction(g2,heldColor,33,77); + } + if (buttons.isButtonLeftJustReleased()) { + drawFunction(g2,releasedColor,33,77); + } + + /* button RIGHT */ + if (buttons.isButtonRightJustPressed()) { + drawFunction(g2,pressedColor,73,77); + } + if (buttons.isButtonRightHeld()) { + drawFunction(g2,heldColor,73,77); + } + if (buttons.isButtonRightJustReleased()) { + drawFunction(g2,releasedColor,73,77); + } + + /* button UP */ + if (buttons.isButtonUpJustPressed()) { + drawFunction(g2,pressedColor,54,60); + } + if (buttons.isButtonUpHeld()) { + drawFunction(g2,heldColor,54,60); + } + if (buttons.isButtonUpJustReleased()) { + drawFunction(g2,releasedColor,54,60); + } + + /* button DOWN */ + if (buttons.isButtonDownJustPressed()) { + drawFunction(g2,pressedColor,54,97); + } + if (buttons.isButtonDownHeld()) { + drawFunction(g2,heldColor,54,97); + } + if (buttons.isButtonDownJustReleased()) { + drawFunction(g2,releasedColor,54,97); + } + + /* button MINUS */ + if (buttons.isButtonMinusJustPressed()) { + drawFunction(g2,pressedColor,20,230); + } + if (buttons.isButtonMinusHeld()) { + drawFunction(g2,heldColor,20,230); + } + if (buttons.isButtonMinusJustReleased()) { + drawFunction(g2,releasedColor,20,230); + } + + /* button PLUS */ + if (buttons.isButtonPlusJustPressed()) { + drawFunction(g2,pressedColor,86,230); + } + if (buttons.isButtonPlusHeld()) { + drawFunction(g2,heldColor,86,230); + } + if (buttons.isButtonPlusJustReleased()) { + drawFunction(g2,releasedColor,86,230); + } + + /* button HOME */ + if (buttons.isButtonHomeJustPressed()) { + drawFunction(g2,pressedColor,53,230); + } + if (buttons.isButtonHomeHeld()) { + drawFunction(g2,heldColor,53,230); + } + if (buttons.isButtonHomeJustReleased()) { + drawFunction(g2,releasedColor,53,230); + } + + buttons = null; + } + + + //put offscreen image on the screen + g.drawImage(mImage, 0, 0, null); + } + + /** + * Function used to factorize code. + * @param g2 where to draw a shape. + * @param col color to use. + * @param x x coordinates. + * @param y y coordinates. + */ + private void drawFunction(Graphics2D g2, Color col, int x, int y) { + g2.setPaint(col); + g2.translate(x, y); + g2.draw(shape); + g2.fill(shape); + g2.setTransform(new AffineTransform()); + } + + /** + * 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(ButtonsEvent arg0) { + setSize(wiimoteImage.getWidth(this), wiimoteImage.getHeight(this)); + buttons = arg0; + repaint(); + } + + public void onIrEvent(IREvent arg0) { + //nothing + } + + public void onMotionSensingEvent(MotionSensingEvent arg0) { + //nothing + } + + public void onStatusEvent(StatusEvent arg0) { + //nothing + } + + public void onDisconnectionEvent(DisconnectionEvent arg0) { + buttons = null; + 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 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/GForcePanel.java b/WiiUseJ/src/wiiusej/utils/GForcePanel.java new file mode 100644 index 0000000..9802688 --- /dev/null +++ b/WiiUseJ/src/wiiusej/utils/GForcePanel.java @@ -0,0 +1,201 @@ +/** + * This file is part of WiiuseJ. + * + * WiiuseJ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * WiiuseJ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WiiuseJ. If not, see . + */ +package wiiusej.utils; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.RenderingHints; +import java.awt.geom.AffineTransform; +import java.util.ArrayList; +import wiiusej.values.GForce; +import wiiusej.wiiuseapievents.ButtonsEvent; +import wiiusej.wiiuseapievents.DisconnectionEvent; +import wiiusej.wiiuseapievents.IREvent; +import wiiusej.wiiuseapievents.MotionSensingEvent; +import wiiusej.wiiuseapievents.StatusEvent; +import wiiusej.wiiuseapievents.WiimoteListener; + +/** + * This panel is used to watch gravity force values from a MotionSensingEvent. + * @author guiguito + */ +public class GForcePanel extends javax.swing.JPanel implements WiimoteListener { + + private Image mImage;//image for double buffering + private Color xColor = Color.RED; + private Color yColor = Color.GREEN; + private Color zColor = Color.BLUE; + private Color backgroundColor = Color.WHITE; + private Color lineColor = Color.BLACK; + private ArrayList values = new ArrayList(); + + /** + * Default constructor of the AccelerationPanel. + */ + public GForcePanel() { + initComponents(); + } + + /** + * Constructor used to choose the colors used by the AccelerationPanel. + * @param bgColor background color. + * @param xxColor color of the acceleration on X axis. + * @param yyColor color of the acceleration on Y axis. + * @param zzColor color of the acceleration on Z axis. + * @param lColor line color. + */ + public GForcePanel(Color bgColor, Color xxColor, Color yyColor, Color zzColor, Color lColor) { + backgroundColor = bgColor; + xColor = xxColor; + yColor = yyColor; + zColor = zzColor; + lineColor = lColor; + 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); + + //draw medium line + double yMiddleFloat = getHeight() / 2.0; + int yMiddle = (int) Math.round(yMiddleFloat); + + g2.setPaint(lineColor); + g2.drawLine(0, yMiddle, getWidth(), yMiddle); + + GForce[] valuesArray = values.toArray(new GForce[0]); + double unit = yMiddleFloat / 5.0; + int previousX = 0; + int previousY = 0; + int previousZ = 0; + //draw curves + for (int i = 0; i < valuesArray.length && i < getWidth(); i++) { + GForce gforce = valuesArray[i]; + //draw X + g2.setPaint(xColor); + int yDelta = (int) Math.round(unit * gforce.getX()); + int y = -1 * yDelta + yMiddle; + g2.drawLine(i - 1, previousX, i, y); + g2.setTransform(new AffineTransform()); + previousX = y; + //draw Y + g2.setPaint(yColor); + yDelta = (int) Math.round(unit * gforce.getY()); + y = -1 * yDelta + yMiddle; + g2.drawLine(i - 1, previousY, i, y); + g2.setTransform(new AffineTransform()); + previousY = y; + //draw Z + g2.setPaint(zColor); + yDelta = (int) Math.round(unit * gforce.getZ()); + y = -1 * yDelta + yMiddle; + g2.drawLine(i - 1, previousZ, i, y); + g2.setTransform(new AffineTransform()); + previousZ = y; + } + + //draw legend + g2.setPaint(xColor); + g2.drawLine(5, getHeight() - 10, 25, getHeight() - 10); + g2.setPaint(yColor); + g2.drawLine(60, getHeight() - 10, 80, getHeight() - 10); + g2.setPaint(zColor); + g2.drawLine(120, getHeight() - 10, 140, getHeight() - 10); + + g2.setPaint(lineColor); + g2.drawString("X", 30, getHeight() - 5); + g2.drawString("Y", 85, getHeight() - 5); + g2.drawString("Z", 145, getHeight() - 5); + g2.drawString("0", 2, yMiddle-5); + g2.drawString("5", 2, 10); + g2.drawString("-5", 2, getHeight()-15); + //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); + } + } + + public void onButtonsEvent(ButtonsEvent arg0) { + //nothing + } + + public void onIrEvent(IREvent arg0) { + //nothing + } + + public void onMotionSensingEvent(MotionSensingEvent arg0) { + if (values.size() >= getWidth()) { + //if there are as many values as pixels in the width + //clear points + values.clear(); + } + values.add(arg0.getGforce()); + repaint(); + } + + public void onStatusEvent(StatusEvent arg0) { + //nothing + } + + public void onDisconnectionEvent(DisconnectionEvent arg0) { + //Clear points. + 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 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/IRPanel.java b/WiiUseJ/src/wiiusej/utils/IRPanel.java new file mode 100644 index 0000000..b4213a1 --- /dev/null +++ b/WiiUseJ/src/wiiusej/utils/IRPanel.java @@ -0,0 +1,192 @@ +/** + * This file is part of WiiuseJ. + * + * WiiuseJ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * WiiuseJ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WiiuseJ. If not, see . + */ +package wiiusej.utils; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.RenderingHints; +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import wiiusej.wiiuseapievents.ButtonsEvent; +import wiiusej.wiiuseapievents.DisconnectionEvent; +import wiiusej.wiiuseapievents.IREvent; +import wiiusej.wiiuseapievents.MotionSensingEvent; +import wiiusej.wiiuseapievents.StatusEvent; +import wiiusej.wiiuseapievents.WiimoteListener; + +/** + * This panel is used to see what the IR camera of the wiimote sees. + * @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; + + /** + * 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(); + } + + 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); + + //draw points + int i = 0; + while (xCoordinates[i] != -1 && yCoordinates[i] != -1 && 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); + + 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); + } + + /** + * 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(ButtonsEvent arg0) { + //nothing + } + + 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(); + } + + public void onMotionSensingEvent(MotionSensingEvent 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(); + } + + /** 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/OrientationPanel.java b/WiiUseJ/src/wiiusej/utils/OrientationPanel.java new file mode 100644 index 0000000..b50a2ce --- /dev/null +++ b/WiiUseJ/src/wiiusej/utils/OrientationPanel.java @@ -0,0 +1,205 @@ +/** + * This file is part of WiiuseJ. + * + * WiiuseJ is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * WiiuseJ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WiiuseJ. If not, see . + */ +package wiiusej.utils; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.RenderingHints; +import java.awt.geom.AffineTransform; +import java.util.ArrayList; +import wiiusej.values.Orientation; +import wiiusej.wiiuseapievents.ButtonsEvent; +import wiiusej.wiiuseapievents.DisconnectionEvent; +import wiiusej.wiiuseapievents.IREvent; +import wiiusej.wiiuseapievents.MotionSensingEvent; +import wiiusej.wiiuseapievents.StatusEvent; +import wiiusej.wiiuseapievents.WiimoteListener; + +/** + * This panel is used to watch orientation values from a MotionSensingEvent. + * @author guiguito + */ +public class OrientationPanel extends javax.swing.JPanel implements WiimoteListener { + + private Image mImage;//image for double buffering + private Color rollColor = Color.RED; + private Color pitchColor = Color.GREEN; + private Color yawColor = Color.BLUE; + private Color backgroundColor = Color.WHITE; + private Color lineColor = Color.BLACK; + private ArrayList values = new ArrayList(); + + /** + * Default constructor. + * Background color : White. + * Roll color : Red. + * Pitch color : Green. + * Yaw color : Blue. + */ + public OrientationPanel() { + initComponents(); + } + + /** + * Constructor used to choose the colors used by the OrientationPanel. + * @param bgColor background color. + * @param rColor roll color. + * @param pColor pitch color. + * @param yColor yaw color. + * @param lColor line color. + */ + public OrientationPanel(Color bgColor, Color rColor, Color pColor, Color yColor, Color lColor) { + backgroundColor = bgColor; + rollColor = rColor; + pitchColor = pColor; + yawColor = yColor; + lineColor = lColor; + 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); + + //draw medium line + double yMiddleFloat = getHeight() / 2.0; + int yMiddle = (int) Math.round(yMiddleFloat); + + g2.setPaint(lineColor); + g2.drawLine(0, yMiddle, getWidth(), yMiddle); + + Orientation[] valuesArray = values.toArray(new Orientation[0]); + double unit = yMiddleFloat / 180.0; + int previousRoll = 0; + int previousPitch = 0; + int previousYaw = 0; + //draw curves + for (int i = 0; i < valuesArray.length && i < getWidth(); i++) { + Orientation orientation = valuesArray[i]; + //draw roll + g2.setPaint(rollColor); + int yDelta = (int) Math.round(unit * orientation.getRoll()); + int y = -1 * yDelta + yMiddle; + g2.drawLine(i-1, previousRoll, i, y); + g2.setTransform(new AffineTransform()); + previousRoll = y; + //draw pitch + g2.setPaint(pitchColor); + yDelta = (int) Math.round(unit * orientation.getPitch()); + y = -1 * yDelta + yMiddle; + g2.drawLine(i-1, previousPitch, i, y); + g2.setTransform(new AffineTransform()); + previousPitch = y; + //draw yaw + g2.setPaint(yawColor); + yDelta = (int) Math.round(unit * orientation.getYaw()); + y = -1 * yDelta + yMiddle; + g2.drawLine(i-1, previousYaw, i, y); + g2.setTransform(new AffineTransform()); + previousYaw = y; + } + + //draw legend + g2.setPaint(rollColor); + g2.drawLine(5, getHeight()-10, 25, getHeight()-10); + g2.setPaint(pitchColor); + g2.drawLine(60, getHeight()-10, 80, getHeight()-10); + g2.setPaint(yawColor); + g2.drawLine(120, getHeight()-10, 140, getHeight()-10); + + g2.setPaint(lineColor); + g2.drawString("Roll", 30, getHeight()-5); + g2.drawString("Pitch", 85, getHeight()-5); + g2.drawString("Yaw", 145, getHeight()-5); + g2.drawString("0", 2, yMiddle-5); + g2.drawString("180", 2, 10); + g2.drawString("-180", 2, getHeight()-15); + //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); + } + } + + public void onButtonsEvent(ButtonsEvent arg0) { + //nothing + } + + public void onIrEvent(IREvent arg0) { + //nothing + } + + public void onMotionSensingEvent(MotionSensingEvent arg0) { + if (values.size() >= getWidth()) { + //if there are as many values as pixels in the width + //clear points + values.clear(); + } + values.add(arg0.getOrientation()); + repaint(); + } + + public void onStatusEvent(StatusEvent arg0) { + //nothing + } + + public void onDisconnectionEvent(DisconnectionEvent arg0) { + //Clear points. + 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 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/wiiuseapievents/EventsGatherer.java b/WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java index b83c33e..5c83d78 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java @@ -107,11 +107,11 @@ public class EventsGatherer { * x coordinates * @param y * y coordinates - * @param rxx + * @param rx * raw X coordinate (0-1023). - * @param ryy + * @param ry * raw Y coordinate (0-1023). - * @param si + * @param size * size of the IR dot (0-15). */ public void addIRPointToPreparedWiiMoteEvent(int x, int y, short rx, @@ -221,7 +221,7 @@ public class EventsGatherer { /** * Return an array containing the events. * - * @return + * @return events received */ public WiiUseApiEvent[] getEvents() { return java.util.Arrays.copyOfRange(events, 0, index); diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java b/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java index 9a7e31e..e8ea39b 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java @@ -145,11 +145,11 @@ public class GenericEvent extends WiiUseApiEvent { * x coordinates. * @param y * y coordinates - * @param rxx + * @param rx * raw X coordinate (0-1023). - * @param ryy + * @param ry * raw Y coordinate (0-1023). - * @param si + * @param size * size of the IR dot (0-15). */ public void addIRpoint(int x, int y, short rx, short ry, short size) { diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java b/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java index 4a99b1c..6007e97 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java @@ -109,11 +109,11 @@ public class IREvent extends WiimoteEvent { * x value * @param y * y value - * @param rxx + * @param rx * raw X coordinate (0-1023). - * @param ryy + * @param ry * raw Y coordinate (0-1023). - * @param si + * @param size * size of the IR dot (0-15). */ public void addIRpoint(int x, int y, short rx, short ry, short size) {