From 1511bbf186a84dd9f2e4e1d5d1bef7533cfc2ae8 Mon Sep 17 00:00:00 2001 From: "guilhem.duche" Date: Sun, 25 May 2008 21:13:03 +0000 Subject: [PATCH] wiiuseJ 0.12 work in progress. git-svn-id: http://wiiusej.googlecode.com/svn/trunk@147 ae48ae66-6a45-0410-b38e-211266189506 --- WiiUseJ/WiiUseJ.dll | Bin 30473 -> 30473 bytes WiiUseJ/src/wiiusej/WiiUseApiManager.java | 2 +- .../src/wiiusej/test/CloseGuiTestCleanly.java | 8 - WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java | 586 ++++++++++++++---- .../src/wiiusej/utils/AccelerationPanel.java | 121 +++- .../src/wiiusej/utils/ButtonsEventPanel.java | 35 +- WiiUseJ/src/wiiusej/utils/GForcePanel.java | 74 ++- WiiUseJ/src/wiiusej/utils/IRPanel.java | 62 +- .../src/wiiusej/utils/OrientationPanel.java | 74 ++- .../physicalevents/JoystickEvent.java | 6 +- .../physicalevents/NunchukEvent.java | 2 +- .../wiiusejevents/utils/EventsGatherer.java | 2 +- .../wiiuseapievents/StatusEvent.java | 8 +- .../wiiuseapievents/WiimoteEvent.java | 2 +- 14 files changed, 770 insertions(+), 212 deletions(-) diff --git a/WiiUseJ/WiiUseJ.dll b/WiiUseJ/WiiUseJ.dll index 3f81f46d65ed3d289f61d8c984df8c317364b41f..c7eab0a069b3bf83d944db8b4ef7474c17ae75b1 100644 GIT binary patch delta 2223 zcmY+Fe^6A{702&=zLkaG?!tmmph(z7A=xC$?t9O;{8|XhFA;zP{w;(0g}6teP5-tRYE>A&W6wy)0!h?4&Cg42oN(28$#~jTIhfW1&YCqWP(~ zN=`BEyw@?IzE}rmRc7Wk3ty_zC=1bQ3ta(rb+W4WA?~l58u}sbAJ_wXRWWcz9ZFl^ z*Xr%D9r$j6tIQCBsJs8g5HjGAvlu)H8#GDGpBA7*b8Y3X&^P#7SR0{#;;-|;;IM5B z^<*)DRDaJ0>!oSW5=oHyfv)}gcb|FwshE@sBD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x^~gr#F!JZfS>!x2ub2f6)qg`~)f4VS#F^0KLdRScRb~3s`puaIVTry%_8;oZjh+NF8vh zx)Xknwhg;1V5t(|r^xu7Yv7COry!}u3oX0Wz?-%EL0;>lL7aOZ`-?Ue_8-_f=mb2q z`-buYe$>PVR(xL(vK&K53rP2->zfZAZ*NCi9u(}kfp>$}oyRYOuTGVew`%U1 zSo}ODK&Xzx1-`9Q(Oa;oo~JKDUA;=#y~?%X2|}KOf%;3z`c-;O93hus+ur-M2aNW! z%3J@J#KF#!C!Qmj@UdM*ufmu1GUei`xmV%|xdoLC9ZK&i{c*hR4*0O)ET&%8sKUq{ zjUCE&R{7X*ln--g9fq|{Wt$a|btAXsNNZ>3(F3IVJB?T-@t?pHoNiL#Lvpd{EOkKY rKAxFLfSP@SbQ13F^V4d0xmgT1ihT=AH<#g=ZEoqHA-}Jsd) 1000) { + normalTimeoutSpinner.setValue("1000"); + } else if (valueInt < 0) { + normalTimeoutSpinner.setValue("0"); + } + } + }//GEN-LAST:event_normalTimeoutSpinnerStateChanged + + private void expansionHandshakeTimeoutSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_expansionHandshakeTimeoutSpinnerStateChanged + String value = expansionHandshakeTimeoutSpinner.getValue().toString(); + boolean isInt = true; + int valueInt = 0; + try { + valueInt = Integer.parseInt(value); + } catch (NumberFormatException e) { + isInt = false; + messageText.setText("Wrong value for expansion handshake timeout."); + } + if (isInt) { + if (valueInt > 1000) { + expansionHandshakeTimeoutSpinner.setValue("1000"); + } else if (valueInt < 0) { + expansionHandshakeTimeoutSpinner.setValue("0"); + } + } + }//GEN-LAST:event_expansionHandshakeTimeoutSpinnerStateChanged + + private void setIrSensitivySpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_setIrSensitivySpinnerStateChanged + String value = setIrSensitivySpinner.getValue().toString(); + boolean isInt = true; + int valueInt = 0; + try { + valueInt = Integer.parseInt(value); + } catch (NumberFormatException e) { + isInt = false; + messageText.setText("Wrong value for IR senstivity."); + } + if (isInt) { + if (valueInt > 5) { + setIrSensitivySpinner.setValue("1000"); + } else if (valueInt < 0) { + setIrSensitivySpinner.setValue("0"); + } + } + }//GEN-LAST:event_setIrSensitivySpinnerStateChanged + + private void setIrSensitivyButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_setIrSensitivyButtonMousePressed + String value = setIrSensitivySpinner.getValue().toString(); + boolean isInt = true; + int valueInt = 0; + try { + valueInt = Integer.parseInt(value); + } catch (NumberFormatException e) { + isInt = false; + messageText.setText("Wrong value for IR sensitivity. It must be an int !"); + } + if (isInt) { + if (valueInt >= 1 && valueInt <= 5) { + wiimote.setIrSensitivity(valueInt); + messageText.setText("IR senstivity set to: " + valueInt + "."); + } else { + messageText.setText("Wrong value for IR senstivity. It muset be between 1 and 5 !"); + } + } + }//GEN-LAST:event_setIrSensitivyButtonMousePressed + + private void setTimeoutButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_setTimeoutButtonMousePressed + //get normal timeout + String value = normalTimeoutSpinner.getValue().toString(); + boolean isInt = true; + short valueInt = 0; + try { + valueInt = Short.parseShort(value); + } catch (NumberFormatException e) { + isInt = false; + messageText.setText("Wrong value for normal timeout. It must be an int !"); + } + //get expansion handshake timeout + String value2 = expansionHandshakeTimeoutSpinner.getValue().toString(); + boolean isInt2 = true; + short valueInt2 = 0; + try { + valueInt2 = Short.parseShort(value2); + } catch (NumberFormatException e) { + isInt2 = false; + messageText.setText("Wrong value for expansion handshake timeout. It must be an int !"); + } + if (isInt && isInt2) { + if (valueInt > 0 && valueInt2 > 0) { + wiimote.setTimeout(valueInt, valueInt2); + messageText.setText("Normal timeout set to: " + valueInt + " and expansion handshake timeout set to: " + valueInt2 + "!"); + } else { + messageText.setText("Wrong value for one of the timeout value. It must be an integer > 0 !"); + } + } + }//GEN-LAST:event_setTimeoutButtonMousePressed + + private void reconnectWiimotesButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_reconnectWiimotesButtonMousePressed + //stop manager + WiiUseApiManager manager = WiiUseApiManager.getInstance(); + manager.shutdown(); + //unregister previous wiimote + onDisconnectionEvent(null); + + //get wiimote + wiimote = WiiUseApiManager.getWiimotes(1, true)[0]; + + //registers listeners + 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(); + + //Reset Gui + //setup buttons In first state + toggleRumbleButton.setText("Activate Rumble"); + toggleRumbleButton.setEnabled(true); + toggleMotionSensingTrackingButton.setText("Activate motion sensing Tracking"); + toggleMotionSensingTrackingButton.setEnabled(true); + toggleIRTrackingButton.setText("Activate IR Tracking"); + toggleIRTrackingButton.setEnabled(true); + toggleContinuousButton.setText("Activate Continuous"); + toggleContinuousButton.setEnabled(true); + toggleScreenAspectRatioButton.setText("Set screen aspect ratio 4/3"); + toggleScreenAspectRatioButton.setEnabled(true); + toggleSensorBarPositionButton.setText("Set sensor bar above"); + toggleSensorBarPositionButton.setEnabled(true); + toggleSmoothingButton.setText("Activate Smoothing"); + toggleSmoothingButton.setEnabled(true); + mouseIRControlButton.setText("Start infrared mouse control"); + mouseIRControlButton.setEnabled(true); + + isFirstStatusGot = false; + getStatusButtonMousePressed(null); + }//GEN-LAST:event_reconnectWiimotesButtonMousePressed + + private void showExpansionWiimoteButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_showExpansionWiimoteButtonMousePressed + System.out.println("fdsfds"); + if (expansionFrame != null) { + System.out.println("aaaaaaaaaa"); + if (showExpansionWiimoteButton.isEnabled()) {//expansion frame not shown + //show it + System.out.println("enabled"); + expansionFrame.setEnabled(true); + expansionFrame.setVisible(true); + showExpansionWiimoteButton.setEnabled(false); + showExpansionWiimoteButton.setText("Hide Nunchuk"); + messageText.setText("Nunchuk displayed !"); + } else {//already being shown + System.out.println("desactivated"); + expansionFrame.setEnabled(false); + expansionFrame.setVisible(false); + showExpansionWiimoteButton.setEnabled(true); + showExpansionWiimoteButton.setText("Show Nunchuk"); + messageText.setText("Nunchuk hidden !"); + } + } + }//GEN-LAST:event_showExpansionWiimoteButtonMousePressed + // 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.JPanel activateMotionSensingPanel; + private javax.swing.JPanel activateRumbleIRPanel; + private javax.swing.JPanel activateSmoothingContinuousPanel; 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.JPanel exPansionPanel; + private javax.swing.JSpinner expansionHandshakeTimeoutSpinner; + private javax.swing.JLabel expansionHandshakeTimeoutText; private javax.swing.JLabel expansionText; private javax.swing.JPanel fixedWiimotePanel; private javax.swing.JPanel gForcePanel; private javax.swing.JButton getStatusButton; + private javax.swing.JPanel getStatusPanel; 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.JSpinner normalTimeoutSpinner; + private javax.swing.JLabel normalTimeoutText; private javax.swing.JButton orientationThresholdButton; - private javax.swing.JPanel orientationThresholdPanel; private javax.swing.JTextField orientationThresholdTextField; + private javax.swing.JButton reconnectWiimotesButton; private javax.swing.JPanel rightPanel; + private javax.swing.JPanel setAccelerationThresholdPanel; + private javax.swing.JPanel setAlphaSmoothingPanel; + private javax.swing.JPanel setIRConfPanel; + private javax.swing.JButton setIrSensitivyButton; + private javax.swing.JPanel setIrSensitivyPanel; + private javax.swing.JSpinner setIrSensitivySpinner; private javax.swing.JButton setLedsButton; + private javax.swing.JPanel setLedsPanel; + private javax.swing.JPanel setOrientationThresholdPanel; + private javax.swing.JButton setTimeoutButton; + private javax.swing.JPanel setTimeoutPanel; private javax.swing.JButton setVirtualResolutionButton; + private javax.swing.JPanel setVirtualResolutionPanel; + private javax.swing.JButton showExpansionWiimoteButton; + private javax.swing.JPanel startMouseControlPanel; private javax.swing.JButton toggleContinuousButton; private javax.swing.JButton toggleIRTrackingButton; private javax.swing.JButton toggleMotionSensingTrackingButton; diff --git a/WiiUseJ/src/wiiusej/utils/AccelerationPanel.java b/WiiUseJ/src/wiiusej/utils/AccelerationPanel.java index d8c9669..c441e5e 100644 --- a/WiiUseJ/src/wiiusej/utils/AccelerationPanel.java +++ b/WiiUseJ/src/wiiusej/utils/AccelerationPanel.java @@ -26,6 +26,7 @@ import java.awt.geom.AffineTransform; import java.util.ArrayList; import wiiusej.values.RawAcceleration; +import wiiusej.wiiusejevents.GenericEvent; import wiiusej.wiiusejevents.physicalevents.ExpansionEvent; import wiiusej.wiiusejevents.physicalevents.IREvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; @@ -42,7 +43,7 @@ import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; * * @author guiguito */ -public class AccelerationPanel extends javax.swing.JPanel implements +public abstract class AccelerationPanel extends javax.swing.JPanel implements WiimoteListener { private Image mImage;// image for double buffering @@ -57,6 +58,30 @@ public class AccelerationPanel extends javax.swing.JPanel implements public AccelerationPanel() { initComponents(); } + + /** + * Constructor used to choose the colors used by the AccelerationPanel. + * + * @param bgColor + * background color. + * @param xColor + * x color. + * @param yColor + * y color. + * @param zColor + * z color. + * @param lColor + * line color. + */ + public AccelerationPanel(Color bgColor, Color xColor, Color yColor, + Color zColor, Color lColor) { + backgroundColor = bgColor; + this.xColor = xColor; + this.yColor = yColor; + this.zColor = zColor; + lineColor = lColor; + initComponents(); + } @Override public void paintComponent(Graphics g) { @@ -125,19 +150,18 @@ public class AccelerationPanel extends javax.swing.JPanel implements // put offscreen image on the screen g.drawImage(mImage, 0, 0, null); } - - /** - * check if the mImage variable has been initialized. If it's not the case - * it initializes it with the dimensions of the panel. mImage is for double - * buffering. - */ - private void checkOffScreenImage() { - Dimension d = getSize(); - if (mImage == null || mImage.getWidth(null) != d.width - || mImage.getHeight(null) != d.height) { - mImage = createImage(d.width, d.height); - } - } + + /** + * check if the mImage variable has been initialized. If it's not the case + * it initializes it with the dimensions of the panel. mImage is for double + * buffering. + */ + private void checkOffScreenImage() { + Dimension d = getSize(); + if (mImage == null || mImage.getWidth(null) != d.width || mImage.getHeight(null) != d.height) { + mImage = createImage(d.width, d.height); + } + } public void onButtonsEvent(WiimoteButtonsEvent arg0) { // nothing @@ -148,17 +172,11 @@ public class AccelerationPanel extends javax.swing.JPanel implements } 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(); + draw(arg0); } - public void onExpansionEvent(ExpansionEvent e) { - // nothing + public void onExpansionEvent(ExpansionEvent arg0) { + draw(arg0); } public void onStatusEvent(StatusEvent arg0) { @@ -171,14 +189,67 @@ public class AccelerationPanel extends javax.swing.JPanel implements repaint(); } - public void onNunchukInsertedEvent(NunchukInsertedEvent e) { + public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) { // nothing } - public void onNunchukRemovedEvent(NunchukRemovedEvent e) { + public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { // nothing } + + private void draw(GenericEvent arg0){ + if (values.size() >= getWidth()) { + // if there are as many values as pixels in the width + // clear points + values.clear(); + } + RawAcceleration rawAcceleration = getRawAccelerationValue(arg0); + if (rawAcceleration != null) values.add(rawAcceleration); + repaint(); + } + + public abstract RawAcceleration getRawAccelerationValue(GenericEvent e); + public Color getBackgroundColor() { + return backgroundColor; + } + + public Color getLineColor() { + return lineColor; + } + + public Color getXColor() { + return xColor; + } + + public Color getYColor() { + return yColor; + } + + public Color getZColor() { + return zColor; + } + + public void setBackgroundColor(Color backgroundColor) { + this.backgroundColor = backgroundColor; + } + + public void setLineColor(Color lineColor) { + this.lineColor = lineColor; + } + + public void setXColor(Color xColor) { + this.xColor = xColor; + } + + public void setYColor(Color yColor) { + this.yColor = yColor; + } + + public void setZColor(Color zColor) { + this.zColor = zColor; + } + /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always diff --git a/WiiUseJ/src/wiiusej/utils/ButtonsEventPanel.java b/WiiUseJ/src/wiiusej/utils/ButtonsEventPanel.java index 7c36552..4497e28 100644 --- a/WiiUseJ/src/wiiusej/utils/ButtonsEventPanel.java +++ b/WiiUseJ/src/wiiusej/utils/ButtonsEventPanel.java @@ -26,7 +26,6 @@ import java.awt.Shape; import java.awt.Toolkit; import java.awt.geom.AffineTransform; -import wiiusej.wiiusejevents.physicalevents.ButtonsEvent; import wiiusej.wiiusejevents.physicalevents.ExpansionEvent; import wiiusej.wiiusejevents.physicalevents.IREvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; @@ -304,6 +303,40 @@ public class ButtonsEventPanel extends javax.swing.JPanel implements // nothing } + public Color getHeldColor() { + return heldColor; + } + + public Color getPressedColor() { + return pressedColor; + } + + public Color getReleasedColor() { + return releasedColor; + } + + public Shape getShape() { + return shape; + } + + public void setHeldColor(Color heldColor) { + this.heldColor = heldColor; + } + + public void setPressedColor(Color pressedColor) { + this.pressedColor = pressedColor; + } + + public void setReleasedColor(Color releasedColor) { + this.releasedColor = releasedColor; + } + + public void setShape(Shape shape) { + this.shape = shape; + } + + + /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always diff --git a/WiiUseJ/src/wiiusej/utils/GForcePanel.java b/WiiUseJ/src/wiiusej/utils/GForcePanel.java index 5ecb00f..bc6d86a 100644 --- a/WiiUseJ/src/wiiusej/utils/GForcePanel.java +++ b/WiiUseJ/src/wiiusej/utils/GForcePanel.java @@ -26,6 +26,7 @@ import java.awt.geom.AffineTransform; import java.util.ArrayList; import wiiusej.values.GForce; +import wiiusej.wiiusejevents.GenericEvent; import wiiusej.wiiusejevents.physicalevents.ExpansionEvent; import wiiusej.wiiusejevents.physicalevents.IREvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; @@ -41,7 +42,7 @@ import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; * * @author guiguito */ -public class GForcePanel extends javax.swing.JPanel implements WiimoteListener { +public abstract class GForcePanel extends javax.swing.JPanel implements WiimoteListener { private Image mImage;// image for double buffering private Color xColor = Color.RED; @@ -173,17 +174,11 @@ public class GForcePanel extends javax.swing.JPanel implements WiimoteListener { } 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(); + draw(arg0); } - public void onExpansionEvent(ExpansionEvent e) { - // nothing + public void onExpansionEvent(ExpansionEvent arg0) { + draw(arg0); } public void onStatusEvent(StatusEvent arg0) { @@ -196,14 +191,69 @@ public class GForcePanel extends javax.swing.JPanel implements WiimoteListener { repaint(); } - public void onNunchukInsertedEvent(NunchukInsertedEvent e) { + public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) { // nothing } - public void onNunchukRemovedEvent(NunchukRemovedEvent e) { + public void onNunchukRemovedEvent(NunchukRemovedEvent arg0){ // nothing } + + private void draw(GenericEvent arg0){ + if (values.size() >= getWidth()) { + // if there are as many values as pixels in the width + // clear points + values.clear(); + } + GForce gforce = getGForceValue(arg0); + if (gforce != null) values.add(gforce); + repaint(); + } + + public abstract GForce getGForceValue(GenericEvent e); + public Color getBackgroundColor() { + return backgroundColor; + } + + public Color getLineColor() { + return lineColor; + } + + public Color getXColor() { + return xColor; + } + + public Color getYColor() { + return yColor; + } + + public Color getZColor() { + return zColor; + } + + public void setBackgroundColor(Color backgroundColor) { + this.backgroundColor = backgroundColor; + } + + public void setLineColor(Color lineColor) { + this.lineColor = lineColor; + } + + public void setXColor(Color xColor) { + this.xColor = xColor; + } + + public void setYColor(Color yColor) { + this.yColor = yColor; + } + + public void setZColor(Color zColor) { + this.zColor = zColor; + } + + + /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always diff --git a/WiiUseJ/src/wiiusej/utils/IRPanel.java b/WiiUseJ/src/wiiusej/utils/IRPanel.java index 87ab140..913c308 100644 --- a/WiiUseJ/src/wiiusej/utils/IRPanel.java +++ b/WiiUseJ/src/wiiusej/utils/IRPanel.java @@ -49,7 +49,7 @@ public class IRPanel extends javax.swing.JPanel implements WiimoteListener { private Image mImage;//image for double buffering private int[] xCoordinates; private int[] yCoordinates; - private int nbPoints=-1; + private int nbPoints = -1; /** * Default constructor for IR Panel. @@ -63,7 +63,7 @@ public class IRPanel extends javax.swing.JPanel implements WiimoteListener { initArrays(); initComponents(); } - + /** * Constructor used to parameterize the IR panel. * @param bgColor color. @@ -79,8 +79,8 @@ public class IRPanel extends javax.swing.JPanel implements WiimoteListener { initArrays(); initComponents(); } - - private void initArrays(){ + + private void initArrays() { xCoordinates = new int[MAX_NB_POINTS]; yCoordinates = new int[MAX_NB_POINTS]; for (int i = 0; i < MAX_NB_POINTS; i++) { @@ -135,7 +135,7 @@ public class IRPanel extends javax.swing.JPanel implements WiimoteListener { public void onButtonsEvent(WiimoteButtonsEvent arg0) { //nothing - repaint(); + repaint(); } public void onIrEvent(IREvent arg0) { @@ -158,10 +158,10 @@ public class IRPanel extends javax.swing.JPanel implements WiimoteListener { public void onMotionSensingEvent(MotionSensingEvent arg0) { //nothing } - + public void onExpansionEvent(ExpansionEvent e) { - // nothing - } + // nothing + } public void onStatusEvent(StatusEvent arg0) { //nothing @@ -176,14 +176,46 @@ public class IRPanel extends javax.swing.JPanel implements WiimoteListener { //redraw panel repaint(); } - - public void onNunchukInsertedEvent(NunchukInsertedEvent e) { - // nothing - } - public void onNunchukRemovedEvent(NunchukRemovedEvent e) { - // nothing - } + public void onNunchukInsertedEvent(NunchukInsertedEvent e) { + // nothing + } + + public void onNunchukRemovedEvent(NunchukRemovedEvent e) { + // nothing + } + + public Color getBackgroundColor() { + return backgroundColor; + } + + public Color getBorderColor() { + return borderColor; + } + + public Color getColor() { + return color; + } + + public Shape getShape() { + return shape; + } + + public void setBackgroundColor(Color backgroundColor) { + this.backgroundColor = backgroundColor; + } + + public void setBorderColor(Color borderColor) { + this.borderColor = borderColor; + } + + public void setColor(Color color) { + this.color = color; + } + + public void setShape(Shape shape) { + this.shape = shape; + } /** This method is called from within the constructor to * initialize the form. diff --git a/WiiUseJ/src/wiiusej/utils/OrientationPanel.java b/WiiUseJ/src/wiiusej/utils/OrientationPanel.java index 192cd55..c67bf0d 100644 --- a/WiiUseJ/src/wiiusej/utils/OrientationPanel.java +++ b/WiiUseJ/src/wiiusej/utils/OrientationPanel.java @@ -26,6 +26,7 @@ import java.awt.geom.AffineTransform; import java.util.ArrayList; import wiiusej.values.Orientation; +import wiiusej.wiiusejevents.GenericEvent; import wiiusej.wiiusejevents.physicalevents.ExpansionEvent; import wiiusej.wiiusejevents.physicalevents.IREvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; @@ -41,7 +42,7 @@ import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; * * @author guiguito */ -public class OrientationPanel extends javax.swing.JPanel implements +public abstract class OrientationPanel extends javax.swing.JPanel implements WiimoteListener { private Image mImage;// image for double buffering @@ -175,17 +176,11 @@ public class OrientationPanel extends javax.swing.JPanel implements } 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(); + draw(arg0); } - public void onExpansionEvent(ExpansionEvent e) { - // nothing + public void onExpansionEvent(ExpansionEvent arg0) { + draw(arg0); } public void onStatusEvent(StatusEvent arg0) { @@ -198,14 +193,69 @@ public class OrientationPanel extends javax.swing.JPanel implements repaint(); } - public void onNunchukInsertedEvent(NunchukInsertedEvent e) { + public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) { // nothing } - public void onNunchukRemovedEvent(NunchukRemovedEvent e) { + public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) { // nothing } + + private void draw(GenericEvent arg0){ + if (values.size() >= getWidth()) { + // if there are as many values as pixels in the width + // clear points + values.clear(); + } + Orientation orientation = getOrientationValue(arg0); + if (orientation != null) values.add(orientation); + repaint(); + } + + public abstract Orientation getOrientationValue(GenericEvent e); + public Color getBackgroundColor() { + return backgroundColor; + } + + public Color getLineColor() { + return lineColor; + } + + public Color getPitchColor() { + return pitchColor; + } + + public Color getRollColor() { + return rollColor; + } + + public Color getYawColor() { + return yawColor; + } + + public void setBackgroundColor(Color backgroundColor) { + this.backgroundColor = backgroundColor; + } + + public void setLineColor(Color lineColor) { + this.lineColor = lineColor; + } + + public void setPitchColor(Color pitchColor) { + this.pitchColor = pitchColor; + } + + public void setRollColor(Color rollColor) { + this.rollColor = rollColor; + } + + public void setYawColor(Color yawColor) { + this.yawColor = yawColor; + } + + + /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/JoystickEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/JoystickEvent.java index e10fdb0..5dc7f2f 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/JoystickEvent.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/JoystickEvent.java @@ -53,7 +53,7 @@ public class JoystickEvent extends GenericEvent { * @param center2 * center joystick value 2. */ - public JoystickEvent(int id, int angle, int magnitude, short max1, + public JoystickEvent(int id, float angle, float magnitude, short max1, short max2, short min1, short min2, short center1, short center2) { super(id); this.angle = angle; @@ -74,7 +74,7 @@ public class JoystickEvent extends GenericEvent { * * @return the angle angle the joystick. */ - public float getangle() { + public float getAngle() { return angle; } @@ -83,7 +83,7 @@ public class JoystickEvent extends GenericEvent { * * @return the magnitude magnitude of the joystick. */ - public float getmagnitude() { + public float getMagnitude() { return magnitude; } diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/NunchukEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/NunchukEvent.java index 19c8be9..e3fb076 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/NunchukEvent.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/physicalevents/NunchukEvent.java @@ -92,7 +92,7 @@ public class NunchukEvent extends ExpansionEvent { float orientationThreshold, int accelerationThreshold, boolean smoothingState, float alphaSmooth, float r, float p, float ya, float ar, float ap, float x, float y, float z, short xx, - short yy, short zz, int angle, int magnitude, short max1, + short yy, short zz, float angle, float magnitude, short max1, short max2, short min1, short min2, short center1, short center2) { super(id); buttonsEvent = new NunchukButtonsEvent(id, buttonsJustPressed, diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/utils/EventsGatherer.java b/WiiUseJ/src/wiiusej/wiiusejevents/utils/EventsGatherer.java index 003dd79..3e405bc 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/utils/EventsGatherer.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/utils/EventsGatherer.java @@ -243,7 +243,7 @@ public class EventsGatherer { float orientationThreshold, int accelerationThreshold, boolean smoothingState, float alphaSmooth, float r, float p, float ya, float ar, float ap, float x, float y, float z, short xx, - short yy, short zz, int angle, int magnitude, short max1, + short yy, short zz, float angle, float magnitude, short max1, short max2, short min1, short min2, short center1, short center2){ if (genericEvent != null) { genericEvent.setNunchukEvent(buttonsJustPressed, diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/StatusEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/StatusEvent.java index 8d41f2d..d200bb7 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/StatusEvent.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/StatusEvent.java @@ -242,7 +242,7 @@ public class StatusEvent extends WiiUseApiEvent { * @return true if anything is connected to the wiimote false otherwise. */ public boolean isAttachmentConnected() { - return attachment != EXP_NONE; + return attachment == EXP_NONE; } /** @@ -251,7 +251,7 @@ public class StatusEvent extends WiiUseApiEvent { * @return true if a nunchuk is connected to the wiimote false otherwise. */ public boolean isNunchukConnected() { - return attachment != EXP_NUNCHUK; + return attachment == EXP_NUNCHUK; } /** @@ -260,7 +260,7 @@ public class StatusEvent extends WiiUseApiEvent { * @return true if a classic controller is connected to the wiimote false otherwise. */ public boolean isClassicControllerConnected() { - return attachment != EXP_CLASSIC; + return attachment == EXP_CLASSIC; } /** @@ -269,7 +269,7 @@ public class StatusEvent extends WiiUseApiEvent { * @return true if a guitar hero controllerr is connected to the wiimote false otherwise. */ public boolean isGuitarHeroConnected() { - return attachment != EXP_GUITAR_HERO_3; + return attachment == EXP_GUITAR_HERO_3; } @Override diff --git a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java index 8135be7..3cdd204 100644 --- a/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java +++ b/WiiUseJ/src/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java @@ -295,7 +295,7 @@ public class WiimoteEvent extends WiiUseApiEvent { float orientationThreshold, int accelerationThreshold, boolean smoothingState, float alphaSmooth, float r, float p, float ya, float ar, float ap, float x, float y, float z, short xx, - short yy, short zz, int angle, int magnitude, short max1, + short yy, short zz, float angle, float magnitude, short max1, short max2, short min1, short min2, short center1, short center2) { expansionEvent = new NunchukEvent(getWiimoteId(), buttonsJustPressed, buttonsJustReleased, buttonsHeld, orientationThreshold,