KeyShortcut { public boolean isEvent(@Nonnull final KeyEvent event) { return this.isEvent(event, ALL_MODIFIERS_MASK); } KeyShortcut(@Nonnull final String packed);  KeyShortcut(@Nonnull final String id, final int keyCode, final int modifiers); boolean isCtrl(); boolean isAlt(); boolean isShift(); boolean isMeta(); int getModifiers(); int getKeyCode(); @Nonnull String getID(); boolean isEvent(@Nonnull final KeyEvent event); boolean isEvent(@Nonnull final KeyEvent event, final int modifiersPlayingRole); @Override int hashCode(); @Override boolean equals(@Nullable final Object object); @Nonnull String packToString(); @Override @Nonnull String toString(); boolean doesConflictWith(@Nullable final KeyStroke stroke); @Nonnull String getKeyCodeName(); static final int ALL_MODIFIERS_MASK; }
@Test public void testIsEvent() { final KeyShortcut shortcut = new KeyShortcut("some", KeyEvent.VK_UP, 0); final KeyEvent eventShift = new KeyEvent(Mockito.mock(Component.class), 1, 0L, KeyEvent.SHIFT_MASK, KeyEvent.VK_UP, ' '); final KeyEvent eventShiftCtrl = new KeyEvent(Mockito.mock(Component.class), 1, 0L, KeyEvent.SHIFT_MASK | KeyEvent.CTRL_MASK, KeyEvent.VK_UP, ' '); assertFalse(shortcut.isEvent(eventShift)); assertFalse(shortcut.isEvent(eventShift, KeyShortcut.ALL_MODIFIERS_MASK ^ KeyEvent.CTRL_MASK)); assertTrue(shortcut.isEvent(eventShift, KeyShortcut.ALL_MODIFIERS_MASK ^ KeyEvent.SHIFT_MASK)); assertFalse(shortcut.isEvent(eventShiftCtrl)); assertFalse(shortcut.isEvent(eventShiftCtrl, KeyShortcut.ALL_MODIFIERS_MASK ^ KeyEvent.CTRL_MASK)); assertFalse(shortcut.isEvent(eventShiftCtrl, KeyShortcut.ALL_MODIFIERS_MASK ^ KeyEvent.SHIFT_MASK)); assertTrue(shortcut.isEvent(eventShiftCtrl, KeyShortcut.ALL_MODIFIERS_MASK ^ KeyEvent.SHIFT_MASK ^ KeyEvent.CTRL_MASK)); }