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

The following examples show how to use sun.swing.SwingUtilities2#adjustFocus() . 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: DarkListUIBridge.java    From darklaf with MIT License 6 votes vote down vote up
public void mouseReleased(final MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, list)) {
        return;
    }

    if (list.getDragEnabled()) {
        MouseEvent me = DragRecognitionSupport.mouseReleased(e);
        if (me != null) {
            SwingUtilities2.adjustFocus(list);
            if (!dragPressDidSelection) {
                adjustSelection(me);
            }
        }
    } else {
        list.setValueIsAdjusting(false);
    }
}
 
Example 2
Source File: BasicTreeUI.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Invoked when a mouse button has been pressed on a component.
 */
public void mousePressed(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, tree)) {
        return;
    }

    // if we can't stop any ongoing editing, do nothing
    if (isEditing(tree) && tree.getInvokesStopCellEditing()
                        && !stopEditing(tree)) {
        return;
    }

    completeEditing();

    pressedPath = getClosestPathForLocation(tree, e.getX(), e.getY());

    if (tree.getDragEnabled()) {
        mousePressedDND(e);
    } else {
        SwingUtilities2.adjustFocus(tree);
        handleSelection(e);
    }
}
 
Example 3
Source File: BasicListUI.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
public void mouseReleased(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, list)) {
        return;
    }

    if (list.getDragEnabled()) {
        MouseEvent me = DragRecognitionSupport.mouseReleased(e);
        if (me != null) {
            SwingUtilities2.adjustFocus(list);
            if (!dragPressDidSelection) {
                adjustSelection(me);
            }
        }
    } else {
        list.setValueIsAdjusting(false);
    }
}
 
Example 4
Source File: BasicTreeUI.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked when a mouse button has been pressed on a component.
 */
public void mousePressed(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, tree)) {
        return;
    }

    // if we can't stop any ongoing editing, do nothing
    if (isEditing(tree) && tree.getInvokesStopCellEditing()
                        && !stopEditing(tree)) {
        return;
    }

    completeEditing();

    pressedPath = getClosestPathForLocation(tree, e.getX(), e.getY());

    if (tree.getDragEnabled()) {
        mousePressedDND(e);
    } else {
        SwingUtilities2.adjustFocus(tree);
        handleSelection(e);
    }
}
 
Example 5
Source File: BasicTreeUI.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked when a mouse button has been pressed on a component.
 */
public void mousePressed(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, tree)) {
        return;
    }

    // if we can't stop any ongoing editing, do nothing
    if (isEditing(tree) && tree.getInvokesStopCellEditing()
                        && !stopEditing(tree)) {
        return;
    }

    completeEditing();

    pressedPath = getClosestPathForLocation(tree, e.getX(), e.getY());

    if (tree.getDragEnabled()) {
        mousePressedDND(e);
    } else {
        SwingUtilities2.adjustFocus(tree);
        handleSelection(e);
    }
}
 
Example 6
Source File: BasicTreeUI.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Invoked when a mouse button has been pressed on a component.
 */
public void mousePressed(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, tree)) {
        return;
    }

    // if we can't stop any ongoing editing, do nothing
    if (isEditing(tree) && tree.getInvokesStopCellEditing()
                        && !stopEditing(tree)) {
        return;
    }

    completeEditing();

    pressedPath = getClosestPathForLocation(tree, e.getX(), e.getY());

    if (tree.getDragEnabled()) {
        mousePressedDND(e);
    } else {
        SwingUtilities2.adjustFocus(tree);
        handleSelection(e);
    }
}
 
Example 7
Source File: BasicTreeUI.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Invoked when a mouse button has been pressed on a component.
 */
public void mousePressed(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, tree)) {
        return;
    }

    // if we can't stop any ongoing editing, do nothing
    if (isEditing(tree) && tree.getInvokesStopCellEditing()
                        && !stopEditing(tree)) {
        return;
    }

    completeEditing();

    pressedPath = getClosestPathForLocation(tree, e.getX(), e.getY());

    if (tree.getDragEnabled()) {
        mousePressedDND(e);
    } else {
        SwingUtilities2.adjustFocus(tree);
        handleSelection(e);
    }
}
 
