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;
|
package pm;
|
||||||
|
|
||||||
import pm.event.EventHandler;
|
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 String title;
|
||||||
protected boolean active;
|
protected boolean active;
|
||||||
|
|
||||||
@@ -17,7 +17,9 @@ public abstract class Application extends EventHandler implements Selectable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void exit() {
|
public void exit() {
|
||||||
deactivate();
|
if (active()) {
|
||||||
|
deactivate();
|
||||||
|
}
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,36 +1,51 @@
|
|||||||
package pm;
|
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.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.event.router.GlobalRouter;
|
||||||
import pm.exception.event.spreader.NetworkSpreaderException;
|
import pm.exception.event.router.GlobalRouterException;
|
||||||
|
|
||||||
public class Client extends Manager {
|
public class Client {
|
||||||
public static final String TITLE = "Client";
|
protected Log log = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
public static final String IP = "192.168.1.100";
|
public static final String IP = "127.0.0.1";
|
||||||
public static final int PORT = 6789;
|
public static final int PORT = 6789;
|
||||||
|
|
||||||
public Client(String ip, int port) throws NetworkSpreaderException {
|
protected EventRouter eventRouter;
|
||||||
super(new GlobalRouter(ip, port));
|
protected Device[] deviceArray;
|
||||||
}
|
|
||||||
|
|
||||||
public Client() throws NetworkSpreaderException {
|
public Client() throws GlobalRouterException {
|
||||||
this(IP, PORT);
|
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() {
|
public void start() {
|
||||||
initialise();
|
log.debug("Client");
|
||||||
super.start(false);
|
Mimis mimis = new Mimis(eventRouter, deviceArray);
|
||||||
|
mimis.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
new Main().start();
|
||||||
new Client().start();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String title() {
|
|
||||||
return TITLE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ import pm.macro.State;
|
|||||||
import pm.macro.state.Hold;
|
import pm.macro.state.Hold;
|
||||||
import pm.macro.state.Press;
|
import pm.macro.state.Press;
|
||||||
import pm.macro.state.Release;
|
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 String title;
|
||||||
protected boolean active;
|
protected boolean active;
|
||||||
protected SequenceListener sequenceListener;
|
protected SequenceListener sequenceListener;
|
||||||
@@ -84,7 +84,9 @@ public abstract class Device extends EventHandler implements Selectable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void exit() {
|
public void exit() {
|
||||||
deactivate();
|
if (active()) {
|
||||||
|
deactivate();
|
||||||
|
}
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,11 @@ public class Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean compatible(EventListener eventListener) {
|
public boolean compatible(EventListener eventListener) {
|
||||||
System.out.println("Event compatible()");
|
|
||||||
System.out.println(eventListener);
|
|
||||||
switch (target) {
|
switch (target) {
|
||||||
case ALL:
|
case ALL:
|
||||||
return true;
|
return true;
|
||||||
case MANAGER:
|
case MIMIS:
|
||||||
return eventListener instanceof Manager;
|
return eventListener instanceof Mimis;
|
||||||
case DEVICES:
|
case DEVICES:
|
||||||
return eventListener instanceof Device;
|
return eventListener instanceof Device;
|
||||||
case APPLICATIONS:
|
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.GridLayout;
|
||||||
import java.awt.TextArea;
|
import java.awt.TextArea;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
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 APPLICATION_TITLE = "Applications";
|
||||||
protected static final String DEVICE_TITLE = "Devices";
|
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);
|
super(TITLE);
|
||||||
|
this.mimis = mimis;
|
||||||
|
createFrame(applicationManager, deviceManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void createFrame(Manager<Application> applicationManager, Manager<Device> deviceManager) {
|
||||||
setLayout(new GridLayout(0, 1));
|
setLayout(new GridLayout(0, 1));
|
||||||
//add(new JSeparator());
|
JPanel controlPanel = createControlPanel(applicationManager, deviceManager);
|
||||||
JPanel controlPanel = createControlPanel(applicationArray, deviceArray);
|
|
||||||
JPanel feedbackPanel = createFeedbackPanel();
|
|
||||||
add(controlPanel);
|
add(controlPanel);
|
||||||
|
JPanel feedbackPanel = createFeedbackPanel();
|
||||||
add(feedbackPanel);
|
add(feedbackPanel);
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
|
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||||
pack();
|
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));
|
JPanel controlPanel = new JPanel(new GridLayout(1, 0));
|
||||||
Selector<Application> applicationSelector = new Selector<Application>(APPLICATION_TITLE);
|
JPanel applicationPanel = createManagerPanel(applicationManager, APPLICATION_TITLE);
|
||||||
for (Application application : applicationArray) {
|
controlPanel.add(applicationPanel);
|
||||||
applicationSelector.add(application, application.title());
|
JPanel devicePanel = createManagerPanel(deviceManager, DEVICE_TITLE);
|
||||||
}
|
controlPanel.add(devicePanel);
|
||||||
controlPanel.add(applicationSelector);
|
|
||||||
|
|
||||||
|
|
||||||
Selector<Device> deviceSelector = new Selector<Device>(DEVICE_TITLE);
|
|
||||||
for (Device device : deviceArray) {
|
|
||||||
deviceSelector.add(device, device.title());
|
|
||||||
}
|
|
||||||
controlPanel.add(deviceSelector);
|
|
||||||
|
|
||||||
return controlPanel;
|
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() {
|
protected JPanel createFeedbackPanel() {
|
||||||
JPanel feedbackPanel = new JPanel();
|
JPanel feedbackPanel = new JPanel();
|
||||||
TextArea textArea = new TextArea();
|
TextArea textArea = new TextArea();
|
||||||
@@ -57,4 +67,17 @@ public class GUI extends JFrame {
|
|||||||
feedbackPanel.add(textArea);
|
feedbackPanel.add(textArea);
|
||||||
return feedbackPanel;
|
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.panel.PanelDevice;
|
||||||
import pm.device.player.PlayerDevice;
|
import pm.device.player.PlayerDevice;
|
||||||
import pm.device.wiimote.WiimoteDevice;
|
import pm.device.wiimote.WiimoteDevice;
|
||||||
|
import pm.event.EventRouter;
|
||||||
import pm.event.router.LocalRouter;
|
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 Log log = LogFactory.getLog(getClass());
|
||||||
protected ArrayCycle<Application> applicationCycle;
|
|
||||||
|
protected EventRouter eventRouter;
|
||||||
|
protected Application[] applicationArray;
|
||||||
|
protected Device[] deviceArray;
|
||||||
|
|
||||||
public Main() {
|
public Main() {
|
||||||
super(new LocalRouter());
|
eventRouter = new LocalRouter();
|
||||||
}
|
applicationArray = new Application[] {
|
||||||
|
|
||||||
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[] {
|
|
||||||
new iTunesApplication(),
|
new iTunesApplication(),
|
||||||
new GomPlayerApplication(),
|
new GomPlayerApplication(),
|
||||||
new WMPApplication(),
|
new WMPApplication(),
|
||||||
new MPCApplication(),
|
new MPCApplication(),
|
||||||
new VLCApplication(),
|
new VLCApplication(),
|
||||||
new WinampApplication()};
|
new WinampApplication()};
|
||||||
applicationCycle = new ArrayCycle<Application>(applicationArray);
|
deviceArray = new Device[] {
|
||||||
Device[] deviceArray = new Device[] {
|
new WiimoteDevice(),
|
||||||
new WiimoteDevice(),
|
new PanelDevice(),
|
||||||
new PanelDevice(),
|
new JIntellitypeDevice(),
|
||||||
new JIntellitypeDevice(),
|
new PlayerDevice(),
|
||||||
new PlayerDevice(),
|
new RumblepadDevice(),
|
||||||
new RumblepadDevice(),
|
new Extreme3DDevice(),
|
||||||
new Extreme3DDevice(),
|
new NetworkDevice()};
|
||||||
new NetworkDevice()};
|
|
||||||
GUI gui = new GUI(applicationArray, deviceArray);
|
|
||||||
eventRouter.set(applicationCycle.current());
|
|
||||||
super.start(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exit() {
|
public void start() {
|
||||||
System.out.println("Exit applications...");
|
log.debug("Main");
|
||||||
for (Application application : applicationCycle) {
|
Mimis mimis = new Mimis(eventRouter, applicationArray, deviceArray);
|
||||||
application.exit();
|
mimis.start();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -1,47 +1,61 @@
|
|||||||
package pm;
|
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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import pm.device.javainput.extreme3d.Extreme3DDevice;
|
import pm.manager.SelectButton;
|
||||||
import pm.device.javainput.rumblepad.RumblepadDevice;
|
import pm.manager.Titled;
|
||||||
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;
|
|
||||||
|
|
||||||
public abstract class Manager extends EventHandler {
|
public class Manager<T extends Worker & Titled & Exitable> extends Worker {
|
||||||
protected Log log = LogFactory.getLog(getClass());
|
protected Log log = LogFactory.getLog(getClass());
|
||||||
|
protected static final long serialVersionUID = 1L;
|
||||||
|
protected static final int INTERVAL = 5000;
|
||||||
|
|
||||||
protected ArrayList<Device> deviceList;
|
protected T[] manageableArray;
|
||||||
|
protected Map<T, SelectButton<T>> buttonMap;
|
||||||
|
|
||||||
public Manager(EventRouter eventRouter) {
|
public Manager(String title) {
|
||||||
EventHandler.initialise(eventRouter);
|
log.debug("Manager constructed");
|
||||||
eventRouter.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public Manager(T[] manageableArray) {
|
||||||
initialise();
|
this.manageableArray = manageableArray;
|
||||||
Device[] deviceArray = new Device[] {
|
createButtons();
|
||||||
new WiimoteDevice(),
|
|
||||||
new PanelDevice(),
|
|
||||||
new JIntellitypeDevice(),
|
|
||||||
new PlayerDevice(),
|
|
||||||
new RumblepadDevice(),
|
|
||||||
new Extreme3DDevice(),
|
|
||||||
new NetworkDevice()};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exit() {
|
public void stop() {
|
||||||
log.debug("Exit devices...");
|
super.stop();
|
||||||
for (Device device : deviceList) {
|
for (T manageable : manageableArray) {
|
||||||
device.exit();
|
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 boolean THREAD = true;
|
||||||
protected static final int SLEEP = 100;
|
protected static final int SLEEP = 100;
|
||||||
public static final int CHECK_ALIVE_INTERVAL = 1000;
|
|
||||||
|
|
||||||
protected boolean running = false;
|
protected boolean running = false;
|
||||||
protected boolean active = false;
|
protected boolean active = false;
|
||||||
protected boolean connected;
|
|
||||||
|
|
||||||
|
|
||||||
protected Object lock;
|
|
||||||
|
|
||||||
public void start(boolean thread) {
|
public void start(boolean thread) {
|
||||||
|
log.debug("Start");
|
||||||
running = true;
|
running = true;
|
||||||
|
activate();
|
||||||
if (thread) {
|
if (thread) {
|
||||||
|
log.debug("Start thread");
|
||||||
new Thread(this).start();
|
new Thread(this).start();
|
||||||
} else {
|
} else {
|
||||||
|
log.debug("Run directly");
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
activate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
start(THREAD);
|
start(THREAD);
|
||||||
monitorConnection();
|
|
||||||
connected = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
log.debug("Stop");
|
||||||
|
if (active()) {
|
||||||
|
deactivate();
|
||||||
|
}
|
||||||
running = false;
|
running = false;
|
||||||
deactivate();
|
synchronized (this) {
|
||||||
|
notifyAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sleep(int time) {
|
protected void sleep(int time) {
|
||||||
@@ -57,12 +59,6 @@ public abstract class Worker implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void activate() {
|
public void activate() {
|
||||||
if (!running) {
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
synchronized (this) {
|
|
||||||
notifyAll();
|
|
||||||
}
|
|
||||||
active = true;
|
active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,13 +66,6 @@ public abstract class Worker implements Runnable {
|
|||||||
active = false;
|
active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivate(boolean stop) {
|
|
||||||
deactivate();
|
|
||||||
if (stop && running) {
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void run() {
|
public final void run() {
|
||||||
while (running) {
|
while (running) {
|
||||||
if (active()) {
|
if (active()) {
|
||||||
@@ -84,41 +73,15 @@ public abstract class Worker implements Runnable {
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
log.debug("Wait");
|
||||||
wait();
|
wait();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
log.info(e);
|
log.info(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void work();
|
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();
|
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() {
|
public void deactivate() {
|
||||||
try {
|
try {
|
||||||
synchronized (iTunes) {
|
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 JavaInputListener javaInputListener;
|
||||||
protected Button previousDirectionalButton;
|
protected Button previousDirectionalButton;
|
||||||
|
|
||||||
public void initialise(String name) throws DeviceInitialiseException {
|
public void activate(String name) throws DeviceInitialiseException {
|
||||||
try {
|
try {
|
||||||
javaInputListener = new JavaInputListener(this, getDevice(name));
|
javaInputListener = new JavaInputListener(this, getDevice(name));
|
||||||
javaInputListener.start();
|
javaInputListener.start();
|
||||||
@@ -33,7 +33,7 @@ public abstract class JavaInputDevice extends Device {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exit() {
|
public void deactivate() {
|
||||||
javaInputListener.exit();
|
javaInputListener.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class Extreme3DDevice extends JavaInputDevice {
|
|||||||
new Press(Extreme3DButton.TWO),
|
new Press(Extreme3DButton.TWO),
|
||||||
new Press(Extreme3DButton.ELEVEN),
|
new Press(Extreme3DButton.ELEVEN),
|
||||||
new Release(Extreme3DButton.ONE)),
|
new Release(Extreme3DButton.ONE)),
|
||||||
new Task(Target.MANAGER, Action.EXIT));
|
new Task(Target.MIMIS, Action.EXIT));
|
||||||
} catch (MacroException e) {
|
} catch (MacroException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell
|
|||||||
jit.addIntellitypeListener(this);
|
jit.addIntellitypeListener(this);
|
||||||
add(
|
add(
|
||||||
new Hotkey(Key.PRIOR),
|
new Hotkey(Key.PRIOR),
|
||||||
new Task(Target.MANAGER, Action.PREVIOUS));
|
new Task(Target.MIMIS, Action.PREVIOUS));
|
||||||
add(
|
add(
|
||||||
new Hotkey(Key.NEXT),
|
new Hotkey(Key.NEXT),
|
||||||
new Task(Target.MANAGER, Action.NEXT));
|
new Task(Target.MIMIS, Action.NEXT));
|
||||||
add(
|
add(
|
||||||
new Press(CommandButton.VOLUME_DOWN),
|
new Press(CommandButton.VOLUME_DOWN),
|
||||||
new Task(Target.APPLICATIONS, Action.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));
|
new Task(Target.APPLICATIONS, Action.VOLUME_UP));
|
||||||
add(
|
add(
|
||||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 'x'),
|
new Hotkey(Modifier.CTRL | Modifier.WIN, 'x'),
|
||||||
new Task(Target.MANAGER, Action.EXIT));
|
new Task(Target.MIMIS, Action.EXIT));
|
||||||
add(
|
add(
|
||||||
new Hotkey(Modifier.CTRL | Modifier.SHIFT | Modifier.WIN, 'n'),
|
new Hotkey(Modifier.CTRL | Modifier.SHIFT | Modifier.WIN, 'n'),
|
||||||
new Task(Target.APPLICATION, Action.NEXT));
|
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);
|
this(PORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialise() {
|
public void activate() {
|
||||||
try {
|
try {
|
||||||
server = new Server(port);
|
server = new Server(port);
|
||||||
server.start();
|
server.start();
|
||||||
@@ -42,7 +42,7 @@ public class NetworkDevice extends Device {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exit() {
|
public void deactivate() {
|
||||||
server.stop();
|
server.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,19 +65,21 @@ public class NetworkDevice extends Device {
|
|||||||
System.out.println("Server started");
|
System.out.println("Server started");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void work() {
|
||||||
while (running) {
|
System.out.println("Server is waiting for clients");
|
||||||
System.out.println("Server is waiting for clients");
|
try {
|
||||||
try {
|
Socket socket = serverSocket.accept();
|
||||||
Socket socket = serverSocket.accept();
|
Client client = new Client(socket);
|
||||||
Client client = new Client(socket);
|
client.start();
|
||||||
client.start();
|
System.out.println("Client connected");
|
||||||
System.out.println("Client connected");
|
} catch (IOException e) {}
|
||||||
} catch (IOException e) {}
|
}
|
||||||
}
|
|
||||||
|
public void stop() {
|
||||||
for (Client client : clientList) {
|
for (Client client : clientList) {
|
||||||
client.stop();
|
client.stop();
|
||||||
}
|
}
|
||||||
|
super.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +95,7 @@ public class NetworkDevice extends Device {
|
|||||||
clientList.add(this);
|
clientList.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void work() {
|
||||||
try {
|
try {
|
||||||
Object object;
|
Object object;
|
||||||
do {
|
do {
|
||||||
@@ -109,6 +111,9 @@ public class NetworkDevice extends Device {
|
|||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
System.out.println("stoppen");
|
System.out.println("stoppen");
|
||||||
try {
|
try {
|
||||||
disconnect();
|
disconnect();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class PanelDevice extends Device implements PanelButtonListener {
|
|||||||
super(TITLE);
|
super(TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialise() {
|
public void activate() {
|
||||||
panel = new Panel(this);
|
panel = new Panel(this);
|
||||||
//panel.updateTime(12342398);
|
//panel.updateTime(12342398);
|
||||||
//panel.updatePosition(43);
|
//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));
|
add(new Press(PanelButton.VOLUME_UP), new Task(Target.APPLICATION, Action.VOLUME_UP));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exit() {
|
public void deactivate() {
|
||||||
panel.dispose();
|
panel.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,9 +42,4 @@ public abstract class EventHandler extends EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void action(Action action) {}
|
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 {
|
public abstract class EventListener extends Worker {
|
||||||
protected Queue<Event> eventQueue;
|
protected Queue<Event> eventQueue;
|
||||||
protected Object available;
|
protected Object work;
|
||||||
|
|
||||||
public EventListener() {
|
public EventListener() {
|
||||||
eventQueue = new ConcurrentLinkedQueue<Event>();
|
eventQueue = new ConcurrentLinkedQueue<Event>();
|
||||||
available = new Object();
|
work = new Object();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Event event) {
|
public void add(Event event) {
|
||||||
eventQueue.add(event);
|
eventQueue.add(event);
|
||||||
synchronized (available) {
|
synchronized (work) {
|
||||||
available.notifyAll();
|
work.notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void work() {
|
public final void work() {
|
||||||
while (eventQueue.isEmpty()) {
|
while (eventQueue.isEmpty()) {
|
||||||
synchronized (available) {
|
synchronized (work) {
|
||||||
try {
|
try {
|
||||||
available.wait();
|
work.wait();
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
|
if (!running) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event(eventQueue.poll());
|
event(eventQueue.poll());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
super.stop();
|
||||||
|
synchronized (work) {
|
||||||
|
work.notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void event(Event event);
|
public abstract void event(Event event);
|
||||||
}
|
}
|
||||||
@@ -9,20 +9,20 @@ import pm.Event;
|
|||||||
import pm.Worker;
|
import pm.Worker;
|
||||||
import pm.event.EventRouter;
|
import pm.event.EventRouter;
|
||||||
import pm.event.Feedback;
|
import pm.event.Feedback;
|
||||||
import pm.exception.event.spreader.NetworkSpreaderException;
|
import pm.exception.event.router.GlobalRouterException;
|
||||||
|
|
||||||
public class GlobalRouter extends EventRouter {
|
public class GlobalRouter extends EventRouter {
|
||||||
protected Socket socket;
|
protected Socket socket;
|
||||||
protected ObjectOutputStream objectOutputStream;
|
protected ObjectOutputStream objectOutputStream;
|
||||||
protected ObjectInputStream objectInputStream;
|
protected ObjectInputStream objectInputStream;
|
||||||
|
|
||||||
public GlobalRouter(String ip, int port) throws NetworkSpreaderException {
|
public GlobalRouter(String ip, int port) throws GlobalRouterException {
|
||||||
try {
|
try {
|
||||||
socket = new Socket(ip, port);
|
socket = new Socket(ip, port);
|
||||||
objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
|
objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
|
||||||
objectInputStream = new ObjectInputStream(socket.getInputStream());
|
objectInputStream = new ObjectInputStream(socket.getInputStream());
|
||||||
new Worker() {
|
new Worker() {
|
||||||
public void run() {
|
public void work() {
|
||||||
try {
|
try {
|
||||||
Object object;
|
Object object;
|
||||||
do {
|
do {
|
||||||
@@ -41,7 +41,7 @@ public class GlobalRouter extends EventRouter {
|
|||||||
return;
|
return;
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
} catch (IOException e) {}
|
} catch (IOException e) {}
|
||||||
throw new NetworkSpreaderException();
|
throw new GlobalRouterException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void event(Event event) {
|
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 int index = 0;
|
||||||
//protected Object nonEmpty;
|
//protected Object nonEmpty;
|
||||||
|
|
||||||
public ArrayCycle(E... elementArary) {
|
public ArrayCycle(E... elementArray) {
|
||||||
|
if (elementArray != null) {
|
||||||
//nonEmpty = new Object();
|
//nonEmpty = new Object();
|
||||||
for (E element : elementArary) {
|
for (E element : elementArray) {
|
||||||
add(element);
|
add(element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package pm.value;
|
package pm.value;
|
||||||
|
|
||||||
public enum Target {
|
public enum Target {
|
||||||
ALL, MANAGER, DEVICES, APPLICATIONS, APPLICATION, SELF;
|
ALL, MIMIS, DEVICES, APPLICATIONS, APPLICATION, SELF;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user