public void actionPerformed(ActionEvent e) { KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); Container container = kfm.getCurrentFocusCycleRoot(); FocusTraversalPolicy policy = container.getFocusTraversalPolicy(); if (null == policy) policy = kfm.getDefaultFocusTraversalPolicy(); Component next = moveDown ? policy.getComponentAfter(container, PaletteGroupHeader.this) : policy.getComponentBefore(container, PaletteGroupHeader.this); if (null != next && next instanceof PaletteComponentList) { final PaletteComponentList list = (PaletteComponentList) next; if (list.getModel().getSize() != 0) { list.takeFocusFrom(PaletteGroupHeader.this, list == myComponentList ? 0 : -1); return; } else { next = moveDown ? policy.getComponentAfter(container, next) : policy.getComponentBefore(container, next); } } if (null != next && next instanceof PaletteGroupHeader) { next.requestFocus(); } }
public void actionPerformed(ActionEvent e) { int selIndexBefore = getSelectedIndex(); myDefaultAction.actionPerformed(e); int selIndexCurrent = getSelectedIndex(); if (selIndexBefore != selIndexCurrent) { return; } if (myFocusNext && selIndexCurrent == 0) { return; } KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); Container container = kfm.getCurrentFocusCycleRoot(); FocusTraversalPolicy policy = container.getFocusTraversalPolicy(); if (policy == null) { policy = kfm.getDefaultFocusTraversalPolicy(); } Component next = myFocusNext ? policy.getComponentAfter(container, PaletteItemsComponent.this) : policy.getComponentBefore(container, PaletteItemsComponent.this); if (next instanceof PaletteGroupComponent) { clearSelection(); next.requestFocus(); ((PaletteGroupComponent) next).scrollRectToVisible(next.getBounds()); } }
/** * Uninstalls the sheet on the owner. This method is invoked immediately after the JSheet is * hidden. */ protected void uninstallSheet() { if (isInstalled) { Window owner = getOwner(); if (owner != null) { if (isExperimentalSheet()) { owner.removeWindowListener(windowEventHandler); } else { // Note: We mustn't change the windows focusable state // because // this also affects the focusable state of the JSheet. // owner.setFocusableWindowState(true); owner.setEnabled(true); // ((JFrame) owner).setResizable(true); owner.removeComponentListener(ownerMovementHandler); if (shiftBackLocation != null) { owner.setLocation(shiftBackLocation); } if (oldFocusOwner != null) { owner.toFront(); oldFocusOwner.requestFocus(); } } } isInstalled = false; } }
protected void focusNext(JComponent comp) { FocusTraversalPolicy policy = FlatWelcomeFrame.this.getFocusTraversalPolicy(); if (policy != null) { Component next = policy.getComponentAfter(FlatWelcomeFrame.this, comp); if (next != null) { next.requestFocus(); } } }
protected void focusPrev(JComponent comp) { FocusTraversalPolicy policy = FlatWelcomeFrame.this.getFocusTraversalPolicy(); if (policy != null) { Component prev = policy.getComponentBefore(FlatWelcomeFrame.this, comp); if (prev != null) { prev.requestFocus(); } } }
protected void paintEditor(Graphics g) { Component component = grid.getEditorComponent(); if (component == null) { return; } Rectangle cellBounds = grid.getCellBounds(grid.getEditingRow(), grid.getEditingColumn()); component.setBounds(cellBounds); component.validate(); component.requestFocus(); }
/** * If inputComponent is non-null, the focus is requested on that, otherwise request focus on the * default value */ public void selectInitialValue(JOptionPane op) { if (inputComponent != null) inputComponent.requestFocus(); else { if (initialFocusComponent != null) initialFocusComponent.requestFocus(); if (initialFocusComponent instanceof JButton) { JRootPane root = SwingUtilities.getRootPane(initialFocusComponent); if (root != null) { root.setDefaultButton((JButton) initialFocusComponent); } } } }
public void actionPerformed(ActionEvent e) { JGrid grid = (JGrid) e.getSource(); if (!grid.hasFocus()) { CellEditor cellEditor = grid.getCurrentCellEditor(); if (cellEditor != null && !cellEditor.stopCellEditing()) { return; } grid.requestFocus(); } SelectionModel selectionModel = grid.getSelectionModel(); int anchorRow = selectionModel.getAnchorRow(); int anchorColumn = selectionModel.getAnchorColumn(); grid.editCellAt(anchorRow, anchorColumn, null); Component editorComp = grid.getEditorComponent(); if (editorComp != null) { editorComp.requestFocus(); } }
public void actionPerformed(ActionEvent e) { JListMutable list = (JListMutable) e.getSource(); if (!list.hasFocus()) { CellEditor cellEditor = list.getListCellEditor(); if (cellEditor != null && !cellEditor.stopCellEditing()) { return; } list.requestFocus(); return; } ListSelectionModel rsm = list.getSelectionModel(); int anchorRow = rsm.getAnchorSelectionIndex(); list.editCellAt(anchorRow, null); Component editorComp = list.getEditorComponent(); if (editorComp != null) { editorComp.requestFocus(); } }
public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); if (!table.hasFocus()) { CellEditor cellEditor = table.getCellEditor(); if (cellEditor != null && !cellEditor.stopCellEditing()) { return; } table.requestFocus(); return; } ListSelectionModel rsm = table.getSelectionModel(); int anchorRow = rsm.getAnchorSelectionIndex(); table.editCellAt(anchorRow, PropertySheetTableModel.VALUE_COLUMN); Component editorComp = table.getEditorComponent(); if (editorComp != null) { editorComp.requestFocus(); } }
public void actionPerformed(ActionEvent e) { JDesktopPane dp = (JDesktopPane) e.getSource(); String key = getName(); if (CLOSE == key || MAXIMIZE == key || MINIMIZE == key || RESTORE == key) { setState(dp, key); } else if (ESCAPE == key) { if (sourceFrame == dp.getSelectedFrame() && focusOwner != null) { focusOwner.requestFocus(); } moving = false; resizing = false; sourceFrame = null; focusOwner = null; } else if (MOVE == key || RESIZE == key) { sourceFrame = dp.getSelectedFrame(); if (sourceFrame == null) { return; } moving = (key == MOVE) ? true : false; resizing = (key == RESIZE) ? true : false; focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (!SwingUtilities.isDescendingFrom(focusOwner, sourceFrame)) { focusOwner = null; } sourceFrame.requestFocus(); } else if (LEFT == key || RIGHT == key || UP == key || DOWN == key || SHRINK_RIGHT == key || SHRINK_LEFT == key || SHRINK_UP == key || SHRINK_DOWN == key) { JInternalFrame c = dp.getSelectedFrame(); if (sourceFrame == null || c != sourceFrame || KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != sourceFrame) { return; } Insets minOnScreenInsets = UIManager.getInsets("Desktop.minOnScreenInsets"); Dimension size = c.getSize(); Dimension minSize = c.getMinimumSize(); int dpWidth = dp.getWidth(); int dpHeight = dp.getHeight(); int delta; Point loc = c.getLocation(); if (LEFT == key) { if (moving) { c.setLocation( loc.x + size.width - MOVE_RESIZE_INCREMENT < minOnScreenInsets.right ? -size.width + minOnScreenInsets.right : loc.x - MOVE_RESIZE_INCREMENT, loc.y); } else if (resizing) { c.setLocation(loc.x - MOVE_RESIZE_INCREMENT, loc.y); c.setSize(size.width + MOVE_RESIZE_INCREMENT, size.height); } } else if (RIGHT == key) { if (moving) { c.setLocation( loc.x + MOVE_RESIZE_INCREMENT > dpWidth - minOnScreenInsets.left ? dpWidth - minOnScreenInsets.left : loc.x + MOVE_RESIZE_INCREMENT, loc.y); } else if (resizing) { c.setSize(size.width + MOVE_RESIZE_INCREMENT, size.height); } } else if (UP == key) { if (moving) { c.setLocation( loc.x, loc.y + size.height - MOVE_RESIZE_INCREMENT < minOnScreenInsets.bottom ? -size.height + minOnScreenInsets.bottom : loc.y - MOVE_RESIZE_INCREMENT); } else if (resizing) { c.setLocation(loc.x, loc.y - MOVE_RESIZE_INCREMENT); c.setSize(size.width, size.height + MOVE_RESIZE_INCREMENT); } } else if (DOWN == key) { if (moving) { c.setLocation( loc.x, loc.y + MOVE_RESIZE_INCREMENT > dpHeight - minOnScreenInsets.top ? dpHeight - minOnScreenInsets.top : loc.y + MOVE_RESIZE_INCREMENT); } else if (resizing) { c.setSize(size.width, size.height + MOVE_RESIZE_INCREMENT); } } else if (SHRINK_LEFT == key && resizing) { // Make sure we don't resize less than minimum size. if (minSize.width < (size.width - MOVE_RESIZE_INCREMENT)) { delta = MOVE_RESIZE_INCREMENT; } else { delta = size.width - minSize.width; } // Ensure that we keep the internal frame on the desktop. if (loc.x + size.width - delta < minOnScreenInsets.left) { delta = loc.x + size.width - minOnScreenInsets.left; } c.setSize(size.width - delta, size.height); } else if (SHRINK_RIGHT == key && resizing) { // Make sure we don't resize less than minimum size. if (minSize.width < (size.width - MOVE_RESIZE_INCREMENT)) { delta = MOVE_RESIZE_INCREMENT; } else { delta = size.width - minSize.width; } // Ensure that we keep the internal frame on the desktop. if (loc.x + delta > dpWidth - minOnScreenInsets.right) { delta = (dpWidth - minOnScreenInsets.right) - loc.x; } c.setLocation(loc.x + delta, loc.y); c.setSize(size.width - delta, size.height); } else if (SHRINK_UP == key && resizing) { // Make sure we don't resize less than minimum size. if (minSize.height < (size.height - MOVE_RESIZE_INCREMENT)) { delta = MOVE_RESIZE_INCREMENT; } else { delta = size.height - minSize.height; } // Ensure that we keep the internal frame on the desktop. if (loc.y + size.height - delta < minOnScreenInsets.bottom) { delta = loc.y + size.height - minOnScreenInsets.bottom; } c.setSize(size.width, size.height - delta); } else if (SHRINK_DOWN == key && resizing) { // Make sure we don't resize less than minimum size. if (minSize.height < (size.height - MOVE_RESIZE_INCREMENT)) { delta = MOVE_RESIZE_INCREMENT; } else { delta = size.height - minSize.height; } // Ensure that we keep the internal frame on the desktop. if (loc.y + delta > dpHeight - minOnScreenInsets.top) { delta = (dpHeight - minOnScreenInsets.top) - loc.y; } c.setLocation(loc.x, loc.y + delta); c.setSize(size.width, size.height - delta); } } else if (NEXT_FRAME == key || PREVIOUS_FRAME == key) { dp.selectFrame((key == NEXT_FRAME) ? true : false); } else if (NAVIGATE_NEXT == key || NAVIGATE_PREVIOUS == key) { boolean moveForward = true; if (NAVIGATE_PREVIOUS == key) { moveForward = false; } Container cycleRoot = dp.getFocusCycleRootAncestor(); if (cycleRoot != null) { FocusTraversalPolicy policy = cycleRoot.getFocusTraversalPolicy(); if (policy != null && policy instanceof SortingFocusTraversalPolicy) { SortingFocusTraversalPolicy sPolicy = (SortingFocusTraversalPolicy) policy; boolean idc = sPolicy.getImplicitDownCycleTraversal(); try { sPolicy.setImplicitDownCycleTraversal(false); if (moveForward) { KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent(dp); } else { KeyboardFocusManager.getCurrentKeyboardFocusManager().focusPreviousComponent(dp); } } finally { sPolicy.setImplicitDownCycleTraversal(idc); } } } } }
/** * Forwards key events directly to the input handler. This is slightly faster than using a * KeyListener because some Swing overhead is avoided. * * @since 4.3pre7 */ @Override public void processKeyEvent(KeyEvent evt, int from, boolean global) { if (Debug.DUMP_KEY_EVENTS) { Log.log( Log.DEBUG, this, "Key event : " + AbstractInputHandler.toString(evt) + " from " + from); Log.log(Log.DEBUG, this, view + ".isFocused()=" + view.isFocused() + '.', new Exception()); } if (view.getTextArea().hasFocus() && from == View.VIEW) return; evt = _preprocessKeyEvent(evt); if (evt == null) return; if (Debug.DUMP_KEY_EVENTS) { Log.log( Log.DEBUG, this, "Key event after workaround: " + AbstractInputHandler.toString(evt) + " from " + from); } Component prefixFocusOwner = view.getPrefixFocusOwner(); boolean focusOnTextArea = false; switch (evt.getID()) { case KeyEvent.KEY_TYPED: // if the user pressed eg C+e n n in the // search bar we want focus to go back there // after the prefix is done if (prefixFocusOwner != null) { if (prefixFocusOwner.isShowing()) { prefixFocusOwner.requestFocus(); focusOnTextArea = true; } } if (keyEventInterceptor != null) keyEventInterceptor.keyTyped(evt); else if (from == View.ACTION_BAR || isPrefixActive() || view.getTextArea().hasFocus()) { processKeyEventKeyStrokeHandling(evt, from, "type ", global); } processKeyEventSub(focusOnTextArea); break; case KeyEvent.KEY_PRESSED: if (keyEventInterceptor != null) keyEventInterceptor.keyPressed(evt); else if (KeyEventWorkaround.isBindable(evt.getKeyCode())) { if (prefixFocusOwner != null) { if (prefixFocusOwner.isShowing()) { prefixFocusOwner.requestFocus(); focusOnTextArea = true; } view.setPrefixFocusOwner(null); } processKeyEventKeyStrokeHandling(evt, from, "press", global); processKeyEventSub(focusOnTextArea); } break; case KeyEvent.KEY_RELEASED: if (keyEventInterceptor != null) keyEventInterceptor.keyReleased(evt); break; } } // }}}
public SheetMessage( final Window owner, final String title, final String message, final Icon icon, final String[] buttons, final DialogWrapper.DoNotAskOption doNotAskOption, final String defaultButton, final String focusedButton) { final Window activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); final Component recentFocusOwner = activeWindow == null ? null : activeWindow.getMostRecentFocusOwner(); WeakReference<Component> beforeShowFocusOwner = new WeakReference<Component>(recentFocusOwner); maximizeIfNeeded(owner); myWindow = new JDialog(owner, "This should not be shown", Dialog.ModalityType.APPLICATION_MODAL); myWindow.getRootPane().putClientProperty("apple.awt.draggableWindowBackground", Boolean.FALSE); myWindow.addWindowListener( new WindowAdapter() { @Override public void windowActivated(@NotNull WindowEvent e) { super.windowActivated(e); } }); myParent = owner; myWindow.setUndecorated(true); myWindow.setBackground(Gray.TRANSPARENT); myController = new SheetController( this, title, message, icon, buttons, defaultButton, doNotAskOption, focusedButton); imageHeight = 0; registerMoveResizeHandler(); myWindow.setFocusable(true); myWindow.setFocusableWindowState(true); if (SystemInfo.isJavaVersionAtLeast("1.7")) { myWindow.setSize(myController.SHEET_NC_WIDTH, 0); setWindowOpacity(0.0f); myWindow.addComponentListener( new ComponentAdapter() { @Override public void componentShown(@NotNull ComponentEvent e) { super.componentShown(e); setWindowOpacity(1.0f); myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT); } }); } else { myWindow.setModal(true); myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT); setPositionRelativeToParent(); } startAnimation(true); restoreFullScreenButton = couldBeInFullScreen(); if (restoreFullScreenButton) { FullScreenUtilities.setWindowCanFullScreen(myParent, false); } LaterInvocator.enterModal(myWindow); myWindow.setVisible(true); LaterInvocator.leaveModal(myWindow); Component focusCandidate = beforeShowFocusOwner.get(); if (focusCandidate == null) { focusCandidate = IdeFocusManager.getGlobalInstance() .getLastFocusedFor(IdeFocusManager.getGlobalInstance().getLastFocusedFrame()); } // focusCandidate is null if a welcome screen is closed and ide frame is not opened. // this is ok. We set focus correctly on our frame activation. if (focusCandidate != null) { focusCandidate.requestFocus(); } }