Example 8
Source File: BasicTreeUI.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void mousePressedDND(MouseEvent e) {
    pressedEvent = e;
    boolean grabFocus = true;
    dragStarted = false;
    valueChangedOnPress = false;

    // if we have a valid path and this is a drag initiating event
    if (isActualPath(pressedPath, e.getX(), e.getY()) &&
            DragRecognitionSupport.mousePressed(e)) {

        dragPressDidSelection = false;

        if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
            // do nothing for control - will be handled on release
            // or when drag starts
            return;
        } else if (!e.isShiftDown() && tree.isPathSelected(pressedPath)) {
            // clicking on something that's already selected
            // and need to make it the lead now
            setAnchorSelectionPath(pressedPath);
            setLeadSelectionPath(pressedPath, true);
            return;
        }

        dragPressDidSelection = true;

        // could be a drag initiating event - don't grab focus
        grabFocus = false;
    }

    if (grabFocus) {
        SwingUtilities2.adjustFocus(tree);
    }

    handleSelection(e);
}
 
Example 9
Source File: BasicTreeUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void mouseReleasedDND(MouseEvent e) {
    MouseEvent me = DragRecognitionSupport.mouseReleased(e);
    if (me != null) {
        SwingUtilities2.adjustFocus(tree);
        if (!dragPressDidSelection) {
            handleSelection(me);
        }
    }

    if (!dragStarted) {

        // Note: We don't give the tree a chance to start editing if the
        // mouse press caused a selection change. Otherwise the default
        // tree cell editor will start editing on EVERY press and
        // release. If it turns out that this affects some editors, we
        // can always parameterize this with a client property. ex:
        //
        // if (pressedPath != null &&
        //         (Boolean.TRUE == tree.getClientProperty("Tree.DnD.canEditOnValueChange") ||
        //          !valueChangedOnPress) && ...
        if (pressedPath != null && !valueChangedOnPress &&
                isActualPath(pressedPath, pressedEvent.getX(), pressedEvent.getY())) {

            startEditingOnRelease(pressedPath, pressedEvent, e);
        }
    }
}
 
Example 10
Source File: BasicTreeUI.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void mousePressedDND(MouseEvent e) {
    pressedEvent = e;
    boolean grabFocus = true;
    dragStarted = false;
    valueChangedOnPress = false;

    // if we have a valid path and this is a drag initiating event
    if (isActualPath(pressedPath, e.getX(), e.getY()) &&
            DragRecognitionSupport.mousePressed(e)) {

        dragPressDidSelection = false;

        if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
            // do nothing for control - will be handled on release
            // or when drag starts
            return;
        } else if (!e.isShiftDown() && tree.isPathSelected(pressedPath)) {
            // clicking on something that's already selected
            // and need to make it the lead now
            setAnchorSelectionPath(pressedPath);
            setLeadSelectionPath(pressedPath, true);
            return;
        }

        dragPressDidSelection = true;

        // could be a drag initiating event - don't grab focus
        grabFocus = false;
    }

    if (grabFocus) {
        SwingUtilities2.adjustFocus(tree);
    }

    handleSelection(e);
}
 
Example 11
Source File: BasicTreeUI.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void mousePressedDND(MouseEvent e) {
    pressedEvent = e;
    boolean grabFocus = true;
    dragStarted = false;
    valueChangedOnPress = false;

    // if we have a valid path and this is a drag initiating event
    if (isActualPath(pressedPath, e.getX(), e.getY()) &&
            DragRecognitionSupport.mousePressed(e)) {

        dragPressDidSelection = false;

        if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
            // do nothing for control - will be handled on release
            // or when drag starts
            return;
        } else if (!e.isShiftDown() && tree.isPathSelected(pressedPath)) {
            // clicking on something that's already selected
            // and need to make it the lead now
            setAnchorSelectionPath(pressedPath);
            setLeadSelectionPath(pressedPath, true);
            return;
        }

        dragPressDidSelection = true;

        // could be a drag initiating event - don't grab focus
        grabFocus = false;
    }

    if (grabFocus) {
        SwingUtilities2.adjustFocus(tree);
    }

    handleSelection(e);
}
 
