Voici un exemple d'énumération Java pour représenter les types de claviers mentionnés dans le fichier geometry.yaml (ANSI, ISO, ABNT, JIS, ALT, ERGO). Cette énumération inclut une méthode qui vérifie si les coordonnées d'une touche sont valides pour un type de clavier donné.
[Redacted Copy code
import java.util.List;
import java.util.Map;
public enum KeyboardType {
ANSI(
Map.of(
0, List.of("tlde", "ae01", "ae02", "ae03", "ae04", "ae05", "ae06", "ae07", "ae08", "ae09", "ae10", "ae11", "ae12"),
1, List.of("ad01", "ad02", "ad03", "ad04", "ad05", "ad06", "ad07", "ad08", "ad09", "ad10", "ad11", "ad12", "bksl"),
2, List.of("ac01", "ac02", "ac03", "ac04", "ac05", "ac06", "ac07", "ac08", "ac09", "ac10", "ac11"),
3, List.of("ab01", "ab02", "ab03", "ab04", "ab05", "ab06", "ab07", "ab08", "ab09", "ab10")
)
),
ISO(
Map.of(
0, List.of("tlde", "ae01", "ae02", "ae03", "ae04", "ae05", "ae06", "ae07", "ae08", "ae09", "ae10", "ae11", "ae12"),
1, List.of("ad01", "ad02", "ad03", "ad04", "ad05", "ad06", "ad07", "ad08", "ad09", "ad10", "ad11", "ad12"),
2, List.of("ac01", "ac02", "ac03", "ac04", "ac05", "ac06", "ac07", "ac08", "ac09", "ac10", "ac11", "bksl"),
3, List.of("lsgt", "ab01", "ab02", "ab03", "ab04", "ab05", "ab06", "ab07", "ab08", "ab09", "ab10")
)
),
ABNT(
Map.of(
0, List.of("tlde", "ae01", "ae02", "ae03", "ae04", "ae05", "ae06", "ae07", "ae08", "ae09", "ae10", "ae11", "ae12"),
1, List.of("ad01", "ad02", "ad03", "ad04", "ad05", "ad06", "ad07", "ad08", "ad09", "ad10", "ad11", "ad12"),
2, List.of("ac01", "ac02", "ac03", "ac04", "ac05", "ac06", "ac07", "ac08", "ac09", "ac10", "ac11", "bksl"),
3, List.of("lsgt", "ab01", "ab02", "ab03", "ab04", "ab05", "ab06", "ab07", "ab08", "ab09", "ab10", "ab11")
)
),
JIS(
Map.of(
0, List.of("ae01", "ae02", "ae03", "ae04", "ae05", "ae06", "ae07", "ae08", "ae09", "ae10", "ae11", "ae12", "ae13"),
1, List.of("ad01", "ad02", "ad03", "ad04", "ad05", "ad06", "ad07", "ad08", "ad09", "ad10", "ad11", "ad12"),
2, List.of("ac01", "ac02", "ac03", "ac04", "ac05", "ac06", "ac07", "ac08", "ac09", "ac10", "ac11", "bksl"),
3, List.of("ab01", "ab02", "ab03", "ab04", "ab05", "ab06", "ab07", "ab08", "ab09", "ab10", "ab11")
)
),
ALT(
Map.of(
0, List.of("tlde", "ae01", "ae02", "ae03", "ae04", "ae05", "ae06", "ae07", "ae08", "ae09", "ae10", "ae11", "ae12", "bksl"),
1, List.of("ad01", "ad02", "ad03", "ad04", "ad05", "ad06", "ad07", "ad08", "ad09", "ad10", "ad11", "ad12"),
2, List.of("ac01", "ac02", "ac03", "ac04", "ac05", "ac06", "ac07", "ac08", "ac09", "ac10", "ac11"),
3, List.of("ab01", "ab02", "ab03", "ab04", "ab05", "ab06", "ab07", "ab08", "ab09", "ab10")
)
),
ERGO(
Map.of(
0, List.of("tlde", "ae01", "ae02", "ae03", "ae04", "ae05", "ae06", "ae07", "ae08", "ae09", "ae10", "ae11", "ae12"),
1, List.of("ad01", "ad02", "ad03", "ad04", "ad05", "ad06", "ad07", "ad08", "ad09", "ad10", "ad11", "ad12"),
2, List.of("ac01", "ac02", "ac03", "ac04", "ac05", "ac06", "ac07", "ac08", "ac09", "ac10", "ac11", "bksl"),
3, List.of("lsgt", "ab01", "ab02", "ab03", "ab04", "ab05", "ab06", "ab07", "ab08", "ab09", "ab10")
)
);
private final Map<Integer, List<String>> layout;
KeyboardType(Map<Integer, List<String>> layout) {
this.layout = layout;
}
public boolean isValidKey(int row, String key) {
List<String> keys = layout.get(row);
return keys != null && keys.contains(key);
}
public static void main(String[] args) {
// Exemple d'utilisation
System.out.println(KeyboardType.ANSI.isValidKey(1, "ad01")); // true
System.out.println(KeyboardType.ISO.isValidKey(3, "lsgt")); // true
System.out.println(KeyboardType.ERGO.isValidKey(2, "invalidKey")); // false
}
}
Cela garantit une implémentation robuste et facile à maintenir.