Search in sources :

Example 1 with KeyCombination

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);
}
Also used : KeyCode(javafx.scene.input.KeyCode) KeyCombination(javafx.scene.input.KeyCombination)

Example 2 with KeyCombination

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));
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) KeyCombination(javafx.scene.input.KeyCombination) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with KeyCombination

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));
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) KeyCombination(javafx.scene.input.KeyCombination) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with KeyCombination

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));
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) KeyCombination(javafx.scene.input.KeyCombination) Test(org.junit.Test)

Aggregations

KeyCombination (javafx.scene.input.KeyCombination)4 KeyEvent (javafx.scene.input.KeyEvent)3 Test (org.junit.Test)3 Ignore (org.junit.Ignore)2 KeyCode (javafx.scene.input.KeyCode)1