Gefixt met ApplicationButton
This commit is contained in:
25
java/src/pm/ApplicationButton.java
Normal file
25
java/src/pm/ApplicationButton.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package pm;
|
||||
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
import javax.swing.JToggleButton;
|
||||
|
||||
public class ApplicationButton extends JToggleButton implements ItemListener {
|
||||
protected Application application;
|
||||
|
||||
public ApplicationButton(Application application) {
|
||||
this.application = application;
|
||||
addItemListener(this);
|
||||
}
|
||||
|
||||
public void itemStateChanged(ItemEvent itemEvent) {
|
||||
int state = itemEvent.getStateChange();
|
||||
if (state == ItemEvent.SELECTED) {
|
||||
System.out.println("Selected");
|
||||
} else {
|
||||
System.out.println("Deselected");
|
||||
}
|
||||
//System.out.println(itemEvent.getSource());
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,9 @@
|
||||
package pm;
|
||||
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.ButtonModel;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import pm.exception.application.ApplicationExitException;
|
||||
import pm.exception.application.ApplicationInitialiseException;
|
||||
import pm.util.ArrayCycle;
|
||||
|
||||
public class ApplicationSelector extends JFrame {
|
||||
@@ -30,7 +20,7 @@ public class ApplicationSelector extends JFrame {
|
||||
protected JToggleButton winamp;
|
||||
|
||||
protected JToggleButton[] applicationButtons = {gomPlayer, windowsMediaPlayer, iTunes, mediaPlayerClassic, vlc, winamp};
|
||||
protected String[] applicationNames = {"GOM Player", "Windows Media Player", "iTunes", "Media Player Classic", "VLC", "Winamp"};;
|
||||
protected String[] applicationNames = {"GOM Player", "Windows Media Player", "iTunes", "Media Player Classic", "VLC", "Winamp"};
|
||||
|
||||
public ApplicationSelector(ArrayCycle<Application> applicationCycle) {
|
||||
super(TITLE);
|
||||
@@ -47,48 +37,24 @@ public class ApplicationSelector extends JFrame {
|
||||
for (int i = 0; i < applicationButtons.length; i++) {
|
||||
try {
|
||||
String applicationName = applicationNames[i];
|
||||
applicationButtons[i] = new JToggleButton(applicationName);
|
||||
Application application = (Application) Class.forName(applicationName).newInstance();
|
||||
ToggleChangeListener toggleChangeListener = new ToggleChangeListener(application);
|
||||
applicationButtons[i].addChangeListener(toggleChangeListener);
|
||||
Application application = null;
|
||||
applicationButtons[i] = new ApplicationButton(application);
|
||||
applicationButtons[i].setText(applicationName);
|
||||
Class.forName(applicationName).newInstance();
|
||||
|
||||
System.out.println("App added");
|
||||
} catch (ClassNotFoundException e) {
|
||||
} catch (InstantiationException e) {
|
||||
} catch (IllegalAccessException e) {}
|
||||
} catch (ClassNotFoundException e) {e.printStackTrace();
|
||||
} catch (InstantiationException e) {e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {e.printStackTrace();}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void layoutButtons() {
|
||||
JPanel applicationPanel = new JPanel(new GridLayout(0, 1));
|
||||
for (int i = 0; i < applicationButtons.length; i++) {
|
||||
applicationPanel.add(applicationButtons[i]);
|
||||
System.out.println(applicationButtons[i]);
|
||||
applicationPanel.add(applicationButtons[i]);
|
||||
}
|
||||
add(applicationPanel);
|
||||
}
|
||||
|
||||
protected class ToggleChangeListener implements ChangeListener {
|
||||
Application application;
|
||||
|
||||
public ToggleChangeListener(Application application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public void stateChanged(ChangeEvent changeEvent) {
|
||||
System.out.println("Event!");
|
||||
AbstractButton abstractButton = (AbstractButton) changeEvent.getSource();
|
||||
ButtonModel buttonModel = abstractButton.getModel();
|
||||
boolean armed = buttonModel.isArmed();
|
||||
boolean pressed = buttonModel.isPressed();
|
||||
boolean selected = buttonModel.isSelected();
|
||||
System.out.println("Changed: " + armed + "/" + pressed + "/" + selected);
|
||||
/*try {
|
||||
application.initialise();
|
||||
application.start();
|
||||
applicationCycle.add(application);
|
||||
} catch (ApplicationInitialiseException e) {}*/
|
||||
/*applicationCycle.remove(application);
|
||||
application.exit();*/
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package pm;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import pm.event.EventListener;
|
||||
import pm.value.Target;
|
||||
|
||||
|
||||
@@ -6,10 +6,6 @@ import java.net.URL;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollBar;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import pm.util.swing.HoldButton;
|
||||
import pm.util.swing.HoldButtonListener;
|
||||
import pm.util.swing.ToggleButton;
|
||||
@@ -66,7 +62,7 @@ public class Panel extends JFrame implements HoldButtonListener {
|
||||
protected ToggleButton getToggleButton(String firstName, String secondName, String text) {
|
||||
ImageIcon firstImageIcon = getImageIcon(firstName);
|
||||
ImageIcon secondImageIcon = getImageIcon(secondName);
|
||||
ToggleButton button = new ToggleButton(this, firstImageIcon, secondImageIcon);
|
||||
ToggleButton button = new ToggleButton(this, firstImageIcon, secondImageIcon);
|
||||
button.setToolTipText(text);
|
||||
button.setFocusPainted(false);
|
||||
return button;
|
||||
@@ -188,7 +184,7 @@ public class Panel extends JFrame implements HoldButtonListener {
|
||||
panelButtonListener.buttonReleased(PanelButton.FORWARD);
|
||||
} else if (button.equals(nextButton)) {
|
||||
panelButtonListener.buttonReleased(PanelButton.NEXT);
|
||||
} else if (button.equals(volumeDownButton)) {
|
||||
} else if (button.equals(volumeDownButton)) {
|
||||
panelButtonListener.buttonReleased(PanelButton.VOLUME_DOWN);
|
||||
} else if (button.equals(muteToggleButton)) {
|
||||
panelButtonListener.buttonReleased(PanelButton.MUTE);
|
||||
|
||||
@@ -54,7 +54,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
super.initialise();
|
||||
wiimote = wiimoteService.getDevice(this);
|
||||
wiimote.activateMotionSensing();
|
||||
/*add(
|
||||
add(
|
||||
new Hold(WiimoteButton.A),
|
||||
new Task(Action.TRAIN),
|
||||
new Task(Action.STOP));
|
||||
@@ -67,7 +67,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
add(
|
||||
new Hold(WiimoteButton.HOME),
|
||||
new Task(Action.RECOGNIZE),
|
||||
new Task(Action.STOP));*/
|
||||
new Task(Action.STOP));/*
|
||||
add(
|
||||
new Press(WiimoteButton.A),
|
||||
new Task(Target.APPLICATION, Action.PLAY));
|
||||
@@ -114,7 +114,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
new Press(WiimoteButton.MINUS),
|
||||
new Release(WiimoteButton.TWO)),
|
||||
new Task(Target.APPLICATION, Action.DISLIKE));
|
||||
} catch (StateOrderException e) {}
|
||||
} catch (StateOrderException e) {}*/
|
||||
}
|
||||
|
||||
public void exit() throws DeviceExitException {
|
||||
@@ -167,13 +167,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent event) {
|
||||
if (calibration == null) {
|
||||
calibration = wiimote.getCalibration();
|
||||
}
|
||||
RawAcceleration rawAcceleration = event.getRawAcceleration();
|
||||
Acceleration acceleration = calibration.getAcceleration(rawAcceleration);
|
||||
//System.out.println(event);
|
||||
gestureDevice.add(acceleration.toArray());
|
||||
gestureDevice.add(event.getGforce());
|
||||
}
|
||||
|
||||
public void gestureReceived(GestureEvent event) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.wiigee.event.GestureListener;
|
||||
import pm.device.wiimote.gesture.event.Close;
|
||||
import pm.device.wiimote.gesture.event.Recognize;
|
||||
import pm.device.wiimote.gesture.event.Train;
|
||||
import wiiusej.values.GForce;
|
||||
|
||||
public class GestureDevice extends Device /*implements AccelerationListener */{
|
||||
public static final boolean AUTOFILTERING = true;
|
||||
@@ -27,6 +28,13 @@ public class GestureDevice extends Device /*implements AccelerationListener */{
|
||||
addGestureListener(gestureListener);
|
||||
}
|
||||
|
||||
public void add(GForce gforce) {
|
||||
add(new double[] {
|
||||
gforce.getX(),
|
||||
gforce.getY(),
|
||||
gforce.getY()});
|
||||
}
|
||||
|
||||
public void add(double[] vector) {
|
||||
//System.out.printf("%f %f %f\n", vector[0], vector[1], vector[2]);
|
||||
fireAccelerationEvent(vector);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package pm.util.swing;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
|
||||
import pm.util.ArrayCycle;
|
||||
|
||||
|
||||
@@ -347,6 +347,4 @@ public class WiiUseApi {
|
||||
* the object where we store all the new events.
|
||||
*/
|
||||
native void specialPoll(EventsGatherer gath);
|
||||
|
||||
native short[] getCalibration(int id);
|
||||
}
|
||||
|
||||
@@ -662,12 +662,4 @@ public class WiiUseApiManager extends Thread {
|
||||
protected void finalize() throws Throwable {
|
||||
shutdown();
|
||||
}
|
||||
|
||||
public Calibration getCalibration(int id) {
|
||||
short[] data = wiiuse.getCalibration(id);
|
||||
return new Calibration(
|
||||
new RawAcceleration(data[0], data[1], data[2]),
|
||||
new RawAcceleration(data[3], data[4], data[5]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@ public class Calibration {
|
||||
protected RawAcceleration zeroAcceleration;
|
||||
protected RawAcceleration gAcceleration;
|
||||
protected RawAcceleration differenceAcceleration;
|
||||
|
||||
|
||||
public Calibration(RawAcceleration zeroAcceleration, RawAcceleration gAcceleration) {
|
||||
this.zeroAcceleration = zeroAcceleration;
|
||||
this.gAcceleration = gAcceleration;
|
||||
differenceAcceleration = new RawAcceleration(
|
||||
(short) (zeroAcceleration.getX() - gAcceleration.getX()),
|
||||
(short) (zeroAcceleration.getY() - gAcceleration.getY()),
|
||||
(short) (zeroAcceleration.getZ() - gAcceleration.getZ()));
|
||||
(short) (gAcceleration.getX() - zeroAcceleration.getX()),
|
||||
(short) (gAcceleration.getY() - zeroAcceleration.getY()),
|
||||
(short) (gAcceleration.getZ() - zeroAcceleration.getZ()));
|
||||
System.out.println(zeroAcceleration);
|
||||
System.out.println(gAcceleration);
|
||||
System.out.println(differenceAcceleration);
|
||||
@@ -29,8 +29,8 @@ public class Calibration {
|
||||
|
||||
public Acceleration getAcceleration(RawAcceleration rawAcceleration) {
|
||||
return new Acceleration(
|
||||
(rawAcceleration.getX() - zeroAcceleration.getX()),// / (double) gAcceleration.getX(),
|
||||
(rawAcceleration.getY() - zeroAcceleration.getY()),// / (double) gAcceleration.getY(),
|
||||
(rawAcceleration.getZ() - zeroAcceleration.getZ()));// / (double) gAcceleration.getZ());
|
||||
(rawAcceleration.getX() - zeroAcceleration.getX()) / (double) differenceAcceleration.getX(),
|
||||
(rawAcceleration.getY() - zeroAcceleration.getY()) / (double) differenceAcceleration.getY(),
|
||||
(rawAcceleration.getZ() - zeroAcceleration.getZ()) / (double) differenceAcceleration.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user