Nieuwe reorganisaties en onder andere Gui gebruikersvriendelijker gemaakt. Meeste dingen zouden moeten werken, maar toch nog testen!

This commit is contained in:
2012-03-03 21:01:44 +00:00
parent af6dcc4a78
commit 601e4a2464
39 changed files with 432 additions and 691 deletions

View File

@@ -1,6 +1,7 @@
package com.dt.iTunesController;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.DispatchEvents;
@@ -17,7 +18,7 @@ public class iTunes {
ActiveXComponent iTunes;
iTunesEvents iTunesEvents;
DispatchEvents dispatchEvents;
/**
* Initiate iTunes Controller.
* @return
@@ -25,7 +26,7 @@ public class iTunes {
public void connect() {
iTunes = new ActiveXComponent("iTunes.Application");
}
/**
* Add an event handler to the iTunes controller.
* @param itef The class that will handle the iTunes events.
@@ -531,4 +532,8 @@ public class iTunes {
public void playlistAddCurrentTrack(String name) {
playlistAddTrack(name, getCurrentTrack());
}
public void release() {
ComThread.Release();
}
}

View File

@@ -2,6 +2,4 @@ package mimis;
import mimis.input.Input;
public interface Button extends Input {
//public String getCode();
}
public interface Button extends Input {}

View File

@@ -1,23 +1,24 @@
package mimis;
import mimis.exception.worker.ActivateException;
import mimis.util.swing.Dialog;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class Client {
protected Log log = LogFactory.getLog(getClass());
public class Client extends Main {
public static final String IP = "127.0.0.1";
public static final int PORT = 6789;
public Client(String ip, int port) {
super();
//eventRouter = new GlobalRouter(ip, port);
}
public void activate() throws ActivateException {
super.activate();
}
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

@@ -5,10 +5,7 @@ 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;
@@ -41,7 +38,7 @@ public class Gui extends Component {
createFrame(buttonManagerArray);
}
public void activate() throws ActivateException {
protected void activate() throws ActivateException {
listen(Feedback.class);
super.activate();
}
@@ -67,12 +64,7 @@ public class Gui extends Component {
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);
controlPanel.add(buttonManager.createPanel());
}
}
return controlPanel;

View File

@@ -1,56 +1,70 @@
package mimis;
import mimis.application.TestApplication;
import javax.swing.UIManager;
import mimis.application.cmd.windows.gomplayer.GomPlayerApplication;
import mimis.application.cmd.windows.photoviewer.PhotoViewerApplication;
import mimis.application.cmd.windows.winamp.WinampApplication;
import mimis.application.cmd.windows.wmp.WMPApplication;
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.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.manager.CurrentButtonManager;
import mimis.value.Action;
import mimis.value.Target;
import mimis.worker.Component;
public class Main extends Component {
protected TestApplication app;
protected Manager manager;
protected ButtonManager applicationManager, deviceManager;
public class Main extends Mimis {
protected CurrentButtonManager applicationManager;
protected ButtonManager deviceManager;
protected Gui gui;
protected ArrayCycle<Component> componentCycle;
public Main() {
this.router = new Router();
static {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {}
}
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);
public Main() {
super(
new WinampApplication(), new GomPlayerApplication(), new WMPApplication(), new MPCApplication(), // WindowsApplication
new VLCApplication(), // CMDApplication
new iPodApplication(), // LircApplication
new PhotoViewerApplication(), // RobotApplication
new iTunesApplication()); // Component
/* Create general manager */
manager = new Manager(initialize(true, router, new Parser(), gui));
/* Create gui from application and device managers */
applicationManager = new CurrentButtonManager(router, componentCycle, "Applications", currentArray);
deviceManager = new ButtonManager("Devices", initialize(false,
new Extreme3DDevice(), new RumblepadDevice(), // JavaInputDevice
new JIntellitypeDevice(), new PanelDevice(), new LircDevice(), new WiimoteDevice(), new NetworkDevice())); // Component
gui = new Gui(this, applicationManager, deviceManager);
manager.add(initialize(false, gui));
}
public void activate() throws ActivateException {
super.activate();
listen(Task.class);
/* 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();
/* Force display of currenct component when gui started */
gui.start();
while (!gui.active());
end(Action.CURRENT);
}
protected void deactivate() throws DeactivateException {
@@ -59,7 +73,6 @@ public class Main extends Component {
log.debug("Stop managers");
applicationManager.stop();
deviceManager.stop();
manager.stop();
}
public void exit() {
@@ -68,39 +81,15 @@ public class Main extends Component {
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) {
super.end(action);
switch (action) {
case CURRENT:
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();
applicationManager.currentChanged();
break;
}
}

79
java/src/mimis/Mimis.java Normal file
View File

@@ -0,0 +1,79 @@
package mimis;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.input.Feedback;
import mimis.input.Task;
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;
public abstract class Mimis extends Component {
protected Component[] currentArray;
protected Manager manager;
protected ArrayCycle<Component> componentCycle;
public Mimis(Component... currentArray) {
this.currentArray = initialize(false, currentArray);
componentCycle = new ArrayCycle<Component>(currentArray);
router = new Router();
manager = new Manager(initialize(true, router, new Parser()));
}
public void activate() throws ActivateException {
manager.start();
super.activate();
}
protected void deactivate() throws DeactivateException {
super.deactivate();
manager.stop();
}
public void exit() {
super.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 CURRENT:
route(new Feedback("Current component: " + componentCycle.current().getTitle()));
break;
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;
}
}
}

View File

@@ -1,53 +0,0 @@
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

@@ -23,7 +23,7 @@ public abstract class CMDApplication extends Component {
this.title = title;
}
public void activate() throws ActivateException {
protected void activate() throws ActivateException {
super.activate();
String path = getPath();
if (path == null) {
@@ -40,12 +40,16 @@ public abstract class CMDApplication extends Component {
}
public boolean active() {
return active = Native.isRunning(program);
boolean running = Native.isRunning(program);
if (!active && running) {
active = true;
start();
}
return active = running;
}
protected synchronized void deactivate() throws DeactivateException {
super.deactivate();
log.debug(process);
if (process != null) {
process.destroy();
}

View File

@@ -16,14 +16,20 @@ public abstract class WindowsApplication extends CMDApplication {
protected String window;
protected int handle;
public WindowsApplication(String title, String window) {
this(null, title, window);
}
public WindowsApplication(String program, String title, String window) {
super(program, title);
this.window = window;
handle = 0;
}
public void activate() throws ActivateException {
super.activate();
protected void activate() throws ActivateException {
if (program != null) {
super.activate();
}
handle = Native.getHandle(window);
if (handle < 1) {
sleep(START_SLEEP);
@@ -36,15 +42,21 @@ public abstract class WindowsApplication extends CMDApplication {
}
public boolean active() {
if (!active) {
if (!active || program == null) {
handle = Native.getHandle(window);
system(Command.System.MAXIMIZE);
if (handle > 0 && program == null) {
start();
}
}
return super.active();
return program == null ? handle > 0 : super.active();
}
protected void deactivate() throws DeactivateException {
super.deactivate();
if (process == null) {
active = false;
} else {
super.deactivate();
}
close();
}
@@ -62,7 +74,6 @@ public abstract class WindowsApplication extends CMDApplication {
protected int user(int wParam, int lParam) {
return Native.sendMessage(handle, Windows.WM_USER, wParam, lParam);
//return Windows.sendMessage(handle, Windows.WM_USER + wParam, 0, 0);
}
protected void system(Command.System system) {
@@ -75,7 +86,8 @@ public abstract class WindowsApplication extends CMDApplication {
protected void key(Type type, int code) {
int scanCode = Native.mapVirtualKey(code, Windows.MAPVK_VK_TO_VSC);
Native.postMessage(handle, type.getCode(), code, 1 | (scanCode << 16));
Native.postMessage(handle, type.getCode(), code, 1 | (scanCode << 16) | 1 << 30);
sleep(200);
}
protected void key(Type type, char character) {

View File

@@ -1,13 +1,15 @@
package mimis.application;
package mimis.application.cmd.windows.photoviewer;
import mimis.application.robot.RobotApplication;
import mimis.application.cmd.windows.WindowsApplication;
import mimis.exception.worker.DeactivateException;
import mimis.value.Action;
import mimis.value.Key;
import mimis.value.Type;
import mimis.worker.Worker;
public class PhotoViewerApplication extends RobotApplication {
public class PhotoViewerApplication extends WindowsApplication {
protected final static String TITLE = "Photo Viewer";
protected final static String WINDOW = "Photo_Lightweight_Viewer";
protected static final int ZOOM_SLEEP = 100;
protected static final int DELETE_SLEEP = 2000;
@@ -16,7 +18,7 @@ public class PhotoViewerApplication extends RobotApplication {
protected boolean fullscreen;
public PhotoViewerApplication() {
super(TITLE);
super(TITLE, WINDOW);
zoomWorker = new ZoomWorker();
fullscreen = false;
}
@@ -49,38 +51,44 @@ public class PhotoViewerApplication extends RobotApplication {
case VOLUME_DOWN:
zoomWorker.stop();
break;
case FORWARD:
break;
case REWIND:
break;
case NEXT:
press(Key.RIGHT);
key(Type.DOWN, Key.RIGHT);
break;
case PREVIOUS:
press(Key.LEFT);
key(Type.DOWN, Key.LEFT);
break;
case FORWARD:
key(Type.DOWN, Key.CONTROL);
//key(Type.DOWN, '.');
//key(Type.DOWN, Key.DECIMAL);
key(Type.DOWN, Key.OEM_PERIOD);
//key(Type.UP, Key.OEM_PERIOD);
//key(Type.UP, Key.CONTROL);
break;
case MUTE:
press(Key.CONTROL);
press(Key.NUMPAD0);
release(Key.CONTROL);
key(Type.DOWN, Key.CONTROL);
key(Type.DOWN, Key.NUMPAD0);
//press(Key.CONTROL);
//press(Key.NUMPAD0);
//release(Key.CONTROL);
break;
case FULLSCREEN:
press(fullscreen ? Key.ESCAPE : Key.F11);
key(Type.DOWN, fullscreen ? Key.ESCAPE : Key.F11);
fullscreen = !fullscreen;
break;
case DISLIKE:
boolean restore = false;
/*boolean restore = false;
if (fullscreen) {
end(Action.FULLSCREEN);
sleep(DELETE_SLEEP);
restore = true;
}
press(Key.F16);
press('Y');
key(Type.DOWN, Key.F16);
key(Type.DOWN, 'Y');
if (restore) {
sleep(DELETE_SLEEP);
end(Action.FULLSCREEN);
}
}*/
break;
}
}
@@ -95,7 +103,7 @@ public class PhotoViewerApplication extends RobotApplication {
public void work() {
Key key = zoomDirection > 0 ? Key.ADD : Key.SUBTRACT;
press(key);
key(Type.DOWN, key);
sleep(ZOOM_SLEEP);
}
}

View File

@@ -3,6 +3,7 @@ package mimis.application.cmd.windows.winamp;
import mimis.application.cmd.windows.WindowsApplication;
import mimis.exception.worker.DeactivateException;
import mimis.value.Action;
import mimis.value.Command;
import mimis.worker.Worker;
public class WinampApplication extends WindowsApplication {
@@ -48,7 +49,7 @@ public class WinampApplication extends WindowsApplication {
seekWorker = new SeekWorker();
}
protected void deactivate() throws DeactivateException {
public void deactivate() throws DeactivateException {
super.deactivate();
volumeWorker.stop();
seekWorker.stop();
@@ -82,6 +83,7 @@ public class WinampApplication extends WindowsApplication {
log.trace("WinampApplication end: " + action);
switch (action) {
case PLAY:
log.debug("play");
switch (user(0, IPC_ISPLAYING)) {
case STATUS_STOPPED:
command(WINAMP_BUTTON2);
@@ -127,6 +129,7 @@ public class WinampApplication extends WindowsApplication {
command(WINAMP_FILE_QUIT);
break;
case VISUALISER:
system(Command.System.MAXIMIZE);
command(WINAMP_VISPLUGIN);
break;
}

View File

@@ -53,7 +53,7 @@ public class WMPApplication extends WindowsApplication {
break;
}
}
public void end(Action action) {
log.trace("WMPApplication end: " + action);
switch (action) {
@@ -69,7 +69,7 @@ public class WMPApplication extends WindowsApplication {
break;
}
}
protected class VolumeWorker extends Worker {
protected int volumeChangeSign;

View File

@@ -2,7 +2,6 @@ package mimis.application.itunes;
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;
@@ -14,8 +13,7 @@ import com.dt.iTunesController.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;
protected static final boolean EVENTS = false;
protected static final int VOLUME_CHANGE_RATE = 5;
protected static final int VOLUME_SLEEP = 100;
@@ -24,35 +22,29 @@ public class iTunesApplication extends Component implements iTunesEventsInterfac
protected iTunes iTunes;
protected VolumeWorker volumeWorker;
protected boolean handle;
protected boolean quiting;
protected boolean events, handle;
public iTunesApplication() {
super(TITLE);
iTunes = new iTunes();
volumeWorker = new VolumeWorker();
handle = quiting = false;
this(EVENTS);
}
protected void activate() throws ActivateException {
synchronized (iTunes) {
iTunes.connect();
if (!handle) {
iTunes.addEventHandler(this);
handle = true;
}
public iTunesApplication(boolean events) {
super(TITLE);
this.events = events;
volumeWorker = new VolumeWorker();
handle = false;
}
protected synchronized void activate() throws ActivateException {
iTunes = new iTunes();
iTunes.connect();
if (events) {
iTunes.addEventHandler(this);
}
super.activate();
}
public boolean active() {
if (!active && !quiting && Native.isRunning(PROGRAM)) {
try {
activate();
} catch (ActivateException e) {
log.error(e);
}
}
public synchronized boolean active() {
try {
iTunes.getMute();
active = true;
@@ -62,22 +54,29 @@ public class iTunesApplication extends Component implements iTunesEventsInterfac
return active;
}
protected void deactivate() throws DeactivateException {
super.deactivate();
volumeWorker.stop();
try {
if (QUIT) {
quiting = true;
synchronized (iTunes) {
iTunes.quit();
}
quiting = false;
protected synchronized void deactivate() throws DeactivateException {
if (events) {
exit();
} else {
super.deactivate();
volumeWorker.stop();
try {
iTunes.release();
} catch (Exception e) {
log.error(e);
throw new DeactivateException();
}
} catch (Exception e) {
throw new DeactivateException();
}
}
public synchronized void exit() {
try {
iTunes.quit();
} catch (Exception e) {}
volumeWorker.exit();
super.exit();
}
protected void begin(Action action) {
log.trace("iTunesApplication begin: " + action);
if (!active) return;

View File

@@ -10,10 +10,6 @@ import mimis.worker.Component;
public class RobotApplication extends Component {
protected Robot robot;
public RobotApplication(String title) {
super(title);
}
public void activate() throws ActivateException {
try {
robot = new Robot();
@@ -24,7 +20,7 @@ public class RobotApplication extends Component {
}
super.activate();
}
public void press(Key key) {
robot.keyPress(key.getCode());
}

View File

@@ -75,6 +75,10 @@ public class LircDevice extends Component implements LircButtonListener, SignalL
}
public void add(Signal signal, Button button) {
add(signal, button, true);
}
public void add(Signal signal, Button button, boolean general) {
switch (signal) {
case BEGIN:
route(new Press(button));
@@ -84,15 +88,17 @@ public class LircDevice extends Component implements LircButtonListener, SignalL
break;
}
String string = button.toString();
for (Button colorButton : ColorButton.values()) {
if (colorButton.toString().equals(string)) {
add(signal, ColorButton.valueOf(string));
if (general) {
String string = button.toString();
for (Button colorButton : ColorButton.values()) {
if (colorButton.toString().equals(string)) {
add(signal, ColorButton.valueOf(string), false);
}
}
}
for (Button numberButton : NumberButton.values()) {
if (numberButton.toString().equals(string)) {
add(signal, ColorButton.valueOf(string));
for (Button numberButton : NumberButton.values()) {
if (numberButton.toString().equals(string)) {
add(signal, NumberButton.valueOf(string), false);
}
}
}
}

View File

@@ -7,6 +7,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -64,6 +65,7 @@ public class LircService extends Worker {
log.trace("Activate LircService");
try {
socket = new Socket(ip, port);
socket.setSoTimeout(SLEEP);
inputStream = socket.getInputStream();
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
@@ -87,7 +89,7 @@ public class LircService extends Worker {
return active;
}
public synchronized void deactivate() throws DeactivateException {
public void deactivate() throws DeactivateException {
log.trace("Deactivate LircService");
super.deactivate();
try {
@@ -114,6 +116,7 @@ public class LircService extends Worker {
} catch (UnknownButtonException e) {
log.error(e);
}
} catch (SocketTimeoutException e) {
} catch (IOException e) {
log.error(e);
}

View File

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

View File

@@ -9,7 +9,7 @@ import mimis.exception.worker.DeactivateException;
import mimis.worker.Worker;
public class WiimoteDiscovery extends Worker {
protected static final String WIISCAN = "wiiscan.exe";
protected static final String WIISCAN = "wiiscan";
protected static final int TIMEOUT = 1000;
protected WiimoteDevice wiimoteDevice;
protected Process process;
@@ -36,7 +36,6 @@ public class WiimoteDiscovery extends Worker {
Scanner scanner = new Scanner(process.getInputStream());
while (scanner.hasNext()) {
String line = scanner.nextLine();
log.error(line);
if (line.contains("error: BluetoothSetServiceState()")) {
disconnect = true;
return false;

View File

@@ -1,10 +1,14 @@
package mimis.manager;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.border.TitledBorder;
import mimis.worker.Worker;
@@ -19,7 +23,7 @@ public class ButtonManager extends Manager {
}
public ButtonManager(String title, Worker... workerArray) {
this.workerArray = workerArray;
super(workerArray);
this.title = title;
createButtons();
}
@@ -27,22 +31,47 @@ public class ButtonManager extends Manager {
public String getTitle() {
return title;
}
public JToggleButton[] getButtons() {
return buttonMap.values().toArray(new JToggleButton[]{});
public WorkerButton[] getButtons() {
return buttonMap.values().toArray(new WorkerButton[]{});
}
protected void createButtons() {
buttonMap = new HashMap<Worker, WorkerButton>();
for (Worker worker : workerArray) {
for (Worker worker : workerList) {
WorkerButton button = new WorkerButton(worker);
buttonMap.put(worker, button);
}
}
public JPanel createPanel() {
/* Initialize components */
GridBagLayout gridBagLayout = new GridBagLayout();
GridBagConstraints gridBagConstraints = new GridBagConstraints();
JPanel panel = new JPanel(gridBagLayout);
/* Set border */
TitledBorder border = new TitledBorder(getTitle());
border.setTitleJustification(TitledBorder.CENTER);
panel.setBorder(border);
/* Initialize constraints */
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
gridBagConstraints.weightx = 1;
gridBagConstraints.weighty = 1;
/* Add buttons */
for (JToggleButton button : getButtons()) {
gridBagLayout.setConstraints(button, gridBagConstraints);
panel.add(button);
}
return panel;
}
protected void work() {
long before = Calendar.getInstance().getTimeInMillis();
for (Worker worker : workerArray) {
for (Worker worker : workerList) {
buttonMap.get(worker).setPressed(worker.active());
}
long after = Calendar.getInstance().getTimeInMillis();

View File

@@ -0,0 +1,99 @@
package mimis.manager;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.TitledBorder;
import mimis.input.Task;
import mimis.router.Router;
import mimis.util.ArrayCycle;
import mimis.value.Action;
import mimis.value.Signal;
import mimis.value.Target;
import mimis.worker.Component;
import mimis.worker.Worker;
public class CurrentButtonManager extends ButtonManager implements ActionListener {
protected Router router;
protected ArrayCycle<Component> componentCycle;
protected Map<JRadioButton, Worker> radioButtonMap;
public CurrentButtonManager(Router router, ArrayCycle<Component> componentCycle, String title, Worker... workerArray) {
super(title, workerArray);
this.componentCycle = componentCycle;
this.router = router;
radioButtonMap = new HashMap<JRadioButton, Worker>();
}
public JPanel createPanel() {
/* Initialize components */
ButtonGroup buttonGroup = new ButtonGroup();
GridBagLayout gridBagLayout = new GridBagLayout();
GridBagConstraints gridBagConstraints = new GridBagConstraints();
JPanel panel = new JPanel(gridBagLayout);
/* Set border */
TitledBorder border = new TitledBorder(getTitle());
border.setTitleJustification(TitledBorder.CENTER);
panel.setBorder(border);
/* Initialize constraints */
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.weighty = 1;
for (WorkerButton button : getButtons()) {
/* Add button */
gridBagConstraints.gridwidth = GridBagConstraints.RELATIVE;
gridBagConstraints.weightx = 1;
gridBagLayout.setConstraints(button, gridBagConstraints);
panel.add(button);
/* Add radio button */
JRadioButton radioButton = new JRadioButton();
buttonGroup.add(radioButton);
radioButton.addActionListener(this);
radioButtonMap.put(radioButton, button.worker);
gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
gridBagConstraints.weightx = 0;
gridBagLayout.setConstraints(radioButton, gridBagConstraints);
panel.add(radioButton);
}
return panel;
}
public void actionPerformed(ActionEvent event) {
JRadioButton radioButton = (JRadioButton) event.getSource();
if (radioButtonMap.containsKey(radioButton)) {
Worker worker = radioButtonMap.get(radioButton);
if (componentCycle.contains(worker)) {
while (!componentCycle.current().equals(worker)) {
componentCycle.next();
}
router.add(new Task(Action.CURRENT, Target.MAIN, Signal.END));
}
}
}
public void currentChanged() {
Worker worker = componentCycle.current();
if (radioButtonMap.containsValue(worker)) {
for (Entry<JRadioButton, Worker> entry : radioButtonMap.entrySet()) {
if (entry.getValue().equals(worker)) {
JRadioButton radioButton = (JRadioButton) entry.getKey();
radioButton.setSelected(true);
return;
}
}
}
}
}

View File

@@ -1,5 +1,7 @@
package mimis.manager;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import mimis.exception.worker.DeactivateException;
@@ -8,33 +10,42 @@ import mimis.worker.Worker;
public class Manager extends Worker {
protected static final int INTERVAL = 1000;
protected Worker[] workerArray;
protected ArrayList<Worker> workerList;
public Manager(Worker... workerArray) {
this.workerArray = workerArray;
workerList = new ArrayList<Worker>();
add(workerArray);
}
public void add(Worker... workerArray) {
workerList.addAll(Arrays.asList(workerArray));
}
public void remove(Worker... workerArray) {
workerList.removeAll(Arrays.asList(workerArray));
}
protected void deactivate() throws DeactivateException {
super.deactivate();
for (Worker worker : workerArray) {
for (Worker worker : workerList) {
worker.stop();
}
}
public void exit() {
super.exit();
for (Worker worker : workerArray) {
for (Worker worker : workerList) {
worker.exit();
}
}
public int count() {
return workerArray.length;
return workerList.size();
}
protected void work() {
long before = Calendar.getInstance().getTimeInMillis();
for (Worker worker : workerArray) {
for (Worker worker : workerList) {
worker.active();
}
long after = Calendar.getInstance().getTimeInMillis();

View File

@@ -62,7 +62,7 @@ public class Parser extends Component {
}
public void input(State state) {
log.trace("input(State)");
//log.trace("input(State)");
Component component = state.getComponent();
if (!activeMap.containsKey(component)) {
activeMap.put(component, new ArrayList<Active>());

View File

@@ -1,31 +0,0 @@
package mimis.event.router;
import mimis.Event;
import mimis.event.EventListener;
import mimis.event.EventRouter;
import mimis.event.Task;
import mimis.event.feedback.TextFeedback;
import mimis.value.Target;
public class LocalRouter extends EventRouter {
public void event(Event event) {
Target target = event.getTarget();
switch (target) {
case APPLICATION:
if (application != null) {
application.add(event);
}
if (event instanceof Task) {
Task task = (Task) event;
add(new TextFeedback(String.format("Action (%s): %s", task.getSignal(), task.getAction())));
}
break;
default:
for (EventListener eventListener : eventListenerList) {
if (event.compatible(eventListener)) {
eventListener.add(event);
}
}
}
}
}

View File

@@ -8,28 +8,6 @@ public class Native {
System.loadLibrary("mimis");
}
public void start() {
int handle = getHandle("Winamp v1.x");
System.out.println(handle);
//sendMessage(handle, Windows.WM_CLOSE, 0, 0);
/*
while (true) {//Winamp v1.x
System.out.println(isRunning("winamp.exe"));
//System.out.println(new Native().terminate("winamp.exe"));
//System.out.println(new Native().running("wmplayer.exe"));
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}*/
}
public static void main(String[] args) {
new Native().start();
}
public native static int getHandle(String window);
public static int sendMessage(int handle, Windows windows, int wParam, int lParam) {

View File

@@ -1,5 +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, ADD, REMOVE, RESET;
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, CURRENT;
}

View File

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

View File

@@ -61,6 +61,7 @@ public abstract class Component extends Listener<Input> {
public void input(Input input) {
if (input instanceof Task) {
log.debug("task " + ((Task) input).getAction());
task((Task) input);
} else if (input instanceof Feedback) {
feedback((Feedback) input);

View File

@@ -1,73 +0,0 @@
package mimis.worker;
import java.util.Timer;
import java.util.TimerTask;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
public class Periodic extends Worker {
public static final int PERIOD = 500;
protected TimerTask timerTask;
protected Timer timer;
protected int period;
public Periodic() {
this(PERIOD);
}
public Periodic(int period) {
this.period = period;
timerTask = new TimerTask() {
public void run() {
if (deactivate) {
cancel();
}
work();
}
};
timer = new Timer();
}
protected void activate() throws ActivateException {
timer.scheduleAtFixedRate(timerTask, 0, period);
}
protected void deactivate() throws DeactivateException {
//timer.cancel();
}
protected void work() {
log.debug("work!");
}
public void test() {
Periodic periodic = new Periodic();
periodic.start();
sleep(1000);
periodic.stop();
sleep(1000);
periodic.start();
sleep(10000);
System.exit(1);
Worker worker = new Worker() {
protected void work() {
log.debug("work()");
sleep();
}
};
worker.start();
sleep(1000);
worker.stop();
sleep(1000);
worker.start();
worker.start();
}
public static void main(String[] args) {
new Periodic().test();
}
}

View File

@@ -9,9 +9,11 @@ import org.apache.commons.logging.LogFactory;
public abstract class Worker implements Runnable {
protected Log log = LogFactory.getLog(getClass());
protected static final boolean THREAD = true;
protected static final boolean THREAD = false;
protected static final boolean INTERRUPT = false;
protected static final int SLEEP = 100;
protected boolean interrupt;
protected boolean run = false;
protected boolean active = false;
protected boolean activate = false;
@@ -24,11 +26,11 @@ public abstract class Worker implements Runnable {
if (!run) {
run = true;
if (thread) {
log.debug("Start thread");
new Thread(this, getClass().getName()).start();
} else {
log.debug("Run directly");
run();
} else {
log.debug("Start thread");
new Thread(this, getClass().getName()).start();
}
} else {
notifyAll();

View File

@@ -1,13 +1,11 @@
package wiiusej.wiiusejevents.physicalevents;
public class BalanceBoardEvent extends ExpansionEvent {
protected BalanceBoardButtonsEvent buttonsEvent;
protected JoystickEvent balanceBoardJoystickEvent;
public BalanceBoardEvent(int id, float topRight, float bottomRight,
float bottomLeft, float topLeft) {
super(id);
System.out.println(String.format("%f %f %f %f", topRight, bottomRight, bottomLeft, topLeft));
/*balanceBoardJoystickEvent = new JoystickEvent(id, angle,
magnitude, max1, max2, min1, min2, center1, center2);*/
@@ -30,4 +28,4 @@ public class BalanceBoardEvent extends ExpansionEvent {
return out;
}
}
}