diff --git a/java/src/mimis/Application.java b/java/src/mimis/Application.java new file mode 100644 index 0000000..d27f488 --- /dev/null +++ b/java/src/mimis/Application.java @@ -0,0 +1,25 @@ +package mimis; + +import mimis.event.EventHandler; +import mimis.manager.Titled; + +public abstract class Application extends EventHandler implements Titled, Exitable { + protected String title; + protected boolean active; + + public Application(String title) { + this.title = title; + active = false; + } + + public String title() { + return title; + } + + public void exit() { + if (active()) { + deactivate(); + } + stop(); + } +} \ No newline at end of file diff --git a/java/src/mimis/Button.java b/java/src/mimis/Button.java new file mode 100644 index 0000000..0fbafb8 --- /dev/null +++ b/java/src/mimis/Button.java @@ -0,0 +1,3 @@ +package mimis; + +public interface Button {} diff --git a/java/src/mimis/Client.java b/java/src/mimis/Client.java new file mode 100644 index 0000000..b5866f1 --- /dev/null +++ b/java/src/mimis/Client.java @@ -0,0 +1,54 @@ +package mimis; + +import mimis.device.javainput.extreme3d.Extreme3DDevice; +import mimis.device.javainput.rumblepad.RumblepadDevice; +import mimis.device.jintellitype.JIntellitypeDevice; +import mimis.device.lirc.LircDevice; +import mimis.device.network.NetworkDevice; +import mimis.device.panel.PanelDevice; +import mimis.device.player.PlayerDevice; +import mimis.device.wiimote.WiimoteDevice; +import mimis.event.EventRouter; +import mimis.event.router.GlobalRouter; +import mimis.exception.event.router.GlobalRouterException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + + +public class Client { + protected Log log = LogFactory.getLog(getClass()); + + public static final String IP = "127.0.0.1"; + public static final int PORT = 6789; + + protected EventRouter eventRouter; + protected Device[] deviceArray; + + public Client() throws GlobalRouterException { + this(IP, PORT); + } + + public Client(String ip, int port) throws GlobalRouterException { + eventRouter = new GlobalRouter(ip, port); + deviceArray = new Device[] { + new LircDevice(), + new WiimoteDevice(), + new PanelDevice(), + new JIntellitypeDevice(), + new PlayerDevice(), + new RumblepadDevice(), + new Extreme3DDevice(), + new NetworkDevice()}; + } + + public void start() { + log.debug("Client"); + Mimis mimis = new Mimis(eventRouter, deviceArray); + mimis.start(); + } + + public static void main(String[] args) { + new Main().start(); + } +} diff --git a/java/src/mimis/Device.java b/java/src/mimis/Device.java new file mode 100644 index 0000000..f4b05a9 --- /dev/null +++ b/java/src/mimis/Device.java @@ -0,0 +1,92 @@ +package mimis; + +import mimis.event.EventHandler; +import mimis.event.Task; +import mimis.event.task.Continuous; +import mimis.event.task.Stopper; +import mimis.macro.Sequence; +import mimis.macro.SequenceListener; +import mimis.macro.State; +import mimis.macro.state.Hold; +import mimis.macro.state.Press; +import mimis.macro.state.Release; +import mimis.manager.Titled; + +public abstract class Device extends EventHandler implements Titled, Exitable { + protected String title; + protected boolean active; + protected SequenceListener sequenceListener; + + static { + SequenceListener.initialise(eventRouter); + } + + public Device(String title) { + this.title = title; + active = false; + sequenceListener = new SequenceListener(this); + } + + /* Register macro's */ + protected void add(Sequence sequence, Task task) { + sequenceListener.add(sequence, task); + } + + protected void add(State state, Task task) { + add(new Sequence(state), task); + } + + protected void add(Press press, Task task, boolean macro) { + if (macro) { + add(new Macro(press), task); + } else { + add((State) press, task); + } + } + + protected void add(Press press, Task task) { + add(press, task, true); + } + + protected void add(Hold hold, Task pressTask, Task releaseTask) { + Button button = hold.getButton(); + add(new Press(button), pressTask, false); + add(new Release(button), releaseTask); + } + + protected void add(Sequence startSequence, Sequence stopSequence, Continuous continuous) { + add(startSequence, continuous); + add(stopSequence, new Stopper(continuous)); + } + + protected void add(State startEvent, State stopEvent, Continuous continuous) { + add(startEvent, continuous); + add(stopEvent, new Stopper(continuous)); + } + + protected void add(Press startPress, Press stopPress, Continuous continuous) { + add(new Macro(startPress), continuous); + add(new Macro(stopPress), new Stopper(continuous)); + } + + protected void add(Hold hold, Continuous continuous) { + Button button = hold.getButton(); + add(new Press(button), new Release(button), continuous); + } + + /* Recognize events */ + protected void add(State state) { + sequenceListener.add(state); + } + + public String title() { + return title; + } + + public void exit() { + if (active()) { + deactivate(); + } + stop(); + } +} diff --git a/java/src/mimis/Event.java b/java/src/mimis/Event.java new file mode 100644 index 0000000..d7eb0d7 --- /dev/null +++ b/java/src/mimis/Event.java @@ -0,0 +1,33 @@ +package mimis; + +import mimis.event.EventListener; +import mimis.value.Target; + +public class Event { + protected static final long serialVersionUID = 1L; + + protected Target target; + + public Event(Target target) { + this.target = target; + } + + public Target getTarget() { + return target; + } + + public boolean compatible(EventListener eventListener) { + switch (target) { + case ALL: + return true; + case MIMIS: + return eventListener instanceof Mimis; + case DEVICES: + return eventListener instanceof Device; + case APPLICATIONS: + return eventListener instanceof Application; + default: + return false; + } + } +} diff --git a/java/src/mimis/Exitable.java b/java/src/mimis/Exitable.java new file mode 100644 index 0000000..86d5ea6 --- /dev/null +++ b/java/src/mimis/Exitable.java @@ -0,0 +1,5 @@ +package mimis; + +public interface Exitable { + public void exit(); +} diff --git a/java/src/mimis/GUI.java b/java/src/mimis/GUI.java new file mode 100644 index 0000000..5a1d398 --- /dev/null +++ b/java/src/mimis/GUI.java @@ -0,0 +1,83 @@ +package mimis; + +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.JToggleButton; +import javax.swing.SwingConstants; +import javax.swing.WindowConstants; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class GUI extends JFrame { + protected Log log = LogFactory.getLog(getClass()); + protected static final long serialVersionUID = 1L; + + protected static final String TITLE = "Mimis GUI"; + protected static final String APPLICATION_TITLE = "Applications"; + protected static final String DEVICE_TITLE = "Devices"; + + protected Mimis mimis; + + public GUI(Mimis mimis, Manager applicationManager, Manager deviceManager) { + super(TITLE); + this.mimis = mimis; + createFrame(applicationManager, deviceManager); + } + + protected void createFrame(Manager applicationManager, Manager deviceManager) { + setLayout(new GridLayout(0, 1)); + 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(Manager applicationManager, Manager deviceManager) { + JPanel controlPanel = new JPanel(new GridLayout(1, 0)); + 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(); + textArea.setEditable(false); + 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(); + } +} diff --git a/java/src/mimis/Macro.java b/java/src/mimis/Macro.java new file mode 100644 index 0000000..e5e7766 --- /dev/null +++ b/java/src/mimis/Macro.java @@ -0,0 +1,49 @@ +package mimis; + +import java.util.ArrayList; + +import mimis.exception.macro.StateOrderException; +import mimis.macro.Sequence; +import mimis.macro.State; +import mimis.macro.state.Hold; +import mimis.macro.state.Press; +import mimis.macro.state.Release; + + +public class Macro extends Sequence { + public Macro(Press press) { + Button button = press.getButton(); + this.eventArray = new State[] {press, new Release(button)}; + } + + public Macro(State... eventArray) throws StateOrderException { + ArrayList