@Override public void actionPerformed(ActionEvent evt) { switch (command) { case TAB_OUT_FORWARD: KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent(); break; case TAB_OUT_BACK: KeyboardFocusManager.getCurrentKeyboardFocusManager().focusPreviousComponent(); break; case EDIT_PLUGIN: int[] rows = table.getSelectedRows(); Object[] state = new Object[rows.length]; for (int i = 0; i < rows.length; i++) { state[i] = pluginModel.getValueAt(rows[i], 0); } for (int i = 0; i < rows.length; i++) { pluginModel.setValueAt(state[i].equals(Boolean.FALSE), rows[i], 0); } break; case CLOSE_PLUGIN_MANAGER: window.ok(); break; default: throw new InternalError(); } }
/* * Create using the specified focus policy */ public TabFocusHandler(JTabbedPane tabbedPane, int focusPolicy) { if (focusPolicy != RESET_FOCUS && focusPolicy != RETAIN_FOCUS) throw new IllegalArgumentException("Invalid focus policy"); this.tabbedPane = tabbedPane; this.focusPolicy = focusPolicy; // Add listeners to manage a tab change tabbedPane.addChangeListener(this); KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); focusManager.addPropertyChangeListener("permanentFocusOwner", this); }
/* * The method maps the list of the active windows to the window's AppContext, * then the method registers ActiveWindowListener, GuiDisposedListener listeners; * it executes the initilialization only once per AppContext. */ @SuppressWarnings("unchecked") private static void initActiveWindowsTracking(Window w) { AppContext appContext = AppContext.getAppContext(); synchronized (appContext) { List<WWindowPeer> l = (List<WWindowPeer>) appContext.get(ACTIVE_WINDOWS_KEY); if (l == null) { l = new LinkedList<WWindowPeer>(); appContext.put(ACTIVE_WINDOWS_KEY, l); appContext.addPropertyChangeListener(AppContext.GUI_DISPOSED, guiDisposedListener); KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); kfm.addPropertyChangeListener("activeWindow", activeWindowListener); } } }
public void propertyChange(PropertyChangeEvent e) { boolean isDisposed = (Boolean) e.getNewValue(); if (isDisposed != true) { if (log.isLoggable(PlatformLogger.Level.FINE)) { log.fine(" Assertion (newValue != true) failed for AppContext.GUI_DISPOSED "); } } AppContext appContext = AppContext.getAppContext(); synchronized (appContext) { appContext.remove(ACTIVE_WINDOWS_KEY); appContext.removePropertyChangeListener(AppContext.GUI_DISPOSED, this); KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); kfm.removePropertyChangeListener("activeWindow", activeWindowListener); } }
private void addListeners() { control.addTrackListener(this); // There's a chance the control might have loaded all its tracks before we add ourselves as a // tracklistener, so spawn a thread to check if this is so control .getExecutor() .execute( new CatchingRunnable() { public void doRun() throws Exception { checkTracksLoaded(); } }); // Grab our events... KeyboardFocusManager.getCurrentKeyboardFocusManager() .addKeyEventDispatcher(new KeyEventHandler()); }
private void doAssert(Map<String, String> expected, PlaybackRunner.StatusCallback cb) throws AssertionError { final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (owner == null) { throw new AssertionError("No component focused"); } Component eachParent = owner; final LinkedHashMap<String, String> actual = new LinkedHashMap<String, String>(); while (eachParent != null) { if (eachParent instanceof TestableUi) { ((TestableUi) eachParent).putInfo(actual); } eachParent = eachParent.getParent(); } Set testedKeys = new LinkedHashSet<String>(); for (String eachKey : expected.keySet()) { testedKeys.add(eachKey); final String actualValue = actual.get(eachKey); final String expectedValue = expected.get(eachKey); if (!expectedValue.equals(actualValue)) { throw new AssertionError( eachKey + " expected: " + expectedValue + " but was: " + actualValue); } } Map<String, String> untested = new HashMap<String, String>(); for (String eachKey : actual.keySet()) { if (testedKeys.contains(eachKey)) continue; untested.put(eachKey, actual.get(eachKey)); } StringBuffer untestedText = new StringBuffer(); for (String each : untested.keySet()) { if (untestedText.length() > 0) { untestedText.append(","); } untestedText.append(each).append("=").append(untested.get(each)); } cb.message("Untested info: " + untestedText.toString(), getLine()); }
void deinstallAcceleratorListener() { KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventPostProcessor(this); }
/** * @return <code>true</code> if and only if the passed event is already dispatched by the <code> * IdeKeyEventDispatcher</code> and there is no need for any other processing of the event. */ public boolean dispatchKeyEvent(final KeyEvent e) { if (myDisposed) return false; if (e.isConsumed()) { return false; } // http://www.jetbrains.net/jira/browse/IDEADEV-12372 if (e.getKeyCode() == KeyEvent.VK_CONTROL) { if (e.getID() == KeyEvent.KEY_PRESSED) { myLeftCtrlPressed = e.getKeyLocation() == KeyEvent.KEY_LOCATION_LEFT; } else if (e.getID() == KeyEvent.KEY_RELEASED) { myLeftCtrlPressed = false; } } else if (e.getKeyCode() == KeyEvent.VK_ALT) { if (e.getID() == KeyEvent.KEY_PRESSED) { myRightAltPressed = e.getKeyLocation() == KeyEvent.KEY_LOCATION_RIGHT; } else if (e.getID() == KeyEvent.KEY_RELEASED) { myRightAltPressed = false; } } KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); Component focusOwner = focusManager.getFocusOwner(); // shortcuts should not work in shortcut setup fields if (focusOwner instanceof ShortcutTextField) { return false; } if (focusOwner instanceof JTextComponent && ((JTextComponent) focusOwner).isEditable()) { if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED && e.getKeyChar() != KeyEvent.VK_ESCAPE) { MacUIUtil.hideCursor(); } } MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager(); MenuElement[] selectedPath = menuSelectionManager.getSelectedPath(); if (selectedPath.length > 0) { if (!(selectedPath[0] instanceof ComboPopup)) { // The following couple of lines of code is a PATCH!!! // It is needed to ignore ENTER KEY_TYPED events which sometimes can reach editor when an // action // is invoked from main menu via Enter key. setState(KeyState.STATE_PROCESSED); setPressedWasProcessed(true); return false; } } // Keymap shortcuts (i.e. not local shortcuts) should work only in: // - main frame // - floating focusedWindow // - when there's an editor in contexts Window focusedWindow = focusManager.getFocusedWindow(); boolean isModalContext = focusedWindow != null && isModalContext(focusedWindow); final DataManager dataManager = DataManager.getInstance(); if (dataManager == null) return false; DataContext dataContext = dataManager.getDataContext(); myContext.setDataContext(dataContext); myContext.setFocusOwner(focusOwner); myContext.setModalContext(isModalContext); myContext.setInputEvent(e); try { if (getState() == KeyState.STATE_INIT) { return inInitState(); } else if (getState() == KeyState.STATE_PROCESSED) { return inProcessedState(); } else if (getState() == KeyState.STATE_WAIT_FOR_SECOND_KEYSTROKE) { return inWaitForSecondStrokeState(); } else if (getState() == KeyState.STATE_SECOND_STROKE_IN_PROGRESS) { return inSecondStrokeInProgressState(); } else if (getState() == KeyState.STATE_KEY_GESTURE_PROCESSOR) { return myKeyGestureProcessor.process(); } else { throw new IllegalStateException("state = " + getState()); } } finally { myContext.clear(); } }