diff options
| author | Jules Aguillon | 2022-03-05 18:15:36 +0100 |
|---|---|---|
| committer | Jules Aguillon | 2022-03-05 19:22:01 +0100 |
| commit | e92504ae92873ca7f0efa80421893bc69f98fa11 (patch) | |
| tree | 617658973d150e51bb398c1b9b937a5098a5e3fa /srcs/juloo.keyboard2/KeyboardData.java | |
| parent | 4964bfb87f8d7dab50990864e274d4bc494f67b0 (diff) | |
| download | unexpected-keyboard-e92504ae92873ca7f0efa80421893bc69f98fa11.tar.gz unexpected-keyboard-e92504ae92873ca7f0efa80421893bc69f98fa11.zip | |
Improve the code for dynamic updates of the layout
Diffstat (limited to 'srcs/juloo.keyboard2/KeyboardData.java')
| -rw-r--r-- | srcs/juloo.keyboard2/KeyboardData.java | 69 |
1 files changed, 4 insertions, 65 deletions
diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index 90085e5..81b6870 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; class KeyboardData { @@ -184,7 +185,8 @@ class KeyboardData public Key replaceKeys(MapKeys f) { - return new Key(f.map(key0), f.map(key1), f.map(key2), f.map(key3), f.map(key4), width, shift, edgekeys); + return new Key(f.apply(key0), f.apply(key1), f.apply(key2), + f.apply(key3), f.apply(key4), width, shift, edgekeys); } /** New key with the width multiplied by 's'. */ @@ -194,70 +196,7 @@ class KeyboardData } } - public static abstract interface MapKeys - { - public abstract KeyValue map(KeyValue k); - } - - public static class ReplaceKeysByFlags implements MapKeys - { - private final int _flags; - private final KeyValue _replacement; - - public ReplaceKeysByFlags(int flags, KeyValue r) - { - _flags = flags; - _replacement = r; - } - - public KeyValue map(KeyValue k) - { - return (k != null && (k.flags & _flags) != 0) ? _replacement : k; - } - } - - public static class ReplaceKeysByEvent implements MapKeys - { - private final int _eventCode; - private final KeyValue _replacement; - - public ReplaceKeysByEvent(int ev, KeyValue r) - { - _eventCode = ev; - _replacement = r; - } - - public KeyValue map(KeyValue k) - { - return (k != null && k.eventCode == _eventCode) ? _replacement : k; - } - } - - /* Replace two keys at the same time. Used for swaping keys. */ - public static class ReplaceKeysByEvent2 implements MapKeys - { - private final int _e1; - private final KeyValue _r1; - private final int _e2; - private final KeyValue _r2; - - public ReplaceKeysByEvent2(int e1, KeyValue r1, int e2, KeyValue r2) - { - _e1 = e1; - _r1 = r1; - _e2 = e2; - _r2 = r2; - } - - public KeyValue map(KeyValue k) - { - if (k == null) - return null; - if (k.eventCode == _e1) return _r1; - if (k.eventCode == _e2) return _r2; - return k; - } - } + public static abstract interface MapKeys extends Function<KeyValue, KeyValue> { } /** Parsing utils */ |
