Mechanisme van devices tot applicaties gecontroleerd, gerepareerd en uitgetest: Panel en Jintellitype -> Winamp.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
log4j.rootLogger=DEBUG, CA
|
||||
log4j.rootLogger=TRACE, CA
|
||||
log4j.appender.CA=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
|
||||
@@ -1,8 +1,11 @@
|
||||
package mimis;
|
||||
|
||||
import mimis.event.EventHandler;
|
||||
import mimis.event.Task;
|
||||
import mimis.exception.WorkerException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.manager.Titled;
|
||||
import mimis.value.Action;
|
||||
|
||||
public abstract class Application extends EventHandler implements Titled, Exitable {
|
||||
protected String title;
|
||||
@@ -10,13 +13,34 @@ public abstract class Application extends EventHandler implements Titled, Exitab
|
||||
|
||||
public Application(String title) {
|
||||
this.title = title;
|
||||
active = false;
|
||||
//initialise();
|
||||
}
|
||||
|
||||
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 ACTIVATE:
|
||||
try {
|
||||
if (active()) {
|
||||
deactivate();
|
||||
} else {
|
||||
activate();
|
||||
}
|
||||
} catch (WorkerException e) {
|
||||
log.error(e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.event(event);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (active()) {
|
||||
try {
|
||||
|
||||
@@ -4,6 +4,7 @@ import mimis.event.EventHandler;
|
||||
import mimis.event.Task;
|
||||
import mimis.event.task.Continuous;
|
||||
import mimis.event.task.Stopper;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.macro.Sequence;
|
||||
import mimis.macro.SequenceListener;
|
||||
@@ -15,21 +16,15 @@ import mimis.manager.Titled;
|
||||
|
||||
public abstract class Device extends EventHandler implements Titled, Exitable {
|
||||
protected String title;
|
||||
protected boolean active;
|
||||
protected SequenceListener sequenceListener;
|
||||
|
||||
static {
|
||||
SequenceListener.initialise(eventRouter);
|
||||
}
|
||||
|
||||
public Device(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
log.fatal("start");
|
||||
|
||||
public void activate() throws ActivateException {
|
||||
super.activate();
|
||||
sequenceListener = new SequenceListener(this);
|
||||
super.start();
|
||||
}
|
||||
|
||||
/* Register macro's */
|
||||
|
||||
@@ -4,10 +4,10 @@ import java.awt.GridLayout;
|
||||
import java.awt.TextArea;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
@@ -55,7 +55,7 @@ public class GUI extends JFrame {
|
||||
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()) {
|
||||
for (JButton button : manager.getButtons()) {
|
||||
panel.add(button);
|
||||
}
|
||||
return panel;
|
||||
@@ -84,7 +84,11 @@ public class GUI extends JFrame {
|
||||
public void write(String string) {
|
||||
textArea.append(string);
|
||||
}
|
||||
|
||||
|
||||
public void writeLine(String string) {
|
||||
write(string + "\n");
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
textArea.setText(null);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import mimis.exception.worker.ActivateException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
||||
public class Main {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.JButton;
|
||||
|
||||
import mimis.manager.SelectButton;
|
||||
import mimis.manager.Titled;
|
||||
@@ -19,10 +19,6 @@ public class Manager<T extends Worker & Titled & Exitable> extends Worker {
|
||||
|
||||
protected T[] manageableArray;
|
||||
protected Map<T, SelectButton<T>> buttonMap;
|
||||
|
||||
public Manager(String title) {
|
||||
log.debug("Manager constructed");
|
||||
}
|
||||
|
||||
public Manager(T[] manageableArray) {
|
||||
this.manageableArray = manageableArray;
|
||||
@@ -30,7 +26,6 @@ public class Manager<T extends Worker & Titled & Exitable> extends Worker {
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
super.stop();
|
||||
for (T manageable : manageableArray) {
|
||||
manageable.stop();
|
||||
}
|
||||
@@ -45,15 +40,17 @@ public class Manager<T extends Worker & Titled & Exitable> extends Worker {
|
||||
}
|
||||
}
|
||||
|
||||
protected JToggleButton[] getButtons() {
|
||||
return buttonMap.values().toArray(new JToggleButton[]{});
|
||||
protected JButton[] getButtons() {
|
||||
return buttonMap.values().toArray(new JButton[]{});
|
||||
}
|
||||
|
||||
protected void work() {
|
||||
long before = Calendar.getInstance().getTimeInMillis();
|
||||
for (T manageable : manageableArray) {
|
||||
boolean active = manageable.active();
|
||||
buttonMap.get(manageable).setPressed(active);
|
||||
//buttonMap.get(manageable).getModel().setArmed(active);
|
||||
|
||||
buttonMap.get(manageable).getModel().setPressed(active);
|
||||
}
|
||||
long after = Calendar.getInstance().getTimeInMillis();
|
||||
int sleep = INTERVAL - (int) (after - before);
|
||||
|
||||
@@ -5,6 +5,7 @@ import mimis.event.EventRouter;
|
||||
import mimis.event.Feedback;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.feedback.TextFeedback;
|
||||
import mimis.macro.SequenceListener;
|
||||
import mimis.util.ArrayCycle;
|
||||
import mimis.value.Action;
|
||||
|
||||
@@ -35,16 +36,28 @@ public class Mimis extends EventHandler {
|
||||
}
|
||||
|
||||
public Mimis(EventRouter eventRouter, Application[] applicationArray, Device[] deviceArray) {
|
||||
EventHandler.initialise(eventRouter);
|
||||
applicationManager = new Manager<Application>(applicationArray);
|
||||
deviceManager = new Manager<Device>(deviceArray);
|
||||
|
||||
this.applicationArray = applicationArray;
|
||||
this.deviceArray = deviceArray;
|
||||
applicationCycle = new ArrayCycle<Application>(applicationArray);
|
||||
|
||||
log.debug("Initialise EventHandler and SequenceListener");
|
||||
EventHandler.initialise(eventRouter);
|
||||
SequenceListener.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);
|
||||
}
|
||||
|
||||
public void activate() throws ActivateException {
|
||||
log.debug("Activate event router");
|
||||
eventRouter.activate();
|
||||
|
||||
log.debug("Activate managers");
|
||||
applicationManager.activate();
|
||||
deviceManager.activate();
|
||||
@@ -85,10 +98,10 @@ public class Mimis extends EventHandler {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void feedback(Feedback feedback) {
|
||||
if (feedback instanceof TextFeedback) {
|
||||
gui.write(((TextFeedback) feedback).getText());
|
||||
gui.writeLine(((TextFeedback) feedback).getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ public abstract class Worker implements Runnable {
|
||||
protected boolean active = false;
|
||||
|
||||
public void start(boolean thread) {
|
||||
log.trace("Start");
|
||||
running = true;
|
||||
if (thread) {
|
||||
log.debug("Start thread");
|
||||
@@ -69,10 +68,10 @@ public abstract class Worker implements Runnable {
|
||||
}
|
||||
|
||||
public void activate(boolean thread) {
|
||||
active = true;
|
||||
if (!running) {
|
||||
start(thread);
|
||||
}
|
||||
active = true;
|
||||
synchronized (this) {
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public abstract class WindowsApplication extends CMDApplication {
|
||||
|
||||
public void activate() throws ActivateException {
|
||||
handle = Windows.findWindow(name, null);
|
||||
log.info(handle);
|
||||
if (handle < 1) {
|
||||
super.activate();
|
||||
sleep(START_SLEEP);
|
||||
@@ -34,7 +35,11 @@ public abstract class WindowsApplication extends CMDApplication {
|
||||
throw new ActivateException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean active() {
|
||||
return (handle = Windows.findWindow(name, null)) > 0;
|
||||
}
|
||||
|
||||
protected void command(Command command) {
|
||||
Windows.sendMessage(handle, Windows.WM_APPCOMMAND, handle, command.getCode() << 16);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public class WinampApplication extends WindowsApplication {
|
||||
}
|
||||
|
||||
public void action(Action action) {
|
||||
log.fatal(handle);
|
||||
log.trace("WinampApplication: " + action);
|
||||
switch (action) {
|
||||
case PLAY:
|
||||
|
||||
@@ -57,6 +57,7 @@ public class iTunesApplication extends Application implements iTunesEventsInterf
|
||||
|
||||
protected void action(Action action) {
|
||||
log.trace("iTunesApplication: " + action);
|
||||
if (!active) return;
|
||||
switch (action) {
|
||||
case PLAY:
|
||||
iTunes.playPause();
|
||||
|
||||
@@ -18,17 +18,22 @@ import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
public abstract class JavaInputDevice extends Device {
|
||||
public JavaInputDevice(String title) {
|
||||
protected String name;
|
||||
|
||||
public JavaInputDevice(String title, String name) {
|
||||
super(title);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
protected JavaInputListener javaInputListener;
|
||||
protected Button previousDirectionalButton;
|
||||
|
||||
public void activate(String name) throws ActivateException {
|
||||
log.fatal("act");
|
||||
public void activate() throws ActivateException {
|
||||
super.activate();
|
||||
try {
|
||||
javaInputListener = new JavaInputListener(this, getDevice(name));
|
||||
JXInputDevice jxinputDevice = getDevice(name);
|
||||
log.debug(jxinputDevice);
|
||||
javaInputListener = new JavaInputListener(this, jxinputDevice);
|
||||
} catch (DeviceNotFoundException e) {
|
||||
throw new ActivateException();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import mimis.event.Task;
|
||||
import mimis.exception.MacroException;
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.exception.button.UnknownDirectionException;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.macro.state.Hold;
|
||||
import mimis.macro.state.Press;
|
||||
import mimis.macro.state.Release;
|
||||
@@ -17,14 +18,15 @@ import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
public class Extreme3DDevice extends JavaInputDevice {
|
||||
protected static final String TITLE = "Extreme 3D";
|
||||
protected static final String NAME = "Logitech Extreme 3D";
|
||||
|
||||
public Extreme3DDevice() {
|
||||
super(NAME);
|
||||
super(TITLE, NAME);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
super.start();
|
||||
public void activate() throws ActivateException {
|
||||
super.activate();
|
||||
try {
|
||||
add(
|
||||
new Press(Extreme3DButton.TWELVE),
|
||||
|
||||
@@ -5,16 +5,16 @@ import mimis.exception.button.UnknownButtonException;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
|
||||
public enum RumblepadButton implements Button {
|
||||
ONE ("SelectButton 0"),
|
||||
TWO ("SelectButton 1"),
|
||||
THREE ("SelectButton 2"),
|
||||
FOUR ("SelectButton 3"),
|
||||
FIVE ("SelectButton 4"),
|
||||
SIX ("SelectButton 5"),
|
||||
SEVEN ("SelectButton 6"),
|
||||
EIGHT ("SelectButton 7"),
|
||||
NINE ("SelectButton 8"),
|
||||
TEN ("SelectButton 9");
|
||||
ONE ("Button 0"),
|
||||
TWO ("Button 1"),
|
||||
THREE ("Button 2"),
|
||||
FOUR ("Button 3"),
|
||||
FIVE ("Button 4"),
|
||||
SIX ("Button 5"),
|
||||
SEVEN ("Button 6"),
|
||||
EIGHT ("Button 7"),
|
||||
NINE ("Button 8"),
|
||||
TEN ("Button 9");
|
||||
|
||||
protected String code;
|
||||
|
||||
|
||||
@@ -17,20 +17,15 @@ import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
public class RumblepadDevice extends JavaInputDevice {
|
||||
protected static final String TITLE = "RumblePad";
|
||||
protected static final String NAME = "Logitech RumblePad 2 USB";
|
||||
|
||||
public RumblepadDevice() {
|
||||
super(NAME);
|
||||
super(TITLE, NAME);
|
||||
}
|
||||
|
||||
public void activate() throws ActivateException {
|
||||
super.activate();
|
||||
start();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
log.fatal("start");
|
||||
|
||||
add(
|
||||
new Press(RumblepadButton.ONE),
|
||||
new Task(Target.APPLICATION, Action.PLAY));
|
||||
@@ -58,7 +53,6 @@ public class RumblepadDevice extends JavaInputDevice {
|
||||
add(
|
||||
new Hold(RumblepadButton.TEN),
|
||||
new Continuous(Action.VOLUME_UP, Target.APPLICATION, 100));
|
||||
super.start();
|
||||
}
|
||||
|
||||
protected Button getButton(JXInputButtonEvent event) throws UnknownButtonException {
|
||||
|
||||
@@ -34,6 +34,10 @@ public class Hotkey implements Button {
|
||||
this(key.getCode());
|
||||
}
|
||||
|
||||
public Hotkey(int modifier, Key key) {
|
||||
this(modifier, key.getCode());
|
||||
}
|
||||
|
||||
public static void initialise(ArrayList<Hotkey> actionList, JIntellitype jit) {
|
||||
Hotkey.hotkeyList = actionList;
|
||||
Hotkey.jit = jit;
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||
import mimis.Device;
|
||||
import mimis.event.Task;
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.macro.state.Press;
|
||||
import mimis.macro.state.Release;
|
||||
import mimis.value.Action;
|
||||
@@ -29,8 +30,8 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell
|
||||
Hotkey.initialise(hotkeyList, jit);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
super.start();
|
||||
public void activate() throws ActivateException {
|
||||
super.activate();
|
||||
jit.addHotKeyListener(this);
|
||||
jit.addIntellitypeListener(this);
|
||||
add(
|
||||
@@ -61,6 +62,7 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell
|
||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 'r'),
|
||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 's'),
|
||||
new Continuous(Action.REPEAT, Target.APPLICATIONS, 500));*/
|
||||
|
||||
}
|
||||
|
||||
protected void add(Hotkey hotkey, Task task) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import javax.swing.WindowConstants;
|
||||
|
||||
import mimis.Device;
|
||||
import mimis.event.Task;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.macro.state.Press;
|
||||
import mimis.macro.state.Release;
|
||||
import mimis.value.Action;
|
||||
@@ -20,7 +21,8 @@ public class PanelDevice extends Device implements PanelButtonListener {
|
||||
super(TITLE);
|
||||
}
|
||||
|
||||
public void activate() {
|
||||
public void activate() throws ActivateException {
|
||||
super.activate();
|
||||
panel = new Panel(this) {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
protected void processWindowEvent(WindowEvent e) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import mimis.event.Feedback;
|
||||
import mimis.event.Task;
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.exception.device.DeviceNotFoundException;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.macro.state.Hold;
|
||||
import mimis.macro.state.Press;
|
||||
import mimis.macro.state.Release;
|
||||
@@ -45,7 +46,16 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
gestureDevice.add(this);
|
||||
}
|
||||
|
||||
public void initialise() {
|
||||
public void activate() throws ActivateException {
|
||||
super.activate();
|
||||
try {
|
||||
wiimote = wiimoteService.getDevice(this);
|
||||
} catch (DeviceNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
wiimote.activateMotionSensing();
|
||||
|
||||
add(
|
||||
new Hold(WiimoteButton.A),
|
||||
new Task(Action.TRAIN),
|
||||
@@ -167,16 +177,6 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
wiimote.rumble(RUMBLE);
|
||||
}
|
||||
|
||||
public void activate() {
|
||||
try {
|
||||
wiimote = wiimoteService.getDevice(this);
|
||||
} catch (DeviceNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
wiimote.activateMotionSensing();
|
||||
}
|
||||
|
||||
public void deactivate() {
|
||||
wiimote.deactivateMotionSensing();
|
||||
}
|
||||
|
||||
@@ -11,12 +11,8 @@ public abstract class EventHandler extends EventListener {
|
||||
EventHandler.eventRouter = eventRouter;
|
||||
}
|
||||
|
||||
protected void initialise() {
|
||||
eventRouter.add(this);
|
||||
}
|
||||
|
||||
public void event(Event event) {
|
||||
System.out.println(event);
|
||||
log.debug("aaa" + event);
|
||||
if (event instanceof Feedback) {
|
||||
feedback((Feedback) event);
|
||||
} else if (event instanceof Task) {
|
||||
|
||||
@@ -16,6 +16,7 @@ public abstract class EventListener extends Worker {
|
||||
}
|
||||
|
||||
public void add(Event event) {
|
||||
log.info("event " + event + " " + active);
|
||||
eventQueue.add(event);
|
||||
synchronized (work) {
|
||||
work.notifyAll();
|
||||
|
||||
@@ -17,8 +17,10 @@ public abstract class EventRouter extends EventListener {
|
||||
eventListenerList = new ArrayList<EventListener>();
|
||||
}
|
||||
|
||||
public void add(EventListener eventListener) {
|
||||
eventListenerList.add(eventListener);
|
||||
public void add(EventListener... eventListenerArray) {
|
||||
for (EventListener eventListener : eventListenerArray) {
|
||||
eventListenerList.add(eventListener);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(EventListener eventListener) {
|
||||
|
||||
@@ -7,8 +7,7 @@ import mimis.value.Target;
|
||||
|
||||
public class LocalRouter extends EventRouter {
|
||||
public void event(Event event) {
|
||||
System.out.println("LocalSpreader krijgt event via evet()");
|
||||
System.out.println(application);
|
||||
System.out.println("LocalSpreader krijgt event via event() " + event.getTarget());
|
||||
Target target = event.getTarget();
|
||||
switch (target) {
|
||||
case APPLICATION:
|
||||
@@ -19,6 +18,7 @@ public class LocalRouter extends EventRouter {
|
||||
default:
|
||||
for (EventListener eventListener : eventListenerList) {
|
||||
if (event.compatible(eventListener)) {
|
||||
log.trace(eventListener);
|
||||
eventListener.add(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,18 @@ package mimis.macro;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import mimis.Event;
|
||||
import mimis.event.EventHandler;
|
||||
import mimis.event.EventListener;
|
||||
import mimis.event.Task;
|
||||
import mimis.value.Target;
|
||||
|
||||
|
||||
public class SequenceListener {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
|
||||
protected EventHandler eventHandler;
|
||||
protected ArrayList<Sequence> sequenceList;
|
||||
protected HashMap<Sequence, Event> eventMap;
|
||||
@@ -37,6 +41,7 @@ public class SequenceListener {
|
||||
}
|
||||
|
||||
public void add(State state) {
|
||||
log.trace(state);
|
||||
for (Sequence sequence : sequenceList) {
|
||||
activeList.add(new Active(sequence));
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
package mimis.manager;
|
||||
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JToggleButton;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import mimis.Worker;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class SelectButton<T extends Worker & Titled> extends JToggleButton implements ItemListener {
|
||||
public class SelectButton<T extends Worker & Titled> extends JButton implements ActionListener {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
|
||||
protected static final long serialVersionUID = 1L;
|
||||
@@ -22,31 +20,23 @@ public class SelectButton<T extends Worker & Titled> extends JToggleButton imple
|
||||
public SelectButton(T activatable) {
|
||||
this.activatable = activatable;
|
||||
setText(activatable.title());
|
||||
addItemListener(this);
|
||||
setFocusable(false);
|
||||
addActionListener(this);
|
||||
}
|
||||
|
||||
public void itemStateChanged(ItemEvent itemEvent) {
|
||||
int state = itemEvent.getStateChange();
|
||||
if (state == ItemEvent.SELECTED) {
|
||||
log.trace("Selected: " + activatable.title());
|
||||
setPressed(false);
|
||||
try {
|
||||
activatable.activate();
|
||||
} catch (ActivateException e) {
|
||||
log.error(e);
|
||||
}
|
||||
} else {
|
||||
log.trace("Deselected: " + activatable.title());
|
||||
setPressed(true);
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
if (activatable.active()) {
|
||||
try {
|
||||
activatable.deactivate();
|
||||
} catch (DeactivateException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setPressed(boolean pressed) {
|
||||
getModel().setPressed(pressed);
|
||||
} else {
|
||||
try {
|
||||
activatable.activate();
|
||||
} catch (ActivateException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,5 +16,5 @@ public enum Action {
|
||||
VOLUME_DOWN,
|
||||
VOLUME_UP,
|
||||
FULLSCREEN,
|
||||
TRAIN, STOP, SAVE, RECOGNIZE, LOAD, SHUFFLE, FADEOUT, QUIT, VISUALISER, LIKE, DISLIKE;
|
||||
TRAIN, STOP, SAVE, RECOGNIZE, LOAD, SHUFFLE, FADEOUT, QUIT, VISUALISER, LIKE, DISLIKE, ACTIVATE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user