Java Code Examples for sun.swing.SwingUtilities2#compositeRequestFocus()

The following examples show how to use sun.swing.SwingUtilities2#compositeRequestFocus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicSplitPaneUI.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void toggleFocus(JSplitPane splitPane) {
    Component left = splitPane.getLeftComponent();
    Component right = splitPane.getRightComponent();

    KeyboardFocusManager manager =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Component focus = manager.getFocusOwner();
    Component focusOn = getNextSide(splitPane, focus);
    if (focusOn != null) {
        // don't change the focus if the new focused component belongs
        // to the same splitpane and the same side
        if ( focus!=null &&
             ( (SwingUtilities.isDescendingFrom(focus, left) &&
                SwingUtilities.isDescendingFrom(focusOn, left)) ||
               (SwingUtilities.isDescendingFrom(focus, right) &&
                SwingUtilities.isDescendingFrom(focusOn, right)) ) ) {
            return;
        }
        SwingUtilities2.compositeRequestFocus(focusOn);
    }
}
 
Example 2
Source File: BasicSplitPaneUI.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void toggleFocus(JSplitPane splitPane) {
    Component left = splitPane.getLeftComponent();
    Component right = splitPane.getRightComponent();

    KeyboardFocusManager manager =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Component focus = manager.getFocusOwner();
    Component focusOn = getNextSide(splitPane, focus);
    if (focusOn != null) {
        // don't change the focus if the new focused component belongs
        // to the same splitpane and the same side
        if ( focus!=null &&
             ( (SwingUtilities.isDescendingFrom(focus, left) &&
                SwingUtilities.isDescendingFrom(focusOn, left)) ||
               (SwingUtilities.isDescendingFrom(focus, right) &&
                SwingUtilities.isDescendingFrom(focusOn, right)) ) ) {
            return;
        }
        SwingUtilities2.compositeRequestFocus(focusOn);
    }
}
 
Example 3
Source File: BasicSplitPaneUI.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private void toggleFocus(JSplitPane splitPane) {
    Component left = splitPane.getLeftComponent();
    Component right = splitPane.getRightComponent();

    KeyboardFocusManager manager =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Component focus = manager.getFocusOwner();
    Component focusOn = getNextSide(splitPane, focus);
    if (focusOn != null) {
        // don't change the focus if the new focused component belongs
        // to the same splitpane and the same side
        if ( focus!=null &&
             ( (SwingUtilities.isDescendingFrom(focus, left) &&
                SwingUtilities.isDescendingFrom(focusOn, left)) ||
               (SwingUtilities.isDescendingFrom(focus, right) &&
                SwingUtilities.isDescendingFrom(focusOn, right)) ) ) {
            return;
        }
        SwingUtilities2.compositeRequestFocus(focusOn);
    }
}
 
Example 4
Source File: BasicLabelUI.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private void doRelease(JLabel label) {
    Component labelFor = label.getLabelFor();
    if (labelFor != null && labelFor.isEnabled()) {
        InputMap inputMap = SwingUtilities.getUIInputMap(label, JComponent.WHEN_FOCUSED);
        if (inputMap != null) {
            // inputMap should never be null.
            int dka = label.getDisplayedMnemonic();
            inputMap.remove(KeyStroke.getKeyStroke(dka, BasicLookAndFeel.getFocusAcceleratorKeyMask(), true));
            inputMap.remove(KeyStroke.getKeyStroke(dka, 0, true));
            inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ALT, 0, true));
        }
        if (labelFor instanceof Container &&
                ((Container) labelFor).isFocusCycleRoot()) {
            labelFor.requestFocus();
        } else {
            SwingUtilities2.compositeRequestFocus(labelFor);
        }
    }
}
 
Example 5
Source File: BasicLabelUI.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void doRelease(JLabel label) {
    Component labelFor = label.getLabelFor();
    if (labelFor != null && labelFor.isEnabled()) {
        InputMap inputMap = SwingUtilities.getUIInputMap(label, JComponent.WHEN_FOCUSED);
        if (inputMap != null) {
            // inputMap should never be null.
            int dka = label.getDisplayedMnemonic();
            inputMap.remove(KeyStroke.getKeyStroke(dka, BasicLookAndFeel.getFocusAcceleratorKeyMask(), true));
            inputMap.remove(KeyStroke.getKeyStroke(dka, 0, true));
            inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ALT, 0, true));
        }
        if (labelFor instanceof Container &&
                ((Container) labelFor).isFocusCycleRoot()) {
            labelFor.requestFocus();
        } else {
            SwingUtilities2.compositeRequestFocus(labelFor);
        }
    }
}
 
