From 401690c8a63321b97490a88b742eb2a86ca8d4de Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Tue, 8 Feb 2011 16:33:31 +0000 Subject: [PATCH] Implementatie JIntellitype hotkeys en commands voltooid. Mogelijk tot registreren van enkelvoudige events in plaats van macro toegevoegd. --- java/src/pm/Main.java | 8 +- java/src/pm/device/Device.java | 10 +++ .../pm/device/javainput/JavaInputDevice.java | 8 +- .../javainput/extreme3d/Extreme3DDevice.java | 1 + .../pm/device/jintellitype/CommandButton.java | 73 +++++++++++++++++++ java/src/pm/device/jintellitype/Hotkey.java | 37 ++++++++++ .../pm/device/jintellitype/HotkeyButton.java | 23 ++++++ .../jintellitype/JIntellitypeDevice.java | 67 +++++++++++++++++ java/src/pm/listener/MacroListener.java | 5 ++ 9 files changed, 225 insertions(+), 7 deletions(-) create mode 100644 java/src/pm/device/jintellitype/CommandButton.java create mode 100644 java/src/pm/device/jintellitype/Hotkey.java create mode 100644 java/src/pm/device/jintellitype/HotkeyButton.java create mode 100644 java/src/pm/device/jintellitype/JIntellitypeDevice.java diff --git a/java/src/pm/Main.java b/java/src/pm/Main.java index 8d190eb..550f14a 100644 --- a/java/src/pm/Main.java +++ b/java/src/pm/Main.java @@ -8,6 +8,7 @@ import pm.application.Application; import pm.application.voorbeeld.VoorbeeldApplication; import pm.device.Device; import pm.device.javainput.extreme3d.Extreme3DDevice; +import pm.device.jintellitype.JIntellitypeDevice; import pm.exception.ActionException; import pm.exception.action.NotImplementedActionException; import pm.exception.action.UnknownTargetException; @@ -47,10 +48,11 @@ public class Main { } public void start() throws Exception { - //addDevice(new ExampleDevice()); - //addDevice(new RumblepadDevice()); + //add(new ExampleDevice()); + //add(new RumblepadDevice()); add(new Extreme3DDevice()); - + add(new JIntellitypeDevice()); + Application application = new VoorbeeldApplication(); add(application); diff --git a/java/src/pm/device/Device.java b/java/src/pm/device/Device.java index 86cb959..e0a52f5 100644 --- a/java/src/pm/device/Device.java +++ b/java/src/pm/device/Device.java @@ -2,8 +2,10 @@ package pm.device; import pm.Action; import pm.Macro; +import pm.exception.MacroException; import pm.listener.ActionListener; import pm.listener.MacroListener; +import pm.macro.Event; public abstract class Device extends ActionListener { protected MacroListener macroListener; @@ -16,6 +18,14 @@ public abstract class Device extends ActionListener { macroListener.add(macro, action); } + public void add(Event event, Action action) throws MacroException { + macroListener.add(event, action); + } + + public void add(Event event) { + macroListener.add(event); + } + public void start() {} public void exit() {} } diff --git a/java/src/pm/device/javainput/JavaInputDevice.java b/java/src/pm/device/javainput/JavaInputDevice.java index d7ab342..778f6ff 100644 --- a/java/src/pm/device/javainput/JavaInputDevice.java +++ b/java/src/pm/device/javainput/JavaInputDevice.java @@ -56,10 +56,10 @@ public abstract class JavaInputDevice extends Device { Button button = Extreme3DButton.create(event); if (event.getButton().getState()) { System.out.println("Press: " + button); - macroListener.add(new Press(button)); + add(new Press(button)); } else { System.out.println("Release: " + button); - macroListener.add(new Release(button)); + add(new Release(button)); } //System.out.println(button); //System.out.println(button.getType() + " " + button.getName() +" " + ); @@ -72,11 +72,11 @@ public abstract class JavaInputDevice extends Device { if (event.getDirectional().isCentered()) { if (previousDirectionalButton != null) { System.out.println("Release: " + previousDirectionalButton); - macroListener.add(new Release(previousDirectionalButton)); + add(new Release(previousDirectionalButton)); } } else { System.out.println("Press: " + button); - macroListener.add(new Press(button)); + add(new Press(button)); previousDirectionalButton = button; } //System.out.println(Extreme3DDirection.create(event)); diff --git a/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java b/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java index 81f277b..411bc5a 100644 --- a/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java +++ b/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java @@ -20,6 +20,7 @@ public class Extreme3DDevice extends JavaInputDevice { public void start() { super.start(); try { + add(new Macro(new Press(Extreme3DButton.TWELVE)), Action.TEST.setTarget(Target.APPLICATION)); add( new Macro( new Hold(Extreme3DButton.ONE), diff --git a/java/src/pm/device/jintellitype/CommandButton.java b/java/src/pm/device/jintellitype/CommandButton.java new file mode 100644 index 0000000..875f764 --- /dev/null +++ b/java/src/pm/device/jintellitype/CommandButton.java @@ -0,0 +1,73 @@ +package pm.device.jintellitype; + +import com.melloware.jintellitype.JIntellitype; + +import pm.Button; +import pm.exception.event.UnknownButtonException; + +public enum CommandButton implements Button { + BROWSER_BACKWARD (JIntellitype.APPCOMMAND_BROWSER_BACKWARD), + BROWSER_FORWARD (JIntellitype.APPCOMMAND_BROWSER_FORWARD), + BROWSER_REFRESH (JIntellitype.APPCOMMAND_BROWSER_REFRESH), + BROWSER_STOP (JIntellitype.APPCOMMAND_BROWSER_STOP), + BROWSER_SEARCH (JIntellitype.APPCOMMAND_BROWSER_SEARCH), + BROWSER_FAVOURITES (JIntellitype.APPCOMMAND_BROWSER_FAVOURITES), + BROWSER_HOME (JIntellitype.APPCOMMAND_BROWSER_HOME), + VOLUME_MUTE (JIntellitype.APPCOMMAND_VOLUME_MUTE), + VOLUME_DOWN (JIntellitype.APPCOMMAND_VOLUME_DOWN), + VOLUME_UP (JIntellitype.APPCOMMAND_VOLUME_UP), + MEDIA_NEXTTRACK (JIntellitype.APPCOMMAND_MEDIA_NEXTTRACK), + MEDIA_PREVIOUSTRACK (JIntellitype.APPCOMMAND_MEDIA_PREVIOUSTRACK), + MEDIA_STOP (JIntellitype.APPCOMMAND_MEDIA_STOP), + MEDIA_PLAY_PAUSE (JIntellitype.APPCOMMAND_MEDIA_PLAY_PAUSE), + LAUNCH_MAIL (JIntellitype.APPCOMMAND_LAUNCH_MAIL), + LAUNCH_MEDIA_SELECT (JIntellitype.APPCOMMAND_LAUNCH_MEDIA_SELECT), + LAUNCH_APP1 (JIntellitype.APPCOMMAND_LAUNCH_APP1), + LAUNCH_APP2 (JIntellitype.APPCOMMAND_LAUNCH_APP2), + BASS_DOWN (JIntellitype.APPCOMMAND_BASS_DOWN), + BASS_BOOST (JIntellitype.APPCOMMAND_BASS_BOOST), + BASS_UP (JIntellitype.APPCOMMAND_BASS_UP), + TREBLE_DOWN (JIntellitype.APPCOMMAND_TREBLE_DOWN), + TREBLE_UP (JIntellitype.APPCOMMAND_TREBLE_UP), + MICROPHONE_VOLUME_MUTE (JIntellitype.APPCOMMAND_MICROPHONE_VOLUME_MUTE), + MICROPHONE_VOLUME_DOWN (JIntellitype.APPCOMMAND_MICROPHONE_VOLUME_DOWN), + MICROPHONE_VOLUME_UP (JIntellitype.APPCOMMAND_MICROPHONE_VOLUME_UP), + HELP (JIntellitype.APPCOMMAND_HELP), + FIND (JIntellitype.APPCOMMAND_FIND), + NEW (JIntellitype.APPCOMMAND_NEW), + OPEN (JIntellitype.APPCOMMAND_OPEN), + CLOSE (JIntellitype.APPCOMMAND_CLOSE), + SAVE (JIntellitype.APPCOMMAND_SAVE), + PRINT (JIntellitype.APPCOMMAND_PRINT), + UNDO (JIntellitype.APPCOMMAND_UNDO), + REDO (JIntellitype.APPCOMMAND_REDO), + COPY (JIntellitype.APPCOMMAND_COPY), + CUT (JIntellitype.APPCOMMAND_CUT), + PASTE (JIntellitype.APPCOMMAND_PASTE), + REPLY_TO_MAIL (JIntellitype.APPCOMMAND_REPLY_TO_MAIL), + FORWARD_MAIL (JIntellitype.APPCOMMAND_FORWARD_MAIL), + SEND_MAIL (JIntellitype.APPCOMMAND_SEND_MAIL), + SPELL_CHECK (JIntellitype.APPCOMMAND_SPELL_CHECK), + DICTATE_OR_COMMAND_CONTROL_TOGGLE (JIntellitype.APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE), + MIC_ON_OFF_TOGGLE (JIntellitype.APPCOMMAND_MIC_ON_OFF_TOGGLE), + CORRECTION_LIST (JIntellitype.APPCOMMAND_CORRECTION_LIST); + + protected int code; + + private CommandButton(int code) { + this.code = code; + } + + public int getCode() { + return code; + } + + public static CommandButton create(int code) throws UnknownButtonException { + for (CommandButton button : CommandButton.values()) { + if (button.getCode() == code) { + return button; + } + } + throw new UnknownButtonException(); + } +} diff --git a/java/src/pm/device/jintellitype/Hotkey.java b/java/src/pm/device/jintellitype/Hotkey.java new file mode 100644 index 0000000..ed1c340 --- /dev/null +++ b/java/src/pm/device/jintellitype/Hotkey.java @@ -0,0 +1,37 @@ +package pm.device.jintellitype; + +import java.util.ArrayList; + +import com.melloware.jintellitype.JIntellitype; + +import pm.macro.event.Press; + +public class Hotkey extends Press { + protected static ArrayList hotkeyList; + protected static JIntellitype jit; + + public Hotkey(int modifier, int keycode) { + super(null); + int id = hotkeyList.size(); + button = new HotkeyButton(id); + jit.registerHotKey(id, modifier, keycode); + hotkeyList.add(this); + } + + public Hotkey(int modifier, char keycode) { + this(modifier, (int) keycode); + } + + public Hotkey(char keycode) { + this(0, (int) keycode); + } + + public Hotkey(int keycode) { + this(0, keycode); + } + + public static void initialise(ArrayList actionList, JIntellitype jit) { + Hotkey.hotkeyList = actionList; + Hotkey.jit = jit; + } +} diff --git a/java/src/pm/device/jintellitype/HotkeyButton.java b/java/src/pm/device/jintellitype/HotkeyButton.java new file mode 100644 index 0000000..0fd4fda --- /dev/null +++ b/java/src/pm/device/jintellitype/HotkeyButton.java @@ -0,0 +1,23 @@ +package pm.device.jintellitype; + +import com.melloware.jintellitype.JIntellitype; + +import pm.Button; + +public class HotkeyButton implements Button { + public static final int + MOD_ALT = JIntellitype.MOD_ALT, + MOD_CTRL = JIntellitype.MOD_CONTROL, + MOD_SHIFT = JIntellitype.MOD_SHIFT, + MOD_WIN = JIntellitype.MOD_WIN; + + protected int code; + + public HotkeyButton(int code) { + this.code = code; + } + + public int getCode() { + return code; + } +} diff --git a/java/src/pm/device/jintellitype/JIntellitypeDevice.java b/java/src/pm/device/jintellitype/JIntellitypeDevice.java new file mode 100644 index 0000000..a5b3f43 --- /dev/null +++ b/java/src/pm/device/jintellitype/JIntellitypeDevice.java @@ -0,0 +1,67 @@ +package pm.device.jintellitype; + +import java.util.ArrayList; + +import com.melloware.jintellitype.HotkeyListener; +import com.melloware.jintellitype.IntellitypeListener; +import com.melloware.jintellitype.JIntellitype; + +import pm.Action; +import pm.Target; +import pm.device.Device; +import pm.exception.EventException; +import pm.exception.MacroException; +import pm.macro.event.Press; +import pm.macro.event.Release; + +public class JIntellitypeDevice extends Device implements HotkeyListener, IntellitypeListener { + protected ArrayList hotkeyList; + protected JIntellitype jit; + + public JIntellitypeDevice() { + hotkeyList = new ArrayList(); + jit = JIntellitype.getInstance(); + Hotkey.initialise(hotkeyList, jit); + } + + public void start() { + super.start(); + jit.addHotKeyListener(this); + jit.addIntellitypeListener(this); + try { + add( + new Hotkey(HotkeyButton.MOD_CTRL | HotkeyButton.MOD_WIN, 'I'), + Action.EXIT.setTarget(Target.MAIN)); + add( + new Press(CommandButton.VOLUME_UP), + Action.EXIT.setTarget(Target.MAIN)); + } catch (MacroException e) { + e.printStackTrace(); + } + } + + public void onIntellitype(int command) { + CommandButton commandButton; + try { + commandButton = CommandButton.create(command); + System.out.println(commandButton); + add(new Press(commandButton)); + add(new Release(commandButton)); + } catch (EventException e) { + // Todo: deze exception verder omhoog gooien + e.printStackTrace(); + } + } + + public void onHotKey(int id) { + Hotkey hotkey = hotkeyList.get(id); + add(hotkeyList.get(id)); + add(new Release(hotkey.getButton())); + } + + public void exit() { + jit.removeHotKeyListener(this); + jit.removeIntellitypeListener(this); + jit.cleanUp(); + } +} diff --git a/java/src/pm/listener/MacroListener.java b/java/src/pm/listener/MacroListener.java index 4e8ad86..b8de44d 100644 --- a/java/src/pm/listener/MacroListener.java +++ b/java/src/pm/listener/MacroListener.java @@ -5,6 +5,7 @@ import java.util.HashMap; import pm.Action; import pm.Macro; +import pm.exception.MacroException; import pm.macro.Active; import pm.macro.Event; @@ -24,6 +25,10 @@ public class MacroListener extends ActionListener { actionMap.put(macro, action); } + public void add(Event event, Action action) throws MacroException { + add(new Macro(event), action); + } + public void add(Event event) { for (Macro macro : macroList) { activeList.add(new Active(macro));