Enkele applicaties en devices grondig getest, omgeschreven naar nieuwigheden en bugs verholpen.

Todo: GOM, VLC, MPC. Interfacen van WMC. Extra knoppen in PanelDevice voor next en previous app?
This commit is contained in:
2011-06-08 20:02:35 +00:00
parent 3bebd1897d
commit ba01c51701
28 changed files with 354 additions and 161 deletions

View File

@@ -7,6 +7,7 @@ import mimis.exception.worker.DeactivateException;
import mimis.manager.Exitable;
import mimis.manager.Titled;
import mimis.value.Action;
import mimis.value.Signal;
public abstract class Application extends EventHandler implements Titled, Exitable {
protected String title;
@@ -26,14 +27,17 @@ public abstract class Application extends EventHandler implements Titled, Exitab
Action action = task.getAction();
switch (action) {
case ACTIVATE:
try {
if (active()) {
deactivate();
} else {
activate();
if (task.getSignal().equals(Signal.BEGIN)) {
try {
log.debug(active());
if (active()) {
deactivate();
} else {
activate();
}
} catch (WorkerException e) {
log.error(e);
}
} catch (WorkerException e) {
log.error(e);
}
return;
}
@@ -41,7 +45,8 @@ public abstract class Application extends EventHandler implements Titled, Exitab
super.event(event);
}
public void stop() {
public void stop() throws DeactivateException {
super.stop();
if (active()) {
try {
deactivate();
@@ -49,6 +54,5 @@ public abstract class Application extends EventHandler implements Titled, Exitab
log.error(e);
}
}
super.stop();
}
}

View File

@@ -32,7 +32,7 @@ public abstract class Device extends EventHandler implements Titled, Exitable {
sequenceParser.reset();
}
public void stop() {
public void stop() throws DeactivateException {
if (active()) {
try {
deactivate();

View File

@@ -11,14 +11,16 @@ import javax.swing.JToggleButton;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import mimis.exception.worker.DeactivateException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class GUI extends JFrame {
protected Log log = LogFactory.getLog(getClass());
protected static final long serialVersionUID = 1L;
protected Log log = LogFactory.getLog(getClass());
protected static final String TITLE = "Mimis GUI";
protected static final String TITLE = "MIMIS Manager";
protected static final String APPLICATION_TITLE = "Applications";
protected static final String DEVICE_TITLE = "Devices";
@@ -69,11 +71,15 @@ public class GUI extends JFrame {
return textPanel;
}
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
protected void processWindowEvent(WindowEvent event) {
if (event.getID() == WindowEvent.WINDOW_CLOSING) {
log.debug("Window closing");
stop();
mimis.stop();
try {
mimis.stop();
} catch (DeactivateException e) {
log.error(e);
}
}
}

View File

@@ -6,6 +6,7 @@ import java.util.Map;
import javax.swing.JToggleButton;
import mimis.exception.worker.DeactivateException;
import mimis.manager.Exitable;
import mimis.manager.ManageButton;
import mimis.manager.Titled;
@@ -26,7 +27,7 @@ public class Manager<T extends Worker & Titled & Exitable> extends Worker {
createButtons();
}
public void stop() {
public void stop() throws DeactivateException {
super.stop();
for (T manageable : manageableArray) {
manageable.stop();

View File

@@ -4,6 +4,7 @@ import mimis.event.EventHandler;
import mimis.event.EventRouter;
import mimis.event.Feedback;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.feedback.TextFeedback;
import mimis.sequence.SequenceParser;
import mimis.util.ArrayCycle;
@@ -73,8 +74,10 @@ public class Mimis extends EventHandler {
super.activate(false);
}
public void stop() {
public void stop() throws DeactivateException {
super.stop();
log.debug("Stop GUI");
gui.stop();
log.debug("Stop event router");
eventRouter.stop();
@@ -95,7 +98,11 @@ public class Mimis extends EventHandler {
add(new TextFeedback("Previous application: " + applicationCycle.current().title()));
break;
case EXIT:
stop();
try {
stop();
} catch (DeactivateException e) {
log.error(e);
}
break;
}
}

View File

@@ -30,14 +30,9 @@ public abstract class Worker implements Runnable {
start(THREAD);
}
public void stop() {
log.trace("Stop");
public void stop() throws DeactivateException {
if (active()) {
try {
deactivate();
} catch (DeactivateException e) {
log.error(e);
}
deactivate();
}
running = false;
synchronized (this) {
@@ -91,7 +86,6 @@ public abstract class Worker implements Runnable {
} else {
try {
synchronized (this) {
log.trace("Wait");
wait();
}
} catch (InterruptedException e) {

View File

@@ -23,8 +23,8 @@ public abstract class CMDApplication extends Application {
}
public void activate() throws ActivateException {
super.activate();
String key = String.format("%s\\%s", REGISTRY, program);
// Check of naam is gevonden in register
String path = Native.getValue(key);
try {
String command = path.startsWith("\"") ? path : String.format("\"%s\"", path);
@@ -33,7 +33,6 @@ public abstract class CMDApplication extends Application {
} catch (IOException e) {
throw new ActivateException();
}
super.activate();
}
public boolean active() {
@@ -45,9 +44,9 @@ public abstract class CMDApplication extends Application {
}
public void deactivate() throws DeactivateException {
super.deactivate();
if (process != null) {
process.destroy();
}
super.deactivate();
}
}

View File

@@ -1,8 +1,13 @@
package mimis.application.cmd.windows;
import java.io.IOException;
import mimis.application.cmd.CMDApplication;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.util.Windows;
import mimis.util.VBScript;
import mimis.value.Command;
import mimis.value.Key;
import mimis.value.Type;
@@ -12,7 +17,6 @@ public abstract class WindowsApplication extends CMDApplication {
protected final static int START_SLEEP = 500;
protected String name;
protected Process process;
protected int handle;
@@ -23,10 +27,10 @@ public abstract class WindowsApplication extends CMDApplication {
}
public void activate() throws ActivateException {
super.activate();
handle = Windows.findWindow(name, null);
log.info(handle);
if (handle < 1) {
super.activate();
sleep(START_SLEEP);
handle = Windows.findWindow(name, null);
}
@@ -40,6 +44,15 @@ public abstract class WindowsApplication extends CMDApplication {
return (handle = Windows.findWindow(name, null)) > 0;
}
public void deactivate() throws DeactivateException {
try {
VBScript.terminate(program);
} catch (IOException e) {
log.error(e);
throw new DeactivateException();
}
}
protected void command(Command command) {
Windows.sendMessage(handle, Windows.WM_APPCOMMAND, handle, command.getCode() << 16);
}

View File

@@ -12,8 +12,8 @@ public class GomPlayerApplication extends WindowsApplication {
super(PROGRAM, TITLE, NAME);
}
public void action(Action action) {
log.trace("GomPlayerApplication: " + action);
public void begin(Action action) {
log.trace("GomPlayerApplication begin: " + action);
switch (action) {
case PLAY:
command(0x800C);

View File

@@ -1,6 +1,9 @@
package mimis.application.cmd.windows.winamp;
import mimis.Worker;
import mimis.application.cmd.windows.WindowsApplication;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.value.Action;
public class WinampApplication extends WindowsApplication {
@@ -30,6 +33,11 @@ public class WinampApplication extends WindowsApplication {
protected final static int WINAMP_BUTTON4_SHIFT = 40147;
protected final static int WINAMP_VISPLUGIN = 40192;
protected static final int VOLUME_SLEEP = 50;
protected static final int SEEK_SLEEP = 100;
protected VolumeWorker volumeWorker;
protected SeekWorker seekWorker;
protected double volume;
protected boolean muted;
protected boolean forward;
@@ -39,29 +47,54 @@ public class WinampApplication extends WindowsApplication {
super(PROGRAM, TITLE, NAME);
volume = getVolume();
muted = volume == 0;
volumeWorker = new VolumeWorker();
seekWorker = new SeekWorker();
}
public void stop() throws DeactivateException {
super.stop();
volumeWorker.stop();
seekWorker.stop();
}
public void begin(Action action) {
log.trace("WinampApplication: " + action);
log.trace("WinampApplication begin: " + action);
switch (action) {
case FORWARD:
forward = true;
while (forward) {
command(WINAMP_FFWD5S);
sleep(200);
}
break;
case REWIND:
command(WINAMP_REW5S);
break;
case VOLUME_UP:
try {
volumeWorker.activate(1);
} catch (ActivateException e) {
log.error(e);
}
break;
case VOLUME_DOWN:
try {
volumeWorker.activate(-1);
} catch (ActivateException e) {
log.error(e);
}
break;
case FORWARD:
try {
seekWorker.activate(1);
} catch (ActivateException e) {
log.error(e);
}
break;
case REWIND:
try {
seekWorker.activate(-1);
} catch (ActivateException e) {
log.error(e);
}
break;
}
}
public void end(Action action) {
log.trace("WinampApplication: " + action);
log.trace("WinampApplication end: " + action);
switch (action) {
case PLAY:
System.out.println(user(0, IPC_ISPLAYING));
switch (user(0, IPC_ISPLAYING)) {
case STATUS_STOPPED:
command(WINAMP_BUTTON2);
@@ -78,10 +111,12 @@ public class WinampApplication extends WindowsApplication {
command(WINAMP_BUTTON1);
break;
case FORWARD:
forward = false;
break;
case REWIND:
command(WINAMP_REW5S);
try {
seekWorker.deactivate();
} catch (DeactivateException e) {
log.error(e);
}
break;
case MUTE:
if (muted) {
@@ -93,11 +128,12 @@ public class WinampApplication extends WindowsApplication {
muted = !muted;
break;
case VOLUME_UP:
command(WINAMP_VOLUMEUP);
break;
case VOLUME_DOWN:
System.out.println(getVolume());
command(WINAMP_VOLUMEDOWN);
try {
volumeWorker.deactivate();
} catch (DeactivateException e) {
log.error(e);
}
break;
case SHUFFLE:
command(WINAMP_FILE_SHUFFLE);
@@ -132,4 +168,32 @@ public class WinampApplication extends WindowsApplication {
public int getElapsed() {
return user(0, IPC_GETOUTPUTTIME) / 1000;
}
protected class VolumeWorker extends Worker {
protected int volumeChangeSign;
public void activate(int volumeChangeSign) throws ActivateException {
super.activate();
this.volumeChangeSign = volumeChangeSign;
}
public void work() {
command(volumeChangeSign > 0 ? WINAMP_VOLUMEUP : WINAMP_VOLUMEDOWN);
sleep(VOLUME_SLEEP);
}
};
protected class SeekWorker extends Worker {
protected int seekDirection;
public void activate(int seekDirection) throws ActivateException {
super.activate();
this.seekDirection = seekDirection;
}
public void work() {
command(seekDirection > 0 ? WINAMP_FFWD5S : WINAMP_REW5S);
sleep(VOLUME_SLEEP);
}
};
}

View File

@@ -1,6 +1,9 @@
package mimis.application.cmd.windows.wmp;
import mimis.Worker;
import mimis.application.cmd.windows.WindowsApplication;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.value.Action;
public class WMPApplication extends WindowsApplication {
@@ -8,12 +11,17 @@ public class WMPApplication extends WindowsApplication {
protected final static String TITLE = "Windows Media Player";
protected final static String NAME = "WMPlayerApp";
protected static final int VOLUME_SLEEP = 120;
protected VolumeWorker volumeWorker;
public WMPApplication() {
super(PROGRAM, TITLE, NAME);
volumeWorker = new VolumeWorker();
}
public void action(Action action) {
log.trace("WMPApplication: " + action);
public void begin(Action action) {
log.trace("WMPApplication begin: " + action);
switch (action) {
case PLAY:
command(18808);
@@ -34,10 +42,18 @@ public class WMPApplication extends WindowsApplication {
command(18817);
break;
case VOLUME_UP:
command(18815);
try {
volumeWorker.activate(1);
} catch (ActivateException e) {
log.error(e);
}
break;
case VOLUME_DOWN:
command(18816);
try {
volumeWorker.activate(-1);
} catch (ActivateException e) {
log.error(e);
}
break;
case SHUFFLE:
command(18842);
@@ -47,4 +63,38 @@ public class WMPApplication extends WindowsApplication {
break;
}
}
public void end(Action action) {
log.trace("WMPApplication end: " + action);
switch (action) {
case FORWARD:
command(18813);
break;
case REWIND:
command(18812);
break;
case VOLUME_UP:
case VOLUME_DOWN:
try {
volumeWorker.deactivate();
} catch (DeactivateException e) {
log.error(e);
}
break;
}
}
protected class VolumeWorker extends Worker {
protected int volumeChangeSign;
public void activate(int volumeChangeSign) throws ActivateException {
super.activate();
this.volumeChangeSign = volumeChangeSign;
}
public void work() {
command (volumeChangeSign > 0 ? 18815 : 18816);
sleep(VOLUME_SLEEP);
}
};
}

View File

@@ -1,8 +1,12 @@
package mimis.application.itunes;
import java.io.IOException;
import mimis.Application;
import mimis.Worker;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.util.VBScript;
import mimis.value.Action;
import com.dt.iTunesController.ITCOMDisabledReason;
@@ -12,19 +16,23 @@ import com.dt.iTunesController.iTunesEventsInterface;
public class iTunesApplication extends Application implements iTunesEventsInterface {
protected static final String TITLE = "iTunes";
protected static final String PROGRAM = "iTunes.exe";
protected static final boolean QUIT = true;
protected static final boolean QUIT = false;
protected static final int VOLUME_CHANGE_RATE = 5;
protected static final int VOLUME_SLEEP = 500;
protected static final int VOLUME_SLEEP = 100;
protected static final String PLAYLIST_LIKE = "Like";
protected static final String PLAYLIST_DISLIKE = "Dislike";
protected iTunes iTunes;
protected boolean volume;
protected VolumeWorker volumeWorker;
protected boolean quiting;
public iTunesApplication() {
super(TITLE);
iTunes = new iTunes();
iTunes = new iTunes();
volumeWorker = new VolumeWorker();
quiting = false;
}
public void activate() throws ActivateException {
@@ -36,6 +44,17 @@ public class iTunesApplication extends Application implements iTunesEventsInterf
}
public boolean active() {
try {
if (!active && !quiting && VBScript.isRunning(PROGRAM)) {
try {
activate();
} catch (ActivateException e) {
log.error(e);
}
}
} catch (IOException e) {
log.error(e);
}
try {
iTunes.getMute();
active = true;
@@ -46,19 +65,26 @@ public class iTunesApplication extends Application implements iTunesEventsInterf
}
public void deactivate() throws DeactivateException {
super.deactivate();
volumeWorker.deactivate();
try {
if (QUIT) {
quiting = true;
synchronized (iTunes) {
iTunes.quit();
}
quiting = false;
}
} catch (Exception e) {
throw new DeactivateException();
} finally {
super.deactivate();
}
}
public void stop() throws DeactivateException {
super.stop();
volumeWorker.stop();
}
protected void begin(Action action) {
log.trace("iTunesApplication begin: " + action);
if (!active) return;
@@ -70,10 +96,18 @@ public class iTunesApplication extends Application implements iTunesEventsInterf
iTunes.rewind();
break;
case VOLUME_UP:
volume(true);
try {
volumeWorker.activate(VOLUME_CHANGE_RATE);
} catch (ActivateException e) {
log.error(e);
}
break;
case VOLUME_DOWN:
volume(false);
try {
volumeWorker.activate(-VOLUME_CHANGE_RATE);
} catch (ActivateException e) {
log.error(e);
}
break;
}
}
@@ -102,7 +136,11 @@ public class iTunesApplication extends Application implements iTunesEventsInterf
break;
case VOLUME_UP:
case VOLUME_DOWN:
volume = false;
try {
volumeWorker.deactivate();
} catch (DeactivateException e) {
log.error(e);
}
break;
case SHUFFLE:
iTunes.toggleShuffle();
@@ -119,15 +157,6 @@ public class iTunesApplication extends Application implements iTunesEventsInterf
}
}
protected void volume(boolean up) {
volume = true;
while (volume) {
int change = (up ? 1 : -1) * VOLUME_CHANGE_RATE;
iTunes.setSoundVolume(getVolume() + change);
sleep(VOLUME_SLEEP);
}
}
protected int getVolume() {
return iTunes.getSoundVolume();
}
@@ -150,5 +179,19 @@ public class iTunesApplication extends Application implements iTunesEventsInterf
public void onCOMCallsEnabledEvent() {}
public void onQuittingEvent() {}
public void onAboutToPromptUserToQuitEvent() {}
public void onSoundVolumeChangedEvent(int newVolume) {}
public void onSoundVolumeChangedEvent(int newVolume) {}
protected class VolumeWorker extends Worker {
protected int volumeChangeRate;
public void activate(int volumeChangeRate) throws ActivateException {
super.activate();
this.volumeChangeRate = volumeChangeRate;
}
public void work() {
iTunes.setSoundVolume(getVolume() + volumeChangeRate);
sleep(VOLUME_SLEEP);
}
};
}

View File

@@ -42,6 +42,7 @@ public abstract class JavaInputDevice extends Device {
}
public void deactivate() throws DeactivateException {
super.deactivate();
if (active) {
javaInputListener.deactivate();
}

View File

@@ -13,7 +13,7 @@ import com.melloware.jintellitype.IntellitypeListener;
import com.melloware.jintellitype.JIntellitype;
public class JIntellitypeDevice extends Device implements HotkeyListener, IntellitypeListener {
protected static final String TITLE = "JIntellitype";
protected static final String TITLE = "Keyboard";
protected JIntellitypeEventMapCycle eventMapCycle;
protected ArrayList<Hotkey> hotkeyList;
@@ -59,6 +59,10 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell
super.deactivate();
jit.removeHotKeyListener(this);
jit.removeIntellitypeListener(this);
}
public void stop() throws DeactivateException {
super.stop();
jit.cleanUp();
}
}

View File

@@ -67,7 +67,7 @@ public class LircDevice extends Device implements LircButtonListener, SignalList
}
}
public void stop() {
public void stop() throws DeactivateException {
multiplexer.stop();
lircService.stop();
super.stop();

View File

@@ -29,8 +29,8 @@ public enum DenonRC176Button implements LircButton {
AMP_VOLUME_DOWN ("AMP_VOL_DOWN"),
AMP_POWER ("AMP_POWER"),
AMP_MUTE ("AMP_MUTE"),
AMP_NEXT ("TUN_CH_UP"),
AMP_PREVIOUS ("TUN_CH_DOWN");
TUNER_UP ("TUN_CH_UP"),
TUNER_DOWN ("TUN_CH_DOWN");
public static final String NAME = "DENON_RC-176";

View File

@@ -9,6 +9,24 @@ public class DenonRC176EventMap extends EventMap {
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));
/* Application */
add(DenonRC176Button.AMP_POWER, new Task(Target.APPLICATION, Action.ACTIVATE));
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));
}
}

View File

@@ -18,13 +18,14 @@ public class PhiliphsRCLE011EventMap extends EventMap {
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.PAUSE));
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.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.RED, new Task(Target.APPLICATION, Action.DISLIKE));
add(PhiliphsRCLE011Button.GREEN, new Task(Target.APPLICATION, Action.LIKE));
}
}

View File

@@ -12,6 +12,7 @@ import mimis.Event;
import mimis.Worker;
import mimis.event.Feedback;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -43,7 +44,7 @@ public class NetworkDevice extends Device {
}
}
public void deactivate() {
public void deactivate() throws DeactivateException {
server.stop();
}
@@ -76,11 +77,11 @@ public class NetworkDevice extends Device {
} catch (IOException e) {}
}
public void stop() {
public void stop() throws DeactivateException {
super.stop();
for (Client client : clientList) {
client.stop();
}
super.stop();
}
}

View File

@@ -1,21 +1,29 @@
package mimis.device.panel;
import java.awt.BorderLayout;
import java.awt.event.WindowEvent;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import mimis.exception.worker.DeactivateException;
import mimis.util.swing.HoldButton;
import mimis.util.swing.HoldButtonListener;
import mimis.util.swing.ToggleButton;
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 PanelButtonListener panelButtonListener;
protected PanelDevice panelDevice;
protected ClassLoader classLoader;
protected HoldButton previousButton;
protected HoldButton rewindButton;
@@ -29,15 +37,16 @@ public class Panel extends JFrame implements HoldButtonListener {
protected HoldButton repeatButton;
protected HoldButton shuffleButton;
Panel(PanelButtonListener panelButtonListener) {
Panel(PanelDevice panelDevice) {
super(TITLE);
this.panelButtonListener = panelButtonListener;
this.panelDevice = panelDevice;
classLoader = getClass().getClassLoader();
createControls();
layoutControls();
pack();
setResizable(false);
setVisible(true);
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
}
protected URL getResource(String name) {
@@ -109,51 +118,62 @@ public class Panel extends JFrame implements HoldButtonListener {
/* Listeners */
public void buttonPressed(HoldButton button) {
if (button.equals(previousButton)) {
panelButtonListener.buttonPressed(PanelButton.PREVIOUS);
panelDevice.buttonPressed(PanelButton.PREVIOUS);
} else if (button.equals(rewindButton)) {
panelButtonListener.buttonPressed(PanelButton.REWIND);
panelDevice.buttonPressed(PanelButton.REWIND);
} else if (button.equals(playPauseToggleButton)) {
panelButtonListener.buttonPressed(PanelButton.PLAY);
panelDevice.buttonPressed(PanelButton.PLAY);
} else if (button.equals(forwardButton)) {
panelButtonListener.buttonPressed(PanelButton.FORWARD);
panelDevice.buttonPressed(PanelButton.FORWARD);
} else if (button.equals(nextButton)) {
panelButtonListener.buttonPressed(PanelButton.NEXT);
panelDevice.buttonPressed(PanelButton.NEXT);
} else if (button.equals(volumeDownButton)) {
panelButtonListener.buttonPressed(PanelButton.VOLUME_DOWN);
panelDevice.buttonPressed(PanelButton.VOLUME_DOWN);
} else if (button.equals(muteToggleButton)) {
panelButtonListener.buttonPressed(PanelButton.MUTE);
panelDevice.buttonPressed(PanelButton.MUTE);
} else if (button.equals(volumeUpButton)) {
panelButtonListener.buttonPressed(PanelButton.VOLUME_UP);
panelDevice.buttonPressed(PanelButton.VOLUME_UP);
} else if (button.equals(repeatButton)) {
panelButtonListener.buttonPressed(PanelButton.REPEAT);
panelDevice.buttonPressed(PanelButton.REPEAT);
} else if (button.equals(shuffleButton)) {
panelButtonListener.buttonPressed(PanelButton.SHUFFLE);
panelDevice.buttonPressed(PanelButton.SHUFFLE);
}
}
public void buttonReleased(HoldButton button) {
if (button.equals(previousButton)) {
panelButtonListener.buttonReleased(PanelButton.PREVIOUS);
panelDevice.buttonReleased(PanelButton.PREVIOUS);
} else if (button.equals(rewindButton)) {
panelButtonListener.buttonReleased(PanelButton.REWIND);
panelDevice.buttonReleased(PanelButton.REWIND);
} else if (button.equals(playPauseToggleButton)) {
panelButtonListener.buttonReleased(PanelButton.PLAY);
panelDevice.buttonReleased(PanelButton.PLAY);
playPauseToggleButton.toggle();
} else if (button.equals(forwardButton)) {
panelButtonListener.buttonReleased(PanelButton.FORWARD);
panelDevice.buttonReleased(PanelButton.FORWARD);
} else if (button.equals(nextButton)) {
panelButtonListener.buttonReleased(PanelButton.NEXT);
panelDevice.buttonReleased(PanelButton.NEXT);
} else if (button.equals(volumeDownButton)) {
panelButtonListener.buttonReleased(PanelButton.VOLUME_DOWN);
panelDevice.buttonReleased(PanelButton.VOLUME_DOWN);
} else if (button.equals(muteToggleButton)) {
panelButtonListener.buttonReleased(PanelButton.MUTE);
panelDevice.buttonReleased(PanelButton.MUTE);
muteToggleButton.toggle();
} else if (button.equals(volumeUpButton)) {
panelButtonListener.buttonReleased(PanelButton.VOLUME_UP);
panelDevice.buttonReleased(PanelButton.VOLUME_UP);
} else if (button.equals(repeatButton)) {
panelButtonListener.buttonReleased(PanelButton.REPEAT);
panelDevice.buttonReleased(PanelButton.REPEAT);
} else if (button.equals(shuffleButton)) {
panelButtonListener.buttonReleased(PanelButton.SHUFFLE);
panelDevice.buttonReleased(PanelButton.SHUFFLE);
}
}
protected void processWindowEvent(WindowEvent event) {
if (event.getID() == WindowEvent.WINDOW_CLOSING) {
log.debug("Window closing");
try {
panelDevice.deactivate();
} catch (DeactivateException e) {
log.error(e);
}
}
}
}

View File

@@ -1,6 +0,0 @@
package mimis.device.panel;
public interface PanelButtonListener {
public void buttonPressed(PanelButton panelButton);
public void buttonReleased(PanelButton panelButton);
}

View File

@@ -1,15 +1,14 @@
package mimis.device.panel;
import java.awt.event.WindowEvent;
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;
public class PanelDevice extends Device implements PanelButtonListener {
public class PanelDevice extends Device {
protected static final String TITLE = "Panel";
protected Panel panel;
protected PanelEventMapCycle eventMapCycle;
@@ -21,32 +20,19 @@ public class PanelDevice extends Device implements PanelButtonListener {
public void activate() throws ActivateException {
super.activate();
panel = new Panel(this) {
protected static final long serialVersionUID = 1L;
protected void processWindowEvent(WindowEvent e) {
log.debug("Window closing");
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
deactivate();
}
}
};
panel = new Panel(this);
panel.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
add(eventMapCycle.player);
}
public boolean active() {
return active = panel != null && panel.isValid();
return active = panel != null;
}
public void deactivate() {
public void deactivate() throws DeactivateException {
super.deactivate();
panel.dispose();
}
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
log.debug("Window closing");
deactivate();
}
panel = null;
}
public void buttonPressed(PanelButton panelButton) {

View File

@@ -80,7 +80,7 @@ public class WiimoteDevice extends Device implements GestureListener {
wiimoteDiscovery.disconnect();
}
public void stop() {
public void stop() throws DeactivateException {
super.stop();
wiimoteService.exit();
}
@@ -133,8 +133,10 @@ public class WiimoteDevice extends Device implements GestureListener {
}
public void feedback(Feedback feedback) {
System.out.println("Wiimote feedback");
wiimote.rumble(RUMBLE);
if (active()) {
log.debug("Wiimote rumble feedback");
wiimote.rumble(RUMBLE);
}
}
/* Connectivity */

View File

@@ -63,7 +63,7 @@ public class WiimoteDiscovery extends Worker {
}
}
public void stop() {
public void stop() throws DeactivateException {
super.stop();
disconnect();
}

View File

@@ -5,6 +5,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import mimis.Event;
import mimis.Worker;
import mimis.exception.worker.DeactivateException;
public abstract class EventListener extends Worker {
protected Queue<Event> eventQueue;
@@ -34,9 +35,9 @@ public abstract class EventListener extends Worker {
}
}
event(eventQueue.poll());
}
}
public void stop() {
public void stop() throws DeactivateException {
super.stop();
synchronized (work) {
work.notifyAll();

View File

@@ -1,5 +1,7 @@
package mimis.manager;
import mimis.exception.worker.DeactivateException;
public interface Exitable {
public void stop();
public void stop() throws DeactivateException;
}

View File

@@ -80,7 +80,6 @@ public class SequenceParser {
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);

View File

@@ -6,33 +6,16 @@ public class ArrayCycle<E> extends ArrayList<E> {
protected static final long serialVersionUID = 1L;
protected int index = 0;
//protected Object nonEmpty;
public ArrayCycle(E... elementArray) {
if (elementArray != null) {
//nonEmpty = new Object();
for (E element : elementArray) {
add(element);
}
}
}
/*public boolean add(E element) {
boolean result = super.add(element);
synchronized (nonEmpty) {
nonEmpty.notifyAll();
}
return result;
}*/
public E current() {
/*while (index == 0) {
synchronized (nonEmpty) {
try {
nonEmpty.wait();
} catch (InterruptedException e) {}
}
}*/
return this.get(index);
}