Example 6
Source File: JInternalFrame.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Requests the internal frame to restore focus to the
 * last subcomponent that had focus. This is used by the UI when
 * the user selected this internal frame --
 * for example, by clicking on the title bar.
 *
 * @since 1.3
 */
public void restoreSubcomponentFocus() {
    if (isIcon()) {
        SwingUtilities2.compositeRequestFocus(getDesktopIcon());
    }
    else {
        Component component = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
        if ((component == null) || !SwingUtilities.isDescendingFrom(component, this)) {
            // FocusPropertyChangeListener will eventually update
            // lastFocusOwner. As focus requests are asynchronous
            // lastFocusOwner may be accessed before it has been correctly
            // updated. To avoid any problems, lastFocusOwner is immediately
            // set, assuming the request will succeed.
            setLastFocusOwner(getMostRecentFocusOwner());
            if (lastFocusOwner == null) {
                // Make sure focus is restored somewhere, so that
                // we don't leave a focused component in another frame while
                // this frame is selected.
                setLastFocusOwner(getContentPane());
            }
            lastFocusOwner.requestFocus();
        }
    }
}
 
Example 7
Source File: JInternalFrame.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Requests the internal frame to restore focus to the
 * last subcomponent that had focus. This is used by the UI when
 * the user selected this internal frame --
 * for example, by clicking on the title bar.
 *
 * @since 1.3
 */
public void restoreSubcomponentFocus() {
    if (isIcon()) {
        SwingUtilities2.compositeRequestFocus(getDesktopIcon());
    }
    else {
        Component component = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
        if ((component == null) || !SwingUtilities.isDescendingFrom(component, this)) {
            // FocusPropertyChangeListener will eventually update
            // lastFocusOwner. As focus requests are asynchronous
            // lastFocusOwner may be accessed before it has been correctly
            // updated. To avoid any problems, lastFocusOwner is immediately
            // set, assuming the request will succeed.
            setLastFocusOwner(getMostRecentFocusOwner());
            if (lastFocusOwner == null) {
                // Make sure focus is restored somewhere, so that
                // we don't leave a focused component in another frame while
                // this frame is selected.
                setLastFocusOwner(getContentPane());
            }
            lastFocusOwner.requestFocus();
        }
    }
}
 
Example 8
Source File: JInternalFrame.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Requests the internal frame to restore focus to the
 * last subcomponent that had focus. This is used by the UI when
 * the user selected this internal frame --
 * for example, by clicking on the title bar.
 *
 * @since 1.3
 */
public void restoreSubcomponentFocus() {
    if (isIcon()) {
        SwingUtilities2.compositeRequestFocus(getDesktopIcon());
    }
    else {
        Component component = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
        if ((component == null) || !SwingUtilities.isDescendingFrom(component, this)) {
            // FocusPropertyChangeListener will eventually update
            // lastFocusOwner. As focus requests are asynchronous
            // lastFocusOwner may be accessed before it has been correctly
            // updated. To avoid any problems, lastFocusOwner is immediately
            // set, assuming the request will succeed.
            setLastFocusOwner(getMostRecentFocusOwner());
            if (lastFocusOwner == null) {
                // Make sure focus is restored somewhere, so that
                // we don't leave a focused component in another frame while
                // this frame is selected.
                setLastFocusOwner(getContentPane());
            }
            lastFocusOwner.requestFocus();
        }
    }
}
 
Example 9
Source File: BasicLabelUI.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
private void doRelease(JLabel label) {
    Component labelFor = label.getLabelFor();
    if (labelFor != null && labelFor.isEnabled()) {
        InputMap inputMap = SwingUtilities.getUIInputMap(label, JComponent.WHEN_FOCUSED);
        if (inputMap != null) {
            // inputMap should never be null.
            int dka = label.getDisplayedMnemonic();
            inputMap.remove(KeyStroke.getKeyStroke(dka, BasicLookAndFeel.getFocusAcceleratorKeyMask(), true));
            inputMap.remove(KeyStroke.getKeyStroke(dka, 0, true));
            inputMap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ALT, 0, true));
        }
        if (labelFor instanceof Container &&
                ((Container) labelFor).isFocusCycleRoot()) {
            labelFor.requestFocus();
        } else {
            SwingUtilities2.compositeRequestFocus(labelFor);
        }
    }
}
 