Example 12
Source File: BasicTableUI.java    From Bytecoder with Apache License 2.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: BasicTreeUI.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void mouseReleasedDND(MouseEvent e) {
    MouseEvent me = DragRecognitionSupport.mouseReleased(e);
    if (me != null) {
        SwingUtilities2.adjustFocus(tree);
        if (!dragPressDidSelection) {
            handleSelection(me);
        }
    }

    if (!dragStarted) {

        // Note: We don't give the tree a chance to start editing if the
        // mouse press caused a selection change. Otherwise the default
        // tree cell editor will start editing on EVERY press and
        // release. If it turns out that this affects some editors, we
        // can always parameterize this with a client property. ex:
        //
        // if (pressedPath != null &&
        //         (Boolean.TRUE == tree.getClientProperty("Tree.DnD.canEditOnValueChange") ||
        //          !valueChangedOnPress) && ...
        if (pressedPath != null && !valueChangedOnPress &&
                isActualPath(pressedPath, pressedEvent.getX(), pressedEvent.getY())) {

            startEditingOnRelease(pressedPath, pressedEvent, e);
        }
    }
}
 
Example 14
Source File: TableUIBridge.java    From darklaf with MIT License 5 votes vote down vote up
public void mousePressed(final 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() &&
                           !DarkUIUtil.isMenuShortcutKeyDown(e) &&
                           !outsidePrefSize;
    }

    if (table.getDragEnabled()) {
        mousePressedDND(e);
    } else {
        SwingUtilities2.adjustFocus(table);
        if (!isFileList) {
            setValueIsAdjusting(true);
        }
        adjustSelection(e);
    }
}
 
Example 15
Source File: BasicTableUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void mouseReleasedDND(MouseEvent e) {
    MouseEvent me = DragRecognitionSupport.mouseReleased(e);
    if (me != null) {
        SwingUtilities2.adjustFocus(table);
        if (!dragPressDidSelection) {
            adjustSelection(me);
        }
    }

    if (!dragStarted) {
        if (isFileList) {
            maybeStartTimer();
            return;
        }

        Point p = e.getPoint();

        if (pressedEvent != null &&
                table.rowAtPoint(p) == pressedRow &&
                table.columnAtPoint(p) == pressedCol &&
                table.editCellAt(pressedRow, pressedCol, pressedEvent)) {

            setDispatchComponent(pressedEvent);
            repostEvent(pressedEvent);

            // This may appear completely odd, but must be done for backward
            // compatibility reasons. Developers have been known to rely on
            // a call to shouldSelectCell after editing has begun.
            CellEditor ce = table.getCellEditor();
            if (ce != null) {
                ce.shouldSelectCell(pressedEvent);
            }
        }
    }
}
 
Example 16
Source File: BasicListUI.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void mousePressed(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, list)) {
        return;
    }

    boolean dragEnabled = list.getDragEnabled();
    boolean grabFocus = true;

    // different behavior if drag is enabled
    if (dragEnabled) {
        int row = SwingUtilities2.loc2IndexFileList(list, e.getPoint());
        // if we have a valid row and this is a drag initiating event
        if (row != -1 && DragRecognitionSupport.mousePressed(e)) {
            dragPressDidSelection = false;

            if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
                // do nothing for control - will be handled on release
                // or when drag starts
                return;
            } else if (!e.isShiftDown() && list.isSelectedIndex(row)) {
                // clicking on something that's already selected
                // and need to make it the lead now
                list.addSelectionInterval(row, row);
                return;
            }

            // could be a drag initiating event - don't grab focus
            grabFocus = false;

            dragPressDidSelection = true;
        }
    } else {
        // When drag is enabled mouse drags won't change the selection
        // in the list, so we only set the isAdjusting flag when it's
        // not enabled
        list.setValueIsAdjusting(true);
    }

    if (grabFocus) {
        SwingUtilities2.adjustFocus(list);
    }

    adjustSelection(e);
}
 
