Implementatie JIntellitype hotkeys en commands voltooid. Mogelijk tot registreren van enkelvoudige events in plaats van macro toegevoegd.

This commit is contained in:
2011-02-08 16:33:31 +00:00
parent 091dcdf855
commit 401690c8a6
9 changed files with 225 additions and 7 deletions

View File

@@ -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);

View File

@@ -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() {}
}

View File

@@ -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));

View File

@@ -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),

View File

@@ -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();
}
}

View File

@@ -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<Hotkey> 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<Hotkey> actionList, JIntellitype jit) {
Hotkey.hotkeyList = actionList;
Hotkey.jit = jit;
}
}

View File

@@ -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;
}
}

View File

@@ -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<Hotkey> hotkeyList;
protected JIntellitype jit;
public JIntellitypeDevice() {
hotkeyList = new ArrayList<Hotkey>();
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();
}
}

View File

@@ -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));