diff --git a/WiiUseJ/img/classiccontroller.png b/WiiUseJ/img/classiccontroller.png new file mode 100644 index 0000000..87a80f4 Binary files /dev/null and b/WiiUseJ/img/classiccontroller.png differ diff --git a/WiiUseJ/src/wiiusej/test/ClassicControllerGuiTest.java b/WiiUseJ/src/wiiusej/test/ClassicControllerGuiTest.java new file mode 100644 index 0000000..f2ff68f --- /dev/null +++ b/WiiUseJ/src/wiiusej/test/ClassicControllerGuiTest.java @@ -0,0 +1,165 @@ +/** + * 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.Wiimote; +import wiiusej.utils.ClassicControllerButtonsEventPanel; +import wiiusej.wiiusejevents.physicalevents.ClassicControllerEvent; +import wiiusej.wiiusejevents.physicalevents.ExpansionEvent; +import wiiusej.wiiusejevents.physicalevents.IREvent; +import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; +import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; +import wiiusej.wiiusejevents.utils.WiimoteListener; +import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent; +import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; + +/** + * This frame is used to display events from a classic controller. + * + * @author guiguito + */ +public class ClassicControllerGuiTest extends javax.swing.JFrame implements WiimoteListener{ + + private Wiimote wiimote; + private static int MAX_SHOULDER = 100; + + /** Creates new form ClassicControllerGuiTest */ + public ClassicControllerGuiTest(Wiimote wiimote) { + initComponents(); + this.wiimote = wiimote; + registerListeners(); + leftShoulderBar.setMaximum(MAX_SHOULDER); + rightShoulderBar.setMaximum(MAX_SHOULDER); + } + + private void registerListeners() { + wiimote.addWiiMoteEventListeners(this); + wiimote.addWiiMoteEventListeners((ClassicControllerButtonsEventPanel)classicControllerPanel); + } + + public void unRegisterListeners() { + wiimote.removeWiiMoteEventListeners(this); + wiimote.removeWiiMoteEventListeners((ClassicControllerButtonsEventPanel)classicControllerPanel); + } + + /** 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() { + + shouldersPanel = new javax.swing.JPanel(); + leftShoulderBar = new javax.swing.JProgressBar(); + rightShoulderBar = new javax.swing.JProgressBar(); + classicControllerPanel = new wiiusej.utils.ClassicControllerButtonsEventPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("WiiuseJ Classic Controller Test GUI"); + setResizable(false); + getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS)); + + shouldersPanel.setLayout(new javax.swing.BoxLayout(shouldersPanel, javax.swing.BoxLayout.LINE_AXIS)); + shouldersPanel.add(leftShoulderBar); + shouldersPanel.add(rightShoulderBar); + + getContentPane().add(shouldersPanel); + + javax.swing.GroupLayout classicControllerPanelLayout = new javax.swing.GroupLayout(classicControllerPanel); + classicControllerPanel.setLayout(classicControllerPanelLayout); + classicControllerPanelLayout.setHorizontalGroup( + classicControllerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 400, Short.MAX_VALUE) + ); + classicControllerPanelLayout.setVerticalGroup( + classicControllerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 284, Short.MAX_VALUE) + ); + + getContentPane().add(classicControllerPanel); + + pack(); + }// //GEN-END:initComponents + + public void onButtonsEvent(WiimoteButtonsEvent arg0) { + // nothing to do + } + + public void onIrEvent(IREvent arg0) { + // nothing to do + } + + public void onMotionSensingEvent(MotionSensingEvent arg0) { + // nothing to do + } + + public void onExpansionEvent(ExpansionEvent arg0) { + if (arg0 instanceof ClassicControllerEvent){ + ClassicControllerEvent classicController = (ClassicControllerEvent)arg0; + float leftShoulder = classicController.getLeftShoulder(); + float rightShoulder = classicController.getRightShoulder(); + leftShoulderBar.setValue(Math.round(leftShoulder*MAX_SHOULDER)); + rightShoulderBar.setValue(Math.round(rightShoulder*MAX_SHOULDER)); + } + + } + + public void onStatusEvent(StatusEvent arg0) { + // nothing to do + } + + public void onDisconnectionEvent(DisconnectionEvent arg0) { + // nothing to do + } + + public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) { + // nothing to do + } + + public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { + // nothing to do + } + + public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) { + // nothing to do + } + + public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) { + // nothing to do + } + + public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent arg0) { + // nothing to do + } + + public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent arg0) { + // nothing to do + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel classicControllerPanel; + private javax.swing.JProgressBar leftShoulderBar; + private javax.swing.JProgressBar rightShoulderBar; + private javax.swing.JPanel shouldersPanel; + // End of variables declaration//GEN-END:variables +} diff --git a/WiiUseJ/src/wiiusej/test/GuitarHero3GuiTest.java b/WiiUseJ/src/wiiusej/test/GuitarHero3GuiTest.java new file mode 100644 index 0000000..f9dc60a --- /dev/null +++ b/WiiUseJ/src/wiiusej/test/GuitarHero3GuiTest.java @@ -0,0 +1,172 @@ +/* + * GuitarHeroGUITest.java + * + * Created on 12 juin 2008, 23:10 + */ +package wiiusej.test; + +import wiiusej.Wiimote; +import wiiusej.utils.GuitarHero3ButtonsEventPanel; +import wiiusej.utils.GuitarHeroJoystickEventPanel; +import wiiusej.wiiusejevents.physicalevents.ExpansionEvent; +import wiiusej.wiiusejevents.physicalevents.GuitarHeroButtonsEvent; +import wiiusej.wiiusejevents.physicalevents.GuitarHeroEvent; +import wiiusej.wiiusejevents.physicalevents.IREvent; +import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; +import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; +import wiiusej.wiiusejevents.utils.WiimoteListener; +import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent; +import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; + +/** + * This frame is used to display events from a Guitar Hero 3. + * @author guiguito + */ +public class GuitarHero3GuiTest extends javax.swing.JFrame implements WiimoteListener { + + private Wiimote wiimote; + private static int MAX_WHAMMY_BAR = 100; + + /** Creates new form GuitarHeroGUITest */ + public GuitarHero3GuiTest(Wiimote wiimote) { + initComponents(); + this.wiimote = wiimote; + whammyProgressBar.setMaximum(MAX_WHAMMY_BAR); + registerListeners(); + } + + private void registerListeners() { + wiimote.addWiiMoteEventListeners(this); + //register panel buttons + wiimote.addWiiMoteEventListeners(guitarHero3ButtonsEventPanel); + //register joystick panel + wiimote.addWiiMoteEventListeners(guitarHero3JoystickPanel); + } + + public void unRegisterListeners() { + wiimote.removeWiiMoteEventListeners(this); + wiimote.removeWiiMoteEventListeners(guitarHero3ButtonsEventPanel); + wiimote.removeWiiMoteEventListeners(guitarHero3JoystickPanel); + } + + /** 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() { + + buttonsEventPanel = new javax.swing.JPanel(); + guitarHero3ButtonsEventPanel = new wiiusej.utils.GuitarHero3ButtonsEventPanel(); + bottomPanel = new javax.swing.JPanel(); + guitarHero3JoystickPanel = new wiiusej.utils.GuitarHeroJoystickEventPanel(); + whammyProgressBar = new javax.swing.JProgressBar(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("WiiuseJ Guitar Hero 3 Test GUI"); + getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS)); + + buttonsEventPanel.setBackground(new java.awt.Color(0, 0, 0)); + + javax.swing.GroupLayout buttonsEventPanelLayout = new javax.swing.GroupLayout(buttonsEventPanel); + buttonsEventPanel.setLayout(buttonsEventPanelLayout); + buttonsEventPanelLayout.setHorizontalGroup( + buttonsEventPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 448, Short.MAX_VALUE) + .addGroup(buttonsEventPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(buttonsEventPanelLayout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(guitarHero3ButtonsEventPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, Short.MAX_VALUE))) + ); + buttonsEventPanelLayout.setVerticalGroup( + buttonsEventPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 111, Short.MAX_VALUE) + .addGroup(buttonsEventPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(buttonsEventPanelLayout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(guitarHero3ButtonsEventPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, Short.MAX_VALUE))) + ); + + getContentPane().add(buttonsEventPanel); + + bottomPanel.setBackground(new java.awt.Color(0, 0, 0)); + bottomPanel.setLayout(new javax.swing.BoxLayout(bottomPanel, javax.swing.BoxLayout.X_AXIS)); + bottomPanel.add(guitarHero3JoystickPanel); + + whammyProgressBar.setBackground(new java.awt.Color(255, 255, 255)); + whammyProgressBar.setForeground(new java.awt.Color(255, 0, 255)); + bottomPanel.add(whammyProgressBar); + + getContentPane().add(bottomPanel); + + pack(); + }// //GEN-END:initComponents + public void onButtonsEvent(WiimoteButtonsEvent arg0) { + // nothing to do + } + + public void onIrEvent(IREvent arg0) { + // nothing to do + } + + public void onMotionSensingEvent(MotionSensingEvent arg0) { + // nothing to do + } + + public void onExpansionEvent(ExpansionEvent arg0) { + if (arg0 instanceof GuitarHeroEvent) { + GuitarHeroEvent guitar = (GuitarHeroEvent) arg0; + //move progress bar for whammy bar + whammyProgressBar.setValue(Math.round(MAX_WHAMMY_BAR*guitar.getWhammyBar())); + } + + } + + public void onStatusEvent(StatusEvent arg0) { + // nothing to do + } + + public void onDisconnectionEvent(DisconnectionEvent arg0) { + // nothing to do + } + + public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) { + // nothing to do + } + + public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { + // nothing to do + } + + public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) { + // nothing to do + } + + public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) { + // nothing to do + } + + public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent arg0) { + // nothing to do + } + + public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent arg0) { + // nothing to do + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel bottomPanel; + private javax.swing.JPanel buttonsEventPanel; + private wiiusej.utils.GuitarHero3ButtonsEventPanel guitarHero3ButtonsEventPanel; + private wiiusej.utils.GuitarHeroJoystickEventPanel guitarHero3JoystickPanel; + private javax.swing.JProgressBar whammyProgressBar; + // End of variables declaration//GEN-END:variables +} diff --git a/WiiUseJ/src/wiiusej/test/NunchukGuiTest.java b/WiiUseJ/src/wiiusej/test/NunchukGuiTest.java index 1068232..d7f284f 100644 --- a/WiiUseJ/src/wiiusej/test/NunchukGuiTest.java +++ b/WiiUseJ/src/wiiusej/test/NunchukGuiTest.java @@ -363,18 +363,22 @@ public class NunchukGuiTest extends javax.swing.JFrame implements if (arg0 instanceof NunchukEvent) { NunchukEvent nunchuk = (NunchukEvent) arg0; NunchukButtonsEvent buttons = nunchuk.getButtonsEvent(); + + //C button if (buttons.isButtonCJustPressed()) { cButton.setEnabled(false); - } - if (buttons.isButtonCJustReleased()) { + }else if (buttons.isButtonCJustReleased()) { cButton.setEnabled(true); } - if (buttons.isButtonZJustPressed()) { + + //Z button + if(buttons.isButtonZJustPressed()) { zButton.setEnabled(false); - } - if (buttons.isButtonZJustReleased()) { + }else if (buttons.isButtonZJustReleased()) { zButton.setEnabled(true); } + + if (isThresholdsRequested) { MotionSensingEvent evt = nunchuk.getNunchukMotionSensingEvent(); nunchukAccelerationTextField.setText(evt diff --git a/WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java b/WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java index e20623f..8dea3c9 100644 --- a/WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java +++ b/WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java @@ -87,11 +87,13 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements public void windowActivated(WindowEvent e) { showExpansionWiimoteButton.setEnabled(false); showExpansionWiimoteButton.setText("Hide Nunchuk"); + //@TODO adapt to the connected Expansion } public void windowDeactivated(WindowEvent e) { showExpansionWiimoteButton.setEnabled(true); showExpansionWiimoteButton.setText("Show Nunchuk"); + //@TODO adapt to the connected Expansion } }; @@ -235,10 +237,27 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements showExpansionWiimoteButton.setText("Show Nunchuk"); expansionFrame = new NunchukGuiTest(wiimote); expansionFrame - .setDefaultCloseOperation(NunchukGuiTest.HIDE_ON_CLOSE); + .setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); expansionFrame.addWindowListener(buttonSetter); isFirstStatusGot = true; - } + }else if(arg0.isClassicControllerConnected()){ + showExpansionWiimoteButton.setEnabled(true); + showExpansionWiimoteButton.setText("Show Classic Controller"); + expansionFrame = new ClassicControllerGuiTest(wiimote); + expansionFrame + .setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); + expansionFrame.addWindowListener(buttonSetter); + isFirstStatusGot = true; + } + else if(arg0.isClassicControllerConnected()){ + showExpansionWiimoteButton.setEnabled(true); + showExpansionWiimoteButton.setText("Show Guitar Hero 3 Controller"); + expansionFrame = new GuitarHero3GuiTest(wiimote); + expansionFrame + .setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); + expansionFrame.addWindowListener(buttonSetter); + isFirstStatusGot = true; + } } messageText.setText("Status received !"); batteryLevelText.setText(arg0.getBatteryLevel() + " %"); @@ -247,7 +266,7 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements led3Button.setEnabled(arg0.isLed3Set()); led4Button.setEnabled(arg0.isLed4Set()); if (arg0.isNunchukConnected()) { - ((NunchukGuiTest) expansionFrame).requestThresholdsUpdate(); + ((NunchukGuiTest) expansionFrame).requestThresholdsUpdate(); } // attachments int eventType = arg0.getEventType(); @@ -279,7 +298,7 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements showExpansionWiimoteButton.setEnabled(true); showExpansionWiimoteButton.setText("Show nunchuk"); expansionFrame = new NunchukGuiTest(wiimote); - expansionFrame.setDefaultCloseOperation(NunchukGuiTest.HIDE_ON_CLOSE); + expansionFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); expansionFrame.addWindowListener(buttonSetter); } @@ -299,21 +318,55 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements } public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) { - // nothing + messageText.setText("Guitar Hero 3 connected !"); + expansionText.setText("Expansion connected : Guitar Hero 3."); + showExpansionWiimoteButton.setEnabled(true); + showExpansionWiimoteButton.setText("Show Guitar Hero 3"); + expansionFrame = new GuitarHero3GuiTest(wiimote); + expansionFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); + expansionFrame.addWindowListener(buttonSetter); } public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) { - // nothing + messageText.setText("Guitar Hero 3 disconnected !"); + expansionText.setText("No expansion connected."); + showExpansionWiimoteButton.setEnabled(false); + showExpansionWiimoteButton.setText("No expansion"); + if (expansionFrame != null) { + if (expansionFrame instanceof GuitarHero3GuiTest) { + ((GuitarHero3GuiTest) expansionFrame).unRegisterListeners(); + } + expansionFrame.setEnabled(false); + expansionFrame.dispose(); + expansionFrame = null; + } } public void onClassicControllerInsertedEvent( ClassicControllerInsertedEvent arg0) { - // nothing + messageText.setText("Nunchuk connected !"); + expansionText.setText("Expansion connected : Classic Controller."); + showExpansionWiimoteButton.setEnabled(true); + showExpansionWiimoteButton.setText("Show Classic Controller"); + expansionFrame = new ClassicControllerGuiTest(wiimote); + expansionFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); + expansionFrame.addWindowListener(buttonSetter); } public void onClassicControllerRemovedEvent( ClassicControllerRemovedEvent arg0) { - // nothing + messageText.setText("Classic controller disconnected !"); + expansionText.setText("No expansion connected."); + showExpansionWiimoteButton.setEnabled(false); + showExpansionWiimoteButton.setText("No expansion"); + if (expansionFrame != null) { + if (expansionFrame instanceof ClassicControllerGuiTest) { + ((ClassicControllerGuiTest) expansionFrame).unRegisterListeners(); + } + expansionFrame.setEnabled(false); + expansionFrame.dispose(); + expansionFrame = null; + } } /** @@ -1222,6 +1275,8 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements if (expansionFrame != null) { if (expansionFrame instanceof NunchukGuiTest) { ((NunchukGuiTest) expansionFrame).unRegisterListeners(); + }else if (expansionFrame instanceof ClassicControllerGuiTest) { + ((ClassicControllerGuiTest) expansionFrame).unRegisterListeners(); } expansionFrame.setEnabled(false); expansionFrame.dispose(); diff --git a/WiiUseJ/src/wiiusej/utils/ButtonsEventPanel.java b/WiiUseJ/src/wiiusej/utils/ButtonsEventPanel.java index c71c312..97f9b19 100644 --- a/WiiUseJ/src/wiiusej/utils/ButtonsEventPanel.java +++ b/WiiUseJ/src/wiiusej/utils/ButtonsEventPanel.java @@ -55,7 +55,7 @@ public class ButtonsEventPanel extends javax.swing.JPanel implements private Color pressedColor = Color.RED; private Color heldColor = Color.ORANGE; private Color releasedColor = Color.YELLOW; - private Shape shape; + private Shape shape = new java.awt.geom.Ellipse2D.Double(0, 0, 13, 13); /** * Default constructor. Red : button just pressed. Orange : button held. @@ -66,7 +66,6 @@ public class ButtonsEventPanel extends javax.swing.JPanel implements java.net.URL url = ButtonsEventPanel.class .getResource("/img/wiimote.png"); wiimoteImage = toolkit.createImage(url); - shape = new java.awt.geom.Ellipse2D.Double(0, 0, 13, 13); initComponents(); } @@ -89,8 +88,7 @@ public class ButtonsEventPanel extends javax.swing.JPanel implements 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); + wiimoteImage = toolkit.createImage("img\\wiimote.png"); initComponents(); } @@ -295,8 +293,7 @@ public class ButtonsEventPanel extends javax.swing.JPanel implements } public void onDisconnectionEvent(DisconnectionEvent arg0) { - buttons = null; - repaint(); + clearView(); } public void onNunchukInsertedEvent(NunchukInsertedEvent e) { diff --git a/WiiUseJ/src/wiiusej/utils/GuitarHero3ButtonsEventPanel.java b/WiiUseJ/src/wiiusej/utils/GuitarHero3ButtonsEventPanel.java new file mode 100644 index 0000000..907a5dc --- /dev/null +++ b/WiiUseJ/src/wiiusej/utils/GuitarHero3ButtonsEventPanel.java @@ -0,0 +1,274 @@ +/** + * 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 wiiusej.wiiusejevents.physicalevents.ExpansionEvent; +import wiiusej.wiiusejevents.physicalevents.GuitarHeroButtonsEvent; +import wiiusej.wiiusejevents.physicalevents.GuitarHeroEvent; +import wiiusej.wiiusejevents.physicalevents.IREvent; +import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; +import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; +import wiiusej.wiiusejevents.utils.WiimoteListener; +import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent; +import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; + +/** + * This panel is used to display what happens on the buttons of the + * Guitar Hero 3 controller. + * @author guiguito + */ +public class GuitarHero3ButtonsEventPanel extends javax.swing.JPanel implements WiimoteListener { + + /** Creates new form GuitarHero3ButtonsEventPanel */ + public GuitarHero3ButtonsEventPanel() { + 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() { + + leftPanel = new javax.swing.JPanel(); + plusButton = new javax.swing.JToggleButton(); + minusButton = new javax.swing.JToggleButton(); + strumPanel = new javax.swing.JPanel(); + strumUpButton = new javax.swing.JToggleButton(); + strumDownButton = new javax.swing.JToggleButton(); + RightPanel = new javax.swing.JPanel(); + coloredButtonsPanel = new javax.swing.JPanel(); + orangeButton = new javax.swing.JToggleButton(); + blueButton = new javax.swing.JToggleButton(); + yellowButton = new javax.swing.JToggleButton(); + redButton = new javax.swing.JToggleButton(); + greenButton = new javax.swing.JToggleButton(); + + setBackground(new java.awt.Color(0, 0, 0)); + setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.X_AXIS)); + + leftPanel.setBackground(new java.awt.Color(0, 0, 0)); + leftPanel.setLayout(new javax.swing.BoxLayout(leftPanel, javax.swing.BoxLayout.LINE_AXIS)); + + plusButton.setBackground(new java.awt.Color(255, 255, 255)); + plusButton.setFont(new java.awt.Font("Arial", 1, 24)); + plusButton.setText("+"); + leftPanel.add(plusButton); + + minusButton.setBackground(new java.awt.Color(255, 255, 255)); + minusButton.setFont(new java.awt.Font("Arial", 1, 24)); + minusButton.setText("-"); + leftPanel.add(minusButton); + + strumPanel.setBackground(new java.awt.Color(0, 0, 0)); + strumPanel.setLayout(new javax.swing.BoxLayout(strumPanel, javax.swing.BoxLayout.Y_AXIS)); + + strumUpButton.setBackground(new java.awt.Color(255, 255, 255)); + strumUpButton.setFont(new java.awt.Font("Arial", 1, 24)); + strumUpButton.setText("Strum UP"); + strumPanel.add(strumUpButton); + + strumDownButton.setBackground(new java.awt.Color(255, 255, 255)); + strumDownButton.setFont(new java.awt.Font("Arial", 1, 24)); + strumDownButton.setText("Strum DOWN"); + strumPanel.add(strumDownButton); + + leftPanel.add(strumPanel); + + add(leftPanel); + + RightPanel.setBackground(new java.awt.Color(0, 0, 0)); + RightPanel.setLayout(new javax.swing.BoxLayout(RightPanel, javax.swing.BoxLayout.LINE_AXIS)); + + coloredButtonsPanel.setLayout(new javax.swing.BoxLayout(coloredButtonsPanel, javax.swing.BoxLayout.LINE_AXIS)); + + orangeButton.setBackground(new java.awt.Color(255, 153, 0)); + orangeButton.setFont(new java.awt.Font("Arial", 1, 24)); + orangeButton.setText("O"); + coloredButtonsPanel.add(orangeButton); + + blueButton.setBackground(new java.awt.Color(0, 0, 204)); + blueButton.setFont(new java.awt.Font("Arial", 1, 24)); + blueButton.setText("O"); + coloredButtonsPanel.add(blueButton); + + yellowButton.setBackground(new java.awt.Color(255, 255, 0)); + yellowButton.setFont(new java.awt.Font("Arial", 1, 24)); + yellowButton.setText("O"); + coloredButtonsPanel.add(yellowButton); + + redButton.setBackground(new java.awt.Color(255, 0, 0)); + redButton.setFont(new java.awt.Font("Arial", 1, 24)); + redButton.setText("O"); + coloredButtonsPanel.add(redButton); + + greenButton.setBackground(new java.awt.Color(51, 255, 0)); + greenButton.setFont(new java.awt.Font("Arial", 1, 24)); + greenButton.setText("O"); + coloredButtonsPanel.add(greenButton); + + RightPanel.add(coloredButtonsPanel); + + add(RightPanel); + }// //GEN-END:initComponents + public void onButtonsEvent(WiimoteButtonsEvent arg0) { + //do nothing + } + + public void onIrEvent(IREvent arg0) { + //do nothing + } + + public void onMotionSensingEvent(MotionSensingEvent arg0) { + //do nothing + } + + public void onExpansionEvent(ExpansionEvent arg0) { + if (arg0 instanceof GuitarHeroEvent) { + GuitarHeroEvent guitar = (GuitarHeroEvent) arg0; + GuitarHeroButtonsEvent buttons = guitar.getButtonsEvent(); + + //orange button + if (buttons.isButtonOrangeJustPressed()) { + orangeButton.setSelected(true); + orangeButton.setText("X"); + } else if (buttons.isButtonOrangeJustReleased()) { + orangeButton.setSelected(false); + orangeButton.setText("O"); + } + + //blue button + if (buttons.isButtonBlueJustPressed()) { + blueButton.setSelected(true); + orangeButton.setText("X"); + } else if (buttons.isButtonBlueJustReleased()) { + blueButton.setSelected(false); + orangeButton.setText("O"); + } + + //Yellow button + if (buttons.isButtonYellowJustPressed()) { + yellowButton.setSelected(true); + yellowButton.setText("X"); + } else if (buttons.isButtonYellowJustReleased()) { + yellowButton.setSelected(false); + yellowButton.setText("O"); + } + + //Red button + if (buttons.isButtonRedJustPressed()) { + redButton.setSelected(true); + redButton.setText("X"); + } else if (buttons.isButtonRedJustReleased()) { + redButton.setSelected(false); + redButton.setText("O"); + } + + //Green button + if (buttons.isButtonGreenJustPressed()) { + greenButton.setSelected(true); + greenButton.setText("X"); + } else if (buttons.isButtonGreenJustReleased()) { + greenButton.setSelected(false); + greenButton.setText("O"); + } + + //Plus button + if (buttons.isButtonPlusJustPressed()) { + plusButton.setSelected(true); + } else if (buttons.isButtonPlusJustReleased()) { + plusButton.setSelected(false); + } + + //Minus button + if (buttons.isButtonMinusJustPressed()) { + minusButton.setSelected(true); + } else if (buttons.isButtonMinusJustReleased()) { + minusButton.setSelected(false); + } + + //Strum up button + if (buttons.isButtonStrumUpJustPressed()) { + strumUpButton.setSelected(true); + } else if (buttons.isButtonStrumUpJustReleased()) { + strumUpButton.setSelected(false); + } + + //Strum down button + if (buttons.isButtonStrumDownJustPressed()) { + strumDownButton.setSelected(true); + } else if (buttons.isButtonStrumDownJustReleased()) { + strumDownButton.setSelected(false); + } + } + } + + public void onStatusEvent(StatusEvent arg0) { + //do nothing + } + + public void onDisconnectionEvent(DisconnectionEvent arg0) { + //do nothing + } + + public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) { + //do nothing + } + + public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { + //do nothing + } + + public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) { + //do nothing + } + + public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) { + //do nothing + } + + public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent arg0) { + //do nothing + } + + public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent arg0) { + //do nothing + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel RightPanel; + private javax.swing.JToggleButton blueButton; + private javax.swing.JPanel coloredButtonsPanel; + private javax.swing.JToggleButton greenButton; + private javax.swing.JPanel leftPanel; + private javax.swing.JToggleButton minusButton; + private javax.swing.JToggleButton orangeButton; + private javax.swing.JToggleButton plusButton; + private javax.swing.JToggleButton redButton; + private javax.swing.JToggleButton strumDownButton; + private javax.swing.JPanel strumPanel; + private javax.swing.JToggleButton strumUpButton; + private javax.swing.JToggleButton yellowButton; + // End of variables declaration//GEN-END:variables +} diff --git a/WiiUseJ/src/wiiusej/utils/GuitarHeroJoystickEventPanel.java b/WiiUseJ/src/wiiusej/utils/GuitarHeroJoystickEventPanel.java new file mode 100644 index 0000000..6fd906f --- /dev/null +++ b/WiiUseJ/src/wiiusej/utils/GuitarHeroJoystickEventPanel.java @@ -0,0 +1,39 @@ +/** + * 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 wiiusej.wiiusejevents.physicalevents.ExpansionEvent; +import wiiusej.wiiusejevents.physicalevents.GuitarHeroEvent; +import wiiusej.wiiusejevents.physicalevents.JoystickEvent; + +/** + * Panel to display Guitar Hero 3 controller joystick events. + * + * @author guiguito + */ +public class GuitarHeroJoystickEventPanel extends JoystickEventPanel{ + + @Override + public JoystickEvent getJoystickEvent(ExpansionEvent e) { + if (e instanceof GuitarHeroEvent){ + return ((GuitarHeroEvent)e).getGuitarHeroJoystickEvent(); + } + return null; + } + +} diff --git a/WiiUseJ/src/wiiusej/utils/JoystickEventPanel.java b/WiiUseJ/src/wiiusej/utils/JoystickEventPanel.java index fe21c78..9e7efe2 100644 --- a/WiiUseJ/src/wiiusej/utils/JoystickEventPanel.java +++ b/WiiUseJ/src/wiiusej/utils/JoystickEventPanel.java @@ -155,7 +155,7 @@ public abstract class JoystickEventPanel extends javax.swing.JPanel implements } public void onExpansionEvent(ExpansionEvent arg0) { - JoystickEvent joy = getJoystikEvent(arg0); + JoystickEvent joy = getJoystickEvent(arg0); if (joy != null) { lastJoystickEvent = joy; } @@ -228,7 +228,7 @@ public abstract class JoystickEventPanel extends javax.swing.JPanel implements this.shape = shape; } - public abstract JoystickEvent getJoystikEvent(ExpansionEvent e); + public abstract JoystickEvent getJoystickEvent(ExpansionEvent e); /** * This method is called from within the constructor to initialize the form. diff --git a/WiiUseJ/src/wiiusej/utils/NunchukJoystickEventPanel.java b/WiiUseJ/src/wiiusej/utils/NunchukJoystickEventPanel.java index a534751..9d088bc 100644 --- a/WiiUseJ/src/wiiusej/utils/NunchukJoystickEventPanel.java +++ b/WiiUseJ/src/wiiusej/utils/NunchukJoystickEventPanel.java @@ -11,6 +11,7 @@ * 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 . */ @@ -28,7 +29,7 @@ import wiiusej.wiiusejevents.physicalevents.NunchukEvent; public class NunchukJoystickEventPanel extends JoystickEventPanel { @Override - public JoystickEvent getJoystikEvent(ExpansionEvent e) { + public JoystickEvent getJoystickEvent(ExpansionEvent e) { if (e instanceof NunchukEvent) { return ((NunchukEvent) e).getNunchukJoystickEvent(); } diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/ClassicControllerEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/ClassicControllerEvent.java index 3474dc6..ce04bd7 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/ClassicControllerEvent.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/ClassicControllerEvent.java @@ -164,7 +164,7 @@ public class ClassicControllerEvent extends ExpansionEvent { public String toString() { String out = ""; /* Status */ - out += "/*********** Classis Controller EVENT : WIIMOTE ID :" + out += "/*********** Classic Controller EVENT : WIIMOTE ID :" + getWiimoteId() + " ********/\n"; out += buttonsEvent; out += "Left shoulder : " + leftShoulder + "\n"; diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/GuitarHeroEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/GuitarHeroEvent.java index f5c30b6..d4796a3 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/GuitarHeroEvent.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/GuitarHeroEvent.java @@ -108,7 +108,7 @@ public class GuitarHeroEvent extends ExpansionEvent{ public String toString() { String out = ""; /* Status */ - out += "/*********** Classis Controller EVENT : WIIMOTE ID :" + getWiimoteId() + out += "/*********** Guitar Hero 3 EVENT : WIIMOTE ID :" + getWiimoteId() + " ********/\n"; out += buttonsEvent; out += "Whammy Bar : "+whammyBar+"\n";