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;
|
package pm;
|
||||||
|
|
||||||
import java.awt.GridLayout;
|
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.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JToggleButton;
|
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;
|
import pm.util.ArrayCycle;
|
||||||
|
|
||||||
public class ApplicationSelector extends JFrame {
|
public class ApplicationSelector extends JFrame {
|
||||||
@@ -30,7 +20,7 @@ public class ApplicationSelector extends JFrame {
|
|||||||
protected JToggleButton winamp;
|
protected JToggleButton winamp;
|
||||||
|
|
||||||
protected JToggleButton[] applicationButtons = {gomPlayer, windowsMediaPlayer, iTunes, mediaPlayerClassic, vlc, 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) {
|
public ApplicationSelector(ArrayCycle<Application> applicationCycle) {
|
||||||
super(TITLE);
|
super(TITLE);
|
||||||
@@ -47,48 +37,24 @@ public class ApplicationSelector extends JFrame {
|
|||||||
for (int i = 0; i < applicationButtons.length; i++) {
|
for (int i = 0; i < applicationButtons.length; i++) {
|
||||||
try {
|
try {
|
||||||
String applicationName = applicationNames[i];
|
String applicationName = applicationNames[i];
|
||||||
applicationButtons[i] = new JToggleButton(applicationName);
|
Application application = null;
|
||||||
Application application = (Application) Class.forName(applicationName).newInstance();
|
applicationButtons[i] = new ApplicationButton(application);
|
||||||
ToggleChangeListener toggleChangeListener = new ToggleChangeListener(application);
|
applicationButtons[i].setText(applicationName);
|
||||||
applicationButtons[i].addChangeListener(toggleChangeListener);
|
Class.forName(applicationName).newInstance();
|
||||||
|
|
||||||
System.out.println("App added");
|
System.out.println("App added");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {e.printStackTrace();
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException e) {e.printStackTrace();
|
||||||
} catch (IllegalAccessException e) {}
|
} catch (IllegalAccessException e) {e.printStackTrace();}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void layoutButtons() {
|
protected void layoutButtons() {
|
||||||
JPanel applicationPanel = new JPanel(new GridLayout(0, 1));
|
JPanel applicationPanel = new JPanel(new GridLayout(0, 1));
|
||||||
for (int i = 0; i < applicationButtons.length; i++) {
|
for (int i = 0; i < applicationButtons.length; i++) {
|
||||||
|
System.out.println(applicationButtons[i]);
|
||||||
applicationPanel.add(applicationButtons[i]);
|
applicationPanel.add(applicationButtons[i]);
|
||||||
}
|
}
|
||||||
add(applicationPanel);
|
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;
|
package pm;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
import pm.event.EventListener;
|
import pm.event.EventListener;
|
||||||
import pm.value.Target;
|
import pm.value.Target;
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ import java.net.URL;
|
|||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
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.HoldButton;
|
||||||
import pm.util.swing.HoldButtonListener;
|
import pm.util.swing.HoldButtonListener;
|
||||||
import pm.util.swing.ToggleButton;
|
import pm.util.swing.ToggleButton;
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
super.initialise();
|
super.initialise();
|
||||||
wiimote = wiimoteService.getDevice(this);
|
wiimote = wiimoteService.getDevice(this);
|
||||||
wiimote.activateMotionSensing();
|
wiimote.activateMotionSensing();
|
||||||
/*add(
|
add(
|
||||||
new Hold(WiimoteButton.A),
|
new Hold(WiimoteButton.A),
|
||||||
new Task(Action.TRAIN),
|
new Task(Action.TRAIN),
|
||||||
new Task(Action.STOP));
|
new Task(Action.STOP));
|
||||||
@@ -67,7 +67,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
add(
|
add(
|
||||||
new Hold(WiimoteButton.HOME),
|
new Hold(WiimoteButton.HOME),
|
||||||
new Task(Action.RECOGNIZE),
|
new Task(Action.RECOGNIZE),
|
||||||
new Task(Action.STOP));*/
|
new Task(Action.STOP));/*
|
||||||
add(
|
add(
|
||||||
new Press(WiimoteButton.A),
|
new Press(WiimoteButton.A),
|
||||||
new Task(Target.APPLICATION, Action.PLAY));
|
new Task(Target.APPLICATION, Action.PLAY));
|
||||||
@@ -114,7 +114,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
new Press(WiimoteButton.MINUS),
|
new Press(WiimoteButton.MINUS),
|
||||||
new Release(WiimoteButton.TWO)),
|
new Release(WiimoteButton.TWO)),
|
||||||
new Task(Target.APPLICATION, Action.DISLIKE));
|
new Task(Target.APPLICATION, Action.DISLIKE));
|
||||||
} catch (StateOrderException e) {}
|
} catch (StateOrderException e) {}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exit() throws DeviceExitException {
|
public void exit() throws DeviceExitException {
|
||||||
@@ -167,13 +167,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onMotionSensingEvent(MotionSensingEvent event) {
|
public void onMotionSensingEvent(MotionSensingEvent event) {
|
||||||
if (calibration == null) {
|
gestureDevice.add(event.getGforce());
|
||||||
calibration = wiimote.getCalibration();
|
|
||||||
}
|
|
||||||
RawAcceleration rawAcceleration = event.getRawAcceleration();
|
|
||||||
Acceleration acceleration = calibration.getAcceleration(rawAcceleration);
|
|
||||||
//System.out.println(event);
|
|
||||||
gestureDevice.add(acceleration.toArray());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gestureReceived(GestureEvent event) {
|
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.Close;
|
||||||
import pm.device.wiimote.gesture.event.Recognize;
|
import pm.device.wiimote.gesture.event.Recognize;
|
||||||
import pm.device.wiimote.gesture.event.Train;
|
import pm.device.wiimote.gesture.event.Train;
|
||||||
|
import wiiusej.values.GForce;
|
||||||
|
|
||||||
public class GestureDevice extends Device /*implements AccelerationListener */{
|
public class GestureDevice extends Device /*implements AccelerationListener */{
|
||||||
public static final boolean AUTOFILTERING = true;
|
public static final boolean AUTOFILTERING = true;
|
||||||
@@ -27,6 +28,13 @@ public class GestureDevice extends Device /*implements AccelerationListener */{
|
|||||||
addGestureListener(gestureListener);
|
addGestureListener(gestureListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void add(GForce gforce) {
|
||||||
|
add(new double[] {
|
||||||
|
gforce.getX(),
|
||||||
|
gforce.getY(),
|
||||||
|
gforce.getY()});
|
||||||
|
}
|
||||||
|
|
||||||
public void add(double[] vector) {
|
public void add(double[] vector) {
|
||||||
//System.out.printf("%f %f %f\n", vector[0], vector[1], vector[2]);
|
//System.out.printf("%f %f %f\n", vector[0], vector[1], vector[2]);
|
||||||
fireAccelerationEvent(vector);
|
fireAccelerationEvent(vector);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package pm.util.swing;
|
package pm.util.swing;
|
||||||
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JButton;
|
|
||||||
|
|
||||||
import pm.util.ArrayCycle;
|
import pm.util.ArrayCycle;
|
||||||
|
|
||||||
|
|||||||
@@ -347,6 +347,4 @@ public class WiiUseApi {
|
|||||||
* the object where we store all the new events.
|
* the object where we store all the new events.
|
||||||
*/
|
*/
|
||||||
native void specialPoll(EventsGatherer gath);
|
native void specialPoll(EventsGatherer gath);
|
||||||
|
|
||||||
native short[] getCalibration(int id);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -662,12 +662,4 @@ public class WiiUseApiManager extends Thread {
|
|||||||
protected void finalize() throws Throwable {
|
protected void finalize() throws Throwable {
|
||||||
shutdown();
|
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]));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ public class Calibration {
|
|||||||
this.zeroAcceleration = zeroAcceleration;
|
this.zeroAcceleration = zeroAcceleration;
|
||||||
this.gAcceleration = gAcceleration;
|
this.gAcceleration = gAcceleration;
|
||||||
differenceAcceleration = new RawAcceleration(
|
differenceAcceleration = new RawAcceleration(
|
||||||
(short) (zeroAcceleration.getX() - gAcceleration.getX()),
|
(short) (gAcceleration.getX() - zeroAcceleration.getX()),
|
||||||
(short) (zeroAcceleration.getY() - gAcceleration.getY()),
|
(short) (gAcceleration.getY() - zeroAcceleration.getY()),
|
||||||
(short) (zeroAcceleration.getZ() - gAcceleration.getZ()));
|
(short) (gAcceleration.getZ() - zeroAcceleration.getZ()));
|
||||||
System.out.println(zeroAcceleration);
|
System.out.println(zeroAcceleration);
|
||||||
System.out.println(gAcceleration);
|
System.out.println(gAcceleration);
|
||||||
System.out.println(differenceAcceleration);
|
System.out.println(differenceAcceleration);
|
||||||
@@ -29,8 +29,8 @@ public class Calibration {
|
|||||||
|
|
||||||
public Acceleration getAcceleration(RawAcceleration rawAcceleration) {
|
public Acceleration getAcceleration(RawAcceleration rawAcceleration) {
|
||||||
return new Acceleration(
|
return new Acceleration(
|
||||||
(rawAcceleration.getX() - zeroAcceleration.getX()),// / (double) gAcceleration.getX(),
|
(rawAcceleration.getX() - zeroAcceleration.getX()) / (double) differenceAcceleration.getX(),
|
||||||
(rawAcceleration.getY() - zeroAcceleration.getY()),// / (double) gAcceleration.getY(),
|
(rawAcceleration.getY() - zeroAcceleration.getY()) / (double) differenceAcceleration.getY(),
|
||||||
(rawAcceleration.getZ() - zeroAcceleration.getZ()));// / (double) gAcceleration.getZ());
|
(rawAcceleration.getZ() - zeroAcceleration.getZ()) / (double) differenceAcceleration.getZ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user