This commit is contained in:
@@ -1,25 +0,0 @@
|
|||||||
package pm;
|
|
||||||
|
|
||||||
import pm.event.EventHandler;
|
|
||||||
import pm.manager.Titled;
|
|
||||||
|
|
||||||
public abstract class Application extends EventHandler implements Titled, Exitable {
|
|
||||||
protected String title;
|
|
||||||
protected boolean active;
|
|
||||||
|
|
||||||
public Application(String title) {
|
|
||||||
this.title = title;
|
|
||||||
active = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String title() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void exit() {
|
|
||||||
if (active()) {
|
|
||||||
deactivate();
|
|
||||||
}
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
package pm;
|
|
||||||
|
|
||||||
public interface Button {}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
package pm;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import pm.device.javainput.extreme3d.Extreme3DDevice;
|
|
||||||
import pm.device.javainput.rumblepad.RumblepadDevice;
|
|
||||||
import pm.device.jintellitype.JIntellitypeDevice;
|
|
||||||
import pm.device.lirc.LircDevice;
|
|
||||||
import pm.device.network.NetworkDevice;
|
|
||||||
import pm.device.panel.PanelDevice;
|
|
||||||
import pm.device.player.PlayerDevice;
|
|
||||||
import pm.device.wiimote.WiimoteDevice;
|
|
||||||
import pm.event.EventRouter;
|
|
||||||
import pm.event.router.GlobalRouter;
|
|
||||||
import pm.exception.event.router.GlobalRouterException;
|
|
||||||
|
|
||||||
public class Client {
|
|
||||||
protected Log log = LogFactory.getLog(getClass());
|
|
||||||
|
|
||||||
public static final String IP = "127.0.0.1";
|
|
||||||
public static final int PORT = 6789;
|
|
||||||
|
|
||||||
protected EventRouter eventRouter;
|
|
||||||
protected Device[] deviceArray;
|
|
||||||
|
|
||||||
public Client() throws GlobalRouterException {
|
|
||||||
this(IP, PORT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Client(String ip, int port) throws GlobalRouterException {
|
|
||||||
eventRouter = new GlobalRouter(ip, port);
|
|
||||||
deviceArray = new Device[] {
|
|
||||||
new LircDevice(),
|
|
||||||
new WiimoteDevice(),
|
|
||||||
new PanelDevice(),
|
|
||||||
new JIntellitypeDevice(),
|
|
||||||
new PlayerDevice(),
|
|
||||||
new RumblepadDevice(),
|
|
||||||
new Extreme3DDevice(),
|
|
||||||
new NetworkDevice()};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
log.debug("Client");
|
|
||||||
Mimis mimis = new Mimis(eventRouter, deviceArray);
|
|
||||||
mimis.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
new Main().start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
package pm;
|
|
||||||
|
|
||||||
import pm.event.EventHandler;
|
|
||||||
import pm.event.Task;
|
|
||||||
import pm.event.task.Continuous;
|
|
||||||
import pm.event.task.Stopper;
|
|
||||||
import pm.macro.Sequence;
|
|
||||||
import pm.macro.SequenceListener;
|
|
||||||
import pm.macro.State;
|
|
||||||
import pm.macro.state.Hold;
|
|
||||||
import pm.macro.state.Press;
|
|
||||||
import pm.macro.state.Release;
|
|
||||||
import pm.manager.Titled;
|
|
||||||
|
|
||||||
public abstract class Device extends EventHandler implements Titled, Exitable {
|
|
||||||
protected String title;
|
|
||||||
protected boolean active;
|
|
||||||
protected SequenceListener sequenceListener;
|
|
||||||
|
|
||||||
static {
|
|
||||||
SequenceListener.initialise(eventRouter);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Device(String title) {
|
|
||||||
this.title = title;
|
|
||||||
active = false;
|
|
||||||
sequenceListener = new SequenceListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Register macro's */
|
|
||||||
protected void add(Sequence sequence, Task task) {
|
|
||||||
sequenceListener.add(sequence, task);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void add(State state, Task task) {
|
|
||||||
add(new Sequence(state), task);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void add(Press press, Task task, boolean macro) {
|
|
||||||
if (macro) {
|
|
||||||
add(new Macro(press), task);
|
|
||||||
} else {
|
|
||||||
add((State) press, task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void add(Press press, Task task) {
|
|
||||||
add(press, task, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void add(Hold hold, Task pressTask, Task releaseTask) {
|
|
||||||
Button button = hold.getButton();
|
|
||||||
add(new Press(button), pressTask, false);
|
|
||||||
add(new Release(button), releaseTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void add(Sequence startSequence, Sequence stopSequence, Continuous continuous) {
|
|
||||||
add(startSequence, continuous);
|
|
||||||
add(stopSequence, new Stopper(continuous));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void add(State startEvent, State stopEvent, Continuous continuous) {
|
|
||||||
add(startEvent, continuous);
|
|
||||||
add(stopEvent, new Stopper(continuous));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void add(Press startPress, Press stopPress, Continuous continuous) {
|
|
||||||
add(new Macro(startPress), continuous);
|
|
||||||
add(new Macro(stopPress), new Stopper(continuous));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void add(Hold hold, Continuous continuous) {
|
|
||||||
Button button = hold.getButton();
|
|
||||||
add(new Press(button), new Release(button), continuous);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Recognize events */
|
|
||||||
protected void add(State state) {
|
|
||||||
sequenceListener.add(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String title() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void exit() {
|
|
||||||
if (active()) {
|
|
||||||
deactivate();
|
|
||||||
}
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package pm;
|
|
||||||
|
|
||||||
import pm.event.EventListener;
|
|
||||||
import pm.value.Target;
|
|
||||||
|
|
||||||
public class Event {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
protected Target target;
|
|
||||||
|
|
||||||
public Event(Target target) {
|
|
||||||
this.target = target;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Target getTarget() {
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean compatible(EventListener eventListener) {
|
|
||||||
switch (target) {
|
|
||||||
case ALL:
|
|
||||||
return true;
|
|
||||||
case MIMIS:
|
|
||||||
return eventListener instanceof Mimis;
|
|
||||||
case DEVICES:
|
|
||||||
return eventListener instanceof Device;
|
|
||||||
case APPLICATIONS:
|
|
||||||
return eventListener instanceof Application;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package pm;
|
|
||||||
|
|
||||||
public interface Exitable {
|
|
||||||
public void exit();
|
|
||||||
}
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
package pm;
|
|
||||||
|
|
||||||
import java.awt.GridLayout;
|
|
||||||
import java.awt.TextArea;
|
|
||||||
import java.awt.event.WindowEvent;
|
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JToggleButton;
|
|
||||||
import javax.swing.SwingConstants;
|
|
||||||
import javax.swing.WindowConstants;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
public class GUI extends JFrame {
|
|
||||||
protected Log log = LogFactory.getLog(getClass());
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
protected static final String TITLE = "Mimis GUI";
|
|
||||||
protected static final String APPLICATION_TITLE = "Applications";
|
|
||||||
protected static final String DEVICE_TITLE = "Devices";
|
|
||||||
|
|
||||||
protected Mimis mimis;
|
|
||||||
|
|
||||||
public GUI(Mimis mimis, Manager<Application> applicationManager, Manager<Device> deviceManager) {
|
|
||||||
super(TITLE);
|
|
||||||
this.mimis = mimis;
|
|
||||||
createFrame(applicationManager, deviceManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void createFrame(Manager<Application> applicationManager, Manager<Device> deviceManager) {
|
|
||||||
setLayout(new GridLayout(0, 1));
|
|
||||||
JPanel controlPanel = createControlPanel(applicationManager, deviceManager);
|
|
||||||
add(controlPanel);
|
|
||||||
JPanel feedbackPanel = createFeedbackPanel();
|
|
||||||
add(feedbackPanel);
|
|
||||||
setResizable(false);
|
|
||||||
setVisible(true);
|
|
||||||
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
|
||||||
pack();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected JPanel createControlPanel(Manager<Application> applicationManager, Manager<Device> deviceManager) {
|
|
||||||
JPanel controlPanel = new JPanel(new GridLayout(1, 0));
|
|
||||||
JPanel applicationPanel = createManagerPanel(applicationManager, APPLICATION_TITLE);
|
|
||||||
controlPanel.add(applicationPanel);
|
|
||||||
JPanel devicePanel = createManagerPanel(deviceManager, DEVICE_TITLE);
|
|
||||||
controlPanel.add(devicePanel);
|
|
||||||
return controlPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected JPanel createManagerPanel(Manager<?> manager, String title) {
|
|
||||||
JPanel panel = new JPanel(new GridLayout(0, 1));
|
|
||||||
panel.add(new JLabel(title, SwingConstants.CENTER));
|
|
||||||
for (JToggleButton button : manager.getButtons()) {
|
|
||||||
panel.add(button);
|
|
||||||
}
|
|
||||||
return panel;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected JPanel createFeedbackPanel() {
|
|
||||||
JPanel feedbackPanel = new JPanel();
|
|
||||||
TextArea textArea = new TextArea();
|
|
||||||
textArea.setEditable(false);
|
|
||||||
feedbackPanel.add(textArea);
|
|
||||||
return feedbackPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void processWindowEvent(WindowEvent e) {
|
|
||||||
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
|
|
||||||
log.debug("Window closing");
|
|
||||||
exit();
|
|
||||||
mimis.exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void exit() {
|
|
||||||
log.debug("Dispose");
|
|
||||||
dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package pm;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import pm.exception.macro.StateOrderException;
|
|
||||||
import pm.macro.Sequence;
|
|
||||||
import pm.macro.State;
|
|
||||||
import pm.macro.state.Hold;
|
|
||||||
import pm.macro.state.Press;
|
|
||||||
import pm.macro.state.Release;
|
|
||||||
|
|
||||||
public class Macro extends Sequence {
|
|
||||||
public Macro(Press press) {
|
|
||||||
Button button = press.getButton();
|
|
||||||
this.eventArray = new State[] {press, new Release(button)};
|
|
||||||
}
|
|
||||||
|
|
||||||
public Macro(State... eventArray) throws StateOrderException {
|
|
||||||
ArrayList<Button> holdList = new ArrayList<Button>();
|
|
||||||
ArrayList<State> eventList = new ArrayList<State>();
|
|
||||||
for (State state : eventArray) {
|
|
||||||
Button button = state.getButton();
|
|
||||||
if (state instanceof Press) {
|
|
||||||
if (holdList.contains(button)) {
|
|
||||||
throw new StateOrderException("Press events cannot follow hold events for the same button.");
|
|
||||||
}
|
|
||||||
eventList.add(state);
|
|
||||||
eventList.add(new Release(button));
|
|
||||||
} else if (state instanceof Release) {
|
|
||||||
if (!holdList.contains(button)) {
|
|
||||||
throw new StateOrderException("Cannot release a button that is not held.");
|
|
||||||
}
|
|
||||||
holdList.remove(button);
|
|
||||||
eventList.add(state);
|
|
||||||
} else if (state instanceof Hold) {
|
|
||||||
if (holdList.contains(button)) {
|
|
||||||
throw new StateOrderException("Cannot hold a button more than once.");
|
|
||||||
}
|
|
||||||
holdList.add(button);
|
|
||||||
eventList.add(new Press(button));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!holdList.isEmpty()) {
|
|
||||||
throw new StateOrderException("One or more buttons are not released.");
|
|
||||||
}
|
|
||||||
this.eventArray = (State[]) eventList.toArray(new State[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
package pm;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import pm.application.cmd.windows.gomplayer.GomPlayerApplication;
|
|
||||||
import pm.application.cmd.windows.winamp.WinampApplication;
|
|
||||||
import pm.application.cmd.windows.wmp.WMPApplication;
|
|
||||||
import pm.application.itunes.iTunesApplication;
|
|
||||||
import pm.application.mpc.MPCApplication;
|
|
||||||
import pm.application.vlc.VLCApplication;
|
|
||||||
import pm.device.javainput.extreme3d.Extreme3DDevice;
|
|
||||||
import pm.device.javainput.rumblepad.RumblepadDevice;
|
|
||||||
import pm.device.jintellitype.JIntellitypeDevice;
|
|
||||||
import pm.device.lirc.LircDevice;
|
|
||||||
import pm.device.network.NetworkDevice;
|
|
||||||
import pm.device.panel.PanelDevice;
|
|
||||||
import pm.device.player.PlayerDevice;
|
|
||||||
import pm.device.wiimote.WiimoteDevice;
|
|
||||||
import pm.event.EventRouter;
|
|
||||||
import pm.event.router.LocalRouter;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
protected Log log = LogFactory.getLog(getClass());
|
|
||||||
|
|
||||||
protected EventRouter eventRouter;
|
|
||||||
protected Application[] applicationArray;
|
|
||||||
protected Device[] deviceArray;
|
|
||||||
|
|
||||||
public Main() {
|
|
||||||
eventRouter = new LocalRouter();
|
|
||||||
applicationArray = new Application[] {
|
|
||||||
new iTunesApplication(),
|
|
||||||
new GomPlayerApplication(),
|
|
||||||
new WMPApplication(),
|
|
||||||
new MPCApplication(),
|
|
||||||
new VLCApplication(),
|
|
||||||
new WinampApplication()};
|
|
||||||
deviceArray = new Device[] {
|
|
||||||
new LircDevice(),
|
|
||||||
new WiimoteDevice(),
|
|
||||||
new PanelDevice(),
|
|
||||||
new JIntellitypeDevice(),
|
|
||||||
new PlayerDevice(),
|
|
||||||
new RumblepadDevice(),
|
|
||||||
new Extreme3DDevice(),
|
|
||||||
new NetworkDevice()};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
log.debug("Main");
|
|
||||||
Mimis mimis = new Mimis(eventRouter, applicationArray, deviceArray);
|
|
||||||
mimis.activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
new Main().start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
package pm;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.swing.JToggleButton;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import pm.manager.SelectButton;
|
|
||||||
import pm.manager.Titled;
|
|
||||||
|
|
||||||
public class Manager<T extends Worker & Titled & Exitable> extends Worker {
|
|
||||||
protected Log log = LogFactory.getLog(getClass());
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
protected static final int INTERVAL = 100;
|
|
||||||
|
|
||||||
protected T[] manageableArray;
|
|
||||||
protected Map<T, SelectButton<T>> buttonMap;
|
|
||||||
|
|
||||||
public Manager(String title) {
|
|
||||||
log.debug("Manager constructed");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Manager(T[] manageableArray) {
|
|
||||||
this.manageableArray = manageableArray;
|
|
||||||
createButtons();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
|
||||||
super.stop();
|
|
||||||
for (T manageable : manageableArray) {
|
|
||||||
manageable.exit();
|
|
||||||
}
|
|
||||||
super.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void createButtons() {
|
|
||||||
buttonMap = new HashMap<T, SelectButton<T>>();
|
|
||||||
for (T manageable : manageableArray) {
|
|
||||||
SelectButton<T> button = new SelectButton<T>(manageable);
|
|
||||||
buttonMap.put(manageable, button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected JToggleButton[] getButtons() {
|
|
||||||
return buttonMap.values().toArray(new JToggleButton[]{});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void work() {
|
|
||||||
long before = Calendar.getInstance().getTimeInMillis();
|
|
||||||
for (T manageable : manageableArray) {
|
|
||||||
boolean active = manageable.active();
|
|
||||||
buttonMap.get(manageable).setPressed(active);
|
|
||||||
}
|
|
||||||
long after = Calendar.getInstance().getTimeInMillis();
|
|
||||||
int sleep = INTERVAL - (int) (after - before);
|
|
||||||
sleep(sleep);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
package pm;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import pm.event.EventHandler;
|
|
||||||
import pm.event.EventRouter;
|
|
||||||
import pm.util.ArrayCycle;
|
|
||||||
import pm.value.Action;
|
|
||||||
|
|
||||||
public class Mimis extends EventHandler {
|
|
||||||
protected Log log = LogFactory.getLog(getClass());
|
|
||||||
|
|
||||||
protected ArrayCycle<Application> applicationCycle;
|
|
||||||
protected Device[] deviceArray;
|
|
||||||
protected Application[] applicationArray;
|
|
||||||
protected GUI gui;
|
|
||||||
|
|
||||||
protected Manager<Application> applicationManager;
|
|
||||||
protected Manager<Device> deviceManager;
|
|
||||||
|
|
||||||
public Mimis(EventRouter eventRouter) {
|
|
||||||
this(eventRouter, new Application[0], new Device[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mimis(EventRouter eventRouter, Application[] applicationArray) {
|
|
||||||
this(eventRouter, applicationArray, new Device[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mimis(EventRouter eventRouter, Device[] deviceArray) {
|
|
||||||
this(eventRouter, new Application[0], deviceArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mimis(EventRouter eventRouter, Application[] applicationArray, Device[] deviceArray) {
|
|
||||||
EventHandler.initialise(eventRouter);
|
|
||||||
applicationManager = new Manager<Application>(applicationArray);
|
|
||||||
deviceManager = new Manager<Device>(deviceArray);
|
|
||||||
|
|
||||||
this.applicationArray = applicationArray;
|
|
||||||
this.deviceArray = deviceArray;
|
|
||||||
applicationCycle = new ArrayCycle<Application>(applicationArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void activate() {
|
|
||||||
log.debug("Activate managers");
|
|
||||||
applicationManager.activate();
|
|
||||||
deviceManager.start();
|
|
||||||
|
|
||||||
log.debug("Create gui");
|
|
||||||
gui = new GUI(this, applicationManager, deviceManager);
|
|
||||||
|
|
||||||
if (applicationCycle.size() > 0) {
|
|
||||||
log.debug("Initialise application cycle");
|
|
||||||
eventRouter.set(applicationCycle.current());
|
|
||||||
}
|
|
||||||
super.activate(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void exit() {
|
|
||||||
log.debug("Stop event router");
|
|
||||||
eventRouter.stop();
|
|
||||||
|
|
||||||
log.debug("Stop managers");
|
|
||||||
applicationManager.stop();
|
|
||||||
deviceManager.stop();
|
|
||||||
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void action(Action action) {
|
|
||||||
log.debug(String.format("action(%s)", action));
|
|
||||||
switch (action) {
|
|
||||||
case NEXT:
|
|
||||||
eventRouter.set(applicationCycle.next());
|
|
||||||
System.out.println(applicationCycle.current());
|
|
||||||
break;
|
|
||||||
case PREVIOUS:
|
|
||||||
eventRouter.set(applicationCycle.previous());
|
|
||||||
System.out.println(applicationCycle.current());
|
|
||||||
break;
|
|
||||||
case EXIT:
|
|
||||||
exit();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package pm;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
|
|
||||||
public class Test {
|
|
||||||
public void start() throws IOException {
|
|
||||||
Class<Application> application = Application.class;
|
|
||||||
Class<?> test = application.getEnclosingClass();
|
|
||||||
System.out.println(test);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] argv) throws IOException {
|
|
||||||
new Test().start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
package pm;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
public abstract class Worker implements Runnable {
|
|
||||||
protected Log log = LogFactory.getLog(getClass());
|
|
||||||
|
|
||||||
protected static final boolean THREAD = true;
|
|
||||||
protected static final int SLEEP = 100;
|
|
||||||
|
|
||||||
protected boolean running = false;
|
|
||||||
protected boolean active = false;
|
|
||||||
|
|
||||||
public void start(boolean thread) {
|
|
||||||
log.debug("Start");
|
|
||||||
running = true;
|
|
||||||
if (thread) {
|
|
||||||
log.debug("Start thread");
|
|
||||||
new Thread(this).start();
|
|
||||||
} else {
|
|
||||||
log.debug("Run directly");
|
|
||||||
run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
start(THREAD);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
|
||||||
log.debug("Stop");
|
|
||||||
if (active()) {
|
|
||||||
deactivate();
|
|
||||||
}
|
|
||||||
running = false;
|
|
||||||
synchronized (this) {
|
|
||||||
notifyAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void sleep(int time) {
|
|
||||||
try {
|
|
||||||
if (time > 0) {
|
|
||||||
Thread.sleep(time);
|
|
||||||
}
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.info(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void sleep() {
|
|
||||||
sleep(SLEEP);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean active() {
|
|
||||||
return active;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void activate() {
|
|
||||||
activate(THREAD);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void activate(boolean thread) {
|
|
||||||
if (!running) {
|
|
||||||
start(thread);
|
|
||||||
}
|
|
||||||
active = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deactivate() {
|
|
||||||
active = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void run() {
|
|
||||||
while (running) {
|
|
||||||
if (active()) {
|
|
||||||
work();
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
synchronized (this) {
|
|
||||||
log.debug("Wait");
|
|
||||||
wait();
|
|
||||||
}
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.info(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void work();
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package pm.application.cmd;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import pm.Application;
|
|
||||||
import pm.util.Native;
|
|
||||||
import pm.util.VBScript;
|
|
||||||
|
|
||||||
public abstract class CMDApplication extends Application {
|
|
||||||
protected final static String REGISTRY = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths";
|
|
||||||
|
|
||||||
protected String program;
|
|
||||||
protected String title;
|
|
||||||
protected Process process;
|
|
||||||
|
|
||||||
public CMDApplication(String program, String title) {
|
|
||||||
super(title);
|
|
||||||
this.program = program;
|
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void activate() {
|
|
||||||
String key = String.format("%s\\%s", REGISTRY, program);
|
|
||||||
// Check of naam is gevonden in register
|
|
||||||
String path = Native.getValue(key);
|
|
||||||
try {
|
|
||||||
String command = path.startsWith("\"") ? path : String.format("\"%s\"", path);
|
|
||||||
command = Native.replaceVariables(command);
|
|
||||||
process = Runtime.getRuntime().exec(command);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
//throw new ApplicationInitialiseException();
|
|
||||||
}
|
|
||||||
super.activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean active() {
|
|
||||||
try {
|
|
||||||
return active = VBScript.isRunning(program);
|
|
||||||
} catch (IOException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deactivate() {
|
|
||||||
if (process != null) {
|
|
||||||
process.destroy();
|
|
||||||
}
|
|
||||||
super.deactivate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
package pm.application.cmd.windows;
|
|
||||||
|
|
||||||
import pm.application.cmd.CMDApplication;
|
|
||||||
import pm.util.Windows;
|
|
||||||
import pm.value.Command;
|
|
||||||
import pm.value.Key;
|
|
||||||
import pm.value.Type;
|
|
||||||
|
|
||||||
public abstract class WindowsApplication extends CMDApplication {
|
|
||||||
protected final static int TERMINATE_SLEEP = 500;
|
|
||||||
protected final static int START_SLEEP = 500;
|
|
||||||
|
|
||||||
protected String name;
|
|
||||||
|
|
||||||
protected Process process;
|
|
||||||
protected int handle;
|
|
||||||
|
|
||||||
public WindowsApplication(String program, String title, String name) {
|
|
||||||
super(program, title);
|
|
||||||
this.name = name;
|
|
||||||
handle = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initialise() {
|
|
||||||
handle = Windows.findWindow(name, null);
|
|
||||||
if (handle < 1) {
|
|
||||||
super.initialise();
|
|
||||||
sleep(START_SLEEP);
|
|
||||||
handle = Windows.findWindow(name, null);
|
|
||||||
}
|
|
||||||
if (handle < 1) {
|
|
||||||
//throw new ApplicationInitialiseException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void command(Command command) {
|
|
||||||
Windows.sendMessage(handle, Windows.WM_APPCOMMAND, handle, command.getCode() << 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void command(int command) {
|
|
||||||
Windows.sendMessage(handle, Windows.WM_COMMAND, command, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int user(int wParam, int lParam) {
|
|
||||||
return Windows.sendMessage(handle, Windows.WM_USER, wParam, lParam);
|
|
||||||
//return Windows.sendMessage(handle, Windows.WM_USER + wParam, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void key(Type key, int code) {
|
|
||||||
int scanCode = Windows.mapVirtualKey(code, Windows.MAPVK_VK_TO_VSC);
|
|
||||||
Windows.postMessage(handle, key.getCode(), code, 1 | (scanCode << 16));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void key(Type key, char character) {
|
|
||||||
key(key, (int) Character.toUpperCase(character));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void key(Type key, Key virtualKey) {
|
|
||||||
key(key, virtualKey.getCode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package pm.application.cmd.windows.gomplayer;
|
|
||||||
|
|
||||||
import pm.application.cmd.windows.WindowsApplication;
|
|
||||||
import pm.value.Action;
|
|
||||||
|
|
||||||
public class GomPlayerApplication extends WindowsApplication {
|
|
||||||
protected final static String PROGRAM = "GOM.exe";
|
|
||||||
protected final static String TITLE = "GOM Player";
|
|
||||||
protected final static String NAME = "GomPlayer1.x";
|
|
||||||
|
|
||||||
public GomPlayerApplication() {
|
|
||||||
super(PROGRAM, TITLE, NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void action(Action action) {
|
|
||||||
System.out.println("GomPlayerApplication: " + action);
|
|
||||||
switch (action) {
|
|
||||||
case PLAY:
|
|
||||||
command(0x800C);
|
|
||||||
break;
|
|
||||||
case FORWARD:
|
|
||||||
command(0x8009);
|
|
||||||
break;
|
|
||||||
case REWIND:
|
|
||||||
command(0x8008);
|
|
||||||
break;
|
|
||||||
case MUTE:
|
|
||||||
command(0x8016);
|
|
||||||
break;
|
|
||||||
case VOLUME_UP:
|
|
||||||
command(0x8014);
|
|
||||||
break;
|
|
||||||
case VOLUME_DOWN:
|
|
||||||
command(0x8013);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
package pm.application.cmd.windows.winamp;
|
|
||||||
|
|
||||||
import pm.application.cmd.windows.WindowsApplication;
|
|
||||||
import pm.value.Action;
|
|
||||||
|
|
||||||
public class WinampApplication extends WindowsApplication {
|
|
||||||
protected final static String PROGRAM = "winamp.exe";
|
|
||||||
protected final static String TITLE = "Winamp";
|
|
||||||
protected final static String NAME = "Winamp v1.x";
|
|
||||||
|
|
||||||
protected final static int STATUS_PLAYING = 1;
|
|
||||||
protected final static int STATUS_PAUSED = 3;
|
|
||||||
protected final static int STATUS_STOPPED = 0;
|
|
||||||
|
|
||||||
protected final static int IPC_ISPLAYING = 104;
|
|
||||||
protected final static int IPC_GETOUTPUTTIME = 105;
|
|
||||||
protected final static int IPC_SETVOLUME = 122;
|
|
||||||
|
|
||||||
protected final static int WINAMP_FILE_QUIT = 40001;
|
|
||||||
protected final static int WINAMP_FILE_REPEAT = 40022;
|
|
||||||
protected final static int WINAMP_FILE_SHUFFLE = 40023;
|
|
||||||
protected final static int WINAMP_BUTTON1 = 40044;
|
|
||||||
protected final static int WINAMP_BUTTON2 = 40045;
|
|
||||||
protected final static int WINAMP_BUTTON3 = 40046;
|
|
||||||
protected final static int WINAMP_BUTTON5 = 40048;
|
|
||||||
protected final static int WINAMP_VOLUMEUP = 40058;
|
|
||||||
protected final static int WINAMP_VOLUMEDOWN = 40059;
|
|
||||||
protected final static int WINAMP_FFWD5S = 40060;
|
|
||||||
protected final static int WINAMP_REW5S = 40061;
|
|
||||||
protected final static int WINAMP_BUTTON4_SHIFT = 40147;
|
|
||||||
protected final static int WINAMP_VISPLUGIN = 40192;
|
|
||||||
|
|
||||||
protected double volume;
|
|
||||||
protected boolean muted;
|
|
||||||
|
|
||||||
public WinampApplication() {
|
|
||||||
super(PROGRAM, TITLE, NAME);
|
|
||||||
volume = getVolume();
|
|
||||||
muted = volume == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void action(Action action) {
|
|
||||||
System.out.println("WinampApplication: " + action);
|
|
||||||
switch (action) {
|
|
||||||
case PLAY:
|
|
||||||
System.out.println(user(0, IPC_ISPLAYING));
|
|
||||||
switch (user(0, IPC_ISPLAYING)) {
|
|
||||||
case STATUS_STOPPED:
|
|
||||||
command(WINAMP_BUTTON2);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
command(WINAMP_BUTTON3);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case NEXT:
|
|
||||||
command(WINAMP_BUTTON5);
|
|
||||||
break;
|
|
||||||
case PREVIOUS:
|
|
||||||
command(WINAMP_BUTTON1);
|
|
||||||
break;
|
|
||||||
case FORWARD:
|
|
||||||
command(WINAMP_FFWD5S);
|
|
||||||
break;
|
|
||||||
case REWIND:
|
|
||||||
command(WINAMP_REW5S);
|
|
||||||
break;
|
|
||||||
case MUTE:
|
|
||||||
System.out.println(getDuration() +" "+ getElapsed());
|
|
||||||
if (muted) {
|
|
||||||
setVolume(volume);
|
|
||||||
} else {
|
|
||||||
volume = getVolume();
|
|
||||||
setVolume(0);
|
|
||||||
}
|
|
||||||
muted = !muted;
|
|
||||||
break;
|
|
||||||
case VOLUME_UP:
|
|
||||||
System.out.println(getVolume());
|
|
||||||
command(WINAMP_VOLUMEUP);
|
|
||||||
break;
|
|
||||||
case VOLUME_DOWN:
|
|
||||||
System.out.println(getVolume());
|
|
||||||
command(WINAMP_VOLUMEDOWN);
|
|
||||||
break;
|
|
||||||
case SHUFFLE:
|
|
||||||
command(WINAMP_FILE_SHUFFLE);
|
|
||||||
break;
|
|
||||||
case REPEAT:
|
|
||||||
command(WINAMP_FILE_REPEAT);
|
|
||||||
break;
|
|
||||||
case FADEOUT:
|
|
||||||
command(WINAMP_BUTTON4_SHIFT);
|
|
||||||
break;
|
|
||||||
case QUIT:
|
|
||||||
command(WINAMP_FILE_QUIT);
|
|
||||||
break;
|
|
||||||
case VISUALISER:
|
|
||||||
command(WINAMP_VISPLUGIN);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getVolume() {
|
|
||||||
return user(-666, IPC_SETVOLUME) / 255f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVolume(double volume) {
|
|
||||||
user((int) Math.ceil(volume * 255), IPC_SETVOLUME);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDuration() {
|
|
||||||
return user(1, IPC_GETOUTPUTTIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getElapsed() {
|
|
||||||
return user(0, IPC_GETOUTPUTTIME) / 1000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package pm.application.cmd.windows.wmp;
|
|
||||||
|
|
||||||
import pm.application.cmd.windows.WindowsApplication;
|
|
||||||
import pm.value.Action;
|
|
||||||
|
|
||||||
public class WMPApplication extends WindowsApplication {
|
|
||||||
protected final static String PROGRAM = "wmplayer.exe";
|
|
||||||
protected final static String TITLE = "Windows Media Player";
|
|
||||||
protected final static String NAME = "WMPlayerApp";
|
|
||||||
|
|
||||||
public WMPApplication() {
|
|
||||||
super(PROGRAM, TITLE, NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void action(Action action) {
|
|
||||||
System.out.println("WMPApplication: " + action);
|
|
||||||
System.out.println(handle);
|
|
||||||
switch (action) {
|
|
||||||
case PLAY:
|
|
||||||
command(18808);
|
|
||||||
break;
|
|
||||||
case NEXT:
|
|
||||||
command(18811);
|
|
||||||
break;
|
|
||||||
case PREVIOUS:
|
|
||||||
command(18810);
|
|
||||||
break;
|
|
||||||
case FORWARD:
|
|
||||||
command(18813);
|
|
||||||
break;
|
|
||||||
case REWIND:
|
|
||||||
command(18812);
|
|
||||||
break;
|
|
||||||
case MUTE:
|
|
||||||
command(18817);
|
|
||||||
break;
|
|
||||||
case VOLUME_UP:
|
|
||||||
command(18815);
|
|
||||||
break;
|
|
||||||
case VOLUME_DOWN:
|
|
||||||
command(18816);
|
|
||||||
break;
|
|
||||||
case SHUFFLE:
|
|
||||||
command(18842);
|
|
||||||
break;
|
|
||||||
case REPEAT:
|
|
||||||
command(18843);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
package pm.application.itunes;
|
|
||||||
|
|
||||||
import pm.Application;
|
|
||||||
import pm.event.Feedback;
|
|
||||||
import pm.value.Action;
|
|
||||||
|
|
||||||
import com.dt.iTunesController.ITCOMDisabledReason;
|
|
||||||
import com.dt.iTunesController.ITTrack;
|
|
||||||
import com.dt.iTunesController.iTunes;
|
|
||||||
import com.dt.iTunesController.iTunesEventsInterface;
|
|
||||||
|
|
||||||
public class iTunesApplication extends Application implements iTunesEventsInterface {
|
|
||||||
protected static final String TITLE = "iTunes";
|
|
||||||
|
|
||||||
protected static final int POSTION_CHANGE_RATE = 1;
|
|
||||||
protected static final int VOLUME_CHANGE_RATE = 5;
|
|
||||||
protected static final String PLAYLIST_LIKE = "Like";
|
|
||||||
protected static final String PLAYLIST_DISLIKE = "Dislike";
|
|
||||||
|
|
||||||
protected iTunes iTunes;
|
|
||||||
|
|
||||||
public iTunesApplication() {
|
|
||||||
super(TITLE);
|
|
||||||
iTunes = new iTunes();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*public boolean active() {
|
|
||||||
return active;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public void activate() {
|
|
||||||
synchronized (iTunes) {
|
|
||||||
iTunes.connect();
|
|
||||||
iTunes.addEventHandler(this);
|
|
||||||
}
|
|
||||||
super.activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean active() {
|
|
||||||
//log.info("Check iTunes");
|
|
||||||
try {
|
|
||||||
iTunes.getCurrentTrack();
|
|
||||||
active = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
//log.fatal(e);
|
|
||||||
active = false;
|
|
||||||
}
|
|
||||||
//log.info(active);
|
|
||||||
return active;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deactivate() {
|
|
||||||
try {
|
|
||||||
synchronized (iTunes) {
|
|
||||||
iTunes.quit();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.info("Unexpected deactivation exception", e);
|
|
||||||
}
|
|
||||||
super.deactivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void action(Action action) {
|
|
||||||
System.out.println("iTunesApplication: " + action);
|
|
||||||
switch (action) {
|
|
||||||
case PLAY:
|
|
||||||
iTunes.playPause();
|
|
||||||
break;
|
|
||||||
case NEXT:
|
|
||||||
iTunes.nextTrack();
|
|
||||||
break;
|
|
||||||
case PREVIOUS:
|
|
||||||
iTunes.previousTrack();
|
|
||||||
break;
|
|
||||||
case FORWARD:
|
|
||||||
iTunes.setPlayerPosition(iTunes.getPlayerPosition() + POSTION_CHANGE_RATE);
|
|
||||||
break;
|
|
||||||
case REWIND:
|
|
||||||
iTunes.setPlayerPosition(iTunes.getPlayerPosition() - POSTION_CHANGE_RATE);
|
|
||||||
break;
|
|
||||||
case MUTE:
|
|
||||||
iTunes.toggleMute();
|
|
||||||
break;
|
|
||||||
case VOLUME_UP:
|
|
||||||
iTunes.setSoundVolume(getVolume() + VOLUME_CHANGE_RATE);
|
|
||||||
break;
|
|
||||||
case VOLUME_DOWN:
|
|
||||||
iTunes.setSoundVolume(getVolume() - VOLUME_CHANGE_RATE);
|
|
||||||
break;
|
|
||||||
case SHUFFLE:
|
|
||||||
iTunes.toggleShuffle();
|
|
||||||
//iTunes.fastForward();
|
|
||||||
break;
|
|
||||||
case REPEAT:
|
|
||||||
iTunes.cycleSongRepeat();
|
|
||||||
//iTunes.resume();
|
|
||||||
break;
|
|
||||||
case LIKE:
|
|
||||||
iTunes.playlistAddCurrentTrack(PLAYLIST_LIKE);
|
|
||||||
break;
|
|
||||||
case DISLIKE:
|
|
||||||
iTunes.playlistAddCurrentTrack(PLAYLIST_DISLIKE);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getVolume() {
|
|
||||||
return iTunes.getSoundVolume();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* iTunesEventInterface => naar eigen class? */
|
|
||||||
public void onDatabaseChangedEvent(int[][] deletedObjectIDs, int[][] changedObjectIDs) {}
|
|
||||||
public void onPlayerPlayEvent(ITTrack iTrack) {
|
|
||||||
if (active) {
|
|
||||||
System.out.println("iTunes play");
|
|
||||||
eventRouter.add(new Feedback());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void onPlayerStopEvent(ITTrack iTrack) {
|
|
||||||
if (active) {
|
|
||||||
System.out.println("iTunes stop");
|
|
||||||
eventRouter.add(new Feedback());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void onPlayerPlayingTrackChangedEvent(ITTrack iTrack) {}
|
|
||||||
public void onCOMCallsDisabledEvent(ITCOMDisabledReason reason) {}
|
|
||||||
public void onCOMCallsEnabledEvent() {}
|
|
||||||
public void onQuittingEvent() {}
|
|
||||||
public void onAboutToPromptUserToQuitEvent() {}
|
|
||||||
public void onSoundVolumeChangedEvent(int newVolume) {}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
package pm.application.mpc;
|
|
||||||
|
|
||||||
import pm.application.cmd.windows.WindowsApplication;
|
|
||||||
import pm.value.Action;
|
|
||||||
|
|
||||||
public class MPCApplication extends WindowsApplication {
|
|
||||||
protected final static String PROGRAM = "mpc-hc.exe";
|
|
||||||
protected final static String TITLE = "Media Player Classic";
|
|
||||||
protected final static String NAME = "MediaPlayerClassicW";
|
|
||||||
|
|
||||||
public MPCApplication() {
|
|
||||||
super(PROGRAM, TITLE, NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void action(Action action) {
|
|
||||||
System.out.println("MPCApplication: " + action);
|
|
||||||
System.out.println(handle);
|
|
||||||
switch (action) {
|
|
||||||
case PLAY:
|
|
||||||
command(889);
|
|
||||||
break;
|
|
||||||
case NEXT:
|
|
||||||
command(921);
|
|
||||||
break;
|
|
||||||
case PREVIOUS:
|
|
||||||
command(920);
|
|
||||||
break;
|
|
||||||
case FORWARD:
|
|
||||||
command(900);
|
|
||||||
break;
|
|
||||||
case REWIND:
|
|
||||||
command(889);
|
|
||||||
break;
|
|
||||||
case MUTE:
|
|
||||||
command(909);
|
|
||||||
break;
|
|
||||||
case VOLUME_UP:
|
|
||||||
command(907);
|
|
||||||
break;
|
|
||||||
case VOLUME_DOWN:
|
|
||||||
command(908);
|
|
||||||
break;
|
|
||||||
case FULLSCREEN:
|
|
||||||
command(830);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String title() {
|
|
||||||
return TITLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
package pm.application.vlc;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import pm.application.cmd.CMDApplication;
|
|
||||||
import pm.value.Action;
|
|
||||||
|
|
||||||
public class VLCApplication extends CMDApplication {
|
|
||||||
protected final static String PROGRAM = "vlc.exe";
|
|
||||||
protected final static String TITLE = "VLC media player";
|
|
||||||
|
|
||||||
protected static final int POSTION_CHANGE_RATE = 1;
|
|
||||||
protected static final int VOLUME_CHANGE_RATE = 20;
|
|
||||||
|
|
||||||
protected static final String HOST = "127.0.0.1"; // localhost
|
|
||||||
protected static final int PORT = 8080;
|
|
||||||
|
|
||||||
protected int volume = 255;
|
|
||||||
protected boolean muted = false;
|
|
||||||
|
|
||||||
public VLCApplication() {
|
|
||||||
super(PROGRAM, TITLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void command(String command) {
|
|
||||||
String request = "http://" + HOST + ":" + PORT + "/requests/status.xml?command=" + command;
|
|
||||||
try {
|
|
||||||
int response = ((HttpURLConnection)(new URL(request)).openConnection()).getResponseCode();
|
|
||||||
System.out.printf("Response: %d\n", response);
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void action(Action action) {
|
|
||||||
System.out.println("VLCApplication: " + action);
|
|
||||||
switch (action) {
|
|
||||||
case PLAY:
|
|
||||||
command("pl_pause");
|
|
||||||
break;
|
|
||||||
case PAUSE:
|
|
||||||
command("pl_pause");
|
|
||||||
break;
|
|
||||||
case NEXT:
|
|
||||||
command("pl_next");
|
|
||||||
break;
|
|
||||||
case PREVIOUS:
|
|
||||||
command("pl_previous");
|
|
||||||
break;
|
|
||||||
case FORWARD:
|
|
||||||
command("command=seek&val=+" + POSTION_CHANGE_RATE);
|
|
||||||
break;
|
|
||||||
case REWIND:
|
|
||||||
command("command=seek&val=-" + POSTION_CHANGE_RATE);
|
|
||||||
break;
|
|
||||||
case MUTE:
|
|
||||||
command("volume&val=" + toggleMute());
|
|
||||||
break;
|
|
||||||
case VOLUME_UP:
|
|
||||||
volumeUp();
|
|
||||||
break;
|
|
||||||
case VOLUME_DOWN:
|
|
||||||
volumeDown();
|
|
||||||
break;
|
|
||||||
case SHUFFLE:
|
|
||||||
command("command=pl_random");
|
|
||||||
break;
|
|
||||||
case REPEAT:
|
|
||||||
command("command=pl_repeat");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void volumeUp() {
|
|
||||||
if (!muted) {
|
|
||||||
volume += VOLUME_CHANGE_RATE;
|
|
||||||
command("volume&val=+" + VOLUME_CHANGE_RATE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void volumeDown() {
|
|
||||||
if (!muted) {
|
|
||||||
volume -= VOLUME_CHANGE_RATE;
|
|
||||||
command("volume&val=-" + VOLUME_CHANGE_RATE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int toggleMute() {
|
|
||||||
muted =! muted;
|
|
||||||
return muted ? 0 : volume;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String title() {
|
|
||||||
return TITLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package pm.device.javainput;
|
|
||||||
|
|
||||||
import pm.Button;
|
|
||||||
import pm.exception.button.UnknownDirectionException;
|
|
||||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
|
||||||
|
|
||||||
public enum DirectionButton implements Button {
|
|
||||||
NORTH (0),
|
|
||||||
NORTHEAST (45),
|
|
||||||
EAST (90),
|
|
||||||
SOUTHEAST (135),
|
|
||||||
SOUTH (180),
|
|
||||||
SOUTHWEST (225),
|
|
||||||
WEST (270),
|
|
||||||
NORTHWEST (315);
|
|
||||||
|
|
||||||
protected int code;
|
|
||||||
|
|
||||||
private DirectionButton(int code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DirectionButton create(int angle) throws UnknownDirectionException {
|
|
||||||
for (DirectionButton button : DirectionButton.values()) {
|
|
||||||
if (button.getCode() == angle) {
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new UnknownDirectionException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DirectionButton create(JXInputDirectionalEvent event) throws UnknownDirectionException {
|
|
||||||
return create(event.getDirectional().getDirection() / 100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
package pm.device.javainput;
|
|
||||||
|
|
||||||
import de.hardcode.jxinput.JXInputDevice;
|
|
||||||
import de.hardcode.jxinput.JXInputManager;
|
|
||||||
import de.hardcode.jxinput.event.JXInputAxisEvent;
|
|
||||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
|
||||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
|
||||||
|
|
||||||
import pm.Button;
|
|
||||||
import pm.Device;
|
|
||||||
import pm.exception.ButtonException;
|
|
||||||
import pm.exception.button.UnknownButtonException;
|
|
||||||
import pm.exception.button.UnknownDirectionException;
|
|
||||||
import pm.exception.device.DeviceInitialiseException;
|
|
||||||
import pm.exception.device.DeviceNotFoundException;
|
|
||||||
import pm.macro.state.Press;
|
|
||||||
import pm.macro.state.Release;
|
|
||||||
|
|
||||||
public abstract class JavaInputDevice extends Device {
|
|
||||||
public JavaInputDevice(String title) {
|
|
||||||
super(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected JavaInputListener javaInputListener;
|
|
||||||
protected Button previousDirectionalButton;
|
|
||||||
|
|
||||||
public void activate(String name) throws DeviceInitialiseException {
|
|
||||||
try {
|
|
||||||
javaInputListener = new JavaInputListener(this, getDevice(name));
|
|
||||||
javaInputListener.start();
|
|
||||||
} catch (DeviceNotFoundException e) {
|
|
||||||
throw new DeviceInitialiseException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deactivate() {
|
|
||||||
javaInputListener.exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void processEvent(JXInputAxisEvent event) {
|
|
||||||
//System.out.println(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void processEvent(JXInputButtonEvent event) throws ButtonException {
|
|
||||||
Button button = getButton(event);
|
|
||||||
if (event.getButton().getState()) {
|
|
||||||
System.out.println("Press: " + button);
|
|
||||||
add(new Press(button));
|
|
||||||
} else {
|
|
||||||
System.out.println("Release: " + button);
|
|
||||||
add(new Release(button));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void processEvent(JXInputDirectionalEvent event) throws UnknownDirectionException {
|
|
||||||
Button button = getButton(event);
|
|
||||||
if (event.getDirectional().isCentered()) {
|
|
||||||
if (previousDirectionalButton != null) {
|
|
||||||
System.out.println("Release: " + previousDirectionalButton);
|
|
||||||
add(new Release(previousDirectionalButton));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.out.println("Press: " + button);
|
|
||||||
add(new Press(button));
|
|
||||||
previousDirectionalButton = button;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract Button getButton(JXInputButtonEvent event) throws UnknownButtonException;
|
|
||||||
protected abstract Button getButton(JXInputDirectionalEvent event) throws UnknownDirectionException;
|
|
||||||
|
|
||||||
public static JXInputDevice getDevice(String name) throws DeviceNotFoundException {
|
|
||||||
int numberOfDevices = JXInputManager.getNumberOfDevices();
|
|
||||||
for (int i = 0; i < numberOfDevices; ++i) {
|
|
||||||
JXInputDevice device = JXInputManager.getJXInputDevice(i);
|
|
||||||
if (device.getName().startsWith(name)) {
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new DeviceNotFoundException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
package pm.device.javainput;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Queue;
|
|
||||||
|
|
||||||
import pm.exception.ButtonException;
|
|
||||||
|
|
||||||
import de.hardcode.jxinput.Axis;
|
|
||||||
import de.hardcode.jxinput.Button;
|
|
||||||
import de.hardcode.jxinput.Directional;
|
|
||||||
import de.hardcode.jxinput.JXInputDevice;
|
|
||||||
import de.hardcode.jxinput.JXInputManager;
|
|
||||||
import de.hardcode.jxinput.event.JXInputAxisEvent;
|
|
||||||
import de.hardcode.jxinput.event.JXInputAxisEventListener;
|
|
||||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
|
||||||
import de.hardcode.jxinput.event.JXInputButtonEventListener;
|
|
||||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
|
||||||
import de.hardcode.jxinput.event.JXInputDirectionalEventListener;
|
|
||||||
import de.hardcode.jxinput.event.JXInputEventManager;
|
|
||||||
|
|
||||||
public class JavaInputListener implements Runnable, JXInputAxisEventListener, JXInputButtonEventListener, JXInputDirectionalEventListener {
|
|
||||||
protected static final int SLEEP = 100;
|
|
||||||
|
|
||||||
protected boolean run;
|
|
||||||
protected JavaInputDevice javaInputDevice;
|
|
||||||
protected JXInputDevice jxinputDevice;
|
|
||||||
protected Queue<JXInputAxisEvent> axisEventQueue;
|
|
||||||
protected Queue<JXInputButtonEvent> buttonEventQueue;
|
|
||||||
protected Queue<JXInputDirectionalEvent> directionalEventQueue;
|
|
||||||
|
|
||||||
public JavaInputListener(JavaInputDevice javaInputDevice, JXInputDevice jxinputDevice) {
|
|
||||||
this.javaInputDevice = javaInputDevice;
|
|
||||||
this.jxinputDevice = jxinputDevice;
|
|
||||||
axisEventQueue = new LinkedList<JXInputAxisEvent>();
|
|
||||||
buttonEventQueue = new LinkedList<JXInputButtonEvent>();
|
|
||||||
directionalEventQueue = new LinkedList<JXInputDirectionalEvent>();
|
|
||||||
addListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addListeners() {
|
|
||||||
for (int i = 0; i < jxinputDevice.getMaxNumberOfAxes(); ++i) {
|
|
||||||
Axis axis = jxinputDevice.getAxis(i);
|
|
||||||
if (axis != null) {
|
|
||||||
JXInputEventManager.addListener(this, axis);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = 0; i < jxinputDevice.getMaxNumberOfButtons(); ++i) {
|
|
||||||
Button button = jxinputDevice.getButton(i);
|
|
||||||
if (button != null) {
|
|
||||||
JXInputEventManager.addListener(this, button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = 0; i < jxinputDevice.getMaxNumberOfDirectionals(); ++i) {
|
|
||||||
Directional directional = jxinputDevice.getDirectional(i);
|
|
||||||
if (directional != null) {
|
|
||||||
JXInputEventManager.addListener(this, directional);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void changed(JXInputAxisEvent event) {
|
|
||||||
axisEventQueue.add(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void changed(JXInputButtonEvent event) {
|
|
||||||
buttonEventQueue.add(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void changed(JXInputDirectionalEvent event) {
|
|
||||||
directionalEventQueue.add(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
new Thread(this).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
run = true;
|
|
||||||
while (run) {
|
|
||||||
JXInputManager.updateFeatures();
|
|
||||||
boolean sleep = true;
|
|
||||||
if (!axisEventQueue.isEmpty()) {
|
|
||||||
javaInputDevice.processEvent(axisEventQueue.poll());
|
|
||||||
sleep = false;
|
|
||||||
}
|
|
||||||
if (!buttonEventQueue.isEmpty()) {
|
|
||||||
try {
|
|
||||||
javaInputDevice.processEvent(buttonEventQueue.poll());
|
|
||||||
} catch (ButtonException e) {}
|
|
||||||
sleep = false;
|
|
||||||
}
|
|
||||||
if (!directionalEventQueue.isEmpty()) {
|
|
||||||
try {
|
|
||||||
javaInputDevice.processEvent(directionalEventQueue.poll());
|
|
||||||
} catch (ButtonException e) {}
|
|
||||||
sleep = false;
|
|
||||||
}
|
|
||||||
if (sleep) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(SLEEP);
|
|
||||||
} catch (InterruptedException e) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void exit() {
|
|
||||||
run = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package pm.device.javainput.extreme3d;
|
|
||||||
|
|
||||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
|
||||||
import pm.Button;
|
|
||||||
import pm.exception.button.UnknownButtonException;
|
|
||||||
|
|
||||||
public enum Extreme3DButton implements Button {
|
|
||||||
ONE ("SelectButton 0"),
|
|
||||||
TWO ("SelectButton 1"),
|
|
||||||
THREE ("SelectButton 2"),
|
|
||||||
FOUR ("SelectButton 3"),
|
|
||||||
FIVE ("SelectButton 4"),
|
|
||||||
SIX ("SelectButton 5"),
|
|
||||||
SEVEN ("SelectButton 6"),
|
|
||||||
EIGHT ("SelectButton 7"),
|
|
||||||
NINE ("SelectButton 8"),
|
|
||||||
TEN ("SelectButton 9"),
|
|
||||||
ELEVEN ("SelectButton 10"),
|
|
||||||
TWELVE ("SelectButton 11");
|
|
||||||
|
|
||||||
protected String code;
|
|
||||||
|
|
||||||
private Extreme3DButton(String code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Extreme3DButton create(String code) throws UnknownButtonException {
|
|
||||||
for (Extreme3DButton button : Extreme3DButton.values()) {
|
|
||||||
if (button.getCode().equals(code)) {
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new UnknownButtonException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Extreme3DButton create(JXInputButtonEvent event) throws UnknownButtonException {
|
|
||||||
return create(event.getButton().getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package pm.device.javainput.extreme3d;
|
|
||||||
|
|
||||||
import pm.Button;
|
|
||||||
import pm.Macro;
|
|
||||||
import pm.device.javainput.DirectionButton;
|
|
||||||
import pm.device.javainput.JavaInputDevice;
|
|
||||||
import pm.event.Task;
|
|
||||||
import pm.exception.MacroException;
|
|
||||||
import pm.exception.button.UnknownButtonException;
|
|
||||||
import pm.exception.button.UnknownDirectionException;
|
|
||||||
import pm.macro.state.Hold;
|
|
||||||
import pm.macro.state.Press;
|
|
||||||
import pm.macro.state.Release;
|
|
||||||
import pm.value.Action;
|
|
||||||
import pm.value.Target;
|
|
||||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
|
||||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
|
||||||
|
|
||||||
public class Extreme3DDevice extends JavaInputDevice {
|
|
||||||
protected static final String NAME = "Logitech Extreme 3D";
|
|
||||||
|
|
||||||
public Extreme3DDevice() {
|
|
||||||
super(NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initialise() {
|
|
||||||
try {
|
|
||||||
add(
|
|
||||||
new Press(Extreme3DButton.TWELVE),
|
|
||||||
new Task(Target.APPLICATION, Action.TEST));
|
|
||||||
add(
|
|
||||||
new Macro(
|
|
||||||
new Hold(Extreme3DButton.ONE),
|
|
||||||
new Press(Extreme3DButton.TWO),
|
|
||||||
new Press(Extreme3DButton.ELEVEN),
|
|
||||||
new Release(Extreme3DButton.ONE)),
|
|
||||||
new Task(Target.MIMIS, Action.EXIT));
|
|
||||||
} catch (MacroException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Button getButton(JXInputButtonEvent event) throws UnknownButtonException {
|
|
||||||
return Extreme3DButton.create(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Button getButton(JXInputDirectionalEvent event) throws UnknownDirectionException {
|
|
||||||
return DirectionButton.create(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package pm.device.javainput.rumblepad;
|
|
||||||
|
|
||||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
|
||||||
import pm.Button;
|
|
||||||
import pm.exception.button.UnknownButtonException;
|
|
||||||
|
|
||||||
public enum RumblepadButton implements Button {
|
|
||||||
ONE ("SelectButton 0"),
|
|
||||||
TWO ("SelectButton 1"),
|
|
||||||
THREE ("SelectButton 2"),
|
|
||||||
FOUR ("SelectButton 3"),
|
|
||||||
FIVE ("SelectButton 4"),
|
|
||||||
SIX ("SelectButton 5"),
|
|
||||||
SEVEN ("SelectButton 6"),
|
|
||||||
EIGHT ("SelectButton 7"),
|
|
||||||
NINE ("SelectButton 8"),
|
|
||||||
TEN ("SelectButton 9");
|
|
||||||
|
|
||||||
protected String code;
|
|
||||||
|
|
||||||
private RumblepadButton(String code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RumblepadButton create(String code) throws UnknownButtonException {
|
|
||||||
for (RumblepadButton button : RumblepadButton.values()) {
|
|
||||||
if (button.getCode().equals(code)) {
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new UnknownButtonException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RumblepadButton create(JXInputButtonEvent event) throws UnknownButtonException {
|
|
||||||
return create(event.getButton().getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
package pm.device.javainput.rumblepad;
|
|
||||||
|
|
||||||
import pm.Button;
|
|
||||||
import pm.device.javainput.DirectionButton;
|
|
||||||
import pm.device.javainput.JavaInputDevice;
|
|
||||||
import pm.event.Task;
|
|
||||||
import pm.event.task.Continuous;
|
|
||||||
import pm.event.task.Dynamic;
|
|
||||||
import pm.exception.button.UnknownButtonException;
|
|
||||||
import pm.exception.button.UnknownDirectionException;
|
|
||||||
import pm.macro.state.Hold;
|
|
||||||
import pm.macro.state.Press;
|
|
||||||
import pm.value.Action;
|
|
||||||
import pm.value.Target;
|
|
||||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
|
||||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
|
||||||
|
|
||||||
public class RumblepadDevice extends JavaInputDevice {
|
|
||||||
protected static final String NAME = "Logitech RumblePad 2 USB";
|
|
||||||
|
|
||||||
public RumblepadDevice() {
|
|
||||||
super(NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initialise(){
|
|
||||||
add(
|
|
||||||
new Press(RumblepadButton.ONE),
|
|
||||||
new Task(Target.APPLICATION, Action.PLAY));
|
|
||||||
add(
|
|
||||||
new Press(RumblepadButton.TWO),
|
|
||||||
new Task(Target.APPLICATION, Action.PAUSE));
|
|
||||||
add(
|
|
||||||
new Press(RumblepadButton.THREE),
|
|
||||||
new Task(Target.APPLICATION, Action.RESUME));
|
|
||||||
add(
|
|
||||||
new Press(RumblepadButton.SIX),
|
|
||||||
new Task(Target.APPLICATION, Action.NEXT));
|
|
||||||
add(
|
|
||||||
new Press(RumblepadButton.EIGHT),
|
|
||||||
new Task(Target.APPLICATION, Action.PREVIOUS));
|
|
||||||
add(
|
|
||||||
new Hold(RumblepadButton.FIVE),
|
|
||||||
new Dynamic(Action.FORWARD, Target.APPLICATION, 200, -30));
|
|
||||||
add(
|
|
||||||
new Hold(RumblepadButton.SEVEN),
|
|
||||||
new Dynamic(Action.REWIND, Target.APPLICATION, 200, -30));
|
|
||||||
add(
|
|
||||||
new Hold(RumblepadButton.NINE),
|
|
||||||
new Continuous(Action.VOLUME_DOWN, Target.APPLICATION, 100));
|
|
||||||
add(
|
|
||||||
new Hold(RumblepadButton.TEN),
|
|
||||||
new Continuous(Action.VOLUME_UP, Target.APPLICATION, 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Button getButton(JXInputButtonEvent event) throws UnknownButtonException {
|
|
||||||
return RumblepadButton.create(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Button getButton(JXInputDirectionalEvent event) throws UnknownDirectionException {
|
|
||||||
return DirectionButton.create(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
package pm.device.jintellitype;
|
|
||||||
|
|
||||||
import com.melloware.jintellitype.JIntellitype;
|
|
||||||
|
|
||||||
import pm.Button;
|
|
||||||
import pm.exception.button.UnknownButtonException;
|
|
||||||
|
|
||||||
public enum CommandButton implements Button {
|
|
||||||
BROWSER_BACKWARD (JIntellitype.APPCOMMAND_BROWSER_BACKWARD),
|
|
||||||
BROWSER_FORWARD (JIntellitype.APPCOMMAND_BROWSER_FORWARD),
|
|
||||||
BROWSER_REFRESH (JIntellitype.APPCOMMAND_BROWSER_REFRESH),
|
|
||||||
BROWSER_STOP (JIntellitype.APPCOMMAND_BROWSER_STOP),
|
|
||||||
BROWSER_SEARCH (JIntellitype.APPCOMMAND_BROWSER_SEARCH),
|
|
||||||
BROWSER_FAVOURITES (JIntellitype.APPCOMMAND_BROWSER_FAVOURITES),
|
|
||||||
BROWSER_HOME (JIntellitype.APPCOMMAND_BROWSER_HOME),
|
|
||||||
VOLUME_MUTE (JIntellitype.APPCOMMAND_VOLUME_MUTE),
|
|
||||||
VOLUME_DOWN (JIntellitype.APPCOMMAND_VOLUME_DOWN),
|
|
||||||
VOLUME_UP (JIntellitype.APPCOMMAND_VOLUME_UP),
|
|
||||||
MEDIA_NEXTTRACK (JIntellitype.APPCOMMAND_MEDIA_NEXTTRACK),
|
|
||||||
MEDIA_PREVIOUSTRACK (JIntellitype.APPCOMMAND_MEDIA_PREVIOUSTRACK),
|
|
||||||
MEDIA_STOP (JIntellitype.APPCOMMAND_MEDIA_STOP),
|
|
||||||
MEDIA_PLAY_PAUSE (JIntellitype.APPCOMMAND_MEDIA_PLAY_PAUSE),
|
|
||||||
LAUNCH_MAIL (JIntellitype.APPCOMMAND_LAUNCH_MAIL),
|
|
||||||
LAUNCH_MEDIA_SELECT (JIntellitype.APPCOMMAND_LAUNCH_MEDIA_SELECT),
|
|
||||||
LAUNCH_APP1 (JIntellitype.APPCOMMAND_LAUNCH_APP1),
|
|
||||||
LAUNCH_APP2 (JIntellitype.APPCOMMAND_LAUNCH_APP2),
|
|
||||||
BASS_DOWN (JIntellitype.APPCOMMAND_BASS_DOWN),
|
|
||||||
BASS_BOOST (JIntellitype.APPCOMMAND_BASS_BOOST),
|
|
||||||
BASS_UP (JIntellitype.APPCOMMAND_BASS_UP),
|
|
||||||
TREBLE_DOWN (JIntellitype.APPCOMMAND_TREBLE_DOWN),
|
|
||||||
TREBLE_UP (JIntellitype.APPCOMMAND_TREBLE_UP),
|
|
||||||
MICROPHONE_VOLUME_MUTE (JIntellitype.APPCOMMAND_MICROPHONE_VOLUME_MUTE),
|
|
||||||
MICROPHONE_VOLUME_DOWN (JIntellitype.APPCOMMAND_MICROPHONE_VOLUME_DOWN),
|
|
||||||
MICROPHONE_VOLUME_UP (JIntellitype.APPCOMMAND_MICROPHONE_VOLUME_UP),
|
|
||||||
HELP (JIntellitype.APPCOMMAND_HELP),
|
|
||||||
FIND (JIntellitype.APPCOMMAND_FIND),
|
|
||||||
NEW (JIntellitype.APPCOMMAND_NEW),
|
|
||||||
OPEN (JIntellitype.APPCOMMAND_OPEN),
|
|
||||||
CLOSE (JIntellitype.APPCOMMAND_CLOSE),
|
|
||||||
SAVE (JIntellitype.APPCOMMAND_SAVE),
|
|
||||||
PRINT (JIntellitype.APPCOMMAND_PRINT),
|
|
||||||
UNDO (JIntellitype.APPCOMMAND_UNDO),
|
|
||||||
REDO (JIntellitype.APPCOMMAND_REDO),
|
|
||||||
COPY (JIntellitype.APPCOMMAND_COPY),
|
|
||||||
CUT (JIntellitype.APPCOMMAND_CUT),
|
|
||||||
PASTE (JIntellitype.APPCOMMAND_PASTE),
|
|
||||||
REPLY_TO_MAIL (JIntellitype.APPCOMMAND_REPLY_TO_MAIL),
|
|
||||||
FORWARD_MAIL (JIntellitype.APPCOMMAND_FORWARD_MAIL),
|
|
||||||
SEND_MAIL (JIntellitype.APPCOMMAND_SEND_MAIL),
|
|
||||||
SPELL_CHECK (JIntellitype.APPCOMMAND_SPELL_CHECK),
|
|
||||||
DICTATE_OR_COMMAND_CONTROL_TOGGLE (JIntellitype.APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE),
|
|
||||||
MIC_ON_OFF_TOGGLE (JIntellitype.APPCOMMAND_MIC_ON_OFF_TOGGLE),
|
|
||||||
CORRECTION_LIST (JIntellitype.APPCOMMAND_CORRECTION_LIST);
|
|
||||||
|
|
||||||
protected int code;
|
|
||||||
|
|
||||||
private CommandButton(int code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CommandButton create(int code) throws UnknownButtonException {
|
|
||||||
for (CommandButton button : CommandButton.values()) {
|
|
||||||
if (button.getCode() == code) {
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new UnknownButtonException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package pm.device.jintellitype;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import com.melloware.jintellitype.JIntellitype;
|
|
||||||
|
|
||||||
import pm.Button;
|
|
||||||
import pm.value.Key;
|
|
||||||
|
|
||||||
public class Hotkey implements Button {
|
|
||||||
protected static ArrayList<Hotkey> hotkeyList;
|
|
||||||
protected static JIntellitype jit;
|
|
||||||
|
|
||||||
public Hotkey(int modifier, int keycode) {
|
|
||||||
int id = hotkeyList.size();
|
|
||||||
jit.registerHotKey(id, modifier, keycode);
|
|
||||||
hotkeyList.add(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hotkey(int modifier, char character) {
|
|
||||||
this(modifier, (int) Character.toUpperCase(character));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hotkey(char character) {
|
|
||||||
this(0, (int) Character.toUpperCase(character));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hotkey(int keycode) {
|
|
||||||
this(0, keycode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hotkey(Key key) {
|
|
||||||
this(key.getCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void initialise(ArrayList<Hotkey> actionList, JIntellitype jit) {
|
|
||||||
Hotkey.hotkeyList = actionList;
|
|
||||||
Hotkey.jit = jit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
package pm.device.jintellitype;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import com.melloware.jintellitype.HotkeyListener;
|
|
||||||
import com.melloware.jintellitype.IntellitypeListener;
|
|
||||||
import com.melloware.jintellitype.JIntellitype;
|
|
||||||
|
|
||||||
import pm.Device;
|
|
||||||
import pm.event.Task;
|
|
||||||
import pm.exception.button.UnknownButtonException;
|
|
||||||
import pm.macro.state.Press;
|
|
||||||
import pm.macro.state.Release;
|
|
||||||
import pm.value.Action;
|
|
||||||
import pm.value.Key;
|
|
||||||
import pm.value.Target;
|
|
||||||
|
|
||||||
public class JIntellitypeDevice extends Device implements HotkeyListener, IntellitypeListener {
|
|
||||||
protected static final String TITLE = "JIntellitype";
|
|
||||||
|
|
||||||
protected ArrayList<Hotkey> hotkeyList;
|
|
||||||
protected JIntellitype jit;
|
|
||||||
|
|
||||||
public JIntellitypeDevice() {
|
|
||||||
super(TITLE);
|
|
||||||
hotkeyList = new ArrayList<Hotkey>();
|
|
||||||
jit = JIntellitype.getInstance();
|
|
||||||
Hotkey.initialise(hotkeyList, jit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initialise() {
|
|
||||||
jit.addHotKeyListener(this);
|
|
||||||
jit.addIntellitypeListener(this);
|
|
||||||
add(
|
|
||||||
new Hotkey(Key.PRIOR),
|
|
||||||
new Task(Target.MIMIS, Action.PREVIOUS));
|
|
||||||
add(
|
|
||||||
new Hotkey(Key.NEXT),
|
|
||||||
new Task(Target.MIMIS, Action.NEXT));
|
|
||||||
add(
|
|
||||||
new Press(CommandButton.VOLUME_DOWN),
|
|
||||||
new Task(Target.APPLICATIONS, Action.VOLUME_DOWN));
|
|
||||||
add(
|
|
||||||
new Press(CommandButton.VOLUME_UP),
|
|
||||||
new Task(Target.APPLICATIONS, Action.VOLUME_UP));
|
|
||||||
add(
|
|
||||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 'x'),
|
|
||||||
new Task(Target.MIMIS, Action.EXIT));
|
|
||||||
add(
|
|
||||||
new Hotkey(Modifier.CTRL | Modifier.SHIFT | Modifier.WIN, 'n'),
|
|
||||||
new Task(Target.APPLICATION, Action.NEXT));
|
|
||||||
add(
|
|
||||||
new Hotkey(Modifier.CTRL | Modifier.SHIFT | Modifier.WIN, 'p'),
|
|
||||||
new Task(Target.APPLICATION, Action.PREVIOUS));
|
|
||||||
/*add(
|
|
||||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 't'),
|
|
||||||
new Task(Action.TEST, Target.MAIN));
|
|
||||||
add(
|
|
||||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 'r'),
|
|
||||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 's'),
|
|
||||||
new Continuous(Action.REPEAT, Target.APPLICATIONS, 500));*/
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void add(Hotkey hotkey, Task task) {
|
|
||||||
add(new Press(hotkey), task);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onIntellitype(int command) {
|
|
||||||
try {
|
|
||||||
CommandButton commandButton = CommandButton.create(command);
|
|
||||||
add(new Press(commandButton));
|
|
||||||
add(new Release(commandButton));
|
|
||||||
} catch (UnknownButtonException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onHotKey(int id) {
|
|
||||||
Hotkey hotkey = hotkeyList.get(id);
|
|
||||||
add(new Press(hotkey));
|
|
||||||
add(new Release(hotkey));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void exit() {
|
|
||||||
super.exit();
|
|
||||||
jit.removeHotKeyListener(this);
|
|
||||||
jit.removeIntellitypeListener(this);
|
|
||||||
jit.cleanUp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package pm.device.jintellitype;
|
|
||||||
|
|
||||||
import com.melloware.jintellitype.JIntellitype;
|
|
||||||
|
|
||||||
import pm.Button;
|
|
||||||
|
|
||||||
public class Modifier implements Button {
|
|
||||||
public static final int
|
|
||||||
ALT = JIntellitype.MOD_ALT,
|
|
||||||
CTRL = JIntellitype.MOD_CONTROL,
|
|
||||||
SHIFT = JIntellitype.MOD_SHIFT,
|
|
||||||
WIN = JIntellitype.MOD_WIN;
|
|
||||||
|
|
||||||
protected int code;
|
|
||||||
|
|
||||||
protected Modifier(int code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.device.lirc;
|
|
||||||
|
|
||||||
import pm.Button;
|
|
||||||
|
|
||||||
public interface LircButton extends Button {
|
|
||||||
public String getCode();
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package pm.device.lirc;
|
|
||||||
|
|
||||||
public interface LircButtonListener {
|
|
||||||
public void add(LircButton lircButton);
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package pm.device.lirc;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import pm.Device;
|
|
||||||
import pm.device.lirc.button.DenonRC176;
|
|
||||||
import pm.device.lirc.button.PhiliphsRCLE011Button;
|
|
||||||
import pm.util.Multiplexer;
|
|
||||||
|
|
||||||
public class LircDevice extends Device implements LircButtonListener {
|
|
||||||
protected static final String TITLE = "Lirc";
|
|
||||||
|
|
||||||
protected Multiplexer multiplexer;
|
|
||||||
protected LircService lircService;
|
|
||||||
|
|
||||||
public LircDevice() {
|
|
||||||
super(TITLE);
|
|
||||||
|
|
||||||
HashMap<String, LircButton[]> buttonMap = new HashMap<String, LircButton[]>();
|
|
||||||
buttonMap.put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values());
|
|
||||||
buttonMap.put(DenonRC176.NAME, DenonRC176.values());
|
|
||||||
|
|
||||||
multiplexer = new Multiplexer();
|
|
||||||
|
|
||||||
lircService = new LircService(buttonMap);
|
|
||||||
lircService.add(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void activate() {
|
|
||||||
lircService.start();
|
|
||||||
super.activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deactivate() {
|
|
||||||
lircService.deactivate();
|
|
||||||
super.deactivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(LircButton lircButton) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
package pm.device.lirc;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.InputMismatchException;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import pm.Worker;
|
|
||||||
import pm.exception.button.UnknownButtonException;
|
|
||||||
|
|
||||||
public class LircService extends Worker {
|
|
||||||
public static final String IP = "127.0.0.1";
|
|
||||||
public static final int PORT = 8765;
|
|
||||||
|
|
||||||
protected ArrayList<LircButtonListener> lircButtonListenerList;
|
|
||||||
protected String ip;
|
|
||||||
protected int port;
|
|
||||||
protected Socket socket;
|
|
||||||
protected InputStream inputStream;
|
|
||||||
protected OutputStream outputStream;
|
|
||||||
protected BufferedReader bufferedReader;
|
|
||||||
protected PrintWriter printWriter;
|
|
||||||
protected HashMap<String, LircButton[]> buttonMap;
|
|
||||||
|
|
||||||
public LircService(HashMap<String, LircButton[]> buttonMap) {
|
|
||||||
this(buttonMap, IP, PORT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LircService(HashMap<String, LircButton[]> buttonMap, String ip, int port) {
|
|
||||||
this.buttonMap = buttonMap;
|
|
||||||
this.ip = ip;
|
|
||||||
this.port = port;
|
|
||||||
lircButtonListenerList = new ArrayList<LircButtonListener>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(LircButtonListener lircButtonListener) {
|
|
||||||
lircButtonListenerList.add(lircButtonListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(LircButtonListener lircButtonListener) {
|
|
||||||
lircButtonListenerList.remove(lircButtonListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void activate() {
|
|
||||||
try {
|
|
||||||
socket = new Socket(ip, port);
|
|
||||||
|
|
||||||
inputStream = socket.getInputStream();
|
|
||||||
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
|
||||||
|
|
||||||
outputStream = socket.getOutputStream();
|
|
||||||
printWriter = new PrintWriter(outputStream);
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
super.activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deactivate() {
|
|
||||||
try {
|
|
||||||
inputStream.close();
|
|
||||||
outputStream.close();
|
|
||||||
socket.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
//e.printStackTrace();
|
|
||||||
}
|
|
||||||
super.deactivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void work() {
|
|
||||||
try {
|
|
||||||
String string = bufferedReader.readLine();
|
|
||||||
try {
|
|
||||||
LircButton lircButton = parseButton(new Scanner(string));
|
|
||||||
log.debug(String.format("Lirc button: %s", lircButton));
|
|
||||||
for (LircButtonListener lircbuttonListener : lircButtonListenerList) {
|
|
||||||
lircbuttonListener.add(lircButton);
|
|
||||||
}
|
|
||||||
} catch (UnknownButtonException e) {}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public LircButton parseButton(Scanner scanner) throws UnknownButtonException {
|
|
||||||
try {
|
|
||||||
scanner.next();
|
|
||||||
scanner.next();
|
|
||||||
String code = scanner.next();
|
|
||||||
String remote = scanner.next();
|
|
||||||
//log.debug(String.format("%s: %s", remote, code));
|
|
||||||
LircButton[] buttonArray = buttonMap.get(remote);
|
|
||||||
if (buttonArray != null) {
|
|
||||||
for (LircButton button : buttonArray) {
|
|
||||||
if (button.getCode().equals(code)) {
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (InputMismatchException e) {}
|
|
||||||
throw new UnknownButtonException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.out.println("hey");
|
|
||||||
//String send = Native.getValue("HKEY_CURRENT_USER\\Software\\LIRC", "password");
|
|
||||||
new LircDevice().start();
|
|
||||||
while (true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package pm.device.lirc.button;
|
|
||||||
|
|
||||||
import pm.device.lirc.LircButton;
|
|
||||||
|
|
||||||
public enum DenonRC176 implements LircButton {
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static final String NAME = "DENON_RC-176";
|
|
||||||
|
|
||||||
protected String code;
|
|
||||||
|
|
||||||
private DenonRC176(String code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package pm.device.lirc.button;
|
|
||||||
|
|
||||||
import pm.device.lirc.LircButton;
|
|
||||||
import pm.exception.button.UnknownButtonException;
|
|
||||||
|
|
||||||
public enum PhiliphsRCLE011Button implements LircButton {
|
|
||||||
POWER ("Standby"),
|
|
||||||
RED ("Red"),
|
|
||||||
GREEN ("Green"),
|
|
||||||
YELLOW ("Yellow"),
|
|
||||||
BLUE ("Blue"),
|
|
||||||
TUNE ("Tune"),
|
|
||||||
RADIO ("Radio"),
|
|
||||||
SQUARE ("Square"),
|
|
||||||
MENU ("Menu"),
|
|
||||||
TEXT ("Text"),
|
|
||||||
UP ("Up"),
|
|
||||||
DOWN ("Down"),
|
|
||||||
LEFT ("Left"),
|
|
||||||
RIGHT ("Right"),
|
|
||||||
VOLUME_UP ("Volume+"),
|
|
||||||
VOLUME_DOWN ("Volume-");
|
|
||||||
/*Mute,
|
|
||||||
Program+,
|
|
||||||
Program-,
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
3,
|
|
||||||
4,
|
|
||||||
5,
|
|
||||||
6
|
|
||||||
7,
|
|
||||||
8,
|
|
||||||
9,
|
|
||||||
0,
|
|
||||||
Clock,
|
|
||||||
Out,
|
|
||||||
i+,
|
|
||||||
screenup,
|
|
||||||
screendown,
|
|
||||||
question;*/
|
|
||||||
|
|
||||||
public static final String NAME = "Philips_RCLE011";
|
|
||||||
|
|
||||||
protected String code;
|
|
||||||
|
|
||||||
private PhiliphsRCLE011Button(String code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PhiliphsRCLE011Button create(String code) throws UnknownButtonException {
|
|
||||||
for (PhiliphsRCLE011Button button : PhiliphsRCLE011Button.values()) {
|
|
||||||
if (button.getCode().equals(code)) {
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new UnknownButtonException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
package pm.device.network;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import pm.Device;
|
|
||||||
import pm.Event;
|
|
||||||
import pm.Worker;
|
|
||||||
import pm.event.Feedback;
|
|
||||||
|
|
||||||
public class NetworkDevice extends Device {
|
|
||||||
protected static final String TITLE = "Network";
|
|
||||||
public static final int PORT = 6789;
|
|
||||||
|
|
||||||
protected Log log = LogFactory.getLog(NetworkDevice.class);
|
|
||||||
protected int port;
|
|
||||||
protected Server server;
|
|
||||||
protected ArrayList<Client> clientList;
|
|
||||||
|
|
||||||
public NetworkDevice(int port) {
|
|
||||||
super(TITLE);
|
|
||||||
this.port = port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NetworkDevice() {
|
|
||||||
this(PORT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void activate() {
|
|
||||||
try {
|
|
||||||
server = new Server(port);
|
|
||||||
server.start();
|
|
||||||
} catch (IOException e) {
|
|
||||||
//throw new DeviceInitialiseException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deactivate() {
|
|
||||||
server.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void feedback(Feedback feedback) {
|
|
||||||
for (Client client : clientList) {
|
|
||||||
try {
|
|
||||||
client.send(feedback);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class Server extends Worker {
|
|
||||||
protected ServerSocket serverSocket;
|
|
||||||
|
|
||||||
public Server(int port) throws IOException {
|
|
||||||
serverSocket = new ServerSocket(port);
|
|
||||||
clientList = new ArrayList<Client>();
|
|
||||||
System.out.println("Server started");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void work() {
|
|
||||||
System.out.println("Server is waiting for clients");
|
|
||||||
try {
|
|
||||||
Socket socket = serverSocket.accept();
|
|
||||||
Client client = new Client(socket);
|
|
||||||
client.start();
|
|
||||||
System.out.println("Client connected");
|
|
||||||
} catch (IOException e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
|
||||||
for (Client client : clientList) {
|
|
||||||
client.stop();
|
|
||||||
}
|
|
||||||
super.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class Client extends Worker {
|
|
||||||
protected Socket socket;
|
|
||||||
protected ObjectInputStream objectInputStream;
|
|
||||||
protected ObjectOutputStream objectOutputStream;
|
|
||||||
|
|
||||||
public Client(Socket socket) throws IOException {
|
|
||||||
this.socket = socket;
|
|
||||||
objectInputStream = new ObjectInputStream(socket.getInputStream());
|
|
||||||
objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
|
|
||||||
clientList.add(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void work() {
|
|
||||||
try {
|
|
||||||
Object object;
|
|
||||||
do {
|
|
||||||
object = objectInputStream.readObject();
|
|
||||||
if (object instanceof Event) {
|
|
||||||
log.debug("event binnen!");
|
|
||||||
eventRouter.add((Event) object);
|
|
||||||
}
|
|
||||||
log.debug("iets te lezen!");
|
|
||||||
} while (object != null);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
|
||||||
System.out.println("stoppen");
|
|
||||||
try {
|
|
||||||
disconnect();
|
|
||||||
} catch (IOException e) {
|
|
||||||
} finally {
|
|
||||||
clientList.remove(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void send(Object object) throws IOException {
|
|
||||||
objectOutputStream.writeObject(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disconnect() throws IOException {
|
|
||||||
objectInputStream.close();
|
|
||||||
objectOutputStream.close();
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,211 +0,0 @@
|
|||||||
package pm.device.panel;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import pm.util.swing.HoldButton;
|
|
||||||
import pm.util.swing.HoldButtonListener;
|
|
||||||
import pm.util.swing.ToggleButton;
|
|
||||||
|
|
||||||
public class Panel extends JFrame implements HoldButtonListener {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
protected final static String TITLE = "MIMIS Panel Device";
|
|
||||||
|
|
||||||
protected PanelButtonListener panelButtonListener;
|
|
||||||
protected ClassLoader classLoader;
|
|
||||||
|
|
||||||
//protected JTextArea feedbackArea;
|
|
||||||
//protected JScrollPane scrollPane;
|
|
||||||
|
|
||||||
protected HoldButton previousButton;
|
|
||||||
protected HoldButton rewindButton;
|
|
||||||
protected HoldButton stopButton;
|
|
||||||
protected ToggleButton playPauseToggleButton;
|
|
||||||
protected HoldButton forwardButton;
|
|
||||||
protected HoldButton nextButton;
|
|
||||||
protected HoldButton volumeDownButton;
|
|
||||||
protected ToggleButton muteToggleButton;
|
|
||||||
protected HoldButton volumeUpButton;
|
|
||||||
protected HoldButton repeatButton;
|
|
||||||
protected HoldButton shuffleButton;
|
|
||||||
|
|
||||||
Panel(PanelButtonListener panelButtonListener) {
|
|
||||||
super(TITLE);
|
|
||||||
this.panelButtonListener = panelButtonListener;
|
|
||||||
classLoader = getClass().getClassLoader();
|
|
||||||
createControls();
|
|
||||||
layoutControls();
|
|
||||||
pack();
|
|
||||||
setResizable(false);
|
|
||||||
setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URL getResource(String name) {
|
|
||||||
return classLoader.getResource(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ImageIcon getImageIcon(String name) {
|
|
||||||
return new ImageIcon(getResource(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected HoldButton getButton(String name, String text) {
|
|
||||||
HoldButton button = new HoldButton(this);
|
|
||||||
button.setIcon(getImageIcon(name));
|
|
||||||
button.setToolTipText(text);
|
|
||||||
button.setFocusPainted(false);
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ToggleButton getToggleButton(String firstName, String secondName, String text) {
|
|
||||||
ImageIcon firstImageIcon = getImageIcon(firstName);
|
|
||||||
ImageIcon secondImageIcon = getImageIcon(secondName);
|
|
||||||
ToggleButton button = new ToggleButton(this, firstImageIcon, secondImageIcon);
|
|
||||||
button.setToolTipText(text);
|
|
||||||
button.setFocusPainted(false);
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void createControls() {
|
|
||||||
previousButton = getButton("icons/previous.png", "Go to previous track");
|
|
||||||
rewindButton = getButton("icons/rewind.png", "Skip backward");
|
|
||||||
playPauseToggleButton = getToggleButton("icons/play.png", "icons/pause.png", "Play/pause");//getButton("icons/play.png", "Play/pause");
|
|
||||||
forwardButton = getButton("icons/forward.png", "Skip forward");
|
|
||||||
nextButton = getButton("icons/next.png", "Go to next track");
|
|
||||||
volumeDownButton = getButton("icons/volumeDown.png", "Decrease volume");
|
|
||||||
muteToggleButton = getToggleButton("icons/mute.png", "icons/unmute.png", "Toggle Mute");
|
|
||||||
volumeUpButton = getButton("icons/volumeUp.png", "Increase volume");
|
|
||||||
repeatButton = getButton("icons/repeat.png", "Repeat");
|
|
||||||
shuffleButton = getButton("icons/shuffle.png", "Shuffle");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void layoutControls() {
|
|
||||||
setLayout(new BorderLayout());
|
|
||||||
//layoutFeedbackPanel();
|
|
||||||
layoutControlPanel();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*protected void layoutFeedbackPanel() {
|
|
||||||
JPanel feedbackPanel = new JPanel();
|
|
||||||
feedbackArea = new JTextArea(10, 32);
|
|
||||||
feedbackArea.setEditable(false);
|
|
||||||
feedbackPanel.add(feedbackArea);
|
|
||||||
|
|
||||||
scrollPane = new JScrollPane();
|
|
||||||
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
|
||||||
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
|
||||||
scrollPane.getViewport().add(feedbackArea);
|
|
||||||
feedbackPanel.add(scrollPane);
|
|
||||||
|
|
||||||
add(feedbackPanel, BorderLayout.SOUTH);
|
|
||||||
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
feedbackArea.append("Hier komt allerlei feedback te staan!\n");
|
|
||||||
|
|
||||||
|
|
||||||
JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
|
|
||||||
scrollBar.setValue(scrollBar.getMaximum());
|
|
||||||
}*/
|
|
||||||
|
|
||||||
protected void layoutControlPanel() {
|
|
||||||
JPanel controlPanel = new JPanel();
|
|
||||||
controlPanel.setLayout(new BorderLayout());
|
|
||||||
|
|
||||||
JPanel upperControlPanel = new JPanel();
|
|
||||||
controlPanel.add(upperControlPanel, BorderLayout.NORTH);
|
|
||||||
upperControlPanel.add(previousButton);
|
|
||||||
upperControlPanel.add(rewindButton);
|
|
||||||
upperControlPanel.add(playPauseToggleButton);
|
|
||||||
upperControlPanel.add(forwardButton);
|
|
||||||
upperControlPanel.add(nextButton);
|
|
||||||
|
|
||||||
JPanel lowerControlPanel = new JPanel();
|
|
||||||
controlPanel.add(lowerControlPanel, BorderLayout.SOUTH);
|
|
||||||
lowerControlPanel.add(repeatButton);
|
|
||||||
lowerControlPanel.add(volumeDownButton);
|
|
||||||
lowerControlPanel.add(muteToggleButton);
|
|
||||||
lowerControlPanel.add(volumeUpButton);
|
|
||||||
lowerControlPanel.add(shuffleButton);
|
|
||||||
|
|
||||||
add(controlPanel, BorderLayout.CENTER);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Listeners */
|
|
||||||
public void buttonPressed(HoldButton button) {
|
|
||||||
if (button.equals(previousButton)) {
|
|
||||||
panelButtonListener.buttonPressed(PanelButton.PREVIOUS);
|
|
||||||
} else if (button.equals(rewindButton)) {
|
|
||||||
panelButtonListener.buttonPressed(PanelButton.REWIND);
|
|
||||||
} else if (button.equals(playPauseToggleButton)) {
|
|
||||||
panelButtonListener.buttonPressed(PanelButton.PLAY);
|
|
||||||
} else if (button.equals(forwardButton)) {
|
|
||||||
panelButtonListener.buttonPressed(PanelButton.FORWARD);
|
|
||||||
} else if (button.equals(nextButton)) {
|
|
||||||
panelButtonListener.buttonPressed(PanelButton.NEXT);
|
|
||||||
} else if (button.equals(volumeDownButton)) {
|
|
||||||
panelButtonListener.buttonPressed(PanelButton.VOLUME_DOWN);
|
|
||||||
} else if (button.equals(muteToggleButton)) {
|
|
||||||
panelButtonListener.buttonPressed(PanelButton.MUTE);
|
|
||||||
} else if (button.equals(volumeUpButton)) {
|
|
||||||
panelButtonListener.buttonPressed(PanelButton.VOLUME_UP);
|
|
||||||
} else if (button.equals(repeatButton)) {
|
|
||||||
panelButtonListener.buttonPressed(PanelButton.REPEAT);
|
|
||||||
} else if (button.equals(shuffleButton)) {
|
|
||||||
panelButtonListener.buttonPressed(PanelButton.SHUFFLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void buttonReleased(HoldButton button) {
|
|
||||||
if (button.equals(previousButton)) {
|
|
||||||
panelButtonListener.buttonReleased(PanelButton.PREVIOUS);
|
|
||||||
} else if (button.equals(rewindButton)) {
|
|
||||||
panelButtonListener.buttonReleased(PanelButton.REWIND);
|
|
||||||
} else if (button.equals(playPauseToggleButton)) {
|
|
||||||
panelButtonListener.buttonReleased(PanelButton.PLAY);
|
|
||||||
playPauseToggleButton.toggle();
|
|
||||||
} else if (button.equals(forwardButton)) {
|
|
||||||
panelButtonListener.buttonReleased(PanelButton.FORWARD);
|
|
||||||
} else if (button.equals(nextButton)) {
|
|
||||||
panelButtonListener.buttonReleased(PanelButton.NEXT);
|
|
||||||
} else if (button.equals(volumeDownButton)) {
|
|
||||||
panelButtonListener.buttonReleased(PanelButton.VOLUME_DOWN);
|
|
||||||
} else if (button.equals(muteToggleButton)) {
|
|
||||||
panelButtonListener.buttonReleased(PanelButton.MUTE);
|
|
||||||
muteToggleButton.toggle();
|
|
||||||
} else if (button.equals(volumeUpButton)) {
|
|
||||||
panelButtonListener.buttonReleased(PanelButton.VOLUME_UP);
|
|
||||||
} else if (button.equals(repeatButton)) {
|
|
||||||
panelButtonListener.buttonReleased(PanelButton.REPEAT);
|
|
||||||
} else if (button.equals(shuffleButton)) {
|
|
||||||
panelButtonListener.buttonReleased(PanelButton.SHUFFLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Feedback */
|
|
||||||
/*public void addFeedback(String format, Object... args) {
|
|
||||||
feedbackArea.append(String.format(format, args));
|
|
||||||
JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
|
|
||||||
scrollBar.setValue(scrollBar.getMaximum());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearFeedback() {
|
|
||||||
feedbackArea.setText("");
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package pm.device.panel;
|
|
||||||
|
|
||||||
import pm.Button;
|
|
||||||
|
|
||||||
public enum PanelButton implements Button {
|
|
||||||
PREVIOUS,
|
|
||||||
REWIND,
|
|
||||||
STOP,
|
|
||||||
PAUSE,
|
|
||||||
PLAY,
|
|
||||||
FORWARD,
|
|
||||||
NEXT,
|
|
||||||
VOLUME_DOWN,
|
|
||||||
MUTE,
|
|
||||||
VOLUME_UP,
|
|
||||||
REPEAT,
|
|
||||||
SHUFFLE;
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package pm.device.panel;
|
|
||||||
|
|
||||||
public interface PanelButtonListener {
|
|
||||||
public void buttonPressed(PanelButton panelButton);
|
|
||||||
public void buttonReleased(PanelButton panelButton);
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
package pm.device.panel;
|
|
||||||
|
|
||||||
import java.awt.event.WindowEvent;
|
|
||||||
|
|
||||||
import javax.swing.WindowConstants;
|
|
||||||
|
|
||||||
import pm.Device;
|
|
||||||
import pm.event.Task;
|
|
||||||
import pm.macro.state.Press;
|
|
||||||
import pm.macro.state.Release;
|
|
||||||
import pm.value.Action;
|
|
||||||
import pm.value.Target;
|
|
||||||
|
|
||||||
public class PanelDevice extends Device implements PanelButtonListener {
|
|
||||||
protected static final String TITLE = "Panel";
|
|
||||||
protected Panel panel;
|
|
||||||
|
|
||||||
public PanelDevice() {
|
|
||||||
super(TITLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void activate() {
|
|
||||||
panel = new Panel(this) {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
protected void processWindowEvent(WindowEvent e) {
|
|
||||||
log.debug("Window closing");
|
|
||||||
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
|
|
||||||
deactivate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
panel.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
|
||||||
//panel.updateTime(12342398);
|
|
||||||
//panel.updatePosition(43);
|
|
||||||
add(new Press(PanelButton.PREVIOUS), new Task(Target.APPLICATION, Action.PREVIOUS));
|
|
||||||
add(new Press(PanelButton.REWIND), new Task(Target.APPLICATION, Action.REWIND));
|
|
||||||
add(new Press(PanelButton.STOP), new Task(Target.APPLICATION, Action.STOP));
|
|
||||||
add(new Press(PanelButton.PAUSE), new Task(Target.APPLICATION, Action.PAUSE));
|
|
||||||
add(new Press(PanelButton.PLAY), new Task(Target.APPLICATION, Action.PLAY));
|
|
||||||
add(new Press(PanelButton.FORWARD), new Task(Target.APPLICATION, Action.FORWARD));
|
|
||||||
add(new Press(PanelButton.NEXT), new Task(Target.APPLICATION, Action.NEXT));
|
|
||||||
add(new Press(PanelButton.VOLUME_DOWN), new Task(Target.APPLICATION, Action.VOLUME_DOWN));
|
|
||||||
add(new Press(PanelButton.MUTE), new Task(Target.APPLICATION, Action.MUTE));
|
|
||||||
add(new Press(PanelButton.VOLUME_UP), new Task(Target.APPLICATION, Action.VOLUME_UP));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean active() {
|
|
||||||
return active = panel != null && panel.isValid();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deactivate() {
|
|
||||||
panel.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void processWindowEvent(WindowEvent e) {
|
|
||||||
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
|
|
||||||
log.debug("Window closing");
|
|
||||||
deactivate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void buttonPressed(PanelButton panelButton) {
|
|
||||||
//Vang hier toggles af om bijvoorbeeld de play/pause en mute knop en veranderen
|
|
||||||
add(new Press(panelButton));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void buttonReleased(PanelButton panelButton) {
|
|
||||||
add(new Release(panelButton));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package pm.device.player;
|
|
||||||
|
|
||||||
import javazoom.jlgui.player.amp.StandalonePlayer;
|
|
||||||
import pm.Device;
|
|
||||||
|
|
||||||
public class PlayerDevice extends Device {
|
|
||||||
protected static final String TITLE = "Player";
|
|
||||||
|
|
||||||
StandalonePlayer standalonePlayer;
|
|
||||||
|
|
||||||
public PlayerDevice() {
|
|
||||||
super(TITLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initialise() {
|
|
||||||
standalonePlayer = new StandalonePlayer();
|
|
||||||
standalonePlayer.loadUI();
|
|
||||||
//standalonePlayer.loadJS();
|
|
||||||
//standalonePlayer.loadPlaylist();
|
|
||||||
//standalonePlayer.
|
|
||||||
System.out.println("niets!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package pm.device.wiimote;
|
|
||||||
|
|
||||||
import pm.Button;
|
|
||||||
import pm.exception.button.UnknownButtonException;
|
|
||||||
|
|
||||||
public enum WiimoteButton implements Button {
|
|
||||||
TWO (0x0001),
|
|
||||||
ONE (0x0002),
|
|
||||||
B (0x0004),
|
|
||||||
A (0x0008),
|
|
||||||
MINUS (0x0010),
|
|
||||||
HOME (0x0080),
|
|
||||||
LEFT (0x0100),
|
|
||||||
RIGHT (0x0200),
|
|
||||||
DOWN (0x0400),
|
|
||||||
UP (0x0800),
|
|
||||||
PLUS (0x1000),
|
|
||||||
ALL (0x1F9F);
|
|
||||||
|
|
||||||
protected int code;
|
|
||||||
|
|
||||||
private WiimoteButton(int code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static WiimoteButton create(int code) throws UnknownButtonException {
|
|
||||||
for (WiimoteButton button : WiimoteButton.values()) {
|
|
||||||
if (button.getCode() == code) {
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new UnknownButtonException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,187 +0,0 @@
|
|||||||
package pm.device.wiimote;
|
|
||||||
|
|
||||||
import org.wiigee.event.GestureEvent;
|
|
||||||
import org.wiigee.event.GestureListener;
|
|
||||||
import org.wiigee.util.Log;
|
|
||||||
|
|
||||||
import pm.Button;
|
|
||||||
import pm.Device;
|
|
||||||
import pm.device.wiimote.gesture.GestureDevice;
|
|
||||||
import pm.event.Feedback;
|
|
||||||
import pm.event.Task;
|
|
||||||
import pm.exception.button.UnknownButtonException;
|
|
||||||
import pm.exception.device.DeviceNotFoundException;
|
|
||||||
import pm.macro.state.Hold;
|
|
||||||
import pm.macro.state.Press;
|
|
||||||
import pm.macro.state.Release;
|
|
||||||
import pm.value.Action;
|
|
||||||
import wiiusej.Wiimote;
|
|
||||||
import wiiusej.values.Calibration;
|
|
||||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
|
||||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
|
||||||
|
|
||||||
public class WiimoteDevice extends Device implements GestureListener {
|
|
||||||
protected static final String TITLE = "Wiimote";
|
|
||||||
|
|
||||||
protected static final int CONNECT_MAX = 10;
|
|
||||||
protected static final int RUMBLE = 150;
|
|
||||||
|
|
||||||
protected static WiimoteService wiimoteService;
|
|
||||||
|
|
||||||
protected Wiimote wiimote;
|
|
||||||
protected Calibration calibration;
|
|
||||||
protected GestureDevice gestureDevice;
|
|
||||||
protected int gestureId = 0;
|
|
||||||
|
|
||||||
static {
|
|
||||||
WiimoteDevice.wiimoteService = new WiimoteService();
|
|
||||||
Log.setLevel(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public WiimoteDevice() {
|
|
||||||
super(TITLE);
|
|
||||||
gestureDevice = new GestureDevice();
|
|
||||||
gestureDevice.add(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initialise() {
|
|
||||||
add(
|
|
||||||
new Hold(WiimoteButton.A),
|
|
||||||
new Task(Action.TRAIN),
|
|
||||||
new Task(Action.STOP));
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.B),
|
|
||||||
new Task(Action.SAVE));
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.DOWN),
|
|
||||||
new Task(Action.LOAD));
|
|
||||||
add(
|
|
||||||
new Hold(WiimoteButton.HOME),
|
|
||||||
new Task(Action.RECOGNIZE),
|
|
||||||
new Task(Action.STOP));/*
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.A),
|
|
||||||
new Task(Target.APPLICATION, Action.PLAY));
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.B),
|
|
||||||
new Task(Target.APPLICATION, Action.MUTE));
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.ONE),
|
|
||||||
new Task(Target.APPLICATION, Action.SHUFFLE));
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.TWO),
|
|
||||||
new Task(Target.APPLICATION, Action.REPEAT));
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.UP),
|
|
||||||
new Task(Target.APPLICATION, Action.NEXT));
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.DOWN),
|
|
||||||
new Task(Target.APPLICATION, Action.PREVIOUS));
|
|
||||||
add(
|
|
||||||
new Hold(WiimoteButton.RIGHT),
|
|
||||||
new Dynamic(Action.FORWARD, Target.APPLICATION, 200, -30));
|
|
||||||
add(
|
|
||||||
new Hold(WiimoteButton.LEFT),
|
|
||||||
new Dynamic(Action.REWIND, Target.APPLICATION, 200, -30));
|
|
||||||
add(
|
|
||||||
new Hold(WiimoteButton.MINUS),
|
|
||||||
new Continuous(Action.VOLUME_DOWN, Target.APPLICATION, 100));
|
|
||||||
add(
|
|
||||||
new Hold(WiimoteButton.PLUS),
|
|
||||||
new Continuous(Action.VOLUME_UP, Target.APPLICATION, 100));
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.HOME),
|
|
||||||
new Task(Target.MANAGER, Action.NEXT));
|
|
||||||
try {
|
|
||||||
add(
|
|
||||||
new Macro(
|
|
||||||
new Hold(WiimoteButton.TWO),
|
|
||||||
new Press(WiimoteButton.PLUS),
|
|
||||||
new Release(WiimoteButton.TWO)),
|
|
||||||
new Task(Target.APPLICATION, Action.LIKE));
|
|
||||||
add(
|
|
||||||
new Macro(
|
|
||||||
new Hold(WiimoteButton.TWO),
|
|
||||||
new Press(WiimoteButton.MINUS),
|
|
||||||
new Release(WiimoteButton.TWO)),
|
|
||||||
new Task(Target.APPLICATION, Action.DISLIKE));
|
|
||||||
} catch (StateOrderException e) {}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public void action(Action action) {
|
|
||||||
switch (action) {
|
|
||||||
case TRAIN:
|
|
||||||
System.out.println("Wiimote Train");
|
|
||||||
gestureDevice.train();
|
|
||||||
break;
|
|
||||||
case STOP:
|
|
||||||
System.out.println("Wiimote Stop");
|
|
||||||
gestureDevice.stop();
|
|
||||||
break;
|
|
||||||
case SAVE:
|
|
||||||
System.out.println("Wiimote Save");
|
|
||||||
gestureDevice.close();
|
|
||||||
gestureDevice.saveGesture(gestureId, "C:\\gesture-" + gestureId);
|
|
||||||
++gestureId;
|
|
||||||
break;
|
|
||||||
case LOAD:
|
|
||||||
for (int i = 0; i < gestureId; ++i) {
|
|
||||||
gestureDevice.loadGesture("C:\\gesture-" + i);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case RECOGNIZE:
|
|
||||||
gestureDevice.recognize();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onButtonsEvent(WiimoteButtonsEvent event) {
|
|
||||||
int pressed = event.getButtonsJustPressed() - event.getButtonsHeld();
|
|
||||||
int released = event.getButtonsJustReleased();
|
|
||||||
try {
|
|
||||||
if (pressed != 0 && released == 0) {
|
|
||||||
Button button = WiimoteButton.create(pressed);
|
|
||||||
System.out.println("Press: " + button);
|
|
||||||
add(new Press(button));
|
|
||||||
} else if (pressed == 0 && released != 0) {
|
|
||||||
Button button = WiimoteButton.create(released);
|
|
||||||
System.out.println("Release: " + button);
|
|
||||||
add(new Release(button));
|
|
||||||
}
|
|
||||||
} catch (UnknownButtonException e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onMotionSensingEvent(MotionSensingEvent event) {
|
|
||||||
gestureDevice.add(event.getGforce());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void gestureReceived(GestureEvent event) {
|
|
||||||
if (event.isValid()) {
|
|
||||||
System.out.printf("id #%d, prob %.0f%%, valid %b\n", event.getId(), 100 * event.getProbability(), event.isValid());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void feedback(Feedback feedback) {
|
|
||||||
System.out.println("Wiimote feedback");
|
|
||||||
wiimote.rumble(RUMBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void activate() {
|
|
||||||
try {
|
|
||||||
wiimote = wiimoteService.getDevice(this);
|
|
||||||
} catch (DeviceNotFoundException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
wiimote.activateMotionSensing();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deactivate() {
|
|
||||||
wiimote.deactivateMotionSensing();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void exit() {
|
|
||||||
wiimoteService.exit();
|
|
||||||
super.exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
package pm.device.wiimote;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import pm.exception.device.DeviceNotFoundException;
|
|
||||||
import wiiusej.WiiUseApiManager;
|
|
||||||
import wiiusej.Wiimote;
|
|
||||||
import wiiusej.wiiusejevents.GenericEvent;
|
|
||||||
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;
|
|
||||||
|
|
||||||
public class WiimoteService extends WiiUseApiManager implements WiimoteListener {
|
|
||||||
protected final boolean RUMBLE = false;
|
|
||||||
|
|
||||||
protected ArrayList<Integer> wiimoteList;
|
|
||||||
protected Wiimote[] wiimoteArray;
|
|
||||||
protected HashMap<Integer, WiimoteDevice> wiimoteDeviceMap;
|
|
||||||
|
|
||||||
WiimoteService() {
|
|
||||||
wiimoteList = new ArrayList<Integer>();
|
|
||||||
wiimoteArray = new Wiimote[0];
|
|
||||||
wiimoteDeviceMap = new HashMap<Integer, WiimoteDevice>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void exit() {
|
|
||||||
if (wiimoteArray != null) {
|
|
||||||
for (Wiimote wiimote : wiimoteArray) {
|
|
||||||
wiimote.disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
definitiveShutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Wiimote getDevice(WiimoteDevice wiimoteDevice) throws DeviceNotFoundException {
|
|
||||||
Wiimote[] wiimoteArray = getWiimotes(1, RUMBLE);
|
|
||||||
for (Wiimote wiimote : wiimoteArray) {
|
|
||||||
int id = wiimote.getId();
|
|
||||||
if (!wiimoteList.contains(id)) {
|
|
||||||
wiimote.addWiiMoteEventListeners(this);
|
|
||||||
wiimoteList.add(id);
|
|
||||||
wiimoteDeviceMap.put(id, wiimoteDevice); // Todo: controleren of dit nodig is. Ligt aan hoe uniek het id is na bijvoorbeeld een reconnect. Wellicht voldoet een arrayList ook.
|
|
||||||
return wiimote;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new DeviceNotFoundException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Wiimote getWiimote(GenericEvent event) {
|
|
||||||
return wiimoteArray[event.getWiimoteId() - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
public WiimoteDevice getWiimoteDevice(GenericEvent event){
|
|
||||||
return wiimoteDeviceMap.get(event.getWiimoteId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onButtonsEvent(WiimoteButtonsEvent event) {
|
|
||||||
getWiimoteDevice(event).onButtonsEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onMotionSensingEvent(MotionSensingEvent event) {
|
|
||||||
getWiimoteDevice(event).onMotionSensingEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onStatusEvent(StatusEvent event) {
|
|
||||||
if (event.isConnected()) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onIrEvent(IREvent e) {}
|
|
||||||
public void onExpansionEvent(ExpansionEvent event) {}
|
|
||||||
public void onDisconnectionEvent(DisconnectionEvent event) {}
|
|
||||||
public void onNunchukInsertedEvent(NunchukInsertedEvent event) {}
|
|
||||||
public void onNunchukRemovedEvent(NunchukRemovedEvent event) {}
|
|
||||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent event) {}
|
|
||||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent event) {}
|
|
||||||
public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent event) {}
|
|
||||||
public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent event) {}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
package pm.device.wiimote.gesture;
|
|
||||||
|
|
||||||
import org.wiigee.device.Device;
|
|
||||||
import org.wiigee.event.ButtonListener;
|
|
||||||
import org.wiigee.event.ButtonPressedEvent;
|
|
||||||
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;
|
|
||||||
//public static final boolean AUTOMOTION = true;
|
|
||||||
|
|
||||||
public GestureDevice(boolean autofiltering/*, boolean automotion*/) {
|
|
||||||
super(autofiltering);
|
|
||||||
/*if (automotion) {
|
|
||||||
addAccelerationListener(this);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public GestureDevice() {
|
|
||||||
this(AUTOFILTERING/*, AUTOMOTION*/);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(GestureListener gestureListener) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void recognize() {
|
|
||||||
fireButtonPressedEvent(new Recognize(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void train() {
|
|
||||||
fireButtonPressedEvent(new Train(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() {
|
|
||||||
fireButtonPressedEvent(new Close(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
|
||||||
fireButtonReleasedEvent(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fireButtonPressedEvent(ButtonPressedEvent buttonPressedEvent) {
|
|
||||||
for (ButtonListener bttnLstnr : buttonlistener) {
|
|
||||||
bttnLstnr.buttonPressReceived(buttonPressedEvent);
|
|
||||||
}
|
|
||||||
if (buttonPressedEvent.isRecognitionInitEvent() || buttonPressedEvent.isTrainInitEvent()) {
|
|
||||||
this.resetAccelerationFilters();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*public void accelerationReceived(AccelerationEvent event) {}
|
|
||||||
|
|
||||||
public void motionStartReceived(MotionStartEvent event) {
|
|
||||||
//System.out.println("Motion start!");
|
|
||||||
recognize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void motionStopReceived(MotionStopEvent event) {
|
|
||||||
//System.out.println("Motion stop!");
|
|
||||||
stop();
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package pm.device.wiimote.gesture.event;
|
|
||||||
|
|
||||||
import org.wiigee.device.Device;
|
|
||||||
import org.wiigee.event.ButtonPressedEvent;
|
|
||||||
|
|
||||||
public class Close extends ButtonPressedEvent {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public Close(Device device) {
|
|
||||||
super(device, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRecognitionInitEvent() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTrainInitEvent() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCloseGestureInitEvent() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package pm.device.wiimote.gesture.event;
|
|
||||||
|
|
||||||
import org.wiigee.device.Device;
|
|
||||||
import org.wiigee.event.ButtonPressedEvent;
|
|
||||||
|
|
||||||
public class Recognize extends ButtonPressedEvent {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public Recognize(Device device) {
|
|
||||||
super(device, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRecognitionInitEvent() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTrainInitEvent() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCloseGestureInitEvent() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package pm.device.wiimote.gesture.event;
|
|
||||||
|
|
||||||
import org.wiigee.device.Device;
|
|
||||||
import org.wiigee.event.ButtonPressedEvent;
|
|
||||||
|
|
||||||
public class Train extends ButtonPressedEvent {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public Train(Device device) {
|
|
||||||
super(device, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRecognitionInitEvent() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTrainInitEvent() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCloseGestureInitEvent() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package pm.event;
|
|
||||||
|
|
||||||
import pm.Event;
|
|
||||||
import pm.event.task.Continuous;
|
|
||||||
import pm.value.Action;
|
|
||||||
|
|
||||||
public abstract class EventHandler extends EventListener {
|
|
||||||
protected static EventRouter eventRouter;
|
|
||||||
|
|
||||||
public static void initialise(EventRouter eventRouter) {
|
|
||||||
EventHandler.eventRouter = eventRouter;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initialise() {
|
|
||||||
eventRouter.add(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void event(Event event) {
|
|
||||||
System.out.println(event);
|
|
||||||
if (event instanceof Feedback) {
|
|
||||||
feedback((Feedback) event);
|
|
||||||
} else if (event instanceof Task) {
|
|
||||||
task((Task) event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void feedback(Feedback feedback) {}
|
|
||||||
|
|
||||||
protected void task(Task task) {
|
|
||||||
Action action = task.getAction();
|
|
||||||
if (task instanceof Continuous) {
|
|
||||||
Continuous continuous = (Continuous) task;
|
|
||||||
do {
|
|
||||||
action(action);
|
|
||||||
continuous.nextIteration();
|
|
||||||
sleep(continuous.getSleep());
|
|
||||||
} while (running && !continuous.getStop());
|
|
||||||
continuous.reset();
|
|
||||||
} else {
|
|
||||||
action(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void action(Action action) {}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package pm.event;
|
|
||||||
|
|
||||||
import java.util.Queue;
|
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
|
||||||
import pm.Event;
|
|
||||||
import pm.Worker;
|
|
||||||
|
|
||||||
public abstract class EventListener extends Worker {
|
|
||||||
protected Queue<Event> eventQueue;
|
|
||||||
protected Object work;
|
|
||||||
|
|
||||||
public EventListener() {
|
|
||||||
eventQueue = new ConcurrentLinkedQueue<Event>();
|
|
||||||
work = new Object();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Event event) {
|
|
||||||
eventQueue.add(event);
|
|
||||||
synchronized (work) {
|
|
||||||
work.notifyAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void work() {
|
|
||||||
while (eventQueue.isEmpty()) {
|
|
||||||
synchronized (work) {
|
|
||||||
try {
|
|
||||||
work.wait();
|
|
||||||
} catch (InterruptedException e) {}
|
|
||||||
if (!running) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event(eventQueue.poll());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
|
||||||
super.stop();
|
|
||||||
synchronized (work) {
|
|
||||||
work.notifyAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void event(Event event);
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package pm.event;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import pm.Application;
|
|
||||||
|
|
||||||
public abstract class EventRouter extends EventListener {
|
|
||||||
protected ArrayList<EventListener> eventListenerList;
|
|
||||||
protected Application application;
|
|
||||||
|
|
||||||
public void set(Application application) {
|
|
||||||
this.application = application;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EventRouter() {
|
|
||||||
eventListenerList = new ArrayList<EventListener>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(EventListener eventListener) {
|
|
||||||
eventListenerList.add(eventListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(EventListener eventListener) {
|
|
||||||
eventListenerList.remove(eventListener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package pm.event;
|
|
||||||
|
|
||||||
import pm.Event;
|
|
||||||
import pm.value.Target;
|
|
||||||
|
|
||||||
public class Feedback extends Event {
|
|
||||||
public Feedback() {
|
|
||||||
super(Target.ALL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package pm.event;
|
|
||||||
|
|
||||||
import pm.Event;
|
|
||||||
import pm.value.Action;
|
|
||||||
import pm.value.Target;
|
|
||||||
|
|
||||||
public class Task extends Event {
|
|
||||||
protected Action action;
|
|
||||||
|
|
||||||
public Task(Target target, Action action) {
|
|
||||||
super(target);
|
|
||||||
this.action = action;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task(Action action) {
|
|
||||||
this(Target.SELF, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Action getAction() {
|
|
||||||
return action;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package pm.event.router;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import pm.Event;
|
|
||||||
import pm.Worker;
|
|
||||||
import pm.event.EventRouter;
|
|
||||||
import pm.event.Feedback;
|
|
||||||
import pm.exception.event.router.GlobalRouterException;
|
|
||||||
|
|
||||||
public class GlobalRouter extends EventRouter {
|
|
||||||
protected Socket socket;
|
|
||||||
protected ObjectOutputStream objectOutputStream;
|
|
||||||
protected ObjectInputStream objectInputStream;
|
|
||||||
|
|
||||||
public GlobalRouter(String ip, int port) throws GlobalRouterException {
|
|
||||||
try {
|
|
||||||
socket = new Socket(ip, port);
|
|
||||||
objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
|
|
||||||
objectInputStream = new ObjectInputStream(socket.getInputStream());
|
|
||||||
new Worker() {
|
|
||||||
public void work() {
|
|
||||||
try {
|
|
||||||
Object object;
|
|
||||||
do {
|
|
||||||
object = objectInputStream.readObject();
|
|
||||||
if (object instanceof Feedback) {
|
|
||||||
add((Feedback) object);
|
|
||||||
}
|
|
||||||
} while (object != null);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return;
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
} catch (IOException e) {}
|
|
||||||
throw new GlobalRouterException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void event(Event event) {
|
|
||||||
System.out.println("NetworkSpreader: event!");
|
|
||||||
//System.out.println(socket.isConnected());
|
|
||||||
try {
|
|
||||||
objectOutputStream.writeObject(event);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package pm.event.router;
|
|
||||||
|
|
||||||
import pm.Event;
|
|
||||||
import pm.event.EventListener;
|
|
||||||
import pm.event.EventRouter;
|
|
||||||
import pm.value.Target;
|
|
||||||
|
|
||||||
public class LocalRouter extends EventRouter {
|
|
||||||
public void event(Event event) {
|
|
||||||
System.out.println("LocalSpreader krijgt event via evet()");
|
|
||||||
System.out.println(application);
|
|
||||||
Target target = event.getTarget();
|
|
||||||
switch (target) {
|
|
||||||
case APPLICATION:
|
|
||||||
if (application != null) {
|
|
||||||
application.add(event);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
for (EventListener eventListener : eventListenerList) {
|
|
||||||
if (event.compatible(eventListener)) {
|
|
||||||
eventListener.add(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package pm.event.task;
|
|
||||||
|
|
||||||
import pm.event.Task;
|
|
||||||
import pm.value.Action;
|
|
||||||
import pm.value.Target;
|
|
||||||
|
|
||||||
public class Continuous extends Task {
|
|
||||||
protected static final int SLEEP = 0;
|
|
||||||
|
|
||||||
protected int sleep;
|
|
||||||
protected int iteration;
|
|
||||||
protected boolean stop;
|
|
||||||
|
|
||||||
public Continuous(Action action, Target target, int sleep) {
|
|
||||||
super(target, action);
|
|
||||||
this.sleep = sleep;
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Continuous(Action action, Target target) {
|
|
||||||
this(action, target, SLEEP);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void nextIteration() {
|
|
||||||
++iteration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
|
||||||
stop = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reset() {
|
|
||||||
iteration = 0;
|
|
||||||
stop = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSleep() {
|
|
||||||
return sleep;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getStop() {
|
|
||||||
return stop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package pm.event.task;
|
|
||||||
|
|
||||||
import pm.value.Action;
|
|
||||||
import pm.value.Target;
|
|
||||||
|
|
||||||
public class Dynamic extends Continuous {
|
|
||||||
protected static final int RATE = 10;
|
|
||||||
|
|
||||||
protected int rate;
|
|
||||||
|
|
||||||
public Dynamic(Action action, Target target, int sleep, int rate) {
|
|
||||||
super(action, target, sleep);
|
|
||||||
this.rate = rate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Dynamic(Action action, Target target, int sleep) {
|
|
||||||
super(action, target, sleep);
|
|
||||||
this.rate = RATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSleep() {
|
|
||||||
return sleep + rate * iteration;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package pm.event.task;
|
|
||||||
|
|
||||||
import pm.event.Task;
|
|
||||||
|
|
||||||
public class Stopper extends Task {
|
|
||||||
protected Continuous continuous;
|
|
||||||
|
|
||||||
public Stopper(Continuous continuous) {
|
|
||||||
super(null, null);
|
|
||||||
this.continuous = continuous;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
|
||||||
continuous.stop(); // Todo: check if the task is really started?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package pm.exception;
|
|
||||||
|
|
||||||
public class ApplicationException extends HandlerException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package pm.exception;
|
|
||||||
|
|
||||||
public class ButtonException extends Exception {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package pm.exception;
|
|
||||||
|
|
||||||
public class DeviceException extends HandlerException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package pm.exception;
|
|
||||||
|
|
||||||
public class EventException extends Exception {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package pm.exception;
|
|
||||||
|
|
||||||
public class HandlerException extends Exception {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package pm.exception;
|
|
||||||
|
|
||||||
public class InitialiseException extends HandlerException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package pm.exception;
|
|
||||||
|
|
||||||
public class MacroException extends Exception {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public MacroException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package pm.exception;
|
|
||||||
|
|
||||||
public class TaskException extends Exception {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package pm.exception;
|
|
||||||
|
|
||||||
public class WorkerException extends Exception {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.application;
|
|
||||||
|
|
||||||
import pm.exception.ApplicationException;
|
|
||||||
|
|
||||||
public class ApplicationExitException extends ApplicationException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.application;
|
|
||||||
|
|
||||||
import pm.exception.InitialiseException;
|
|
||||||
|
|
||||||
public class ApplicationInitialiseException extends InitialiseException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.application.windows;
|
|
||||||
|
|
||||||
import pm.exception.ApplicationException;
|
|
||||||
|
|
||||||
public class WindowsApplicationException extends ApplicationException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.button;
|
|
||||||
|
|
||||||
import pm.exception.ButtonException;
|
|
||||||
|
|
||||||
public class UnknownButtonException extends ButtonException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.button;
|
|
||||||
|
|
||||||
import pm.exception.ButtonException;
|
|
||||||
|
|
||||||
public class UnknownDirectionException extends ButtonException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.device;
|
|
||||||
|
|
||||||
import pm.exception.DeviceException;
|
|
||||||
|
|
||||||
public class DeviceExitException extends DeviceException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.device;
|
|
||||||
|
|
||||||
import pm.exception.InitialiseException;
|
|
||||||
|
|
||||||
public class DeviceInitialiseException extends InitialiseException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package pm.exception.device;
|
|
||||||
|
|
||||||
public class DeviceNotFoundException extends DeviceInitialiseException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.device;
|
|
||||||
|
|
||||||
import pm.exception.DeviceException;
|
|
||||||
|
|
||||||
public class JavaInputDeviceException extends DeviceException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.device.javainput;
|
|
||||||
|
|
||||||
import pm.exception.DeviceException;
|
|
||||||
|
|
||||||
public class JavaInputDeviceSpecificException extends DeviceException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.event;
|
|
||||||
|
|
||||||
import pm.exception.EventException;
|
|
||||||
|
|
||||||
public class SpreaderException extends EventException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.event.router;
|
|
||||||
|
|
||||||
import pm.exception.event.SpreaderException;
|
|
||||||
|
|
||||||
public class GlobalRouterException extends SpreaderException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package pm.exception.macro;
|
|
||||||
|
|
||||||
import pm.exception.MacroException;
|
|
||||||
|
|
||||||
public class StateOrderException extends MacroException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public StateOrderException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.task;
|
|
||||||
|
|
||||||
import pm.exception.TaskException;
|
|
||||||
|
|
||||||
public class ActionException extends TaskException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package pm.exception.task;
|
|
||||||
|
|
||||||
public class TaskNotSupportedException extends Exception {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.task.action;
|
|
||||||
|
|
||||||
import pm.exception.task.ActionException;
|
|
||||||
|
|
||||||
public class ActionDeserializeException extends ActionException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.util;
|
|
||||||
|
|
||||||
import pm.exception.application.windows.WindowsApplicationException;
|
|
||||||
|
|
||||||
public class SendCommandException extends WindowsApplicationException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.util;
|
|
||||||
|
|
||||||
import pm.exception.application.windows.WindowsApplicationException;
|
|
||||||
|
|
||||||
public class SendKeyException extends WindowsApplicationException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.worker;
|
|
||||||
|
|
||||||
import pm.exception.WorkerException;
|
|
||||||
|
|
||||||
public class AlreadyActiveException extends WorkerException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.worker;
|
|
||||||
|
|
||||||
import pm.exception.WorkerException;
|
|
||||||
|
|
||||||
public class AlreadyRunningException extends WorkerException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.worker;
|
|
||||||
|
|
||||||
import pm.exception.WorkerException;
|
|
||||||
|
|
||||||
public class NotActiveException extends WorkerException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.worker;
|
|
||||||
|
|
||||||
import pm.exception.WorkerException;
|
|
||||||
|
|
||||||
public class NotRunningException extends WorkerException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package pm.exception.worker;
|
|
||||||
|
|
||||||
import pm.exception.WorkerException;
|
|
||||||
|
|
||||||
public class StartException extends WorkerException {
|
|
||||||
protected static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package pm.macro;
|
|
||||||
|
|
||||||
|
|
||||||
public class Active {
|
|
||||||
protected Sequence sequence;
|
|
||||||
protected int step;
|
|
||||||
//protected long start;
|
|
||||||
//protected long duration;
|
|
||||||
|
|
||||||
public Active(Sequence sequence) {
|
|
||||||
this.sequence = sequence;
|
|
||||||
step = -1;
|
|
||||||
//start = System.nanoTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Sequence getSequence() {
|
|
||||||
return sequence;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*public long getDuration() {
|
|
||||||
return duration;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public boolean next(State state) {
|
|
||||||
State next = sequence.get(++step);
|
|
||||||
return next == null ? false : state.equals(next);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean last() {
|
|
||||||
return step == sequence.count() - 1;
|
|
||||||
/*boolean last = step == sequence.count() - 1;
|
|
||||||
if (last) {
|
|
||||||
duration = System.nanoTime() - start;
|
|
||||||
}
|
|
||||||
return last;*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package pm.macro;
|
|
||||||
|
|
||||||
public class Sequence {
|
|
||||||
protected State[] eventArray;
|
|
||||||
|
|
||||||
public Sequence(State... eventArray) {
|
|
||||||
this.eventArray = eventArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int count() {
|
|
||||||
return eventArray.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public State get(int i) {
|
|
||||||
return eventArray.length > 0 ? eventArray[i] : null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
package pm.macro;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import pm.Event;
|
|
||||||
import pm.event.Task;
|
|
||||||
import pm.event.EventHandler;
|
|
||||||
import pm.event.EventListener;
|
|
||||||
import pm.value.Target;
|
|
||||||
|
|
||||||
public class SequenceListener {
|
|
||||||
protected EventHandler eventHandler;
|
|
||||||
protected ArrayList<Sequence> sequenceList;
|
|
||||||
protected HashMap<Sequence, Event> eventMap;
|
|
||||||
protected ArrayList<Active> activeList;
|
|
||||||
|
|
||||||
protected static EventListener eventListener;
|
|
||||||
|
|
||||||
public SequenceListener(EventHandler eventHandler) {
|
|
||||||
this.eventHandler = eventHandler;
|
|
||||||
sequenceList = new ArrayList<Sequence>();
|
|
||||||
eventMap = new HashMap<Sequence, Event>();
|
|
||||||
activeList = new ArrayList<Active>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void initialise(EventListener eventListener) {
|
|
||||||
SequenceListener.eventListener = eventListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int add(Sequence sequence, Task task) {
|
|
||||||
int id = sequenceList.size();
|
|
||||||
sequenceList.add(sequence);
|
|
||||||
eventMap.put(sequence, task);
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(State state) {
|
|
||||||
for (Sequence sequence : sequenceList) {
|
|
||||||
activeList.add(new Active(sequence));
|
|
||||||
}
|
|
||||||
ArrayList<Active> removeList = new ArrayList<Active>();
|
|
||||||
for (Active active : activeList) {
|
|
||||||
if (active.next(state)) {
|
|
||||||
if (active.last()) {
|
|
||||||
Event event = eventMap.get(active.getSequence());
|
|
||||||
if (event.getTarget().equals(Target.SELF)) {
|
|
||||||
eventHandler.event(event);
|
|
||||||
} else {
|
|
||||||
eventListener.add(event);
|
|
||||||
}
|
|
||||||
removeList.add(active);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
removeList.add(active);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Active active : removeList) {
|
|
||||||
activeList.remove(active);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package pm.macro;
|
|
||||||
|
|
||||||
import pm.Button;
|
|
||||||
|
|
||||||
public abstract class State {
|
|
||||||
protected Button button;
|
|
||||||
|
|
||||||
public State(Button button) {
|
|
||||||
this.button = button;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Button getButton() {
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(State state) {
|
|
||||||
return state.getClass().equals(getClass()) && state.getButton().equals(button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package pm.macro.state;
|
|
||||||
|
|
||||||
import pm.Button;
|
|
||||||
import pm.macro.State;
|
|
||||||
|
|
||||||
public class Hold extends State {
|
|
||||||
public Hold(Button button) {
|
|
||||||
super(button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package pm.macro.state;
|
|
||||||
|
|
||||||
import pm.Button;
|
|
||||||
import pm.macro.State;
|
|
||||||
|
|
||||||
public class Press extends State {
|
|
||||||
public Press(Button button) {
|
|
||||||
super(button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package pm.macro.state;
|
|
||||||
|
|
||||||
import pm.Button;
|
|
||||||
import pm.macro.State;
|
|
||||||
|
|
||||||
public class Release extends State {
|
|
||||||
public Release(Button button) {
|
|
||||||
super(button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user