diff --git a/java/src/pm/Listener.java b/java/src/pm/Listener.java new file mode 100644 index 0000000..bb0d1af --- /dev/null +++ b/java/src/pm/Listener.java @@ -0,0 +1,28 @@ +package pm; + +public abstract class Listener implements Runnable { + protected static final int SLEEP = 100; + + protected boolean run; + + public void start() { + run = true; + new Thread(this).start(); + } + + public void stop() { + run = false; + } + + protected void sleep(int time) { + try { + if (time > 0) { + Thread.sleep(time); + } + } catch (InterruptedException e) {} + } + + protected void sleep() { + sleep(SLEEP); + } +} diff --git a/java/src/pm/Main.java b/java/src/pm/Main.java index 8502ec2..9ec26d5 100644 --- a/java/src/pm/Main.java +++ b/java/src/pm/Main.java @@ -42,20 +42,19 @@ public class Main extends TaskListener { } public void initialise() throws DeviceInitialiseException { - //add(new JIntellitypeDevice()); + add(new JIntellitypeDevice()); //add(new PlayerDevice()); //add(new RumblepadDevice()); //add(new WiimoteDevice()); //add(new GUIDevice()); - add(new TextDevice()); - add(new LanTextDevice()); + //add(new TextDevice()); + //add(new LanTextDevice()); for (Device device : deviceList) { try { device.initialise(); device.start(); } catch (DeviceInitialiseException e) { remove(device); - e.printStackTrace(); } } @@ -70,7 +69,6 @@ public class Main extends TaskListener { application.start(); } catch (ApplicationInitialiseException e) { remove(application); - e.printStackTrace(); } } } diff --git a/java/src/pm/application/windows/Command.java b/java/src/pm/application/windows/Command.java index 85453a3..bb6b926 100644 --- a/java/src/pm/application/windows/Command.java +++ b/java/src/pm/application/windows/Command.java @@ -1,5 +1,7 @@ package pm.application.windows; +import pm.Button; + public enum Command { BROWSER_BACKWARD (1), BROWSER_FORWARD (2), diff --git a/java/src/pm/device/jintellitype/JIntellitypeDevice.java b/java/src/pm/device/jintellitype/JIntellitypeDevice.java index 22d4be5..58cd530 100644 --- a/java/src/pm/device/jintellitype/JIntellitypeDevice.java +++ b/java/src/pm/device/jintellitype/JIntellitypeDevice.java @@ -8,8 +8,10 @@ import com.melloware.jintellitype.JIntellitype; import pm.Device; import pm.Task; +import pm.application.windows.Command; import pm.exception.EventException; import pm.exception.device.DeviceInitialiseException; +import pm.macro.event.Hold; import pm.macro.event.Press; import pm.macro.event.Release; import pm.task.Continuous; @@ -37,8 +39,11 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell new Hotkey(Key.NEXT), new Task(Action.NEXT, Target.MAIN)); add( - new Hotkey(Modifier.CTRL | Modifier.WIN, 'q'), - new Task(Action.PLAY, Target.APPLICATIONS)); + new Press(CommandButton.VOLUME_DOWN), + new Task(Action.VOLUME_DOWN, Target.APPLICATIONS)); + add( + new Press(CommandButton.VOLUME_UP), + new Task(Action.VOLUME_UP, Target.APPLICATIONS)); add( new Hotkey(Modifier.CTRL | Modifier.WIN, 'x'), new Task(Action.EXIT, Target.MAIN)); diff --git a/java/src/pm/device/text/InputListener.java b/java/src/pm/device/text/InputListener.java index 3a8fabc..6a55526 100644 --- a/java/src/pm/device/text/InputListener.java +++ b/java/src/pm/device/text/InputListener.java @@ -3,33 +3,27 @@ package pm.device.text; import java.io.InputStream; import java.util.Scanner; +import pm.Listener; import pm.Task; import pm.task.TaskManager; import pm.value.Action; import pm.value.Target; -public class InputListener implements Runnable { - protected static final int SLEEP = 100; - - protected boolean run; +public class InputListener extends Listener { protected Scanner input; public InputListener(InputStream inputStream) { input = new Scanner(inputStream); } - public void start() { - new Thread(this).start(); - } - public void run() { run = true; while (running()) { - String textinput = input.next().toUpperCase(); - if(textinput != null) { + String string = input.next().toUpperCase(); + if(string != null) { try { TaskManager.add( - new Task(Action.valueOf(textinput), Target.APPLICATION)); + new Task(Action.valueOf(string), Target.APPLICATION)); } catch(IllegalArgumentException e) {} } try { @@ -43,8 +37,4 @@ public class InputListener implements Runnable { protected boolean running() { return run && input.hasNext(); } - - public void stop() { - run = false; - } } diff --git a/java/src/pm/device/text/lan/SocketListener.java b/java/src/pm/device/text/lan/SocketListener.java index 21c5180..1ea9faf 100644 --- a/java/src/pm/device/text/lan/SocketListener.java +++ b/java/src/pm/device/text/lan/SocketListener.java @@ -6,11 +6,10 @@ import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; +import pm.Listener; import pm.device.text.InputListener; -public class SocketListener implements Runnable { - protected boolean run; - +public class SocketListener extends Listener { protected ServerSocket server; protected ArrayList inputListenerList; @@ -19,12 +18,7 @@ public class SocketListener implements Runnable { inputListenerList = new ArrayList(); } - public void start() { - new Thread(this).start(); - } - public void run() { - run = true; while (run) { try { Socket socket = server.accept(); diff --git a/java/src/pm/device/wiimote/WiimoteDevice.java b/java/src/pm/device/wiimote/WiimoteDevice.java index cf27f3a..825f774 100644 --- a/java/src/pm/device/wiimote/WiimoteDevice.java +++ b/java/src/pm/device/wiimote/WiimoteDevice.java @@ -7,7 +7,6 @@ import org.wiigee.util.Log; import pm.Button; import pm.Device; import pm.Task; -import pm.device.javainput.rumblepad.RumblepadButton; import pm.device.wiimote.gesture.GestureDevice; import pm.exception.device.DeviceInitialiseException; import pm.exception.event.UnknownButtonException; diff --git a/java/src/pm/task/TaskListener.java b/java/src/pm/task/TaskListener.java index dda8230..95d55bc 100644 --- a/java/src/pm/task/TaskListener.java +++ b/java/src/pm/task/TaskListener.java @@ -3,26 +3,18 @@ package pm.task; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; +import pm.Listener; import pm.Task; import pm.value.Action; -public abstract class TaskListener implements Runnable { - protected static final int SLEEP = 100; - +public abstract class TaskListener extends Listener implements Runnable { protected Queue taskQueue; - protected boolean run; public TaskListener() { taskQueue = new ConcurrentLinkedQueue(); - run = false; - } - - public void start() { - new Thread(this).start(); } public final void run() { - run = true; while (run) { if (taskQueue.isEmpty()) { sleep(); @@ -32,26 +24,10 @@ public abstract class TaskListener implements Runnable { } } - public void stop() { - run = false; - } - public void add(Task task) { taskQueue.add(task); } - protected void sleep(int time) { - try { - if (time > 0) { - Thread.sleep(time); - } - } catch (InterruptedException e) {} - } - - protected void sleep() { - sleep(SLEEP); - } - protected void task(Task task) { System.out.println(this); Action action = task.getAction();