use of javafx.scene.input.KeyCombination in project jabref by JabRef.
the class KeyBindingRepository method checkKeyCombinationEquality.
/**
* Check if the given keyCombination equals the given keyEvent
*
* @param combination as KeyCombination
* @param keyEvent as KeEvent
* @return true if matching, else false
*/
public boolean checkKeyCombinationEquality(KeyCombination combination, KeyEvent keyEvent) {
KeyCode code = keyEvent.getCode();
if (code == KeyCode.UNDEFINED) {
return false;
}
// gather the pressed modifier keys
String modifiers = "";
if (keyEvent.isControlDown()) {
modifiers = "ctrl";
}
if (keyEvent.isShiftDown()) {
modifiers += " shift";
}
if (keyEvent.isAltDown()) {
modifiers += " alt";
}
modifiers = modifiers.trim();
String newShortcut = (modifiers.isEmpty()) ? code.toString() : modifiers + " " + code;
KeyCombination pressedCombination = KeyCombination.valueOf(newShortcut);
return combination.equals(pressedCombination);
}
use of javafx.scene.input.KeyCombination in project jabref by JabRef.
the class KeyBindingsDialogViewModelTest method testRandomNewKeyKeyBindingInRepository.
@Test
@Ignore
public void testRandomNewKeyKeyBindingInRepository() {
setKeyBindingViewModel(KeyBinding.CLEANUP);
KeyEvent shortcutKeyEvent = new KeyEvent(KeyEvent.KEY_PRESSED, "K", "K", KeyCode.K, true, true, true, false);
assertFalse(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.CLEANUP, shortcutKeyEvent));
model.setNewBindingForCurrent(shortcutKeyEvent);
KeyCombination combination = KeyCombination.keyCombination(keyBindingRepository.get(KeyBinding.CLEANUP).get());
assertTrue(keyBindingRepository.checkKeyCombinationEquality(combination, shortcutKeyEvent));
assertFalse(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.CLEANUP, shortcutKeyEvent));
}
use of javafx.scene.input.KeyCombination in project jabref by JabRef.
the class KeyBindingsDialogViewModelTest method testSpecialKeysValidKeyBindingIsSaved.
@Test
@Ignore
public void testSpecialKeysValidKeyBindingIsSaved() {
setKeyBindingViewModel(KeyBinding.IMPORT_INTO_NEW_DATABASE);
KeyEvent shortcutKeyEvent = new KeyEvent(KeyEvent.KEY_RELEASED, "F1", "F1", KeyCode.F1, false, false, false, false);
assertFalse(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.IMPORT_INTO_NEW_DATABASE, shortcutKeyEvent));
model.setNewBindingForCurrent(shortcutKeyEvent);
KeyCombination combination = KeyCombination.keyCombination(keyBindingRepository.get(KeyBinding.IMPORT_INTO_NEW_DATABASE).get());
assertTrue(keyBindingRepository.checkKeyCombinationEquality(combination, shortcutKeyEvent));
model.saveKeyBindings();
assertTrue(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.IMPORT_INTO_NEW_DATABASE, shortcutKeyEvent));
}
use of javafx.scene.input.KeyCombination in project jabref by JabRef.
the class KeyBindingsDialogViewModelTest method testInvalidKeyBindingIsNotSaved.
@Test
public void testInvalidKeyBindingIsNotSaved() {
setKeyBindingViewModel(KeyBinding.COPY);
KeyEvent shortcutKeyEvent = new KeyEvent(KeyEvent.KEY_RELEASED, "Q", "Q", KeyCode.Q, false, false, false, false);
assertFalse(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.COPY, shortcutKeyEvent));
model.setNewBindingForCurrent(shortcutKeyEvent);
KeyCombination combination = KeyCombination.keyCombination(keyBindingRepository.get(KeyBinding.COPY).get());
assertFalse(keyBindingRepository.checkKeyCombinationEquality(combination, shortcutKeyEvent));
model.saveKeyBindings();
assertFalse(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.COPY, shortcutKeyEvent));
}
Aggregations