Omzetten JavaInputButton naar flexibel automatisch systeem. Werkt bijna!
This commit is contained in:
15
java/src/pm/device/javainput/JavaInputButton.java
Normal file
15
java/src/pm/device/javainput/JavaInputButton.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package pm.device.javainput;
|
||||
|
||||
import pm.Button;
|
||||
|
||||
public class JavaInputButton implements Button {
|
||||
protected int code;
|
||||
|
||||
public JavaInputButton(int button) {
|
||||
code = button - 1;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.valueOf(code + 1);
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,9 @@ public abstract class JavaInputDevice extends Device {
|
||||
add(new Press(button));
|
||||
} else {
|
||||
System.out.println("Release: " + button);
|
||||
System.out.println(">" + new Release(button));
|
||||
add(new Release(button));
|
||||
System.out.println("erna");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,40 +2,49 @@ package pm.device.javainput.rumblepad;
|
||||
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import pm.Button;
|
||||
import pm.device.javainput.JavaInputButton;
|
||||
import pm.exception.event.UnknownButtonException;
|
||||
|
||||
public enum RumblepadButton implements Button {
|
||||
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");
|
||||
ONE (0),
|
||||
TWO (1),
|
||||
THREE (2),
|
||||
FOUR (3),
|
||||
FIVE (4),
|
||||
SIX (5),
|
||||
SEVEN (6),
|
||||
EIGHT (7),
|
||||
NINE (8),
|
||||
TEN (9);
|
||||
|
||||
protected String code;
|
||||
protected int code;
|
||||
|
||||
private RumblepadButton(String code) {
|
||||
private RumblepadButton(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static RumblepadButton create(String code) throws UnknownButtonException {
|
||||
public static JavaInputButton create(int code) throws UnknownButtonException {
|
||||
for (RumblepadButton button : RumblepadButton.values()) {
|
||||
if (button.getCode().equals(code)) {
|
||||
return button;
|
||||
if (button.getCode() == code) {
|
||||
return new JavaInputButton(code + 1);
|
||||
}
|
||||
}
|
||||
throw new UnknownButtonException();
|
||||
}
|
||||
|
||||
public static RumblepadButton create(JXInputButtonEvent event) throws UnknownButtonException {
|
||||
return create(event.getButton().getName());
|
||||
public static JavaInputButton create(JXInputButtonEvent event) throws UnknownButtonException {
|
||||
String name = event.getButton().getName();
|
||||
String button = name.replaceFirst("Button ", "");
|
||||
int code = Integer.valueOf(button);
|
||||
//System.out.println(name + " " + button + " " + code);
|
||||
return create(code);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.valueOf(getCode());
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import pm.Button;
|
||||
import pm.Macro;
|
||||
import pm.Target;
|
||||
import pm.device.javainput.EightfoldDirection;
|
||||
import pm.device.javainput.JavaInputButton;
|
||||
import pm.device.javainput.JavaInputDevice;
|
||||
import pm.exception.DeviceException;
|
||||
import pm.exception.MacroException;
|
||||
@@ -35,9 +36,7 @@ public class RumblepadDevice extends JavaInputDevice {
|
||||
new Press(RumblepadButton.THREE),
|
||||
Action.RESUME.setTarget(Target.APPLICATION));
|
||||
add(
|
||||
new Macro(
|
||||
new Press(RumblepadButton.NINE)
|
||||
),
|
||||
new Press(new JavaInputButton(9)),
|
||||
Action.EXIT.setTarget(Target.MAIN));
|
||||
} catch (MacroException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -30,6 +30,7 @@ public class MacroListener extends ActionListener {
|
||||
}
|
||||
|
||||
public void add(Event event) {
|
||||
System.out.println("]] binnen " + event);
|
||||
for (Macro macro : macroList) {
|
||||
activeList.add(new Active(macro));
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@ public abstract class Event {
|
||||
}
|
||||
|
||||
public boolean equals(Event event) {
|
||||
System.out.println(getClass() + " " + event.getClass());
|
||||
System.out.println(getButton() + " " + event.getButton());
|
||||
System.out.println(getButton().getClass() + " " + event.getButton().getClass());
|
||||
System.out.println(event.getButton().equals(button));
|
||||
return event.getClass().equals(getClass()) && event.getButton().equals(button);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user