This commit is contained in:
28
java/src/pm/Listener.java
Normal file
28
java/src/pm/Listener.java
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,20 +42,19 @@ public class Main extends TaskListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initialise() throws DeviceInitialiseException {
|
public void initialise() throws DeviceInitialiseException {
|
||||||
//add(new JIntellitypeDevice());
|
add(new JIntellitypeDevice());
|
||||||
//add(new PlayerDevice());
|
//add(new PlayerDevice());
|
||||||
//add(new RumblepadDevice());
|
//add(new RumblepadDevice());
|
||||||
//add(new WiimoteDevice());
|
//add(new WiimoteDevice());
|
||||||
//add(new GUIDevice());
|
//add(new GUIDevice());
|
||||||
add(new TextDevice());
|
//add(new TextDevice());
|
||||||
add(new LanTextDevice());
|
//add(new LanTextDevice());
|
||||||
for (Device device : deviceList) {
|
for (Device device : deviceList) {
|
||||||
try {
|
try {
|
||||||
device.initialise();
|
device.initialise();
|
||||||
device.start();
|
device.start();
|
||||||
} catch (DeviceInitialiseException e) {
|
} catch (DeviceInitialiseException e) {
|
||||||
remove(device);
|
remove(device);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +69,6 @@ public class Main extends TaskListener {
|
|||||||
application.start();
|
application.start();
|
||||||
} catch (ApplicationInitialiseException e) {
|
} catch (ApplicationInitialiseException e) {
|
||||||
remove(application);
|
remove(application);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package pm.application.windows;
|
package pm.application.windows;
|
||||||
|
|
||||||
|
import pm.Button;
|
||||||
|
|
||||||
public enum Command {
|
public enum Command {
|
||||||
BROWSER_BACKWARD (1),
|
BROWSER_BACKWARD (1),
|
||||||
BROWSER_FORWARD (2),
|
BROWSER_FORWARD (2),
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ import com.melloware.jintellitype.JIntellitype;
|
|||||||
|
|
||||||
import pm.Device;
|
import pm.Device;
|
||||||
import pm.Task;
|
import pm.Task;
|
||||||
|
import pm.application.windows.Command;
|
||||||
import pm.exception.EventException;
|
import pm.exception.EventException;
|
||||||
import pm.exception.device.DeviceInitialiseException;
|
import pm.exception.device.DeviceInitialiseException;
|
||||||
|
import pm.macro.event.Hold;
|
||||||
import pm.macro.event.Press;
|
import pm.macro.event.Press;
|
||||||
import pm.macro.event.Release;
|
import pm.macro.event.Release;
|
||||||
import pm.task.Continuous;
|
import pm.task.Continuous;
|
||||||
@@ -37,8 +39,11 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell
|
|||||||
new Hotkey(Key.NEXT),
|
new Hotkey(Key.NEXT),
|
||||||
new Task(Action.NEXT, Target.MAIN));
|
new Task(Action.NEXT, Target.MAIN));
|
||||||
add(
|
add(
|
||||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 'q'),
|
new Press(CommandButton.VOLUME_DOWN),
|
||||||
new Task(Action.PLAY, Target.APPLICATIONS));
|
new Task(Action.VOLUME_DOWN, Target.APPLICATIONS));
|
||||||
|
add(
|
||||||
|
new Press(CommandButton.VOLUME_UP),
|
||||||
|
new Task(Action.VOLUME_UP, Target.APPLICATIONS));
|
||||||
add(
|
add(
|
||||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 'x'),
|
new Hotkey(Modifier.CTRL | Modifier.WIN, 'x'),
|
||||||
new Task(Action.EXIT, Target.MAIN));
|
new Task(Action.EXIT, Target.MAIN));
|
||||||
|
|||||||
@@ -3,33 +3,27 @@ package pm.device.text;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import pm.Listener;
|
||||||
import pm.Task;
|
import pm.Task;
|
||||||
import pm.task.TaskManager;
|
import pm.task.TaskManager;
|
||||||
import pm.value.Action;
|
import pm.value.Action;
|
||||||
import pm.value.Target;
|
import pm.value.Target;
|
||||||
|
|
||||||
public class InputListener implements Runnable {
|
public class InputListener extends Listener {
|
||||||
protected static final int SLEEP = 100;
|
|
||||||
|
|
||||||
protected boolean run;
|
|
||||||
protected Scanner input;
|
protected Scanner input;
|
||||||
|
|
||||||
public InputListener(InputStream inputStream) {
|
public InputListener(InputStream inputStream) {
|
||||||
input = new Scanner(inputStream);
|
input = new Scanner(inputStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
|
||||||
new Thread(this).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
run = true;
|
run = true;
|
||||||
while (running()) {
|
while (running()) {
|
||||||
String textinput = input.next().toUpperCase();
|
String string = input.next().toUpperCase();
|
||||||
if(textinput != null) {
|
if(string != null) {
|
||||||
try {
|
try {
|
||||||
TaskManager.add(
|
TaskManager.add(
|
||||||
new Task(Action.valueOf(textinput), Target.APPLICATION));
|
new Task(Action.valueOf(string), Target.APPLICATION));
|
||||||
} catch(IllegalArgumentException e) {}
|
} catch(IllegalArgumentException e) {}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -43,8 +37,4 @@ public class InputListener implements Runnable {
|
|||||||
protected boolean running() {
|
protected boolean running() {
|
||||||
return run && input.hasNext();
|
return run && input.hasNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
|
||||||
run = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ import java.net.ServerSocket;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import pm.Listener;
|
||||||
import pm.device.text.InputListener;
|
import pm.device.text.InputListener;
|
||||||
|
|
||||||
public class SocketListener implements Runnable {
|
public class SocketListener extends Listener {
|
||||||
protected boolean run;
|
|
||||||
|
|
||||||
protected ServerSocket server;
|
protected ServerSocket server;
|
||||||
protected ArrayList<InputListener> inputListenerList;
|
protected ArrayList<InputListener> inputListenerList;
|
||||||
|
|
||||||
@@ -19,12 +18,7 @@ public class SocketListener implements Runnable {
|
|||||||
inputListenerList = new ArrayList<InputListener>();
|
inputListenerList = new ArrayList<InputListener>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
|
||||||
new Thread(this).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
run = true;
|
|
||||||
while (run) {
|
while (run) {
|
||||||
try {
|
try {
|
||||||
Socket socket = server.accept();
|
Socket socket = server.accept();
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import org.wiigee.util.Log;
|
|||||||
import pm.Button;
|
import pm.Button;
|
||||||
import pm.Device;
|
import pm.Device;
|
||||||
import pm.Task;
|
import pm.Task;
|
||||||
import pm.device.javainput.rumblepad.RumblepadButton;
|
|
||||||
import pm.device.wiimote.gesture.GestureDevice;
|
import pm.device.wiimote.gesture.GestureDevice;
|
||||||
import pm.exception.device.DeviceInitialiseException;
|
import pm.exception.device.DeviceInitialiseException;
|
||||||
import pm.exception.event.UnknownButtonException;
|
import pm.exception.event.UnknownButtonException;
|
||||||
|
|||||||
@@ -3,26 +3,18 @@ package pm.task;
|
|||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
|
import pm.Listener;
|
||||||
import pm.Task;
|
import pm.Task;
|
||||||
import pm.value.Action;
|
import pm.value.Action;
|
||||||
|
|
||||||
public abstract class TaskListener implements Runnable {
|
public abstract class TaskListener extends Listener implements Runnable {
|
||||||
protected static final int SLEEP = 100;
|
|
||||||
|
|
||||||
protected Queue<Task> taskQueue;
|
protected Queue<Task> taskQueue;
|
||||||
protected boolean run;
|
|
||||||
|
|
||||||
public TaskListener() {
|
public TaskListener() {
|
||||||
taskQueue = new ConcurrentLinkedQueue<Task>();
|
taskQueue = new ConcurrentLinkedQueue<Task>();
|
||||||
run = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
new Thread(this).start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void run() {
|
public final void run() {
|
||||||
run = true;
|
|
||||||
while (run) {
|
while (run) {
|
||||||
if (taskQueue.isEmpty()) {
|
if (taskQueue.isEmpty()) {
|
||||||
sleep();
|
sleep();
|
||||||
@@ -32,26 +24,10 @@ public abstract class TaskListener implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
|
||||||
run = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Task task) {
|
public void add(Task task) {
|
||||||
taskQueue.add(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) {
|
protected void task(Task task) {
|
||||||
System.out.println(this);
|
System.out.println(this);
|
||||||
Action action = task.getAction();
|
Action action = task.getAction();
|
||||||
|
|||||||
Reference in New Issue
Block a user