SlideshowFXKeyCombination extends KeyCombination { public static SlideshowFXKeyCombination valueOf(String value) { if (value == null) throw new NullPointerException("The value can not be null"); if (value.isEmpty()) throw new IllegalArgumentException("The value can not be empty"); String determinedText = null; KeyCode determinedCode = KeyCode.UNDEFINED; ModifierValue shiftModifier = ModifierValue.UP; ModifierValue controlModifier = ModifierValue.UP; ModifierValue shortcutModifier = ModifierValue.UP; ModifierValue metaModifier = ModifierValue.UP; ModifierValue altModifier = ModifierValue.UP; final String[] tokens = value.split("\\+"); for (String token : tokens) { switch (token) { case "Shortcut": shortcutModifier = ModifierValue.DOWN; break; case "Ctrl": controlModifier = ModifierValue.DOWN; break; case "Shift": shiftModifier = ModifierValue.DOWN; break; case "Meta": metaModifier = ModifierValue.DOWN; break; case "Alt": altModifier = ModifierValue.DOWN; break; default: determinedText = token; determinedCode = KeyCode.valueOf(determinedText); } } final SlideshowFXKeyCombination combination = new SlideshowFXKeyCombination(determinedText, determinedCode, shiftModifier, controlModifier, altModifier, metaModifier, shortcutModifier); return combination; } SlideshowFXKeyCombination(final String text, final KeyCode code, final ModifierValue shift, final ModifierValue control,
                                     final ModifierValue alt, final ModifierValue meta, final ModifierValue shortcut); String getText(); @Override String getDisplayText(); @Override boolean match(KeyEvent event); static SlideshowFXKeyCombination valueOf(String value); @Override boolean equals(final Object obj); @Override int hashCode(); static final Logger LOGGER; }
@Test public void testShortcutA() { final SlideshowFXKeyCombination combination = SlideshowFXKeyCombination.valueOf("Shortcut+A"); assertCombination(UP, UP, UP, UP, DOWN, "A", combination); }
@Test public void testShiftA() { final SlideshowFXKeyCombination combination = SlideshowFXKeyCombination.valueOf("Shift+A"); assertCombination(DOWN, UP, UP, UP, UP, "A", combination); }
@Test public void testControlA() { final SlideshowFXKeyCombination combination = SlideshowFXKeyCombination.valueOf("Ctrl+A"); assertCombination(UP, UP, DOWN, UP, UP, "A", combination); }
@Test public void testMetaA() { final SlideshowFXKeyCombination combination = SlideshowFXKeyCombination.valueOf("Meta+A"); assertCombination(UP, UP, UP, DOWN, UP, "A", combination); }
@Test public void testAltA() { final SlideshowFXKeyCombination combination = SlideshowFXKeyCombination.valueOf("Alt+A"); assertCombination(UP, DOWN, UP, UP, UP, "A", combination); }
@Test public void testShortcutMetaA() { final SlideshowFXKeyCombination combination = SlideshowFXKeyCombination.valueOf("Shortcut+Meta+A"); assertCombination(UP, UP, UP, DOWN, DOWN, "A", combination); }
@Test public void testMetaShortcutA() { final SlideshowFXKeyCombination combination = SlideshowFXKeyCombination.valueOf("Meta+Shortcut+A"); assertCombination(UP, UP, UP, DOWN, DOWN, "A", combination); }