application cycle verwijderd, structuur input listener aangepast en event manager netter gemaakt.
This commit is contained in:
@@ -71,7 +71,7 @@ public abstract class Device extends EventListener {
|
||||
Button button = hold.getButton();
|
||||
add(new Press(button), new Release(button), continuous);
|
||||
}
|
||||
|
||||
|
||||
/* Register interruptibles *
|
||||
protected void add(Interruptible interruptible) {
|
||||
interruptListener.add(interruptible);
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.ArrayList;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import pm.application.ApplicationCycle;
|
||||
import pm.application.cmd.windows.gomplayer.GomPlayerApplication;
|
||||
import pm.application.cmd.windows.wmp.WMPApplication;
|
||||
import pm.application.example.ExampleApplication;
|
||||
@@ -29,13 +28,14 @@ import pm.exception.application.ApplicationInitialiseException;
|
||||
import pm.exception.device.DeviceExitException;
|
||||
import pm.exception.device.DeviceInitialiseException;
|
||||
import pm.macro.Active;
|
||||
import pm.util.ArrayCycle;
|
||||
import pm.value.Action;
|
||||
|
||||
public class Main extends EventListener {
|
||||
protected Log log = LogFactory.getLog(Main.class);
|
||||
|
||||
//protected String[] deviceClassArray;
|
||||
protected ApplicationCycle applicationCycle;
|
||||
protected ArrayCycle<Application> applicationCycle;
|
||||
protected ArrayList<Device> deviceList;
|
||||
|
||||
public Main() {
|
||||
@@ -45,7 +45,7 @@ public class Main extends EventListener {
|
||||
"pm.device.javainput.rumblepad.RumblepadDevice",
|
||||
"pm.device.javainput.extreme3d.Extreme3DDevice",
|
||||
"pm.device.wiimote.WiimoteDevice"};*/
|
||||
applicationCycle = new ApplicationCycle();
|
||||
applicationCycle = new ArrayCycle<Application>();
|
||||
deviceList = new ArrayList<Device>();
|
||||
EventManager.initialise(applicationCycle);
|
||||
EventManager.add(this);
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package pm.application;
|
||||
|
||||
import pm.Application;
|
||||
import pm.util.ArrayCycle;
|
||||
|
||||
public class ApplicationCycle extends ArrayCycle<Application> {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package pm.device.text;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
import pm.Listener;
|
||||
import pm.event.Task;
|
||||
import pm.event.EventManager;
|
||||
import pm.exception.task.TaskNotSupportedException;
|
||||
import pm.value.Action;
|
||||
import pm.value.Target;
|
||||
|
||||
public class InputListener extends Listener {
|
||||
protected Scanner input;
|
||||
|
||||
public InputListener(InputStream inputStream) {
|
||||
input = new Scanner(inputStream);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
run = true;
|
||||
while (running()) {
|
||||
String string = input.next().toUpperCase();
|
||||
if(string != null) {
|
||||
try {
|
||||
EventManager.add(
|
||||
new Task(Action.valueOf(string), Target.APPLICATION));
|
||||
} catch(IllegalArgumentException e) {}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(SLEEP);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean running() {
|
||||
return run && input.hasNext();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,14 @@
|
||||
package pm.device.text;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
import pm.Device;
|
||||
import pm.Listener;
|
||||
import pm.event.EventManager;
|
||||
import pm.event.Task;
|
||||
import pm.value.Action;
|
||||
import pm.value.Target;
|
||||
|
||||
public class TextDevice extends Device {
|
||||
InputListener inputListener;
|
||||
@@ -16,4 +24,33 @@ public class TextDevice extends Device {
|
||||
public void exit() {
|
||||
inputListener.stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void add(String string) {
|
||||
EventManager.add(new Task(Action.valueOf(string), Target.APPLICATION));
|
||||
}
|
||||
|
||||
public class InputListener extends Listener {
|
||||
protected Scanner input;
|
||||
|
||||
public InputListener(InputStream inputStream) {
|
||||
input = new Scanner(inputStream);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
run = true;
|
||||
while (run && input.hasNext()) {
|
||||
String string = input.next().toUpperCase();
|
||||
if(string != null) {
|
||||
try {
|
||||
add(string);
|
||||
} catch(IllegalArgumentException e) {}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(SLEEP);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,15 +7,15 @@ import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import pm.Listener;
|
||||
import pm.device.text.InputListener;
|
||||
import pm.device.text.TextDevice;
|
||||
|
||||
public class SocketListener extends Listener {
|
||||
protected ServerSocket server;
|
||||
protected ArrayList<InputListener> inputListenerList;
|
||||
protected ArrayList<TextDevice.InputListener> inputListenerList;
|
||||
|
||||
public SocketListener(ServerSocket server) {
|
||||
this.server = server;
|
||||
inputListenerList = new ArrayList<InputListener>();
|
||||
inputListenerList = new ArrayList<TextDevice.InputListener>();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@@ -23,7 +23,7 @@ public class SocketListener extends Listener {
|
||||
try {
|
||||
Socket socket = server.accept();
|
||||
InputStream inputStream = socket.getInputStream();
|
||||
InputListener inputListener = new InputListener(inputStream);
|
||||
TextDevice.InputListener inputListener = new TextDevice().new InputListener(inputStream);
|
||||
inputListenerList.add(inputListener);
|
||||
inputListener.start();
|
||||
} catch (IOException e) {
|
||||
@@ -34,7 +34,7 @@ public class SocketListener extends Listener {
|
||||
|
||||
public void stop() {
|
||||
run = false;
|
||||
for (InputListener inputListener : inputListenerList) {
|
||||
for (TextDevice.InputListener inputListener : inputListenerList) {
|
||||
inputListener.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,15 +5,15 @@ import java.util.ArrayList;
|
||||
import pm.Application;
|
||||
import pm.Device;
|
||||
import pm.Main;
|
||||
import pm.application.ApplicationCycle;
|
||||
import pm.event.task.Stopper;
|
||||
import pm.util.ArrayCycle;
|
||||
import pm.value.Target;
|
||||
|
||||
public class EventManager {
|
||||
protected static ArrayList<EventListener> eventListenerList;
|
||||
protected static ApplicationCycle applicationCycle;
|
||||
protected static ArrayCycle<Application> applicationCycle;
|
||||
|
||||
public static void initialise(ApplicationCycle applicationCycle) {
|
||||
public static void initialise(ArrayCycle<Application> applicationCycle) {
|
||||
eventListenerList = new ArrayList<EventListener>();
|
||||
EventManager.applicationCycle = applicationCycle;
|
||||
}
|
||||
@@ -30,8 +30,7 @@ public class EventManager {
|
||||
|
||||
public static void add(EventListener self, Task task) {
|
||||
if (task instanceof Stopper) {
|
||||
Stopper stopper = (Stopper) task;
|
||||
stopper.stop();
|
||||
((Stopper) task).stop();
|
||||
} else {
|
||||
Target target = task.getTarget();
|
||||
switch (target) {
|
||||
@@ -43,7 +42,7 @@ public class EventManager {
|
||||
applicationCycle.current().add(task);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
default: {
|
||||
for (EventListener eventListener : eventListenerList) {
|
||||
switch (target) {
|
||||
case ALL:
|
||||
@@ -66,11 +65,16 @@ public class EventManager {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void add(Task task) {
|
||||
add(null, task);
|
||||
}
|
||||
|
||||
private static void add(Task task) {
|
||||
if (!task.getTarget().equals(Target.SELF)) {
|
||||
add(null, task);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user