This commit is contained in:
2012-05-28 21:38:35 +02:00
parent b2b22001c6
commit af6dcc4a78
97 changed files with 1330 additions and 2244 deletions

View File

@@ -1,42 +0,0 @@
package mimis;
import mimis.event.EventHandler;
import mimis.event.Task;
import mimis.event.feedback.TextFeedback;
import mimis.manager.Titled;
import mimis.value.Action;
import mimis.value.Signal;
public abstract class Application extends EventHandler implements Titled {
protected String title;
protected boolean active;
public Application(String title) {
this.title = title;
}
public String title() {
return title;
}
public void add(Event event) {
if (event instanceof Task) {
Task task = (Task) event;
Action action = task.getAction();
switch (action) {
case START:
if (task.getSignal().equals(Signal.BEGIN)) {
if (active()) {
eventRouter.add(new TextFeedback("Stop application"));
stop();
} else {
eventRouter.add(new TextFeedback("Start application"));
start();
}
}
return;
}
}
super.event(event);
}
}

View File

@@ -1,3 +1,7 @@
package mimis;
public interface Button {}
import mimis.input.Input;
public interface Button extends Input {
//public String getCode();
}

View File

@@ -1,14 +1,5 @@
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.wiimote.WiimoteDevice;
import mimis.event.EventRouter;
import mimis.event.router.GlobalRouter;
import mimis.util.swing.Dialog;
import org.apache.commons.logging.Log;
@@ -20,30 +11,13 @@ public class Client {
public static final String IP = "127.0.0.1";
public static final int PORT = 6789;
protected EventRouter eventRouter;
protected Device[] deviceArray;
public Client(String ip, int port) {
eventRouter = new GlobalRouter(ip, port);
deviceArray = new Device[] {
new LircDevice(),
new WiimoteDevice(),
new PanelDevice(),
new JIntellitypeDevice(),
new RumblepadDevice(),
new Extreme3DDevice(),
new NetworkDevice()};
}
public void start() {
log.debug("Client");
Mimis mimis = new Mimis(eventRouter, deviceArray);
mimis.start();
//eventRouter = new GlobalRouter(ip, port);
}
public static void main(String[] args) {
String ip = Dialog.question("Server IP:", IP);
int port = Integer.valueOf(Dialog.question("Server Port:", PORT));
new Client(ip, port).start();
//new Client(ip, port).start();
}
}

View File

@@ -1,45 +0,0 @@
package mimis;
import mimis.event.EventHandler;
import mimis.exception.worker.DeactivateException;
import mimis.manager.Titled;
import mimis.sequence.EventMap;
import mimis.sequence.SequenceParser;
import mimis.sequence.State;
public abstract class Device extends EventHandler implements Titled {
protected String title;
protected SequenceParser sequenceParser;
public Device(String title) {
this.title = title;
sequenceParser = new SequenceParser(this);
}
public String title() {
return title;
}
/* Worker */
protected void deactivate() throws DeactivateException {
super.deactivate();
sequenceParser.reset();
}
/* SequenceParser */
protected void add(EventMap eventMap) {
sequenceParser.add(eventMap);
}
protected void remove(EventMap eventMap) {
sequenceParser.remove(eventMap);
}
protected void reset() {
sequenceParser.reset();
}
protected void add(State state) {
sequenceParser.add(state);
}
}

View File

@@ -1,35 +0,0 @@
package mimis;
import java.io.Serializable;
import mimis.event.EventListener;
import mimis.value.Target;
public class Event implements Serializable {
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;
}
}
}

View File