Example 17
Source File: BasicListUI.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void mousePressed(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, list)) {
        return;
    }

    boolean dragEnabled = list.getDragEnabled();
    boolean grabFocus = true;

    // different behavior if drag is enabled
    if (dragEnabled) {
        int row = SwingUtilities2.loc2IndexFileList(list, e.getPoint());
        // if we have a valid row and this is a drag initiating event
        if (row != -1 && DragRecognitionSupport.mousePressed(e)) {
            dragPressDidSelection = false;

            if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
                // do nothing for control - will be handled on release
                // or when drag starts
                return;
            } else if (!e.isShiftDown() && list.isSelectedIndex(row)) {
                // clicking on something that's already selected
                // and need to make it the lead now
                list.addSelectionInterval(row, row);
                return;
            }

            // could be a drag initiating event - don't grab focus
            grabFocus = false;

            dragPressDidSelection = true;
        }
    } else {
        // When drag is enabled mouse drags won't change the selection
        // in the list, so we only set the isAdjusting flag when it's
        // not enabled
        list.setValueIsAdjusting(true);
    }

    if (grabFocus) {
        SwingUtilities2.adjustFocus(list);
    }

    adjustSelection(e);
}
 
Example 18
Source File: BasicListUI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void mousePressed(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, list)) {
        return;
    }

    boolean dragEnabled = list.getDragEnabled();
    boolean grabFocus = true;

    // different behavior if drag is enabled
    if (dragEnabled) {
        int row = SwingUtilities2.loc2IndexFileList(list, e.getPoint());
        // if we have a valid row and this is a drag initiating event
        if (row != -1 && DragRecognitionSupport.mousePressed(e)) {
            dragPressDidSelection = false;

            if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
                // do nothing for control - will be handled on release
                // or when drag starts
                return;
            } else if (!e.isShiftDown() && list.isSelectedIndex(row)) {
                // clicking on something that's already selected
                // and need to make it the lead now
                list.addSelectionInterval(row, row);
                return;
            }

            // could be a drag initiating event - don't grab focus
            grabFocus = false;

            dragPressDidSelection = true;
        }
    } else {
        // When drag is enabled mouse drags won't change the selection
        // in the list, so we only set the isAdjusting flag when it's
        // not enabled
        list.setValueIsAdjusting(true);
    }

    if (grabFocus) {
        SwingUtilities2.adjustFocus(list);
    }

    adjustSelection(e);
}
 
Example 19
Source File: BasicListUI.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void mousePressed(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, list)) {
        return;
    }

    boolean dragEnabled = list.getDragEnabled();
    boolean grabFocus = true;

    // different behavior if drag is enabled
    if (dragEnabled) {
        int row = SwingUtilities2.loc2IndexFileList(list, e.getPoint());
        // if we have a valid row and this is a drag initiating event
        if (row != -1 && DragRecognitionSupport.mousePressed(e)) {
            dragPressDidSelection = false;

            if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
                // do nothing for control - will be handled on release
                // or when drag starts
                return;
            } else if (!e.isShiftDown() && list.isSelectedIndex(row)) {
                // clicking on something that's already selected
                // and need to make it the lead now
                list.addSelectionInterval(row, row);
                return;
            }

            // could be a drag initiating event - don't grab focus
            grabFocus = false;

            dragPressDidSelection = true;
        }
    } else {
        // When drag is enabled mouse drags won't change the selection
        // in the list, so we only set the isAdjusting flag when it's
        // not enabled
        list.setValueIsAdjusting(true);
    }

    if (grabFocus) {
        SwingUtilities2.adjustFocus(list);
    }

    adjustSelection(e);
}
 
Example 20
Source File: BasicListUI.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void mousePressed(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, list)) {
        return;
    }

    boolean dragEnabled = list.getDragEnabled();
    boolean grabFocus = true;

    // different behavior if drag is enabled
    if (dragEnabled) {
        int row = SwingUtilities2.loc2IndexFileList(list, e.getPoint());
        // if we have a valid row and this is a drag initiating event
        if (row != -1 && DragRecognitionSupport.mousePressed(e)) {
            dragPressDidSelection = false;

            if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
                // do nothing for control - will be handled on release
                // or when drag starts
                return;
            } else if (!e.isShiftDown() && list.isSelectedIndex(row)) {
                // clicking on something that's already selected
                // and need to make it the lead now
                list.addSelectionInterval(row, row);
                return;
            }

            // could be a drag initiating event - don't grab focus
            grabFocus = false;

            dragPressDidSelection = true;
        }
    } else {
        // When drag is enabled mouse drags won't change the selection
        // in the list, so we only set the isAdjusting flag when it's
        // not enabled
        list.setValueIsAdjusting(true);
    }

    if (grabFocus) {
        SwingUtilities2.adjustFocus(list);
    }

    adjustSelection(e);
}