Example 10
Source File: JInternalFrame.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Requests the internal frame to restore focus to the
 * last subcomponent that had focus. This is used by the UI when
 * the user selected this internal frame --
 * for example, by clicking on the title bar.
 *
 * @since 1.3
 */
public void restoreSubcomponentFocus() {
    if (isIcon()) {
        SwingUtilities2.compositeRequestFocus(getDesktopIcon());
    }
    else {
        Component component = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
        if ((component == null) || !SwingUtilities.isDescendingFrom(component, this)) {
            // FocusPropertyChangeListener will eventually update
            // lastFocusOwner. As focus requests are asynchronous
            // lastFocusOwner may be accessed before it has been correctly
            // updated. To avoid any problems, lastFocusOwner is immediately
            // set, assuming the request will succeed.
            setLastFocusOwner(getMostRecentFocusOwner());
            if (lastFocusOwner == null) {
                // Make sure focus is restored somewhere, so that
                // we don't leave a focused component in another frame while
                // this frame is selected.
                setLastFocusOwner(getContentPane());
            }
            lastFocusOwner.requestFocus();
        }
    }
}
 
Example 11
Source File: BasicSplitPaneUI.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void toggleFocus(JSplitPane splitPane) {
    Component left = splitPane.getLeftComponent();
    Component right = splitPane.getRightComponent();

    KeyboardFocusManager manager =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Component focus = manager.getFocusOwner();
    Component focusOn = getNextSide(splitPane, focus);
    if (focusOn != null) {
        // don't change the focus if the new focused component belongs
        // to the same splitpane and the same side
        if ( focus!=null &&
             ( (SwingUtilities.isDescendingFrom(focus, left) &&
                SwingUtilities.isDescendingFrom(focusOn, left)) ||
               (SwingUtilities.isDescendingFrom(focus, right) &&
                SwingUtilities.isDescendingFrom(focusOn, right)) ) ) {
            return;
        }
        SwingUtilities2.compositeRequestFocus(focusOn);
    }
}
 
Example 12
Source File: BasicTableUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void mousePressed(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, table)) {
        return;
    }

    if (table.isEditing() && !table.getCellEditor().stopCellEditing()) {
        Component editorComponent = table.getEditorComponent();
        if (editorComponent != null && !editorComponent.hasFocus()) {
            SwingUtilities2.compositeRequestFocus(editorComponent);
        }
        return;
    }

    Point p = e.getPoint();
    pressedRow = table.rowAtPoint(p);
    pressedCol = table.columnAtPoint(p);
    outsidePrefSize = pointOutsidePrefSize(pressedRow, pressedCol, p);

    if (isFileList) {
        shouldStartTimer =
            table.isCellSelected(pressedRow, pressedCol) &&
            !e.isShiftDown() &&
            !BasicGraphicsUtils.isMenuShortcutKeyDown(e) &&
            !outsidePrefSize;
    }

    if (table.getDragEnabled()) {
        mousePressedDND(e);
    } else {
        SwingUtilities2.adjustFocus(table);
        if (!isFileList) {
            setValueIsAdjusting(true);
        }
        adjustSelection(e);
    }
}
 
Example 13
Source File: BasicTableUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void mousePressed(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, table)) {
        return;
    }

    if (table.isEditing() && !table.getCellEditor().stopCellEditing()) {
        Component editorComponent = table.getEditorComponent();
        if (editorComponent != null && !editorComponent.hasFocus()) {
            SwingUtilities2.compositeRequestFocus(editorComponent);
        }
        return;
    }

    Point p = e.getPoint();
    pressedRow = table.rowAtPoint(p);
    pressedCol = table.columnAtPoint(p);
    outsidePrefSize = pointOutsidePrefSize(pressedRow, pressedCol, p);

    if (isFileList) {
        shouldStartTimer =
            table.isCellSelected(pressedRow, pressedCol) &&
            !e.isShiftDown() &&
            !BasicGraphicsUtils.isMenuShortcutKeyDown(e) &&
            !outsidePrefSize;
    }

    if (table.getDragEnabled()) {
        mousePressedDND(e);
    } else {
        SwingUtilities2.adjustFocus(table);
        if (!isFileList) {
            setValueIsAdjusting(true);
        }
        adjustSelection(e);
    }
}
 
Example 14
Source File: BasicTableUI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent ae) {
    table.editCellAt(pressedRow, pressedCol, null);
    Component editorComponent = table.getEditorComponent();
    if (editorComponent != null && !editorComponent.hasFocus()) {
        SwingUtilities2.compositeRequestFocus(editorComponent);
    }
    return;
}
 