@@ -1,101 +0,0 @@
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 mimis.util.Swing;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class GUI extends JFrame {
protected static final long serialVersionUID = 1L;
protected Log log = LogFactory.getLog(getClass());
protected static final String TITLE = "MIMIS Manager";
protected static final String APPLICATION_TITLE = "Applications";
protected static final String DEVICE_TITLE = "Devices";
protected Mimis mimis;
protected TextArea textArea;
public GUI(Mimis mimis, Manager<Application> applicationManager, Manager<Device> deviceManager) {
super(TITLE);
this.mimis = mimis;
setIconImage(Swing.getImage(Mimis.ICON));
createFrame(applicationManager, deviceManager);
}
protected void createFrame(Manager<Application> applicationManager, Manager<Device> deviceManager) {
setLayout(new GridLayout(0, 1));
JPanel controlPanel = createControlPanel(applicationManager, deviceManager);
add(controlPanel);
JPanel feedbackPanel = createTextPanel();
add(feedbackPanel);
setResizable(false);
setVisible(true);
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
pack();
}
protected JPanel createControlPanel(Manager<Application> applicationManager, Manager<Device> deviceManager) {
JPanel controlPanel = new JPanel(new GridLayout(1, 0));
if (applicationManager.count() > 0) {
JPanel applicationPanel = createManagerPanel(applicationManager, APPLICATION_TITLE);
controlPanel.add(applicationPanel);
}
if (deviceManager.count() > 0) {
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 createTextPanel() {
JPanel textPanel = new JPanel();
textArea = new TextArea();
textArea.setEditable(false);
textPanel.add(textArea);
return textPanel;
}
protected void processWindowEvent(WindowEvent event) {
if (event.getID() == WindowEvent.WINDOW_CLOSING) {
log.debug("Window closing");
mimis.exit();
}
}
protected void stop() {
dispose();
}
public void write(String string) {
textArea.append(string);
}
public void writeLine(String string) {
write(string + "\n");
}
public void clear() {
textArea.setText(null);
}
}

106
java/src/mimis/Gui.java Normal file
View File

@@ -0,0 +1,106 @@
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 mimis.exception.worker.ActivateException;
import mimis.input.Feedback;
import mimis.input.Input;
import mimis.manager.ButtonManager;
import mimis.util.Swing;
import mimis.worker.Component;
public class Gui extends Component {
public static final String ICON = "M.png";
public static final String TITLE = "MIMIS Manager";
protected JFrame frame;
protected Component component;
protected TextArea textArea;
public Gui(final Component component, ButtonManager... buttonManagerArray) {
frame = new JFrame(TITLE) {
protected static final long serialVersionUID = 1L;
protected void processWindowEvent(WindowEvent event) {
if (event.getID() == WindowEvent.WINDOW_CLOSING) {
log.debug("Window closing");
component.exit();
}
}
};
this.component = component;
frame.setIconImage(Swing.getImage(ICON));
createFrame(buttonManagerArray);
}
public void activate() throws ActivateException {
listen(Feedback.class);
super.activate();
}
public void exit() {
super.exit();
frame.dispose();
}
protected void createFrame(ButtonManager... buttonManagerArray) {
frame.setLayout(new GridLayout(0, 1));
JPanel controlPanel = createControlPanel(buttonManagerArray);
frame.add(controlPanel);
JPanel feedbackPanel = createTextPanel();
frame.add(feedbackPanel);
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.pack();
}
protected JPanel createControlPanel(ButtonManager... buttonManagerArray) {
JPanel controlPanel = new JPanel(new GridLayout(1, 0));
for (ButtonManager buttonManager : buttonManagerArray) {
if (buttonManager.count() > 0) {
JPanel panel = new JPanel(new GridLayout(0, 1));
panel.add(new JLabel(buttonManager.getTitle(), SwingConstants.CENTER));
for (JToggleButton button : buttonManager.getButtons()) {
panel.add(button);
}
controlPanel.add(panel);
}
}
return controlPanel;
}
protected JPanel createTextPanel() {
JPanel textPanel = new JPanel();
textArea = new TextArea();
textArea.setEditable(false);
textPanel.add(textArea);
return textPanel;
}
public void input(Input input) {
if (input instanceof Feedback) {
writeLine(((Feedback) input).getText());
}
}
public void write(String string) {
textArea.append(string);
}
public void writeLine(String string) {
write(string + "\n");
}
public void clear() {
textArea.setText(null);
}
}

View File

@@ -1,61 +1,111 @@
package mimis;
import mimis.application.PhotoViewerApplication;
import mimis.application.cmd.windows.gomplayer.GomPlayerApplication;
import mimis.application.cmd.windows.winamp.WinampApplication;
import mimis.application.cmd.windows.wmp.WMPApplication;
import mimis.application.TestApplication;
import mimis.application.itunes.iTunesApplication;
import mimis.application.lirc.ipod.iPodApplication;
import mimis.application.mpc.MPCApplication;
import mimis.application.vlc.VLCApplication;
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.wiimote.WiimoteDevice;
import mimis.event.EventRouter;
import mimis.event.router.LocalRouter;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.input.Feedback;
import mimis.input.Task;
import mimis.manager.ButtonManager;
import mimis.manager.Manager;
import mimis.parser.Parser;
import mimis.router.Router;
import mimis.util.ArrayCycle;
import mimis.value.Action;
import mimis.value.Target;
import mimis.worker.Component;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class Main {
protected Log log = LogFactory.getLog(getClass());
protected EventRouter eventRouter;
protected Application[] applicationArray;
protected Device[] deviceArray;
public class Main extends Component {
protected TestApplication app;
protected Manager manager;
protected ButtonManager applicationManager, deviceManager;
protected Gui gui;
protected ArrayCycle<Component> componentCycle;
public Main() {
eventRouter = new LocalRouter();
applicationArray = new Application[] {
new iTunesApplication(),
new GomPlayerApplication(),
new WMPApplication(),
new MPCApplication(),
new VLCApplication(),
new WinampApplication(),
new iPodApplication(),
new PhotoViewerApplication()};
deviceArray = new Device[] {
new LircDevice(),
new WiimoteDevice(),
new PanelDevice(),
new JIntellitypeDevice(),
new RumblepadDevice(),
new Extreme3DDevice(),
new NetworkDevice()};
this.router = new Router();
}
public void start() {
log.debug("Main");
Mimis mimis = new Mimis(eventRouter, applicationArray, deviceArray);
mimis.start();
public void activate() throws ActivateException {
/* Create gui from application and device managers */
Component[] applicationArray = initialize(false, app = new TestApplication(), new iTunesApplication());
applicationManager = new ButtonManager("Applications", applicationArray);
deviceManager = new ButtonManager("Devices", initialize(false, new PanelDevice(), new LircDevice()));
gui = new Gui(this, applicationManager, deviceManager);
/* Create general manager */
manager = new Manager(initialize(true, router, new Parser(), gui));
/* Start managers */
applicationManager.start();
deviceManager.start();
manager.start();
/* Initialize component cycle */
componentCycle = new ArrayCycle<Component>(applicationArray);
listen(Task.class);
super.activate();
app.start();
app.test();
}
protected void deactivate() throws DeactivateException {
super.deactivate();
log.debug("Stop managers");
applicationManager.stop();
deviceManager.stop();
manager.stop();
}
public void exit() {
super.exit();
log.debug("Exit managers");
applicationManager.exit();
deviceManager.exit();
manager.exit();
}
public Component[] initialize(boolean start, Component... componentArray) {
for (Component component : componentArray) {
component.setRouter(router);
if (start) {
component.start();
}
}
return componentArray;
}
public void task(Task task) {
if (task.getTarget().equals(Target.CURRENT)) {
componentCycle.current().add(task);
} else {
super.task(task);
}
}
public void end(Action action) {
switch (action) {
case NEXT:
log.debug("Next component");
route(new Feedback("Next component: " + componentCycle.next().getTitle()));
break;
case PREVIOUS:
log.debug("Previous component");
route(new Feedback("Previous component: " + componentCycle.previous().getTitle()));
break;
case EXIT:
exit();
break;
}
}
public static void main(String[] args) {
new Main().start();
new Main().start(false);
}
}

View File

@@ -1,69 +0,0 @@
package mimis;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JToggleButton;
import mimis.exception.worker.DeactivateException;
import mimis.manager.WorkerButton;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class Manager<T extends Worker> extends Worker {
protected Log log = LogFactory.getLog(getClass());
protected static final long serialVersionUID = 1L;
protected static final int INTERVAL = 1000;
protected Worker[] workerArray;
protected Map<Worker, WorkerButton> buttonMap;
public Manager(T[] workerArray) {
this.workerArray = workerArray;
createButtons();
}
protected void deactivate() throws DeactivateException {
super.deactivate();
for (Worker manageable : workerArray) {
manageable.stop();
}
}
public void exit() {
super.exit();
for (Worker manageable : workerArray) {
manageable.exit();
}
}
public int count() {
return workerArray.length;
}
protected void createButtons() {
buttonMap = new HashMap<Worker, WorkerButton>();
for (Worker manageable : workerArray) {
WorkerButton button = new WorkerButton(manageable);
buttonMap.put(manageable, button);
}
}
protected JToggleButton[] getButtons() {
return buttonMap.values().toArray(new JToggleButton[]{});
}
protected void work() {
long before = Calendar.getInstance().getTimeInMillis();
for (Worker manageable : workerArray) {
boolean active = manageable.active();
WorkerButton button = buttonMap.get(manageable);
button.setPressed(active);
}
long after = Calendar.getInstance().getTimeInMillis();
int sleep = INTERVAL - (int) (after - before);
sleep(sleep);
}
}

View File

@@ -1,122 +0,0 @@
package mimis;
import mimis.event.EventHandler;
import mimis.event.EventRouter;
import mimis.event.Feedback;
import mimis.event.feedback.TextFeedback;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.sequence.SequenceParser;
import mimis.util.ArrayCycle;
import mimis.value.Action;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class Mimis extends EventHandler {
protected Log log = LogFactory.getLog(getClass());
public static final String ICON = "M.png";
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[0], new Device[0]);
}
public Mimis(EventRouter eventRouter, Application[] applicationArray) {
this(eventRouter, applicationArray, new Device[0]);
}
public Mimis(EventRouter eventRouter, Device[] deviceArray) {
this(eventRouter, new Application[0], deviceArray);
}
public Mimis(EventRouter eventRouter, Application[] applicationArray, Device[] deviceArray) {
this.applicationArray = applicationArray;
this.deviceArray = deviceArray;
applicationCycle = new ArrayCycle<Application>(applicationArray);
log.debug("Initialise EventHandler and SequenceParser");
EventHandler.initialise(eventRouter);
SequenceParser.initialise(eventRouter);
log.debug("Add EventListeners to EventRouter");
eventRouter.add(this);
eventRouter.add(applicationArray);
eventRouter.add(deviceArray);
log.debug("Create managers");
applicationManager = new Manager<Application>(applicationArray);
deviceManager = new Manager<Device>(deviceArray);
}
protected void activate() throws ActivateException {
log.debug("Create gui");
gui = new GUI(this, applicationManager, deviceManager);
log.debug("Activate event router");
eventRouter.start();
log.debug("Activate managers");
applicationManager.start();
deviceManager.start();
if (applicationCycle.size() > 0) {
log.debug("Initialise application cycle");
eventRouter.set(applicationCycle.current());
add(new TextFeedback("Current application: " + applicationCycle.current().title()));
}
super.activate();
}
protected void deactivate() throws DeactivateException {
super.deactivate();
log.debug("Stop GUI");
gui.stop();
log.debug("Stop event router");
eventRouter.stop();
log.debug("Stop managers");
applicationManager.stop();
deviceManager.stop();
}
public void exit() {
super.exit();
log.debug("Exit event router");
eventRouter.exit();
log.debug("Exit managers");
applicationManager.exit();
deviceManager.exit();
}
protected void end(Action action) {
switch (action) {
case NEXT:
eventRouter.set(applicationCycle.next());
add(new TextFeedback("Next application: " + applicationCycle.current().title()));
break;
case PREVIOUS:
eventRouter.set(applicationCycle.previous());
add(new TextFeedback("Previous application: " + applicationCycle.current().title()));
break;
case EXIT:
exit();
break;
}
}
protected void feedback(Feedback feedback) {
if (feedback instanceof TextFeedback) {
gui.writeLine(((TextFeedback) feedback).getText());
}
}
}

View File

@@ -0,0 +1,6 @@
package mimis.application;
public interface Application {
}

View File

@@ -1,10 +1,10 @@
package mimis.application;
import mimis.Worker;
import mimis.application.robot.RobotApplication;
import mimis.exception.worker.DeactivateException;
import mimis.value.Action;
import mimis.value.Key;
import mimis.worker.Worker;
public class PhotoViewerApplication extends RobotApplication {
protected final static String TITLE = "Photo Viewer";

View File

@@ -0,0 +1,53 @@
package mimis.application;
import mimis.device.lirc.button.ColorButton;
import mimis.device.wiimote.WiimoteButton;
import mimis.exception.worker.ActivateException;
import mimis.input.Input;
import mimis.input.Task;
import mimis.input.state.Hold;
import mimis.input.state.Press;
import mimis.input.state.Release;
import mimis.input.state.sequence.Sequence;
import mimis.parser.ParserInput;
import mimis.state.TaskMap;
import mimis.value.Action;
import mimis.value.Target;
import mimis.worker.Component;
public class TestApplication extends Component {
public TestApplication() {
super("Test App");
}
public void activate() throws ActivateException {
TaskMap taskMap = new TaskMap();
taskMap.add(new Sequence(
new Hold(ColorButton.BLUE), new Press(WiimoteButton.A), new Release(ColorButton.BLUE)),
new Task(Action.TEST, Target.CURRENT));
route(new ParserInput(Action.ADD, taskMap));
listen(Task.class);
super.activate();
}
public void test() {
while (!active());
route(new Press(ColorButton.BLUE));
/*sleep(1000);
route(new ParserInput(Action.RESET, this, false));*/
sleep(1000);
route(new Press(WiimoteButton.A));
}
public void input(Input input) {
if (input instanceof Task) {
Task task = (Task) input;
log.debug(task.getAction() + " " + task.getSignal() + " " + task.getTarget());
} else {
log.debug(input.getClass());
}
}
}

View File

@@ -3,13 +3,13 @@ package mimis.application.cmd;
import java.io.IOException;
import java.util.Map;
import mimis.Application;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.util.Native;
import mimis.value.Registry;
import mimis.worker.Component;
public abstract class CMDApplication extends Application {
public abstract class CMDApplication extends Component {
protected final static Registry REGISTRY = Registry.LOCAL_MACHINE;
protected final static String KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths";

View File

@@ -1,11 +1,11 @@
package mimis.application.cmd.windows.gomplayer;
import mimis.Worker;
import mimis.application.cmd.windows.WindowsApplication;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.value.Action;
import mimis.value.Amount;
import mimis.worker.Worker;
public class GomPlayerApplication extends WindowsApplication {
protected final static String PROGRAM = "GOM.exe";

View File

@@ -1,9 +1,9 @@
package mimis.application.cmd.windows.winamp;
import mimis.Worker;
import mimis.application.cmd.windows.WindowsApplication;
import mimis.exception.worker.DeactivateException;
import mimis.value.Action;
import mimis.worker.Worker;
public class WinampApplication extends WindowsApplication {
protected final static String PROGRAM = "winamp.exe";

View File

@@ -1,8 +1,8 @@
package mimis.application.cmd.windows.wmp;
import mimis.Worker;
import mimis.application.cmd.windows.WindowsApplication;
import mimis.value.Action;
import mimis.worker.Worker;
public class WMPApplication extends WindowsApplication {
protected final static String PROGRAM = "wmplayer.exe";

View File

@@ -1,18 +1,18 @@
package mimis.application.itunes;
import mimis.Application;
import mimis.Worker;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.util.Native;
import mimis.value.Action;
import mimis.worker.Component;
import mimis.worker.Worker;
import com.dt.iTunesController.ITCOMDisabledReason;
import com.dt.iTunesController.ITTrack;
import com.dt.iTunesController.iTunes;
import com.dt.iTunesController.iTunesEventsInterface;
public class iTunesApplication extends Application implements iTunesEventsInterface {
public class iTunesApplication extends Component implements iTunesEventsInterface {
protected static final String TITLE = "iTunes";
protected static final String PROGRAM = "iTunes.exe";
protected static final boolean QUIT = false;

View File

@@ -1,13 +1,13 @@
package mimis.application.lirc;
import mimis.Application;
import mimis.device.lirc.LircButton;
import mimis.device.lirc.LircService;
import mimis.device.lirc.remote.WC02IPOButton;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.worker.Component;
public class LircApplication extends Application {
public class LircApplication extends Component {
protected LircService lircService;
public LircApplication(String title) {

View File

@@ -1,11 +1,11 @@
package mimis.application.lirc.ipod;
import mimis.Worker;
import mimis.application.lirc.LircApplication;
import mimis.device.lirc.remote.WC02IPOButton;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.value.Action;
import mimis.worker.Worker;
public class iPodApplication extends LircApplication {
protected static final String TITLE = "iPod";

View File

@@ -1,8 +1,8 @@
package mimis.application.mpc;
import mimis.Worker;
import mimis.application.cmd.windows.WindowsApplication;
import mimis.value.Action;
import mimis.worker.Worker;
public class MPCApplication extends WindowsApplication {
protected final static String PROGRAM = "mpc-hc.exe";
@@ -68,7 +68,7 @@ public class MPCApplication extends WindowsApplication {
}
}
public String title() {
public String getTitle() {
return TITLE;
}

View File

@@ -3,11 +3,11 @@ package mimis.application.robot;
import java.awt.AWTException;
import java.awt.Robot;
import mimis.Application;
import mimis.exception.worker.ActivateException;
import mimis.value.Key;
import mimis.worker.Component;
public class RobotApplication extends Application {
public class RobotApplication extends Component {
protected Robot robot;
public RobotApplication(String title) {

View File

@@ -7,7 +7,6 @@ import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import mimis.Worker;
import mimis.application.cmd.CMDApplication;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
@@ -15,6 +14,7 @@ import mimis.util.Native;
import mimis.value.Action;
import mimis.value.Amount;
import mimis.value.Registry;
import mimis.worker.Worker;
public class VLCApplication extends CMDApplication {
protected final static Registry REGISTRY = Registry.CLASSES_ROOT;
@@ -151,7 +151,7 @@ public class VLCApplication extends CMDApplication {
return (muted = !muted) ? 0 : volume;
}
public String title() {
public String getTitle() {
return TITLE;
}

View File

@@ -0,0 +1,5 @@
package mimis.device;
public interface Device {
}

View File

@@ -1,22 +1,22 @@
package mimis.device.javainput;
import mimis.Button;
import mimis.Device;
import mimis.exception.ButtonException;
import mimis.exception.button.UnknownButtonException;
import mimis.exception.button.UnknownDirectionException;
import mimis.exception.device.DeviceNotFoundException;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.sequence.state.Press;
import mimis.sequence.state.Release;
import mimis.input.state.Press;
import mimis.input.state.Release;
import mimis.worker.Component;
import de.hardcode.jxinput.JXInputDevice;
import de.hardcode.jxinput.JXInputManager;
import de.hardcode.jxinput.event.JXInputAxisEvent;
import de.hardcode.jxinput.event.JXInputButtonEvent;
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
public abstract class JavaInputDevice extends Device {
public abstract class JavaInputDevice extends Component {
protected String name;
public JavaInputDevice(String title, String name) {

View File

@@ -3,8 +3,8 @@ package mimis.device.javainput;
import java.util.LinkedList;
import java.util.Queue;
import mimis.Worker;
import mimis.exception.ButtonException;
import mimis.worker.Worker;
import de.hardcode.jxinput.Button;
import de.hardcode.jxinput.Directional;
import de.hardcode.jxinput.JXInputDevice;

View File

@@ -13,18 +13,18 @@ public class Extreme3DDevice extends JavaInputDevice {
protected static final String TITLE = "Extreme 3D";
protected static final String NAME = "Logitech Extreme 3D";
protected static Extreme3DEventMapCycle eventMapCycle;
protected static Extreme3DTaskMapCycle taskMapCycle;
public Extreme3DDevice() {
super(TITLE, NAME);
eventMapCycle = new Extreme3DEventMapCycle();
taskMapCycle = new Extreme3DTaskMapCycle();
}
protected void activate() throws ActivateException {
super.activate();
add(eventMapCycle.mimis);
add(eventMapCycle.player);
add(eventMapCycle.like);
add(taskMapCycle.mimis);
add(taskMapCycle.player);
add(taskMapCycle.like);
}
protected Button getButton(JXInputButtonEvent event) throws UnknownButtonException {

View File

@@ -1,70 +0,0 @@
package mimis.device.javainput.extreme3d;
import mimis.device.EventMapCycle;
import mimis.device.javainput.DirectionButton;
import mimis.event.Task;
import mimis.sequence.EventMap;
import mimis.sequence.state.Press;
import mimis.value.Action;
import mimis.value.Target;
public class Extreme3DEventMapCycle extends EventMapCycle {
protected static final long serialVersionUID = 1L;
public EventMap mimis, player, like;
public Extreme3DEventMapCycle() {
/* Mimis */
mimis = new EventMap();
mimis.add(
new Press(Extreme3DButton.SEVEN),
new Task(Target.MIMIS, Action.PREVIOUS));
mimis.add(
new Press(Extreme3DButton.EIGHT),
new Task(Target.MIMIS, Action.NEXT));
add(mimis);
/* Player */
player = new EventMap();
player.add(
new Press(Extreme3DButton.ONE),
new Task(Target.APPLICATION, Action.PLAY));
player.add(
new Press(Extreme3DButton.TWO),
new Task(Target.APPLICATION, Action.MUTE));
player.add(
new Press(Extreme3DButton.NINE),
new Task(Target.APPLICATION, Action.SHUFFLE));
player.add(
new Press(Extreme3DButton.TEN),
new Task(Target.APPLICATION, Action.REPEAT));
player.add(
new Press(Extreme3DButton.SIX),
new Task(Target.APPLICATION, Action.NEXT));
player.add(
new Press(Extreme3DButton.FOUR),
new Task(Target.APPLICATION, Action.PREVIOUS));
player.add(
new Press(Extreme3DButton.FIVE),
new Task(Target.APPLICATION, Action.FORWARD));
player.add(
new Press(Extreme3DButton.THREE),
new Task(Target.APPLICATION, Action.REWIND));
player.add(
new Press(DirectionButton.SOUTH),
new Task(Target.APPLICATION, Action.VOLUME_DOWN));
player.add(
new Press(DirectionButton.NORTH),
new Task(Target.APPLICATION, Action.VOLUME_UP));
add(player);
like = new EventMap();
like.add(
new Press(Extreme3DButton.ELEVEN),
new Task(Target.APPLICATION, Action.LIKE));
like.add(
new Press(Extreme3DButton.TWELVE),
new Task(Target.APPLICATION, Action.DISLIKE));
add(like);
}
}

View File

@@ -0,0 +1,70 @@
package mimis.device.javainput.extreme3d;
import mimis.device.javainput.DirectionButton;
import mimis.input.Task;
import mimis.input.state.Press;
import mimis.state.TaskMap;
import mimis.state.TaskMapCycle;
import mimis.value.Action;
import mimis.value.Target;
public class Extreme3DTaskMapCycle extends TaskMapCycle {
protected static final long serialVersionUID = 1L;
public TaskMap mimis, player, like;
public Extreme3DTaskMapCycle() {
/* Mimis */
mimis = new TaskMap();
mimis.add(
new Press(Extreme3DButton.SEVEN),
new Task(Action.PREVIOUS, Target.MAIN));
mimis.add(
new Press(Extreme3DButton.EIGHT),
new Task(Action.NEXT, Target.MAIN));
add(mimis);
/* Player */
player = new TaskMap();
player.add(
new Press(Extreme3DButton.ONE),
new Task(Action.PLAY, Target.CURRENT));
player.add(
new Press(Extreme3DButton.TWO),
new Task(Action.MUTE, Target.CURRENT));
player.add(
new Press(Extreme3DButton.NINE),
new Task(Action.SHUFFLE, Target.CURRENT));
player.add(
new Press(Extreme3DButton.TEN),
new Task(Action.REPEAT, Target.CURRENT));
player.add(
new Press(Extreme3DButton.SIX),
new Task(Action.NEXT, Target.CURRENT));
player.add(
new Press(Extreme3DButton.FOUR),
new Task(Action.PREVIOUS, Target.CURRENT));
player.add(
new Press(Extreme3DButton.FIVE),
new Task(Action.FORWARD, Target.CURRENT));
player.add(
new Press(Extreme3DButton.THREE),
new Task(Action.REWIND, Target.CURRENT));
player.add(
new Press(DirectionButton.SOUTH),
new Task(Action.VOLUME_DOWN, Target.CURRENT));
player.add(
new Press(DirectionButton.NORTH),
new Task(Action.VOLUME_UP, Target.CURRENT));
add(player);
like = new TaskMap();
like.add(
new Press(Extreme3DButton.ELEVEN),
new Task(Action.LIKE, Target.CURRENT));
like.add(
new Press(Extreme3DButton.TWELVE),
new Task(Action.DISLIKE, Target.CURRENT));
add(like);
}
}

View File

@@ -13,18 +13,18 @@ public class RumblepadDevice extends JavaInputDevice {
protected static final String TITLE = "RumblePad";
protected static final String NAME = "Logitech RumblePad 2 USB";
protected static RumblepadEventMapCycle eventMapCycle;
protected static RumblepadTaskMapCycle taskMapCycle;
public RumblepadDevice() {
super(TITLE, NAME);
eventMapCycle = new RumblepadEventMapCycle();
taskMapCycle = new RumblepadTaskMapCycle();
}
protected void activate() throws ActivateException {
super.activate();
add(eventMapCycle.mimis);
add(eventMapCycle.player);
add(eventMapCycle.like);
add(taskMapCycle.mimis);
add(taskMapCycle.player);
add(taskMapCycle.like);
}
protected Button getButton(JXInputButtonEvent event) throws UnknownButtonException {

View File

@@ -1,70 +0,0 @@
package mimis.device.javainput.rumblepad;
import mimis.device.EventMapCycle;
import mimis.device.javainput.DirectionButton;
import mimis.event.Task;
import mimis.sequence.EventMap;
import mimis.sequence.state.Press;
import mimis.value.Action;
import mimis.value.Target;
public class RumblepadEventMapCycle extends EventMapCycle {
protected static final long serialVersionUID = 1L;
public EventMap mimis, player, like;
public RumblepadEventMapCycle() {
/* Mimis */
mimis = new EventMap();
mimis.add(
new Press(RumblepadButton.ONE),
new Task(Target.MIMIS, Action.PREVIOUS));
mimis.add(
new Press(RumblepadButton.THREE),
new Task(Target.MIMIS, Action.NEXT));
add(mimis);
/* Player */
player = new EventMap();
player.add(
new Press(DirectionButton.WEST),
new Task(Target.APPLICATION, Action.PLAY));
player.add(
new Press(DirectionButton.EAST),
new Task(Target.APPLICATION, Action.MUTE));
player.add(
new Press(RumblepadButton.NINE),
new Task(Target.APPLICATION, Action.SHUFFLE));
player.add(
new Press(RumblepadButton.TEN),
new Task(Target.APPLICATION, Action.REPEAT));
player.add(
new Press(RumblepadButton.EIGHT),
new Task(Target.APPLICATION, Action.NEXT));
player.add(
new Press(RumblepadButton.SIX),
new Task(Target.APPLICATION, Action.PREVIOUS));
player.add(
new Press(RumblepadButton.SEVEN),
new Task(Target.APPLICATION, Action.FORWARD));
player.add(
new Press(RumblepadButton.FIVE),
new Task(Target.APPLICATION, Action.REWIND));
player.add(
new Press(DirectionButton.SOUTH),
new Task(Target.APPLICATION, Action.VOLUME_DOWN));
player.add(
new Press(DirectionButton.NORTH),
new Task(Target.APPLICATION, Action.VOLUME_UP));
add(player);
like = new EventMap();
like.add(
new Press(RumblepadButton.FOUR),
new Task(Target.APPLICATION, Action.LIKE));
like.add(
new Press(RumblepadButton.TWO),
new Task(Target.APPLICATION, Action.DISLIKE));
add(like);
}
}

View File

@@ -0,0 +1,70 @@
package mimis.device.javainput.rumblepad;
import mimis.device.javainput.DirectionButton;
import mimis.input.Task;
import mimis.input.state.Press;
import mimis.state.TaskMap;
import mimis.state.TaskMapCycle;
import mimis.value.Action;
import mimis.value.Target;
public class RumblepadTaskMapCycle extends TaskMapCycle {
protected static final long serialVersionUID = 1L;
public TaskMap mimis, player, like;
public RumblepadTaskMapCycle() {
/* Mimis */
mimis = new TaskMap();
mimis.add(
new Press(RumblepadButton.ONE),
new Task(Action.PREVIOUS, Target.MAIN));
mimis.add(
new Press(RumblepadButton.THREE),
new Task(Action.NEXT, Target.MAIN));
add(mimis);
/* Player */
player = new TaskMap();
player.add(
new Press(DirectionButton.WEST),
new Task(Action.PLAY, Target.CURRENT));
player.add(
new Press(DirectionButton.EAST),
new Task(Action.MUTE, Target.CURRENT));
player.add(
new Press(RumblepadButton.NINE),
new Task(Action.SHUFFLE, Target.CURRENT));
player.add(
new Press(RumblepadButton.TEN),
new Task(Action.REPEAT, Target.CURRENT));
player.add(
new Press(RumblepadButton.EIGHT),
new Task(Action.NEXT, Target.CURRENT));
player.add(
new Press(RumblepadButton.SIX),
new Task(Action.PREVIOUS, Target.CURRENT));
player.add(
new Press(RumblepadButton.SEVEN),
new Task(Action.FORWARD, Target.CURRENT));
player.add(
new Press(RumblepadButton.FIVE),
new Task(Action.REWIND, Target.CURRENT));
player.add(
new Press(DirectionButton.SOUTH),
new Task(Action.VOLUME_DOWN, Target.CURRENT));
player.add(
new Press(DirectionButton.NORTH),
new Task(Action.VOLUME_UP, Target.CURRENT));
add(player);
like = new TaskMap();
like.add(
new Press(RumblepadButton.FOUR),
new Task(Action.LIKE, Target.CURRENT));
like.add(
new Press(RumblepadButton.TWO),
new Task(Action.DISLIKE, Target.CURRENT));
add(like);
}
}

View File

@@ -9,6 +9,8 @@ import com.melloware.jintellitype.JIntellitype;
public class Hotkey implements Button {
protected static final long serialVersionUID = 1L;
protected static ArrayList<Hotkey> hotkeyList;
protected static JIntellitype jit;

View File

@@ -2,21 +2,21 @@ package mimis.device.jintellitype;
import java.util.ArrayList;
import mimis.Device;
import mimis.exception.button.UnknownButtonException;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.sequence.state.Press;
import mimis.sequence.state.Release;
import mimis.input.state.Press;
import mimis.input.state.Release;
import mimis.worker.Component;
import com.melloware.jintellitype.HotkeyListener;
import com.melloware.jintellitype.IntellitypeListener;
import com.melloware.jintellitype.JIntellitype;
public class JIntellitypeDevice extends Device implements HotkeyListener, IntellitypeListener {
public class JIntellitypeDevice extends Component implements HotkeyListener, IntellitypeListener {
protected static final String TITLE = "Keyboard";
protected JIntellitypeEventMapCycle eventMapCycle;
protected JIntellitypeTaskMapCycle taskMapCycle;
protected ArrayList<Hotkey> hotkeyList;
protected JIntellitype jit;
@@ -25,15 +25,15 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell
hotkeyList = new ArrayList<Hotkey>();
jit = JIntellitype.getInstance();
Hotkey.initialise(hotkeyList, jit);
eventMapCycle = new JIntellitypeEventMapCycle();
taskMapCycle = new JIntellitypeTaskMapCycle();
}
protected void activate() throws ActivateException {
super.activate();
jit.addHotKeyListener(this);
jit.addIntellitypeListener(this);
add(eventMapCycle.mimis);
add(eventMapCycle.player);
add(taskMapCycle.mimis);
add(taskMapCycle.player);
}
public void onIntellitype(int command) {

View File

@@ -1,45 +1,45 @@
package mimis.device.jintellitype;
import mimis.device.EventMapCycle;
import mimis.event.Task;
import mimis.sequence.EventMap;
import mimis.input.Task;
import mimis.state.TaskMap;
import mimis.state.TaskMapCycle;
import mimis.value.Action;
import mimis.value.Key;
import mimis.value.Target;
public class JIntellitypeEventMapCycle extends EventMapCycle {
public class JIntellitypeTaskMapCycle extends TaskMapCycle {
protected static final long serialVersionUID = 1L;
public EventMap mimis, player;
public TaskMap mimis, player;
public JIntellitypeEventMapCycle() {
public JIntellitypeTaskMapCycle() {
/* Mimis */
mimis = new EventMap();
mimis = new TaskMap();
mimis.add(
new Hotkey(Key.PRIOR),
new Task(Target.MIMIS, Action.PREVIOUS));
new Task(Action.PREVIOUS, Target.MAIN));
mimis.add(
new Hotkey(Key.NEXT),
new Task(Target.MIMIS, Action.NEXT));
new Task(Action.NEXT, Target.MAIN));
add(mimis);
/* Player */
player = new EventMap();
player = new TaskMap();
player.add(
CommandButton.VOLUME_DOWN,
new Task(Target.APPLICATIONS, Action.VOLUME_DOWN));
new Task(Action.VOLUME_DOWN, Target.APPLICATIONS));
player.add(
CommandButton.VOLUME_UP,
new Task(Target.APPLICATIONS, Action.VOLUME_UP));
new Task(Action.VOLUME_UP, Target.APPLICATIONS));
player.add(
new Hotkey(Modifier.CTRL | Modifier.WIN, 'x'),
new Task(Target.MIMIS, Action.EXIT));
new Task(Action.EXIT, Target.MAIN));
player.add(
new Hotkey(Modifier.CTRL | Modifier.SHIFT | Modifier.WIN, 'n'),
new Task(Target.APPLICATION, Action.NEXT));
new Task(Action.NEXT, Target.CURRENT));
player.add(
new Hotkey(Modifier.CTRL | Modifier.SHIFT | Modifier.WIN, 'p'),
new Task(Target.APPLICATION, Action.PREVIOUS));
new Task(Action.PREVIOUS, Target.CURRENT));
add(player);
}
}

View File

@@ -4,8 +4,9 @@ import mimis.Button;
import com.melloware.jintellitype.JIntellitype;
public class Modifier implements Button {
protected static final long serialVersionUID = 1L;
public static final int
ALT = JIntellitype.MOD_ALT,
CTRL = JIntellitype.MOD_CONTROL,

View File

@@ -1,43 +1,47 @@
package mimis.device.lirc;
import mimis.Button;
import mimis.Device;
import mimis.device.lirc.button.ColorButton;
import mimis.device.lirc.button.NumberButton;
import mimis.device.lirc.remote.DenonRC176Button;
import mimis.device.lirc.remote.PhiliphsRCLE011Button;
import mimis.device.lirc.remote.SamsungBN5901015AButton;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.sequence.state.Press;
import mimis.sequence.state.Release;
import mimis.input.state.Press;
import mimis.input.state.Release;
import mimis.parser.ParserInput;
import mimis.util.Multiplexer;
import mimis.util.Native;
import mimis.util.multiplexer.SignalListener;
import mimis.value.Action;
import mimis.value.Signal;
import mimis.worker.Component;
public class LircDevice extends Device implements LircButtonListener, SignalListener {
public class LircDevice extends Component implements LircButtonListener, SignalListener<Button> {
protected static final String TITLE = "Lirc";
protected final static String PROGRAM = "winlirc.exe";
protected Multiplexer multiplexer;
protected Multiplexer<Button> multiplexer;
protected LircService lircService;
protected LircEventMapCycle eventMapCycle;
protected LircTaskMapCycle taskMapCycle;
public LircDevice() {
super(TITLE);
multiplexer = new Multiplexer(this);
multiplexer = new Multiplexer<Button>(this);
lircService = new LircService();
lircService.put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values());
lircService.put(DenonRC176Button.NAME, DenonRC176Button.values());
lircService.put(SamsungBN5901015AButton.NAME, SamsungBN5901015AButton.values());
lircService.add(this);
eventMapCycle = new LircEventMapCycle();
taskMapCycle = new LircTaskMapCycle();
}
protected void activate() throws ActivateException {
lircService.start();
add(eventMapCycle.denonRC176);
add(eventMapCycle.philiphsRCLE011);
add(eventMapCycle.samsungBN5901015A);
route(new ParserInput(Action.ADD, taskMapCycle.denonRC176));
route(new ParserInput(Action.ADD, taskMapCycle.philiphsRCLE011));
route(new ParserInput(Action.ADD, taskMapCycle.samsungBN5901015A));
super.activate();
}
@@ -70,14 +74,26 @@ public class LircDevice extends Device implements LircButtonListener, SignalList
multiplexer.add(lircButton);
}
public void add(Signal signal, Object object) {
public void add(Signal signal, Button button) {
switch (signal) {
case BEGIN:
add(new Press((Button) object));
route(new Press(button));
break;
case END:
add(new Release((Button) object));
route(new Release(button));
break;
}
}
String string = button.toString();
for (Button colorButton : ColorButton.values()) {
if (colorButton.toString().equals(string)) {
add(signal, ColorButton.valueOf(string));
}
}
for (Button numberButton : NumberButton.values()) {
if (numberButton.toString().equals(string)) {
add(signal, ColorButton.valueOf(string));
}
}
}
}

View File

@@ -1,33 +0,0 @@
package mimis.device.lirc;
import mimis.device.EventMapCycle;
import mimis.device.lirc.remote.DenonRC176EventMap;
import mimis.device.lirc.remote.PhiliphsRCLE011EventMap;
import mimis.device.lirc.remote.SamsungBN5901015AEventMap;
import mimis.sequence.EventMap;
public class LircEventMapCycle extends EventMapCycle {
protected static final long serialVersionUID = 1L;
public EventMap denonRC176, philiphsRCLE011, samsungBN5901015A;
public LircEventMapCycle() {
add(denonRC176 = new DenonRC176EventMap());
add(philiphsRCLE011 = new PhiliphsRCLE011EventMap());
add(samsungBN5901015A = new SamsungBN5901015AEventMap());
/*
player = new EventMap();
player.add(PanelButton.PREVIOUS, new Task(Target.APPLICATION, Action.PREVIOUS));
player.add(PanelButton.REWIND, new Task(Target.APPLICATION, Action.REWIND));
player.add(PanelButton.STOP, new Task(Target.APPLICATION, Action.STOP));
player.add(PanelButton.PAUSE, new Task(Target.APPLICATION, Action.PAUSE));
player.add(PanelButton.PLAY, new Task(Target.APPLICATION, Action.PLAY));
player.add(PanelButton.FORWARD, new Task(Target.APPLICATION, Action.FORWARD));
player.add(PanelButton.NEXT, new Task(Target.APPLICATION, Action.NEXT));
player.add(PanelButton.VOLUME_DOWN, new Task(Target.APPLICATION, Action.VOLUME_DOWN));
player.add(PanelButton.MUTE, new Task(Target.APPLICATION, Action.MUTE));
player.add(PanelButton.VOLUME_UP, new Task(Target.APPLICATION, Action.VOLUME_UP));
player.add(PanelButton.REPEAT, new Task(Target.APPLICATION, Action.REPEAT));
player.add(PanelButton.SHUFFLE, new Task(Target.APPLICATION, Action.SHUFFLE));
add(player);*/
}
}

View File

@@ -14,12 +14,12 @@ import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.Scanner;
import mimis.Worker;
import mimis.exception.button.UnknownButtonException;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.util.Native;
import mimis.value.Registry;
import mimis.worker.Worker;
public class LircService extends Worker {
public static final String IP = "localhost";

View File

@@ -0,0 +1,19 @@
package mimis.device.lirc;
import mimis.device.lirc.remote.DenonRC176EventMap;
import mimis.device.lirc.remote.PhiliphsRCLE011EventMap;
import mimis.device.lirc.remote.SamsungBN5901015AEventMap;
import mimis.state.TaskMap;
import mimis.state.TaskMapCycle;
public class LircTaskMapCycle extends TaskMapCycle {
protected static final long serialVersionUID = 1L;
public TaskMap denonRC176, philiphsRCLE011, samsungBN5901015A;
public LircTaskMapCycle() {
add(denonRC176 = new DenonRC176EventMap());
add(philiphsRCLE011 = new PhiliphsRCLE011EventMap());
add(samsungBN5901015A = new SamsungBN5901015AEventMap());
}
}

View File

@@ -1,7 +1,7 @@
package mimis.device.lirc.remote;
package mimis.device.lirc.button;
import mimis.Button;
public enum ColorButton implements Button {
RED, GREEN, YELLOW, BLUE;
}
}

View File

@@ -0,0 +1,7 @@
package mimis.device.lirc.button;
import mimis.Button;
public enum NumberButton implements Button {
ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE;
}

View File

@@ -1,32 +1,32 @@
package mimis.device.lirc.remote;
import mimis.event.Task;
import mimis.sequence.EventMap;
import mimis.input.Task;
import mimis.state.TaskMap;
import mimis.value.Action;
import mimis.value.Target;
public class DenonRC176EventMap extends EventMap {
public class DenonRC176EventMap extends TaskMap {
protected static final long serialVersionUID = 1L;
public DenonRC176EventMap() {
/* Mimis */
add(DenonRC176Button.TUNER_UP, new Task(Target.MIMIS, Action.NEXT));
add(DenonRC176Button.TUNER_DOWN, new Task(Target.MIMIS, Action.PREVIOUS));
add(DenonRC176Button.TUNER_UP, new Task(Action.NEXT, Target.MAIN));
add(DenonRC176Button.TUNER_DOWN, new Task(Action.PREVIOUS, Target.MAIN));
/* Application */
add(DenonRC176Button.AMP_POWER, new Task(Target.APPLICATION, Action.START));
add(DenonRC176Button.CD_NEXT, new Task(Target.APPLICATION, Action.NEXT));
add(DenonRC176Button.CD_PREVIOUS, new Task(Target.APPLICATION, Action.PREVIOUS));
add(DenonRC176Button.TAPE_REWIND, new Task(Target.APPLICATION, Action.REWIND));
add(DenonRC176Button.CD_PLAY, new Task(Target.APPLICATION, Action.PLAY));
add(DenonRC176Button.CD_PAUSE, new Task(Target.APPLICATION, Action.PLAY));
add(DenonRC176Button.TAPE_FORWARD, new Task(Target.APPLICATION, Action.FORWARD));
add(DenonRC176Button.AMP_MUTE, new Task(Target.APPLICATION, Action.MUTE));
add(DenonRC176Button.AMP_VOLUME_UP, new Task(Target.APPLICATION, Action.VOLUME_UP));
add(DenonRC176Button.AMP_VOLUME_DOWN, new Task(Target.APPLICATION, Action.VOLUME_DOWN));
add(DenonRC176Button.CD_REPEAT, new Task(Target.APPLICATION, Action.REPEAT));
add(DenonRC176Button.CD_SHUFFLE, new Task(Target.APPLICATION, Action.SHUFFLE));
add(DenonRC176Button.TAPE_AB, new Task(Target.APPLICATION, Action.LIKE));
add(DenonRC176Button.TAPE_REC, new Task(Target.APPLICATION, Action.DISLIKE));
add(DenonRC176Button.AMP_POWER, new Task(Action.START, Target.CURRENT));
add(DenonRC176Button.CD_NEXT, new Task(Action.NEXT, Target.CURRENT));
add(DenonRC176Button.CD_PREVIOUS, new Task(Action.PREVIOUS, Target.CURRENT));
add(DenonRC176Button.TAPE_REWIND, new Task(Action.REWIND, Target.CURRENT));
add(DenonRC176Button.CD_PLAY, new Task(Action.PLAY, Target.CURRENT));
add(DenonRC176Button.CD_PAUSE, new Task(Action.PLAY, Target.CURRENT));
add(DenonRC176Button.TAPE_FORWARD, new Task(Action.FORWARD, Target.CURRENT));
add(DenonRC176Button.AMP_MUTE, new Task(Action.MUTE, Target.CURRENT));
add(DenonRC176Button.AMP_VOLUME_UP, new Task(Action.VOLUME_UP, Target.CURRENT));
add(DenonRC176Button.AMP_VOLUME_DOWN, new Task(Action.VOLUME_DOWN, Target.CURRENT));
add(DenonRC176Button.CD_REPEAT, new Task(Action.REPEAT, Target.CURRENT));
add(DenonRC176Button.CD_SHUFFLE, new Task(Action.SHUFFLE, Target.CURRENT));
add(DenonRC176Button.TAPE_AB, new Task(Action.LIKE, Target.CURRENT));
add(DenonRC176Button.TAPE_REC, new Task(Action.DISLIKE, Target.CURRENT));
}
}

View File

@@ -1,32 +1,32 @@
package mimis.device.lirc.remote;
import mimis.event.Task;
import mimis.sequence.EventMap;
import mimis.input.Task;
import mimis.state.TaskMap;
import mimis.value.Action;
import mimis.value.Target;
public class PhiliphsRCLE011EventMap extends EventMap {
public class PhiliphsRCLE011EventMap extends TaskMap {
protected static final long serialVersionUID = 1L;
public PhiliphsRCLE011EventMap() {
/* Mimis */
add(PhiliphsRCLE011Button.UP, new Task(Target.MIMIS, Action.NEXT));
add(PhiliphsRCLE011Button.DOWN, new Task(Target.MIMIS, Action.PREVIOUS));
add(PhiliphsRCLE011Button.UP, new Task(Action.NEXT, Target.MAIN));
add(PhiliphsRCLE011Button.DOWN, new Task(Action.PREVIOUS, Target.MAIN));
/* Application */
add(PhiliphsRCLE011Button.POWER, new Task(Target.APPLICATION, Action.START));
add(PhiliphsRCLE011Button.PROGRAM_UP, new Task(Target.APPLICATION, Action.NEXT));
add(PhiliphsRCLE011Button.PROGRAM_DOWN, new Task(Target.APPLICATION, Action.PREVIOUS));
add(PhiliphsRCLE011Button.LEFT, new Task(Target.APPLICATION, Action.REWIND));
add(PhiliphsRCLE011Button.TUNE, new Task(Target.APPLICATION, Action.PLAY));
add(PhiliphsRCLE011Button.RIGHT, new Task(Target.APPLICATION, Action.FORWARD));
add(PhiliphsRCLE011Button.VOLUME_DOWN, new Task(Target.APPLICATION, Action.VOLUME_DOWN));
add(PhiliphsRCLE011Button.MUTE, new Task(Target.APPLICATION, Action.MUTE));
add(PhiliphsRCLE011Button.VOLUME_UP, new Task(Target.APPLICATION, Action.VOLUME_UP));
add(PhiliphsRCLE011Button.CLOCK, new Task(Target.APPLICATION, Action.REPEAT));
add(PhiliphsRCLE011Button.OUT, new Task(Target.APPLICATION, Action.SHUFFLE));
add(PhiliphsRCLE011Button.SQUARE, new Task(Target.APPLICATION, Action.FULLSCREEN));
add(PhiliphsRCLE011Button.RED, new Task(Target.APPLICATION, Action.DISLIKE));
add(PhiliphsRCLE011Button.GREEN, new Task(Target.APPLICATION, Action.LIKE));
add(PhiliphsRCLE011Button.POWER, new Task(Action.START, Target.CURRENT));
add(PhiliphsRCLE011Button.PROGRAM_UP, new Task(Action.NEXT, Target.CURRENT));
add(PhiliphsRCLE011Button.PROGRAM_DOWN, new Task(Action.PREVIOUS, Target.CURRENT));
add(PhiliphsRCLE011Button.LEFT, new Task(Action.REWIND, Target.CURRENT));
add(PhiliphsRCLE011Button.TUNE, new Task(Action.PLAY, Target.CURRENT));
add(PhiliphsRCLE011Button.RIGHT, new Task(Action.FORWARD, Target.CURRENT));
add(PhiliphsRCLE011Button.VOLUME_DOWN, new Task(Action.VOLUME_DOWN, Target.CURRENT));
add(PhiliphsRCLE011Button.MUTE, new Task(Action.MUTE, Target.CURRENT));
add(PhiliphsRCLE011Button.VOLUME_UP, new Task(Action.VOLUME_UP, Target.CURRENT));
add(PhiliphsRCLE011Button.CLOCK, new Task(Action.REPEAT, Target.CURRENT));
add(PhiliphsRCLE011Button.OUT, new Task(Action.SHUFFLE, Target.CURRENT));
add(PhiliphsRCLE011Button.SQUARE, new Task(Action.FULLSCREEN, Target.CURRENT));
add(PhiliphsRCLE011Button.RED, new Task(Action.DISLIKE, Target.CURRENT));
add(PhiliphsRCLE011Button.GREEN, new Task(Action.LIKE, Target.CURRENT));
}
}

View File

@@ -1,14 +1,14 @@
package mimis.device.lirc.remote;
import mimis.event.Task;
import mimis.sequence.EventMap;
import mimis.input.Task;
import mimis.state.TaskMap;
import mimis.value.Action;
import mimis.value.Target;
public class SamsungBN5901015AEventMap extends EventMap {
public class SamsungBN5901015AEventMap extends TaskMap {
protected static final long serialVersionUID = 1L;
public SamsungBN5901015AEventMap() {
add(SamsungBN5901015AButton.VOLUME_UP, new Task(Target.APPLICATION, Action.VOLUME_UP));
add(SamsungBN5901015AButton.VOLUME_UP, new Task(Action.VOLUME_UP, Target.CURRENT));
}
}

View File

@@ -9,21 +9,20 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ConcurrentLinkedQueue;
import mimis.Device;
import mimis.Event;
import mimis.Worker;
import mimis.event.Feedback;
import mimis.event.Task;
import mimis.event.feedback.TextFeedback;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.input.Feedback;
import mimis.input.Input;
import mimis.input.Task;
import mimis.value.Action;
import mimis.value.Target;
import mimis.worker.Component;
import mimis.worker.Worker;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class NetworkDevice extends Device {
public class NetworkDevice extends Component {
protected static final String TITLE = "Network";
public static final int PORT = 6789;
@@ -95,7 +94,7 @@ public class NetworkDevice extends Device {
protected synchronized void deactivate() throws DeactivateException {
super.deactivate();
try {
eventRouter.add(new TextFeedback("[NetworkDevice] Closing server socket"));
route(new Feedback("[NetworkDevice] Closing server socket"));
serverSocket.close();
} catch (IOException e) {
log.error(e);
@@ -108,11 +107,11 @@ public class NetworkDevice extends Device {
public void work() {
try {
eventRouter.add(new TextFeedback("[NetworkDevice] Wating for clients"));
route(new Feedback("[NetworkDevice] Wating for clients"));
Socket socket = serverSocket.accept();
Client client = new Client(socket);
client.start();
eventRouter.add(new TextFeedback("[NetworkDevice] Client connected: " + socket.getInetAddress()));
route(new Feedback("[NetworkDevice] Client connected: " + socket.getInetAddress()));
} catch (IOException e) {
log.error(e);
}
@@ -151,9 +150,9 @@ public class NetworkDevice extends Device {
Object object;
do {
object = objectInputStream.readObject();
if (object instanceof Event) {
if (object instanceof Input) {
log.trace(object);
eventRouter.add((Event) object);
route((Input) object);
}
} while (object != null);
} catch (IOException e) {
@@ -166,7 +165,7 @@ public class NetworkDevice extends Device {
protected void deactivate() throws DeactivateException {
super.deactivate();
send(new Task(Target.SELF, Action.STOP));
send(new Task(Action.STOP, Target.SELF));
clientList.remove(this);
try {
inputStream.close();
@@ -175,7 +174,7 @@ public class NetworkDevice extends Device {
} catch (IOException e) {
log.error(e);
}
eventRouter.add(new TextFeedback("[NetworkDevice] Client disconnected: " + socket.getInetAddress()));
route(new Feedback("[NetworkDevice] Client disconnected: " + socket.getInetAddress()));
}
public void send(Object object) {

View File

@@ -8,7 +8,7 @@ import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import mimis.Mimis;
import mimis.Gui;
import mimis.util.Swing;
import mimis.util.swing.HoldButton;
import mimis.util.swing.HoldButtonListener;
@@ -20,7 +20,6 @@ import org.apache.commons.logging.LogFactory;
public class Panel extends JFrame implements HoldButtonListener {
protected static final long serialVersionUID = 1L;
protected Log log = LogFactory.getLog(getClass());
protected final static String TITLE = "MIMIS Panel Device";
protected PanelDevice panelDevice;
@@ -42,7 +41,7 @@ public class Panel extends JFrame implements HoldButtonListener {
Panel(PanelDevice panelDevice) {
super(TITLE);
this.panelDevice = panelDevice;
setIconImage(Swing.getImage(Mimis.ICON));
setIconImage(Swing.getImage(Gui.ICON));
createControls();
layoutControls();
pack();

View File

@@ -1,28 +1,27 @@
package mimis.device.panel;
import javax.swing.WindowConstants;
import mimis.Device;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.sequence.state.Press;
import mimis.sequence.state.Release;
import mimis.input.state.Press;
import mimis.input.state.Release;
import mimis.parser.ParserInput;
import mimis.value.Action;
import mimis.worker.Component;
public class PanelDevice extends Device {
public class PanelDevice extends Component {
protected static final String TITLE = "Panel";
protected Panel panel;
protected PanelEventMapCycle eventMapCycle;
protected PanelTaskMapCycle taskMapCycle;
public PanelDevice() {
super(TITLE);
eventMapCycle = new PanelEventMapCycle();
taskMapCycle = new PanelTaskMapCycle();
}
protected void activate() throws ActivateException {
super.activate();
panel = new Panel(this);
panel.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
add(eventMapCycle.player);
route(new ParserInput(Action.ADD, taskMapCycle.player));
super.activate();
}
public boolean active() {
@@ -30,17 +29,16 @@ public class PanelDevice extends Device {
}
protected void deactivate() throws DeactivateException {
log.debug("deactive() " + panel);
super.deactivate();
panel.dispose();
panel = null;
}
public void buttonPressed(PanelButton panelButton) {
add(new Press(panelButton));
route(new Press(panelButton));
}
public void buttonReleased(PanelButton panelButton) {
add(new Release(panelButton));
route(new Release(panelButton));
}
}

View File

@@ -1,33 +0,0 @@
package mimis.device.panel;
import mimis.device.EventMapCycle;
import mimis.event.Task;
import mimis.sequence.EventMap;
import mimis.sequence.state.Press;
import mimis.value.Action;
import mimis.value.Target;
public class PanelEventMapCycle extends EventMapCycle {
protected static final long serialVersionUID = 1L;
public EventMap player;
public PanelEventMapCycle() {
/* Player */
player = new EventMap();
player.add(new Press(PanelButton.UP), new Task(Target.MIMIS, Action.PREVIOUS));
player.add(new Press(PanelButton.PREVIOUS), new Task(Target.APPLICATION, Action.PREVIOUS));
player.add(new Press(PanelButton.REWIND), new Task(Target.APPLICATION, Action.REWIND));
player.add(new Press(PanelButton.STOP), new Task(Target.APPLICATION, Action.STOP));
player.add(new Press(PanelButton.PAUSE), new Task(Target.APPLICATION, Action.PAUSE));
player.add(new Press(PanelButton.PLAY), new Task(Target.APPLICATION, Action.PLAY));
player.add(new Press(PanelButton.FORWARD), new Task(Target.APPLICATION, Action.FORWARD));
player.add(new Press(PanelButton.DOWN), new Task(Target.MIMIS, Action.NEXT));
player.add(new Press(PanelButton.NEXT), new Task(Target.APPLICATION, Action.NEXT));
player.add(new Press(PanelButton.VOLUME_DOWN), new Task(Target.APPLICATION, Action.VOLUME_DOWN));
player.add(new Press(PanelButton.MUTE), new Task(Target.APPLICATION, Action.MUTE));
player.add(new Press(PanelButton.VOLUME_UP), new Task(Target.APPLICATION, Action.VOLUME_UP));
player.add(new Press(PanelButton.REPEAT), new Task(Target.APPLICATION, Action.REPEAT));
player.add(new Press(PanelButton.SHUFFLE), new Task(Target.APPLICATION, Action.SHUFFLE));
add(player);
}
}

View File

@@ -0,0 +1,33 @@
package mimis.device.panel;
import mimis.input.Task;
import mimis.input.state.Press;
import mimis.state.TaskMap;
import mimis.state.TaskMapCycle;
import mimis.value.Action;
import mimis.value.Target;
public class PanelTaskMapCycle extends TaskMapCycle {
protected static final long serialVersionUID = 1L;
public TaskMap player;
public PanelTaskMapCycle() {
/* Player */
player = new TaskMap();
player.add(new Press(PanelButton.UP), new Task(Action.PREVIOUS, Target.MAIN));
player.add(new Press(PanelButton.PREVIOUS), new Task(Action.PREVIOUS, Target.CURRENT));
player.add(new Press(PanelButton.REWIND), new Task(Action.REWIND, Target.CURRENT));
player.add(new Press(PanelButton.STOP), new Task(Action.STOP, Target.CURRENT));
player.add(new Press(PanelButton.PAUSE), new Task(Action.PAUSE, Target.CURRENT));
player.add(new Press(PanelButton.PLAY), new Task(Action.PLAY, Target.CURRENT));
player.add(new Press(PanelButton.FORWARD), new Task(Action.FORWARD, Target.CURRENT));
player.add(new Press(PanelButton.DOWN), new Task(Action.NEXT, Target.MAIN));
player.add(new Press(PanelButton.NEXT), new Task(Action.NEXT, Target.CURRENT));
player.add(new Press(PanelButton.VOLUME_DOWN), new Task(Action.VOLUME_DOWN, Target.CURRENT));
player.add(new Press(PanelButton.MUTE), new Task(Action.MUTE, Target.CURRENT));
player.add(new Press(PanelButton.VOLUME_UP), new Task(Action.VOLUME_UP, Target.CURRENT));
player.add(new Press(PanelButton.REPEAT), new Task(Action.REPEAT, Target.CURRENT));
player.add(new Press(PanelButton.SHUFFLE), new Task(Action.SHUFFLE, Target.CURRENT));
add(player);
}

View File

@@ -1,18 +1,19 @@
package mimis.device.wiimote;
import mimis.Button;
import mimis.Device;
import mimis.Worker;
import mimis.device.wiimote.gesture.GestureDevice;
import mimis.event.Feedback;
import mimis.exception.button.UnknownButtonException;
import mimis.exception.device.DeviceNotFoundException;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.sequence.state.Press;
import mimis.sequence.state.Release;
import mimis.input.Feedback;
import mimis.input.state.Press;
import mimis.input.state.Release;
import mimis.parser.ParserInput;
import mimis.util.ArrayCycle;
import mimis.value.Action;
import mimis.worker.Component;
import mimis.worker.Worker;
import org.wiigee.event.GestureEvent;
import org.wiigee.event.GestureListener;
@@ -23,7 +24,7 @@ import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
public class WiimoteDevice extends Device implements GestureListener {
public class WiimoteDevice extends Component implements GestureListener {
protected static final String TITLE = "Wiimote";
protected static final int RUMBLE = 50;
protected static final int CONNECTED_TIMEOUT = 500;
@@ -31,7 +32,7 @@ public class WiimoteDevice extends Device implements GestureListener {
protected static final int LED_SLEEP = 50;
protected static WiimoteService wiimoteService;
protected WiimoteEventMapCycle eventMapCycle;
protected WiimoteTaskMapCycle taskMapCycle;
protected WiimoteDiscovery wiimoteDiscovery;
protected Wiimote wiimote;
protected boolean connected;
@@ -47,7 +48,7 @@ public class WiimoteDevice extends Device implements GestureListener {
public WiimoteDevice() {
super(TITLE);
eventMapCycle = new WiimoteEventMapCycle();
taskMapCycle = new WiimoteTaskMapCycle();
wiimoteDiscovery = new WiimoteDiscovery(this);
gestureDevice = new GestureDevice();
gestureDevice.add(this);
@@ -57,7 +58,7 @@ public class WiimoteDevice extends Device implements GestureListener {
/* Worker */
protected void activate() throws ActivateException {
add(eventMapCycle.player);
add(taskMapCycle.player);
wiimote = null;
try {
connect();
@@ -117,14 +118,15 @@ public class WiimoteDevice extends Device implements GestureListener {
switch (action) {
case SHIFT:
log.debug("Shift");
reset();
add(eventMapCycle.mimis);
add(eventMapCycle.like);
route(new ParserInput(Action.RESET, taskMapCycle.player));
add(taskMapCycle.mimis);
add(taskMapCycle.like);
break;
case UNSHIFT:
log.debug("Unshift");
reset();
add(eventMapCycle.player);
route(new ParserInput(Action.RESET, taskMapCycle.mimis));
route(new ParserInput(Action.RESET, taskMapCycle.like));
add(taskMapCycle.player);
break;
case TRAIN:
log.debug("Gesture train");

View File

@@ -3,10 +3,10 @@ package mimis.device.wiimote;
import java.io.IOException;
import java.util.Scanner;
import mimis.Worker;
import mimis.exception.device.DeviceNotFoundException;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.worker.Worker;
public class WiimoteDiscovery extends Worker {
protected static final String WIISCAN = "wiiscan.exe";

View File

@@ -1,50 +0,0 @@
package mimis.device.wiimote;
import mimis.device.EventMapCycle;
import mimis.event.Task;
import mimis.sequence.EventMap;
import mimis.sequence.state.Release;
import mimis.value.Action;
import mimis.value.Target;
public class WiimoteEventMapCycle extends EventMapCycle {
protected static final long serialVersionUID = 1L;
public EventMap mimis, player, gesture, like, shift;
public WiimoteEventMapCycle() {
/* Mimis */
mimis = new EventMap();
mimis.add(WiimoteButton.HOME, new Task(Target.MIMIS, Action.NEXT));
mimis.add(new Release(WiimoteButton.B), new Task(Target.SELF, Action.UNSHIFT));
/* Gesture */
gesture = new EventMap();
gesture.add(WiimoteButton.A, new Task(Action.TRAIN));
gesture.add(WiimoteButton.B, new Task(Action.SAVE));
gesture.add(WiimoteButton.DOWN, new Task(Action.LOAD));
gesture.add(WiimoteButton.HOME, new Task(Action.RECOGNIZE));
add(gesture);
/* Player */
player = new EventMap();
player.add(WiimoteButton.A, new Task(Target.APPLICATION, Action.PLAY));
player.add(WiimoteButton.B, new Task(Target.SELF, Action.SHIFT));
player.add(WiimoteButton.HOME, new Task(Target.APPLICATION, Action.MUTE));
player.add(WiimoteButton.ONE, new Task(Target.APPLICATION, Action.SHUFFLE));
player.add(WiimoteButton.TWO, new Task(Target.APPLICATION, Action.REPEAT));
player.add(WiimoteButton.UP, new Task(Target.APPLICATION, Action.NEXT));
player.add(WiimoteButton.DOWN, new Task(Target.APPLICATION, Action.PREVIOUS));
player.add(WiimoteButton.RIGHT, new Task(Target.APPLICATION, Action.FORWARD));
player.add(WiimoteButton.LEFT, new Task(Target.APPLICATION, Action.REWIND));
player.add(WiimoteButton.MINUS, new Task(Target.APPLICATION, Action.VOLUME_DOWN));
player.add(WiimoteButton.PLUS, new Task(Target.APPLICATION, Action.VOLUME_UP));
add(player);
/* Like */
like = new EventMap();
like.add(WiimoteButton.PLUS, new Task(Target.APPLICATION, Action.LIKE));
like.add(WiimoteButton.MINUS, new Task(Target.APPLICATION, Action.DISLIKE));
add(like);
}
}

View File

@@ -0,0 +1,50 @@
package mimis.device.wiimote;
import mimis.input.Task;
import mimis.input.state.Release;
import mimis.state.TaskMap;
import mimis.state.TaskMapCycle;
import mimis.value.Action;
import mimis.value.Target;
public class WiimoteTaskMapCycle extends TaskMapCycle {
protected static final long serialVersionUID = 1L;
public TaskMap mimis, player, gesture, like, shift;
public WiimoteTaskMapCycle() {
/* Mimis */
mimis = new TaskMap();
mimis.add(WiimoteButton.HOME, new Task(Action.NEXT, Target.MAIN));
mimis.add(new Release(WiimoteButton.B), new Task(Action.UNSHIFT, Target.SELF));
/* Gesture */
gesture = new TaskMap();
gesture.add(WiimoteButton.A, new Task(Action.TRAIN));
gesture.add(WiimoteButton.B, new Task(Action.SAVE));
gesture.add(WiimoteButton.DOWN, new Task(Action.LOAD));
gesture.add(WiimoteButton.HOME, new Task(Action.RECOGNIZE));
add(gesture);
/* Player */
player = new TaskMap();
player.add(WiimoteButton.A, new Task(Action.PLAY, Target.CURRENT));
player.add(WiimoteButton.B, new Task(Action.SHIFT, Target.SELF));
player.add(WiimoteButton.HOME, new Task(Action.MUTE, Target.CURRENT));
player.add(WiimoteButton.ONE, new Task(Action.SHUFFLE, Target.CURRENT));
player.add(WiimoteButton.TWO, new Task(Action.REPEAT, Target.CURRENT));
player.add(WiimoteButton.UP, new Task(Action.NEXT, Target.CURRENT));
player.add(WiimoteButton.DOWN, new Task(Action.PREVIOUS, Target.CURRENT));
player.add(WiimoteButton.RIGHT, new Task(Action.FORWARD, Target.CURRENT));
player.add(WiimoteButton.LEFT, new Task(Action.REWIND, Target.CURRENT));
player.add(WiimoteButton.MINUS, new Task(Action.VOLUME_DOWN, Target.CURRENT));
player.add(WiimoteButton.PLUS, new Task(Action.VOLUME_UP, Target.CURRENT));
add(player);
/* Like */
like = new TaskMap();
like.add(WiimoteButton.PLUS, new Task(Action.LIKE, Target.CURRENT));
like.add(WiimoteButton.MINUS, new Task(Action.DISLIKE, Target.CURRENT));
add(like);
}
}

View File

@@ -1,43 +0,0 @@
package mimis.event;
import mimis.Event;
import mimis.sequence.SequenceParser;
import mimis.value.Action;
public abstract class EventHandler extends EventListener {
protected static EventRouter eventRouter;
protected static SequenceParser sequenceParser;
static {
//sequenceParser = new SequenceParser();
}
public static void initialise(EventRouter eventRouter) {
EventHandler.eventRouter = eventRouter;
}
public final void event(Event event) {
if (event instanceof Feedback) {
feedback((Feedback) event);
} else if (event instanceof Task) {
task((Task) event);
}
}
protected void feedback(Feedback feedback) {}
protected final void task(Task task) {
Action action = task.getAction();
switch (task.getSignal()) {
case BEGIN:
begin(action);
break;
case END:
end(action);
break;
}
}
protected void begin(Action action) {}
protected void end(Action action) {}
}

View File

@@ -1,38 +0,0 @@
package mimis.event;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import mimis.Event;
import mimis.Worker;
public abstract class EventListener extends Worker {
protected Queue<Event> eventQueue;
public EventListener() {
eventQueue = new ConcurrentLinkedQueue<Event>();
}
public void add(Event event) {
log.debug("[EventListener] Add event:" + event + " " + event.getTarget());
eventQueue.add(event);
synchronized (this) {
notifyAll();
}
}
public final void work() {
while (!eventQueue.isEmpty()) {
event(eventQueue.poll());
}
synchronized (this) {
try {
wait();
} catch (InterruptedException e) {
log.info(e);
}
}
}
public abstract void event(Event event);
}

View File

@@ -1,28 +0,0 @@
package mimis.event;
import java.util.ArrayList;
import mimis.Application;
public abstract class EventRouter extends EventListener {
protected ArrayList<EventListener> eventListenerList;
protected Application application;
public void set(Application application) {
this.application = application;
}
public EventRouter() {
eventListenerList = new ArrayList<EventListener>();
}
public void add(EventListener... eventListenerArray) {
for (EventListener eventListener : eventListenerArray) {
eventListenerList.add(eventListener);
}
}
public void remove(EventListener eventListener) {
eventListenerList.remove(eventListener);
}
}

View File

@@ -1,12 +0,0 @@
package mimis.event;
import mimis.Event;
import mimis.value.Target;
public class Feedback extends Event {
protected static final long serialVersionUID = 1L;
public Feedback() {
super(Target.ALL);
}
}

View File

@@ -1,41 +0,0 @@
package mimis.event;
import mimis.Event;
import mimis.value.Action;
import mimis.value.Signal;
import mimis.value.Target;
public class Task extends Event {
protected static final long serialVersionUID = 1L;
public static final Target TARGET = Target.SELF;
protected Action action;
protected Signal signal;
public Task(Action action) {
this(TARGET, action);
}
public Task(Target target, Action action) {
this(target, action, null);
}
public Task(Target target, Action action, Signal signal) {
super(target);
this.action = action;
this.signal = signal;
}
public Action getAction() {
return action;
}
public Signal getSignal() {
return signal;
}
public Task setSignal(Signal signal) {
return new Task(target, action, signal);
}
}

View File

@@ -1,17 +1,16 @@
package mimis.event.feedback;
package mimis.input;
import mimis.event.Feedback;
public class TextFeedback extends Feedback {
public class Feedback implements Input {
protected static final long serialVersionUID = 1L;
protected String text;
public TextFeedback(String text) {
public Feedback(String text) {
this.text = text;
}
public String getText() {
return text;
}
}
}

View File

@@ -0,0 +1,5 @@
package mimis.input;
import java.io.Serializable;
public interface Input extends Serializable {}

View File

@@ -0,0 +1,47 @@
package mimis.input;
import mimis.value.Action;
import mimis.input.Task;
import mimis.value.Signal;
import mimis.value.Target;
public class Task implements Input {
protected static final long serialVersionUID = 1L;
public static final Target TARGET = Target.ALL;
public static final Signal SIGNAL = Signal.NONE;
protected Target target;
protected Action action;
protected Signal signal;
public Task(Action action) {
this(action, TARGET);
}
public Task(Action action, Target target) {
this(action, target, SIGNAL);
}
public Task(Action action, Target target, Signal signal) {
this.target = target;
this.action = action;
this.signal = signal;
}
public Target getTarget() {
return target;
}
public Action getAction() {
return action;
}
public Signal getSignal() {
return signal;
}
public Task setSignal(Signal signal) {
return new Task(action, target, signal);
}

View File

@@ -1,9 +1,10 @@
package mimis.sequence.state;
package mimis.input.state;
import mimis.Button;
import mimis.sequence.State;
public class Hold extends State {
protected static final long serialVersionUID = 1L;
public Hold(Button button) {
super(button);
}

View File

@@ -1,9 +1,10 @@
package mimis.sequence.state;
package mimis.input.state;
import mimis.Button;
import mimis.sequence.State;
public class Press extends State {
protected static final long serialVersionUID = 1L;
public Press(Button button) {
super(button);
}

View File

@@ -0,0 +1,11 @@
package mimis.input.state;
import mimis.Button;
public class Release extends State {
protected static final long serialVersionUID = 1L;
public Release(Button button) {
super(button);
}
}

View File

@@ -0,0 +1,33 @@
package mimis.input.state;
import mimis.Button;
import mimis.input.Input;
import mimis.input.state.State;
import mimis.worker.Component;
public abstract class State implements Input {
protected static final long serialVersionUID = 1L;
protected Button button;
protected Component component;
public Button getButton() {
return button;
}
public State(Button button) {
this.button = button;
}
public void setComponent(Component component) {
this.component = component;
}
public Component getComponent() {
return component;
}
public boolean equals(State state, boolean type) {
return (type || state.getClass().equals(getClass())) && state.getButton().equals(button);
}
}

View File

@@ -1,13 +1,13 @@
package mimis;
package mimis.input.state.sequence;
import java.util.ArrayList;
import mimis.Button;
import mimis.exception.macro.StateOrderException;
import mimis.sequence.Sequence;
import mimis.sequence.State;
import mimis.sequence.state.Hold;
import mimis.sequence.state.Press;
import mimis.sequence.state.Release;
import mimis.input.state.Hold;
import mimis.input.state.Press;
import mimis.input.state.Release;
import mimis.input.state.State;
public class Macro extends Sequence {

View File

@@ -1,4 +1,6 @@
package mimis.sequence;
package mimis.input.state.sequence;
import mimis.input.state.State;
public class Sequence {
protected State[] eventArray;

View File

@@ -0,0 +1,52 @@
package mimis.manager;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JToggleButton;
import mimis.worker.Worker;
public class ButtonManager extends Manager {
protected static final String TITLE = "Workers";
protected String title;
protected Map<Worker, WorkerButton> buttonMap;
public ButtonManager(Worker... workerArray) {
this(TITLE, workerArray);
}
public ButtonManager(String title, Worker... workerArray) {
this.workerArray = workerArray;
this.title = title;
createButtons();
}
public String getTitle() {
return title;
}
public JToggleButton[] getButtons() {
return buttonMap.values().toArray(new JToggleButton[]{});
}
protected void createButtons() {
buttonMap = new HashMap<Worker, WorkerButton>();
for (Worker worker : workerArray) {
WorkerButton button = new WorkerButton(worker);
buttonMap.put(worker, button);
}
}
protected void work() {
long before = Calendar.getInstance().getTimeInMillis();
for (Worker worker : workerArray) {
buttonMap.get(worker).setPressed(worker.active());
}
long after = Calendar.getInstance().getTimeInMillis();
int sleep = INTERVAL - (int) (after - before);
sleep(sleep);
}
}

View File

@@ -0,0 +1,44 @@
package mimis.manager;
import java.util.Calendar;
import mimis.exception.worker.DeactivateException;
import mimis.worker.Worker;
public class Manager extends Worker {
protected static final int INTERVAL = 1000;
protected Worker[] workerArray;
public Manager(Worker... workerArray) {
this.workerArray = workerArray;
}
protected void deactivate() throws DeactivateException {
super.deactivate();
for (Worker worker : workerArray) {
worker.stop();
}
}
public void exit() {
super.exit();
for (Worker worker : workerArray) {
worker.exit();
}
}
public int count() {
return workerArray.length;
}
protected void work() {
long before = Calendar.getInstance().getTimeInMillis();
for (Worker worker : workerArray) {
worker.active();
}
long after = Calendar.getInstance().getTimeInMillis();
int sleep = INTERVAL - (int) (after - before);
sleep(sleep);
}
}

View File

@@ -1,5 +1,5 @@
package mimis.manager;
public interface Titled {
public String title();
public String getTitle();
}

View File

@@ -3,27 +3,26 @@ package mimis.manager;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.Action;
import javax.swing.JToggleButton;
import mimis.Worker;
import mimis.worker.Component;
import mimis.worker.Worker;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class WorkerButton extends JToggleButton implements MouseListener {
protected static final long serialVersionUID = 1L;
protected Log log = LogFactory.getLog(getClass());
protected static final long serialVersionUID = 1L;
protected Worker worker;
protected Action action;
public WorkerButton(Worker worker) {
this.worker = worker;
setFocusable(false);
addMouseListener(this);
if (worker instanceof Titled) {
setText(((Titled) worker).title());
if (worker instanceof Component) {
setText(((Component) worker).getTitle());
}
}
@@ -43,7 +42,7 @@ public class WorkerButton extends JToggleButton implements MouseListener {
public void mouseReleased(MouseEvent e) {}
public void setPressed(boolean pressed) {
if (!isSelected() && pressed || isSelected() && !pressed) {
if ((!isSelected() && pressed) || (isSelected() && !pressed)) {
doClick();
}
}

View File

@@ -0,0 +1,135 @@
package mimis.parser;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
import mimis.exception.worker.ActivateException;
import mimis.input.Input;
import mimis.input.Task;
import mimis.input.state.State;
import mimis.input.state.sequence.Sequence;
import mimis.state.Active;
import mimis.state.TaskMap;
import mimis.value.Action;
import mimis.value.Signal;
import mimis.value.Target;
import mimis.worker.Component;
public class Parser extends Component {
protected TaskMap taskMap;
protected ArrayList<Sequence> sequenceList;
protected HashMap<Component, ArrayList<Active>> activeMap;
public Parser() {
taskMap = new TaskMap();
sequenceList = new ArrayList<Sequence>();
activeMap = new HashMap<Component, ArrayList<Active>>();
}
public void activate() throws ActivateException {
listen(ParserInput.class);
listen(State.class);
super.activate();
}
public void input(Input input) {
if (input instanceof ParserInput) {
input((ParserInput) input);
} else if (input instanceof State) {
input((State) input);
}
}
public void input(ParserInput parserInput) {
log.trace("input(ParserInput)");
Action action = parserInput.getAction();
try {
switch (action) {
case ADD:
add(parserInput.getTaskMap());
return;
case REMOVE:
remove(parserInput.getTaskMap());
return;
case RESET:
reset(parserInput.getComponent(), parserInput.getEnd());
return;
}
} catch (NullPointerException e) {
log.error("Illegal use of ParserInput");
}
}
public void input(State state) {
log.trace("input(State)");
Component component = state.getComponent();
if (!activeMap.containsKey(component)) {
activeMap.put(component, new ArrayList<Active>());
}
ArrayList<Active> activeList = activeMap.get(component);
for (Sequence sequence : sequenceList) {
activeList.add(new Active(sequence));
}
ArrayList<Active> removeList = new ArrayList<Active>();
for (Active active : activeList) {
if (active.next(state)) {
Task task = taskMap.get(active.getSequence());
if (active.first()) {
route(component, (Task) task, Signal.BEGIN);
}
if (active.last()) {
route(component, (Task) task, Signal.END);
removeList.add(active);
}
} else {
removeList.add(active);
}
}
for (Active active : removeList) {
activeList.remove(active);
}
activeMap.put(component, activeList);
if (activeList.isEmpty()) {
activeMap.remove(activeList);
}
}
protected void add(TaskMap taskMap) {
log.trace("add(TaskMap)");
this.taskMap.putAll(taskMap);
sequenceList.addAll(taskMap.keySet());
}
protected void remove(TaskMap taskMap) {
for (Entry<Sequence, Task> eventEntry : taskMap.entrySet()) {
Sequence sequence = eventEntry.getKey();
this.taskMap.remove(sequence);
sequenceList.remove(sequence);
for (Entry<Component, ArrayList<Active>> activeEntry : activeMap.entrySet()) {
ArrayList<Active> activeList = activeEntry.getValue();
activeList.remove(sequence);
}
}
}
protected void reset(Component component, boolean end) {
ArrayList<Active> activeList = activeMap.get(component);
if (end) {
for (Active active : activeList) {
Task task = taskMap.get(active.getSequence());
route(component, task, Signal.END);
}
}
activeList.clear();
}
protected void route(Component component, Task task, Signal signal) {
task = task.setSignal(signal);
if (task.getTarget().equals(Target.SELF)) {
component.add(task);
} else {
route(task);
}
}
}

View File

@@ -0,0 +1,42 @@
package mimis.parser;
import mimis.input.Input;
import mimis.state.TaskMap;
import mimis.value.Action;
import mimis.worker.Component;
public class ParserInput implements Input {
protected static final long serialVersionUID = 1L;
protected Action action;
protected TaskMap taskMap;
protected Component component;
protected boolean end;
public ParserInput(Action action, TaskMap taskMap) {
this.action = action;
this.taskMap = taskMap;
}
public ParserInput(Action action, Component component, boolean end) {
this.action = action;
this.component = component;
this.end = end;
}
public Action getAction() {
return action;
}
public TaskMap getTaskMap() {
return taskMap;
}
public Component getComponent() {
return component;
}
public boolean getEnd() {
return end;
}
}

View File

@@ -1,18 +1,18 @@
package mimis.event.router;
package mimis.router;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import mimis.Event;
import mimis.Worker;
import mimis.event.EventRouter;
import mimis.event.Feedback;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.input.Feedback;
import mimis.input.Task;
import mimis.worker.Component;
import mimis.worker.Worker;
public class GlobalRouter extends EventRouter {
public class GlobalRouter extends Component {
protected String ip;
protected int port;
protected Client client;
@@ -37,9 +37,9 @@ public class GlobalRouter extends EventRouter {
client.stop();
}
public void event(Event event) {
public void task(Task task) {
try {
client.send(event);
client.send(task);
} catch (IOException e) {
log.error(e);
}

View File

@@ -0,0 +1,75 @@
package mimis.router;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
import mimis.Main;
import mimis.application.Application;
import mimis.device.Device;
import mimis.input.Input;
import mimis.input.Task;
import mimis.worker.Component;
public class Router extends Component {
protected HashMap<Component, ArrayList<Class<? extends Input>>> listenMap;
public Router() {
listenMap = new HashMap<Component, ArrayList<Class<? extends Input>>>();
}
public synchronized void listen(Component component, Class<? extends Input> clazz) {
if (!listenMap.containsKey(component)) {
listenMap.put(component, new ArrayList<Class<? extends Input>>());
}
ArrayList<Class<? extends Input>> listenList = listenMap.get(component);
if (!listenList.contains(clazz)) {
listenList.add(clazz);
}
}
public synchronized void ignore(Component component, Class<?> clazz) {
if (listenMap.containsKey(component)) {
ArrayList<Class<? extends Input>> listenList = listenMap.get(component);
listenList.remove(clazz);
if (listenList.isEmpty()) {
listenMap.remove(listenList);
}
}
}
public synchronized void input(Input input) {
for (Entry<Component, ArrayList<Class<? extends Input>>> entry : listenMap.entrySet()) {
Component component = entry.getKey();
if (input instanceof Task) {
if (!target((Task) input, component)) {
continue;
}
}
ArrayList<Class<? extends Input>> listenList = entry.getValue();
for (Class<?> clazz : listenList) {
if (clazz.isInstance(input)) {
component.add(input);
}
}
}
}
protected boolean target(Task task, Component component) {
switch (task.getTarget()) {
case ALL:
return true;
case MAIN:
case CURRENT:
return component instanceof Main;
case DEVICES:
return component instanceof Device;
case APPLICATIONS:
return component instanceof Application;
default:
return false;
}
}
}

View File

@@ -1,90 +0,0 @@
package mimis.sequence;
import java.util.ArrayList;
import java.util.Map.Entry;
import mimis.Event;
import mimis.event.EventHandler;
import mimis.event.EventListener;
import mimis.event.Task;
import mimis.value.Signal;
import mimis.value.Target;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class SequenceParser {
protected Log log = LogFactory.getLog(getClass());
protected EventHandler self;
protected EventMap eventMap;
protected ArrayList<Sequence> sequenceList;
protected ArrayList<Active> activeList;
protected static EventListener eventListener;
public SequenceParser(EventHandler self) {
this.self = self;
eventMap = new EventMap();
sequenceList = new ArrayList<Sequence>();
activeList = new ArrayList<Active>();
}
public static void initialise(EventListener eventListener) {
SequenceParser.eventListener = eventListener;
}
public synchronized void add(EventMap eventMap) {
this.eventMap.putAll(eventMap);
sequenceList.addAll(eventMap.keySet());
}
public synchronized void remove(EventMap eventMap) {
for (Entry<Sequence, Event> entry : eventMap.entrySet()) {
Sequence sequence = entry.getKey();
this.eventMap.remove(sequence);
sequenceList.remove(sequence);
activeList.remove(sequence);
}
}
public synchronized void reset() {
eventMap.clear();
sequenceList.clear();
activeList.clear();
}
public synchronized void add(State state) {
for (Sequence sequence : sequenceList) {
activeList.add(new Active(sequence));
}
ArrayList<Active> removeList = new ArrayList<Active>();
for (Active active : activeList) {
if (active.next(state)) {
Event event = eventMap.get(active.getSequence());
if (active.first()) {
add(event, Signal.BEGIN);
} else if (active.last()) {
add(event, Signal.END);
removeList.add(active);
}
} else {
removeList.add(active);
}
}
for (Active active : removeList) {
activeList.remove(active);
}
}
protected synchronized void add(Event event, Signal signal) {
if (event instanceof Task) {
event = ((Task) event).setSignal(signal);
}
if (event.getTarget().equals(Target.SELF)) {
self.add(event);
} else {
eventListener.add(event);
}
}
}

View File

@@ -1,19 +0,0 @@
package mimis.sequence;
import mimis.Button;
public abstract class State {
protected Button button;
public State(Button button) {
this.button = button;
}
public Button getButton() {
return button;
}
public boolean equals(State state) {
return state.getClass().equals(getClass()) && state.getButton().equals(button);
}
}

View File

@@ -1,10 +0,0 @@
package mimis.sequence.state;
import mimis.Button;
import mimis.sequence.State;
public class Release extends State {
public Release(Button button) {
super(button);
}
}

View File

@@ -1,4 +1,9 @@
package mimis.sequence;
package mimis.state;
import mimis.input.state.Hold;
import mimis.input.state.Press;
import mimis.input.state.State;
import mimis.input.state.sequence.Sequence;
public class Active {
protected Sequence sequence;
@@ -15,7 +20,11 @@ public class Active {
public boolean next(State state) {
State next = sequence.get(++step);
return next == null ? false : state.equals(next);
if (next == null) {
return false;
}
boolean type = state instanceof Press && next instanceof Hold;
return state.equals(next, type);
}
public boolean first() {

View File

@@ -1,14 +1,16 @@
package mimis.sequence;
package mimis.state;
import java.util.HashMap;
import mimis.Button;
import mimis.Event;
import mimis.Macro;
import mimis.event.Task;
import mimis.sequence.state.Press;
import mimis.input.Input;
import mimis.input.Task;
import mimis.input.state.Press;
import mimis.input.state.State;
import mimis.input.state.sequence.Macro;
import mimis.input.state.sequence.Sequence;
public class EventMap extends HashMap<Sequence, Event> {
public class TaskMap extends HashMap<Sequence, Task> implements Input {
protected static final long serialVersionUID = 1L;
public void add(Button button, Task task) {
@@ -34,4 +36,5 @@ public class EventMap extends HashMap<Sequence, Event> {
public void add(Sequence sequence, Task task) {
put(sequence, task);
}
}

View File

@@ -1,12 +1,13 @@
package mimis.device;
package mimis.state;
import mimis.sequence.EventMap;
import mimis.input.Input;
import mimis.state.TaskMap;
import mimis.util.ArrayCycle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class EventMapCycle extends ArrayCycle<EventMap> {
public class TaskMapCycle extends ArrayCycle<TaskMap> implements Input {
protected static final long serialVersionUID = 1L;
protected Log log = LogFactory.getLog(getClass());

View File

@@ -1,7 +0,0 @@
TODO
------------
exceptions en foutmeldingen nakijken/afhandelen/loggen
feedback uitbreiden
mogelijkheid tot webstart onderzoeken

View File

@@ -1,32 +1,32 @@
package mimis.util;
import mimis.Worker;
import mimis.util.multiplexer.SignalListener;
import mimis.value.Signal;
import mimis.worker.Worker;
public class Multiplexer extends Worker {
public class Multiplexer<T> extends Worker {
public static final int TIMEOUT = 150;
protected int threshold;
protected Object object;
protected SignalListener signalListener;
protected T type;
protected SignalListener<T> signalListener;
protected boolean end;
public Multiplexer(SignalListener signalListener) {
public Multiplexer(SignalListener<T> signalListener) {
this(signalListener, TIMEOUT);
}
public Multiplexer(SignalListener signalListener, int treshold) {
public Multiplexer(SignalListener<T> signalListener, int treshold) {
this.signalListener = signalListener;
}
public synchronized void add(Object object) {
if (this.object == null) {
public synchronized void add(T object) {
if (this.type == null) {
signalListener.add(Signal.BEGIN, object);
this.object = object;
this.type = object;
end = true;
start();
} else if (this.object.equals(object)) {
} else if (this.type.equals(object)) {
end = false;
notifyAll();
} else {
@@ -45,8 +45,8 @@ public class Multiplexer extends Worker {
}
} catch (InterruptedException e) {}
if (end) {
signalListener.add(Signal.END, object);
object = null;
signalListener.add(Signal.END, type);
type = null;
stop();
}
end = !end;

View File

@@ -2,6 +2,6 @@ package mimis.util.multiplexer;
import mimis.value.Signal;
public interface SignalListener {
public void add(Signal signal, Object object);
public interface SignalListener<T> {
public void add(Signal signal, T type);
}

View File

@@ -1,20 +1,5 @@
package mimis.value;
public enum Action {
EXIT,
FORWARD,
MUTE,
NEXT,
PAUSE,
PLAY,
PREVIOUS,
REPEAT,
RESUME,
REWIND,
START,
TEST,
VOLUME_DOWN,
VOLUME_UP,
FULLSCREEN,
TRAIN, STOP, SAVE, RECOGNIZE, LOAD, SHUFFLE, FADEOUT, QUIT, VISUALISER, LIKE, DISLIKE, ACTIVATE, SHIFT, UNSHIFT;
EXIT, FORWARD, MUTE, NEXT, PAUSE, PLAY, PREVIOUS, REPEAT, RESUME, REWIND, START, TEST, VOLUME_DOWN, VOLUME_UP, FULLSCREEN, TRAIN, STOP, SAVE, RECOGNIZE, LOAD, SHUFFLE, FADEOUT, QUIT, VISUALISER, LIKE, DISLIKE, ACTIVATE, SHIFT, UNSHIFT, ADD, REMOVE, RESET;
}

View File

@@ -1,5 +1,5 @@
package mimis.value;
public enum Signal {
BEGIN, END;
}
BEGIN, END, NONE;
}

View File

@@ -1,5 +1,5 @@
package mimis.value;
public enum Target {
ALL, MIMIS, DEVICES, APPLICATIONS, APPLICATION, SELF;
ALL, MAIN, DEVICES, APPLICATIONS, SELF, CURRENT;
}

View File

@@ -0,0 +1,102 @@
package mimis.worker;
import mimis.input.Feedback;
import mimis.input.Input;
import mimis.input.Task;
import mimis.input.state.State;
import mimis.router.Router;
import mimis.value.Action;
public abstract class Component extends Listener<Input> {
protected static final String TITLE = "Component";
protected String title;
protected Router router;
public Component() {
this(TITLE);
}
public Component(String title) {
this.title = title;
}
public void setRouter(Router router) {
this.router = router;
}
public String getTitle() {
return title;
}
public void listen(Class<? extends Input> clazz) {
if (router == null) {
log.error("Router not set");
} else {
router.listen(this, clazz);
}
}
public void ignore(Class<? extends Input> clazz) {
if (router == null) {
log.error("Router not set");
} else {
router.ignore(this, clazz);
}
}
public void route(Input input) {
if (router == null) {
log.error("Router not set");
} else {
if (input instanceof State) {
State state = (State) input;
if (state.getComponent() == null) {
state.setComponent(this);
}
}
router.add(input);
}
}
public void input(Input input) {
if (input instanceof Task) {
task((Task) input);
} else if (input instanceof Feedback) {
feedback((Feedback) input);
}
}
protected void task(Task task) {
Action action = task.getAction();
switch (task.getSignal()) {
case BEGIN:
switch (action) {
case START:
start();
break;
case STOP:
stop();
break;
case EXIT:
exit();
break;
default:
begin(action);
break;
}
break;
case END:
end(action);
break;
default:
action(action);
break;
}
}
protected void feedback(Feedback feedback) {}
protected void action(Action action) {}
protected void begin(Action action) {}
protected void end(Action action) {}
}

View File

@@ -3,7 +3,6 @@ package mimis.worker;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import mimis.Worker;
public abstract class Listener<E> extends Worker {
protected Queue<E> queue;
@@ -12,11 +11,9 @@ public abstract class Listener<E> extends Worker {
queue = new ConcurrentLinkedQueue<E>();
}
public void add(E element) {
public synchronized void add(E element) {
queue.add(element);
synchronized (this) {
notifyAll();
}
notifyAll();
}
public final void work() {

View File

@@ -3,7 +3,6 @@ package mimis.worker;
import java.util.Timer;
import java.util.TimerTask;
import mimis.Worker;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;

View File

@@ -1,4 +1,4 @@
package mimis;
package mimis.worker;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;