LircDevice begonnen. Main en Client omgeschreven: nu niet meer via Manager, maar via Mimis. Manager wordt nu gebruikt om Applications / Devices in te beheren. In de Managers worden de knoppen aangemaakt, die weer door de GUI worden weergegeven. Tegelijkertijd draait in de Manager een Worker die controleert of er actief is. Interfaces toegevoegd: Exitable en Titled. Verder een aantal ongebruikte dingen weggehaald en naamgevingen aangepast. Nog eens goed alle namen nalopen!
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package pm;
|
||||
|
||||
import pm.event.EventHandler;
|
||||
import pm.selector.Selectable;
|
||||
import pm.manager.Titled;
|
||||
|
||||
public abstract class Application extends EventHandler implements Selectable {
|
||||
public abstract class Application extends EventHandler implements Titled, Exitable {
|
||||
protected String title;
|
||||
protected boolean active;
|
||||
|
||||
@@ -17,7 +17,9 @@ public abstract class Application extends EventHandler implements Selectable {
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
deactivate();
|
||||
if (active()) {
|
||||
deactivate();
|
||||
}
|
||||
stop();
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,51 @@
|
||||
package pm;
|
||||
|
||||
import pm.event.router.GlobalRouter;
|
||||
import pm.exception.event.spreader.NetworkSpreaderException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class Client extends Manager {
|
||||
public static final String TITLE = "Client";
|
||||
|
||||
public static final String IP = "192.168.1.100";
|
||||
import pm.device.javainput.extreme3d.Extreme3DDevice;
|
||||
import pm.device.javainput.rumblepad.RumblepadDevice;
|
||||
import pm.device.jintellitype.JIntellitypeDevice;
|
||||
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;
|
||||
|
||||
public Client(String ip, int port) throws NetworkSpreaderException {
|
||||
super(new GlobalRouter(ip, port));
|
||||
}
|
||||
protected EventRouter eventRouter;
|
||||
protected Device[] deviceArray;
|
||||
|
||||
public Client() throws NetworkSpreaderException {
|
||||
public Client() throws GlobalRouterException {
|
||||
this(IP, PORT);
|
||||
}
|
||||
|
||||
public Client(String ip, int port) throws GlobalRouterException {
|
||||
eventRouter = new GlobalRouter(ip, port);
|
||||
deviceArray = new Device[] {
|
||||
new WiimoteDevice(),
|
||||
new PanelDevice(),
|
||||
new JIntellitypeDevice(),
|
||||
new PlayerDevice(),
|
||||
new RumblepadDevice(),
|
||||
new Extreme3DDevice(),
|
||||
new NetworkDevice()};
|
||||
}
|
||||
|
||||
public void start() {
|
||||
initialise();
|
||||
super.start(false);
|
||||
log.debug("Client");
|
||||
Mimis mimis = new Mimis(eventRouter, deviceArray);
|
||||
mimis.start();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
new Client().start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String title() {
|
||||
return TITLE;
|
||||
new Main().start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ import pm.macro.State;
|
||||
import pm.macro.state.Hold;
|
||||
import pm.macro.state.Press;
|
||||
import pm.macro.state.Release;
|
||||
import pm.selector.Selectable;
|
||||
import pm.manager.Titled;
|
||||
|
||||
public abstract class Device extends EventHandler implements Selectable {
|
||||
public abstract class Device extends EventHandler implements Titled, Exitable {
|
||||
protected String title;
|
||||
protected boolean active;
|
||||
protected SequenceListener sequenceListener;
|
||||
@@ -84,7 +84,9 @@ public abstract class Device extends EventHandler implements Selectable {
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
deactivate();
|
||||
if (active()) {
|
||||
deactivate();
|
||||
}
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,11 @@ public class Event {
|
||||
}
|
||||
|
||||
public boolean compatible(EventListener eventListener) {
|
||||
System.out.println("Event compatible()");
|
||||
System.out.println(eventListener);
|
||||
switch (target) {
|
||||
case ALL:
|
||||
return true;
|
||||
case MANAGER:
|
||||
return eventListener instanceof Manager;
|
||||
case MIMIS:
|
||||
return eventListener instanceof Mimis;
|
||||
case DEVICES:
|
||||
return eventListener instanceof Device;
|
||||
case APPLICATIONS:
|
||||
|
||||
5
java/src/pm/Exitable.java
Normal file
5
java/src/pm/Exitable.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package pm;
|
||||
|
||||
public interface Exitable {
|
||||
public void exit();
|
||||
}
|
||||
@@ -2,11 +2,14 @@ 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.JSeparator;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -19,37 +22,44 @@ public class GUI extends JFrame {
|
||||
protected static final String APPLICATION_TITLE = "Applications";
|
||||
protected static final String DEVICE_TITLE = "Devices";
|
||||
|
||||
public GUI(Application[] applicationArray, Device[] deviceArray) {
|
||||
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));
|
||||
//add(new JSeparator());
|
||||
JPanel controlPanel = createControlPanel(applicationArray, deviceArray);
|
||||
JPanel feedbackPanel = createFeedbackPanel();
|
||||
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(Application[] applicationArray, Device[] deviceArray) {
|
||||
protected JPanel createControlPanel(Manager<Application> applicationManager, Manager<Device> deviceManager) {
|
||||
JPanel controlPanel = new JPanel(new GridLayout(1, 0));
|
||||
Selector<Application> applicationSelector = new Selector<Application>(APPLICATION_TITLE);
|
||||
for (Application application : applicationArray) {
|
||||
applicationSelector.add(application, application.title());
|
||||
}
|
||||
controlPanel.add(applicationSelector);
|
||||
|
||||
|
||||
Selector<Device> deviceSelector = new Selector<Device>(DEVICE_TITLE);
|
||||
for (Device device : deviceArray) {
|
||||
deviceSelector.add(device, device.title());
|
||||
}
|
||||
controlPanel.add(deviceSelector);
|
||||
|
||||
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();
|
||||
@@ -57,4 +67,17 @@ public class GUI extends JFrame {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,63 +16,39 @@ 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;
|
||||
import pm.util.ArrayCycle;
|
||||
import pm.value.Action;
|
||||
|
||||
public class Main extends Manager {
|
||||
public class Main {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
protected ArrayCycle<Application> applicationCycle;
|
||||
|
||||
protected EventRouter eventRouter;
|
||||
protected Application[] applicationArray;
|
||||
protected Device[] deviceArray;
|
||||
|
||||
public Main() {
|
||||
super(new LocalRouter());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
super.start();
|
||||
Application[] applicationArray = new Application[] {
|
||||
eventRouter = new LocalRouter();
|
||||
applicationArray = new Application[] {
|
||||
new iTunesApplication(),
|
||||
new GomPlayerApplication(),
|
||||
new WMPApplication(),
|
||||
new MPCApplication(),
|
||||
new VLCApplication(),
|
||||
new WinampApplication()};
|
||||
applicationCycle = new ArrayCycle<Application>(applicationArray);
|
||||
Device[] deviceArray = new Device[] {
|
||||
new WiimoteDevice(),
|
||||
new PanelDevice(),
|
||||
new JIntellitypeDevice(),
|
||||
new PlayerDevice(),
|
||||
new RumblepadDevice(),
|
||||
new Extreme3DDevice(),
|
||||
new NetworkDevice()};
|
||||
GUI gui = new GUI(applicationArray, deviceArray);
|
||||
eventRouter.set(applicationCycle.current());
|
||||
super.start(false);
|
||||
deviceArray = new Device[] {
|
||||
new WiimoteDevice(),
|
||||
new PanelDevice(),
|
||||
new JIntellitypeDevice(),
|
||||
new PlayerDevice(),
|
||||
new RumblepadDevice(),
|
||||
new Extreme3DDevice(),
|
||||
new NetworkDevice()};
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
System.out.println("Exit applications...");
|
||||
for (Application application : applicationCycle) {
|
||||
application.exit();
|
||||
}
|
||||
public void start() {
|
||||
log.debug("Main");
|
||||
Mimis mimis = new Mimis(eventRouter, applicationArray, deviceArray);
|
||||
mimis.start();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -1,47 +1,61 @@
|
||||
package pm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.device.javainput.extreme3d.Extreme3DDevice;
|
||||
import pm.device.javainput.rumblepad.RumblepadDevice;
|
||||
import pm.device.jintellitype.JIntellitypeDevice;
|
||||
import pm.device.network.NetworkDevice;
|
||||
import pm.device.panel.PanelDevice;
|
||||
import pm.device.player.PlayerDevice;
|
||||
import pm.device.wiimote.WiimoteDevice;
|
||||
import pm.event.EventHandler;
|
||||
import pm.event.EventRouter;
|
||||
import pm.manager.SelectButton;
|
||||
import pm.manager.Titled;
|
||||
|
||||
public abstract class Manager extends EventHandler {
|
||||
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 = 5000;
|
||||
|
||||
protected ArrayList<Device> deviceList;
|
||||
|
||||
public Manager(EventRouter eventRouter) {
|
||||
EventHandler.initialise(eventRouter);
|
||||
eventRouter.start();
|
||||
protected T[] manageableArray;
|
||||
protected Map<T, SelectButton<T>> buttonMap;
|
||||
|
||||
public Manager(String title) {
|
||||
log.debug("Manager constructed");
|
||||
}
|
||||
|
||||
public void start() {
|
||||
initialise();
|
||||
Device[] deviceArray = new Device[] {
|
||||
new WiimoteDevice(),
|
||||
new PanelDevice(),
|
||||
new JIntellitypeDevice(),
|
||||
new PlayerDevice(),
|
||||
new RumblepadDevice(),
|
||||
new Extreme3DDevice(),
|
||||
new NetworkDevice()};
|
||||
public Manager(T[] manageableArray) {
|
||||
this.manageableArray = manageableArray;
|
||||
createButtons();
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
log.debug("Exit devices...");
|
||||
for (Device device : deviceList) {
|
||||
device.exit();
|
||||
public void stop() {
|
||||
super.stop();
|
||||
for (T manageable : manageableArray) {
|
||||
manageable.exit();
|
||||
}
|
||||
stop();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
86
java/src/pm/Mimis.java
Normal file
86
java/src/pm/Mimis.java
Normal file
@@ -0,0 +1,86 @@
|
||||
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[] {}, new Device[] {});
|
||||
}
|
||||
|
||||
public Mimis(EventRouter eventRouter, Application[] applicationArray) {
|
||||
this(eventRouter, applicationArray, new Device[] {});
|
||||
}
|
||||
|
||||
public Mimis(EventRouter eventRouter, Device[] deviceArray) {
|
||||
this(eventRouter, new Application[] {}, 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 start() {
|
||||
log.debug("Start managers");
|
||||
applicationManager.start();
|
||||
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.start(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,29 +0,0 @@
|
||||
package pm;
|
||||
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import pm.selector.SelectButton;
|
||||
|
||||
public class Selector<T extends Worker> extends JPanel {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
public Selector(String title) {
|
||||
setLayout(new GridLayout(0, 1));
|
||||
add(new JLabel(title, SwingConstants.CENTER));
|
||||
log.debug("Selector constructed");
|
||||
}
|
||||
|
||||
protected void add(T worker, String title) {
|
||||
SelectButton<T> button = new SelectButton<T>(worker, title);
|
||||
add(button);
|
||||
log.debug(String.format("Item added: %s", title));
|
||||
}
|
||||
}
|
||||
@@ -8,34 +8,36 @@ public abstract class Worker implements Runnable {
|
||||
|
||||
protected static final boolean THREAD = true;
|
||||
protected static final int SLEEP = 100;
|
||||
public static final int CHECK_ALIVE_INTERVAL = 1000;
|
||||
|
||||
protected boolean running = false;
|
||||
protected boolean active = false;
|
||||
protected boolean connected;
|
||||
|
||||
|
||||
protected Object lock;
|
||||
|
||||
public void start(boolean thread) {
|
||||
log.debug("Start");
|
||||
running = true;
|
||||
activate();
|
||||
if (thread) {
|
||||
log.debug("Start thread");
|
||||
new Thread(this).start();
|
||||
} else {
|
||||
log.debug("Run directly");
|
||||
run();
|
||||
}
|
||||
activate();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
start(THREAD);
|
||||
monitorConnection();
|
||||
connected = false;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
log.debug("Stop");
|
||||
if (active()) {
|
||||
deactivate();
|
||||
}
|
||||
running = false;
|
||||
deactivate();
|
||||
synchronized (this) {
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
protected void sleep(int time) {
|
||||
@@ -57,12 +59,6 @@ public abstract class Worker implements Runnable {
|
||||
}
|
||||
|
||||
public void activate() {
|
||||
if (!running) {
|
||||
start();
|
||||
}
|
||||
synchronized (this) {
|
||||
notifyAll();
|
||||
}
|
||||
active = true;
|
||||
}
|
||||
|
||||
@@ -70,13 +66,6 @@ public abstract class Worker implements Runnable {
|
||||
active = false;
|
||||
}
|
||||
|
||||
public void deactivate(boolean stop) {
|
||||
deactivate();
|
||||
if (stop && running) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
public final void run() {
|
||||
while (running) {
|
||||
if (active()) {
|
||||
@@ -84,41 +73,15 @@ public abstract class Worker implements Runnable {
|
||||
} else {
|
||||
try {
|
||||
synchronized (this) {
|
||||
log.debug("Wait");
|
||||
wait();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
log.info(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void work();
|
||||
|
||||
public boolean connected() {
|
||||
return connected;
|
||||
}
|
||||
|
||||
protected void monitorConnection() {
|
||||
new Thread() {
|
||||
protected long timestamp = System.currentTimeMillis();
|
||||
|
||||
public void run() {
|
||||
while (super.isAlive()) {
|
||||
if (timestamp + (2 * CHECK_ALIVE_INTERVAL) > System.currentTimeMillis()) {
|
||||
timestamp = System.currentTimeMillis();
|
||||
connected = true;
|
||||
log.debug("Het gaat nog helemaal goed");
|
||||
} else {
|
||||
log.debug("Het interval is overschreden");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(CHECK_ALIVE_INTERVAL);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
connected = false;
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,19 @@ public class iTunesApplication extends Application implements iTunesEventsInterf
|
||||
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) {
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package pm.client;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.net.Socket;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class LanTextClient {
|
||||
static final String HOST = "127.0.0.1"; // localhost
|
||||
static final int PORT = 1234;
|
||||
|
||||
protected Socket socket;
|
||||
protected Scanner input;
|
||||
protected PrintStream output;
|
||||
|
||||
public LanTextClient(String host, int port) {
|
||||
try {
|
||||
socket = new Socket(HOST, PORT);
|
||||
input = new Scanner(System.in);
|
||||
output = new PrintStream(socket.getOutputStream());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public LanTextClient() {
|
||||
this(HOST, PORT);
|
||||
}
|
||||
|
||||
protected void start() {
|
||||
while (true) {
|
||||
output.println(input.nextLine());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] argv) {
|
||||
new LanTextClient().start();
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public abstract class JavaInputDevice extends Device {
|
||||
protected JavaInputListener javaInputListener;
|
||||
protected Button previousDirectionalButton;
|
||||
|
||||
public void initialise(String name) throws DeviceInitialiseException {
|
||||
public void activate(String name) throws DeviceInitialiseException {
|
||||
try {
|
||||
javaInputListener = new JavaInputListener(this, getDevice(name));
|
||||
javaInputListener.start();
|
||||
@@ -33,7 +33,7 @@ public abstract class JavaInputDevice extends Device {
|
||||
}
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
public void deactivate() {
|
||||
javaInputListener.exit();
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class Extreme3DDevice extends JavaInputDevice {
|
||||
new Press(Extreme3DButton.TWO),
|
||||
new Press(Extreme3DButton.ELEVEN),
|
||||
new Release(Extreme3DButton.ONE)),
|
||||
new Task(Target.MANAGER, Action.EXIT));
|
||||
new Task(Target.MIMIS, Action.EXIT));
|
||||
} catch (MacroException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell
|
||||
jit.addIntellitypeListener(this);
|
||||
add(
|
||||
new Hotkey(Key.PRIOR),
|
||||
new Task(Target.MANAGER, Action.PREVIOUS));
|
||||
new Task(Target.MIMIS, Action.PREVIOUS));
|
||||
add(
|
||||
new Hotkey(Key.NEXT),
|
||||
new Task(Target.MANAGER, Action.NEXT));
|
||||
new Task(Target.MIMIS, Action.NEXT));
|
||||
add(
|
||||
new Press(CommandButton.VOLUME_DOWN),
|
||||
new Task(Target.APPLICATIONS, Action.VOLUME_DOWN));
|
||||
@@ -45,7 +45,7 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell
|
||||
new Task(Target.APPLICATIONS, Action.VOLUME_UP));
|
||||
add(
|
||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 'x'),
|
||||
new Task(Target.MANAGER, Action.EXIT));
|
||||
new Task(Target.MIMIS, Action.EXIT));
|
||||
add(
|
||||
new Hotkey(Modifier.CTRL | Modifier.SHIFT | Modifier.WIN, 'n'),
|
||||
new Task(Target.APPLICATION, Action.NEXT));
|
||||
|
||||
24
java/src/pm/device/lirc/LircDevice.java
Normal file
24
java/src/pm/device/lirc/LircDevice.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package pm.device.lirc;
|
||||
|
||||
import pm.Device;
|
||||
|
||||
public class LircDevice extends Device {
|
||||
protected static final String TITLE = "Lirc";
|
||||
|
||||
protected LircService lircService;
|
||||
|
||||
public LircDevice(String title) {
|
||||
super(title);
|
||||
lircService = new LircService();
|
||||
}
|
||||
|
||||
public void activate() {
|
||||
lircService.activate();
|
||||
super.activate();
|
||||
}
|
||||
|
||||
public void deactivate() {
|
||||
lircService.deactivate();
|
||||
super.deactivate();
|
||||
}
|
||||
}
|
||||
70
java/src/pm/device/lirc/LircService.java
Normal file
70
java/src/pm/device/lirc/LircService.java
Normal file
@@ -0,0 +1,70 @@
|
||||
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 pm.Worker;
|
||||
|
||||
public class LircService extends Worker {
|
||||
public static final String IP = "127.0.0.1";
|
||||
public static final int PORT = 6789;
|
||||
|
||||
protected String ip;
|
||||
protected int port;
|
||||
protected Socket socket;
|
||||
protected InputStream inputStream;
|
||||
protected OutputStream outputStream;
|
||||
protected BufferedReader bufferedReader;
|
||||
protected PrintWriter printWriter;
|
||||
|
||||
public LircService() {
|
||||
this(IP, PORT);
|
||||
}
|
||||
|
||||
public LircService(String ip, int port) {
|
||||
this.ip = ip;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
System.out.println(string);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class NetworkDevice extends Device {
|
||||
this(PORT);
|
||||
}
|
||||
|
||||
public void initialise() {
|
||||
public void activate() {
|
||||
try {
|
||||
server = new Server(port);
|
||||
server.start();
|
||||
@@ -42,7 +42,7 @@ public class NetworkDevice extends Device {
|
||||
}
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
public void deactivate() {
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@@ -65,19 +65,21 @@ public class NetworkDevice extends Device {
|
||||
System.out.println("Server started");
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (running) {
|
||||
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 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +95,7 @@ public class NetworkDevice extends Device {
|
||||
clientList.add(this);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
public void work() {
|
||||
try {
|
||||
Object object;
|
||||
do {
|
||||
@@ -109,6 +111,9 @@ public class NetworkDevice extends Device {
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
System.out.println("stoppen");
|
||||
try {
|
||||
disconnect();
|
||||
@@ -117,7 +122,7 @@ public class NetworkDevice extends Device {
|
||||
clientList.remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void send(Object object) throws IOException {
|
||||
objectOutputStream.writeObject(object);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class PanelDevice extends Device implements PanelButtonListener {
|
||||
super(TITLE);
|
||||
}
|
||||
|
||||
public void initialise() {
|
||||
public void activate() {
|
||||
panel = new Panel(this);
|
||||
//panel.updateTime(12342398);
|
||||
//panel.updatePosition(43);
|
||||
@@ -31,7 +31,7 @@ public class PanelDevice extends Device implements PanelButtonListener {
|
||||
add(new Press(PanelButton.VOLUME_UP), new Task(Target.APPLICATION, Action.VOLUME_UP));
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
public void deactivate() {
|
||||
panel.dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -177,9 +177,9 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
}
|
||||
|
||||
public void deactivate() {
|
||||
wiimote.deactivateMotionSensing();
|
||||
wiimote.deactivateMotionSensing();
|
||||
}
|
||||
|
||||
|
||||
public void exit() {
|
||||
wiimoteService.exit();
|
||||
super.exit();
|
||||
|
||||
@@ -42,9 +42,4 @@ public abstract class EventHandler extends EventListener {
|
||||
}
|
||||
|
||||
protected void action(Action action) {}
|
||||
|
||||
public void activate() {
|
||||
super.activate();
|
||||
add(new Feedback());
|
||||
}
|
||||
}
|
||||
@@ -7,30 +7,40 @@ import pm.Worker;
|
||||
|
||||
public abstract class EventListener extends Worker {
|
||||
protected Queue<Event> eventQueue;
|
||||
protected Object available;
|
||||
protected Object work;
|
||||
|
||||
public EventListener() {
|
||||
eventQueue = new ConcurrentLinkedQueue<Event>();
|
||||
available = new Object();
|
||||
work = new Object();
|
||||
}
|
||||
|
||||
public void add(Event event) {
|
||||
eventQueue.add(event);
|
||||
synchronized (available) {
|
||||
available.notifyAll();
|
||||
synchronized (work) {
|
||||
work.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
public final void work() {
|
||||
while (eventQueue.isEmpty()) {
|
||||
synchronized (available) {
|
||||
synchronized (work) {
|
||||
try {
|
||||
available.wait();
|
||||
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);
|
||||
}
|
||||
@@ -9,20 +9,20 @@ import pm.Event;
|
||||
import pm.Worker;
|
||||
import pm.event.EventRouter;
|
||||
import pm.event.Feedback;
|
||||
import pm.exception.event.spreader.NetworkSpreaderException;
|
||||
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 NetworkSpreaderException {
|
||||
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 run() {
|
||||
public void work() {
|
||||
try {
|
||||
Object object;
|
||||
do {
|
||||
@@ -41,7 +41,7 @@ public class GlobalRouter extends EventRouter {
|
||||
return;
|
||||
} catch (UnknownHostException e) {
|
||||
} catch (IOException e) {}
|
||||
throw new NetworkSpreaderException();
|
||||
throw new GlobalRouterException();
|
||||
}
|
||||
|
||||
public void event(Event event) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package pm.exception.event.router;
|
||||
|
||||
import pm.exception.event.SpreaderException;
|
||||
|
||||
public class GlobalRouterException extends SpreaderException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pm.exception.event.spreader;
|
||||
|
||||
import pm.exception.event.SpreaderException;
|
||||
|
||||
public class NetworkSpreaderException extends SpreaderException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
41
java/src/pm/manager/SelectButton.java
Normal file
41
java/src/pm/manager/SelectButton.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package pm.manager;
|
||||
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JToggleButton;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import pm.Worker;
|
||||
|
||||
public class SelectButton<T extends Worker & Titled> extends JToggleButton implements ItemListener {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
|
||||
protected static final long serialVersionUID = 1L;
|
||||
protected T activatable;
|
||||
protected Action action;
|
||||
|
||||
public SelectButton(T activatable) {
|
||||
this.activatable = activatable;
|
||||
setText(activatable.title());
|
||||
addItemListener(this);
|
||||
//getModel().setPressed(true);
|
||||
}
|
||||
|
||||
public void itemStateChanged(ItemEvent itemEvent) {
|
||||
int state = itemEvent.getStateChange();
|
||||
if (state == ItemEvent.SELECTED) {
|
||||
System.out.println("Selected");
|
||||
activatable.activate();
|
||||
} else {
|
||||
System.out.println("Deselected");
|
||||
activatable.deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
public void setPressed(boolean pressed) {
|
||||
getModel().setPressed(pressed);
|
||||
}
|
||||
}
|
||||
5
java/src/pm/manager/Titled.java
Normal file
5
java/src/pm/manager/Titled.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package pm.manager;
|
||||
|
||||
public interface Titled {
|
||||
public String title();
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package pm.selector;
|
||||
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import javax.swing.JToggleButton;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import pm.Worker;
|
||||
|
||||
public class SelectButton<T extends Worker> extends JToggleButton implements ItemListener {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
|
||||
protected static final long serialVersionUID = 1L;
|
||||
protected T activatable;
|
||||
|
||||
public static final int CHECK_ALIVE_INTERVAL = 1000;
|
||||
|
||||
public SelectButton(T activatable, String title) {
|
||||
this.activatable = activatable;
|
||||
setText(title);
|
||||
addItemListener(this);
|
||||
monitorApplication();
|
||||
}
|
||||
|
||||
public void itemStateChanged(ItemEvent itemEvent) {
|
||||
int state = itemEvent.getStateChange();
|
||||
if (state == ItemEvent.SELECTED) {
|
||||
System.out.println("Selected");
|
||||
activatable.activate();
|
||||
} else {
|
||||
System.out.println("Deselected");
|
||||
activatable.deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
protected void monitorApplication() {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
while (super.isAlive()) {
|
||||
if (!activatable.connected()) {
|
||||
//log.debug("Nu moet het knopje uit gaan!");
|
||||
}
|
||||
try {
|
||||
Thread.sleep(CHECK_ALIVE_INTERVAL);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package pm.selector;
|
||||
|
||||
public interface Selectable {
|
||||
public String title();
|
||||
}
|
||||
@@ -8,10 +8,12 @@ public class ArrayCycle<E> extends ArrayList<E> {
|
||||
protected int index = 0;
|
||||
//protected Object nonEmpty;
|
||||
|
||||
public ArrayCycle(E... elementArary) {
|
||||
public ArrayCycle(E... elementArray) {
|
||||
if (elementArray != null) {
|
||||
//nonEmpty = new Object();
|
||||
for (E element : elementArary) {
|
||||
add(element);
|
||||
for (E element : elementArray) {
|
||||
add(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package pm.value;
|
||||
|
||||
public enum Target {
|
||||
ALL, MANAGER, DEVICES, APPLICATIONS, APPLICATION, SELF;
|
||||
ALL, MIMIS, DEVICES, APPLICATIONS, APPLICATION, SELF;
|
||||
}
|
||||
Reference in New Issue
Block a user