Example 15
Source File: BasicTableUI.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void mousePressed(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, table)) {
        return;
    }

    if (table.isEditing() && !table.getCellEditor().stopCellEditing()) {
        Component editorComponent = table.getEditorComponent();
        if (editorComponent != null && !editorComponent.hasFocus()) {
            SwingUtilities2.compositeRequestFocus(editorComponent);
        }
        return;
    }

    Point p = e.getPoint();
    pressedRow = table.rowAtPoint(p);
    pressedCol = table.columnAtPoint(p);
    outsidePrefSize = pointOutsidePrefSize(pressedRow, pressedCol, p);

    if (isFileList) {
        shouldStartTimer =
            table.isCellSelected(pressedRow, pressedCol) &&
            !e.isShiftDown() &&
            !BasicGraphicsUtils.isMenuShortcutKeyDown(e) &&
            !outsidePrefSize;
    }

    if (table.getDragEnabled()) {
        mousePressedDND(e);
    } else {
        SwingUtilities2.adjustFocus(table);
        if (!isFileList) {
            setValueIsAdjusting(true);
        }
        adjustSelection(e);
    }
}
 
Example 16
Source File: BasicTableUI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent ae) {
    table.editCellAt(pressedRow, pressedCol, null);
    Component editorComponent = table.getEditorComponent();
    if (editorComponent != null && !editorComponent.hasFocus()) {
        SwingUtilities2.compositeRequestFocus(editorComponent);
    }
    return;
}
 
Example 17
Source File: BasicTableUI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent ae) {
    table.editCellAt(pressedRow, pressedCol, null);
    Component editorComponent = table.getEditorComponent();
    if (editorComponent != null && !editorComponent.hasFocus()) {
        SwingUtilities2.compositeRequestFocus(editorComponent);
    }
    return;
}
 
Example 18
Source File: BasicTableUI.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void mousePressed(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, table)) {
        return;
    }

    if (table.isEditing() && !table.getCellEditor().stopCellEditing()) {
        Component editorComponent = table.getEditorComponent();
        if (editorComponent != null && !editorComponent.hasFocus()) {
            SwingUtilities2.compositeRequestFocus(editorComponent);
        }
        return;
    }

    Point p = e.getPoint();
    pressedRow = table.rowAtPoint(p);
    pressedCol = table.columnAtPoint(p);
    outsidePrefSize = pointOutsidePrefSize(pressedRow, pressedCol, p);

    if (isFileList) {
        shouldStartTimer =
            table.isCellSelected(pressedRow, pressedCol) &&
            !e.isShiftDown() &&
            !BasicGraphicsUtils.isMenuShortcutKeyDown(e) &&
            !outsidePrefSize;
    }

    if (table.getDragEnabled()) {
        mousePressedDND(e);
    } else {
        SwingUtilities2.adjustFocus(table);
        if (!isFileList) {
            setValueIsAdjusting(true);
        }
        adjustSelection(e);
    }
}
 
Example 19
Source File: DarkTableUI.java    From darklaf with MIT License 5 votes vote down vote up
protected void startEditing(final int row, final int column) {
    table.editCellAt(row, column, null);
    Component editorComponent = table.getEditorComponent();
    if (editorComponent != null && !editorComponent.hasFocus()) {
        SwingUtilities2.compositeRequestFocus(editorComponent);
    }
}
 
Example 20
Source File: BasicTableUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void mousePressed(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, table)) {
        return;
    }

    if (table.isEditing() && !table.getCellEditor().stopCellEditing()) {
        Component editorComponent = table.getEditorComponent();
        if (editorComponent != null && !editorComponent.hasFocus()) {
            SwingUtilities2.compositeRequestFocus(editorComponent);
        }
        return;
    }

    Point p = e.getPoint();
    pressedRow = table.rowAtPoint(p);
    pressedCol = table.columnAtPoint(p);
    outsidePrefSize = pointOutsidePrefSize(pressedRow, pressedCol, p);

    if (isFileList) {
        shouldStartTimer =
            table.isCellSelected(pressedRow, pressedCol) &&
            !e.isShiftDown() &&
            !BasicGraphicsUtils.isMenuShortcutKeyDown(e) &&
            !outsidePrefSize;
    }

    if (table.getDragEnabled()) {
        mousePressedDND(e);
    } else {
        SwingUtilities2.adjustFocus(table);
        if (!isFileList) {
            setValueIsAdjusting(true);
        }
        adjustSelection(e);
    }
}