sun.swing.SwingUtilities2 Java Examples

The following examples show how to use sun.swing.SwingUtilities2. 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: WindowsGraphicsUtils.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Renders a text String in Windows without the mnemonic.
 * This is here because the WindowsUI hierarchy doesn't match the Component hierarchy. All
 * the overriden paintText methods of the ButtonUI delegates will call this static method.
 * <p>
 * @param g Graphics context
 * @param b Current button to render
 * @param textRect Bounding rectangle to render the text.
 * @param text String to render
 */
public static void paintText(Graphics g, AbstractButton b,
                                    Rectangle textRect, String text,
                                    int textShiftOffset) {
    FontMetrics fm = SwingUtilities2.getFontMetrics(b, g);

    int mnemIndex = b.getDisplayedMnemonicIndex();
    // W2K Feature: Check to see if the Underscore should be rendered.
    if (WindowsLookAndFeel.isMnemonicHidden() == true) {
        mnemIndex = -1;
    }

    XPStyle xp = XPStyle.getXP();
    if (xp != null && !(b instanceof JMenuItem)) {
        paintXPText(b, g, textRect.x + textShiftOffset,
                    textRect.y + fm.getAscent() + textShiftOffset,
                    text, mnemIndex);
    } else {
        paintClassicText(b, g, textRect.x + textShiftOffset,
                         textRect.y + fm.getAscent() + textShiftOffset,
                         text, mnemIndex);
    }
}
 
Example #2
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 #3
Source File: AquaTabbedPaneUI.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
    final View v = getTextViewForTab(tabIndex);
    if (v != null) {
        v.paint(g2d, textRect);
        return;
    }

    if (title == null) return;

    final Color color = tabPane.getForegroundAt(tabIndex);
    if (color instanceof UIResource) {
        // sja fix getTheme().setThemeTextColor(g, isSelected, isPressed && tracking, tabPane.isEnabledAt(tabIndex));
        if (tabPane.isEnabledAt(tabIndex)) {
            g2d.setColor(Color.black);
        } else {
            g2d.setColor(Color.gray);
        }
    } else {
        g2d.setColor(color);
    }

    g2d.setFont(font);
    SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
 
Example #4
Source File: AquaTabbedPaneUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
    final View v = getTextViewForTab(tabIndex);
    if (v != null) {
        v.paint(g2d, textRect);
        return;
    }

    if (title == null) return;

    final Color color = tabPane.getForegroundAt(tabIndex);
    if (color instanceof UIResource) {
        // sja fix getTheme().setThemeTextColor(g, isSelected, isPressed && tracking, tabPane.isEnabledAt(tabIndex));
        if (tabPane.isEnabledAt(tabIndex)) {
            g2d.setColor(Color.black);
        } else {
            g2d.setColor(Color.gray);
        }
    } else {
        g2d.setColor(color);
    }

    g2d.setFont(font);
    SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
 
Example #5
Source File: MetalToggleButtonUI.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    FontMetrics fm = SwingUtilities2.getFontMetrics(b, g);
    int mnemIndex = b.getDisplayedMnemonicIndex();

    /* Draw the Text */
    if(model.isEnabled()) {
        /*** paint the text normally */
        g.setColor(b.getForeground());
    }
    else {
        /*** paint the text disabled ***/
        if (model.isSelected()) {
            g.setColor(c.getBackground());
        } else {
            g.setColor(getDisabledTextColor());
        }
    }
    SwingUtilities2.drawStringUnderlineCharAt(c, g, text, mnemIndex,
            textRect.x, textRect.y + fm.getAscent());
}
 
Example #6
Source File: DefaultCaret.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * If button 1 is pressed, this is implemented to
 * request focus on the associated text component,
 * and to set the caret position. If the shift key is held down,
 * the caret will be moved, potentially resulting in a selection,
 * otherwise the
 * caret position will be set to the new location.  If the component
 * is not enabled, there will be no request for focus.
 *
 * @param e the mouse event
 * @see MouseListener#mousePressed
 */
public void mousePressed(MouseEvent e) {
    int nclicks = SwingUtilities2.getAdjustedClickCount(getComponent(), e);

    if (SwingUtilities.isLeftMouseButton(e)) {
        if (e.isConsumed()) {
            shouldHandleRelease = true;
        } else {
            shouldHandleRelease = false;
            adjustCaretAndFocus(e);
            if (nclicks == 2
                && SwingUtilities2.canEventAccessSystemClipboard(e)) {
                selectWord(e);
            }
        }
    }
}
 
Example #7
Source File: DefaultCaret.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * If button 1 is pressed, this is implemented to
 * request focus on the associated text component,
 * and to set the caret position. If the shift key is held down,
 * the caret will be moved, potentially resulting in a selection,
 * otherwise the
 * caret position will be set to the new location.  If the component
 * is not enabled, there will be no request for focus.
 *
 * @param e the mouse event
 * @see MouseListener#mousePressed
 */
public void mousePressed(MouseEvent e) {
    int nclicks = SwingUtilities2.getAdjustedClickCount(getComponent(), e);

    if (SwingUtilities.isLeftMouseButton(e)) {
        if (e.isConsumed()) {
            shouldHandleRelease = true;
        } else {
            shouldHandleRelease = false;
            adjustCaretAndFocus(e);
            if (nclicks == 2
                && SwingUtilities2.canEventAccessSystemClipboard(e)) {
                selectWord(e);
            }
        }
    }
}
 
Example #8
Source File: BasicFileChooserUI.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public void mouseClicked(MouseEvent evt) {
    // Note: we can't depend on evt.getSource() because of backward
    // compatibility
    if (list != null &&
        SwingUtilities.isLeftMouseButton(evt) &&
        (evt.getClickCount()%2 == 0)) {

        int index = SwingUtilities2.loc2IndexFileList(list, evt.getPoint());
        if (index >= 0) {
            File f = (File)list.getModel().getElementAt(index);
            try {
                // Strip trailing ".."
                f = ShellFolder.getNormalizedFile(f);
            } catch (IOException ex) {
                // That's ok, we'll use f as is
            }
            if(getFileChooser().isTraversable(f)) {
                list.clearSelection();
                changeDirectory(f);
            } else {
                getFileChooser().approveSelection();
            }
        }
    }
}
 
Example #9
Source File: DefaultCaret.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * If button 1 is pressed, this is implemented to
 * request focus on the associated text component,
 * and to set the caret position. If the shift key is held down,
 * the caret will be moved, potentially resulting in a selection,
 * otherwise the
 * caret position will be set to the new location.  If the component
 * is not enabled, there will be no request for focus.
 *
 * @param e the mouse event
 * @see MouseListener#mousePressed
 */
public void mousePressed(MouseEvent e) {
    int nclicks = SwingUtilities2.getAdjustedClickCount(getComponent(), e);

    if (SwingUtilities.isLeftMouseButton(e)) {
        if (e.isConsumed()) {
            shouldHandleRelease = true;
        } else {
            shouldHandleRelease = false;
            adjustCaretAndFocus(e);
            if (nclicks == 2
                && SwingUtilities2.canEventAccessSystemClipboard(e)) {
                selectWord(e);
            }
        }
    }
}
 
Example #10
Source File: BasicTreeUI.java    From dragonwell8_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 #11
Source File: AquaTabbedPaneContrastUI.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
    final View v = getTextViewForTab(tabIndex);
    if (v != null) {
        v.paint(g2d, textRect);
        return;
    }

    if (title == null) return;

    final Color color = tabPane.getForegroundAt(tabIndex);
    if (color instanceof UIResource) {
        g2d.setColor(getNonSelectedTabTitleColor());
        if (tabPane.getSelectedIndex() == tabIndex) {
            boolean pressed = isPressedAt(tabIndex);
            boolean enabled = tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex);
            Color textColor = getSelectedTabTitleColor(enabled, pressed);
            Color shadowColor = getSelectedTabTitleShadowColor(enabled);
            AquaUtils.paintDropShadowText(g2d, tabPane, font, metrics, textRect.x, textRect.y, 0, 1, textColor, shadowColor, title);
            return;
        }
    } else {
        g2d.setColor(color);
    }
    g2d.setFont(font);
    SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
 
Example #12
Source File: Utilities.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the given composed text passed from an input method.
 *
 * @param view View hosting text
 * @param attr the attributes containing the composed text
 * @param g  the graphics context
 * @param x  the X origin
 * @param y  the Y origin
 * @param p0 starting offset in the composed text to be rendered
 * @param p1 ending offset in the composed text to be rendered
 * @return  the new insertion position
 */
static int drawComposedText(View view, AttributeSet attr, Graphics g,
                            int x, int y, int p0, int p1)
                                 throws BadLocationException {
    Graphics2D g2d = (Graphics2D)g;
    AttributedString as = (AttributedString)attr.getAttribute(
        StyleConstants.ComposedTextAttribute);
    as.addAttribute(TextAttribute.FONT, g.getFont());

    if (p0 >= p1)
        return x;

    AttributedCharacterIterator aci = as.getIterator(null, p0, p1);
    return x + (int)SwingUtilities2.drawString(
                         getJComponent(view), g2d,aci,x,y);
}
 
Example #13
Source File: BasicSplitPaneUI.java    From openjdk-jdk9 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 #14
Source File: DefaultCaret.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * If button 1 is pressed, this is implemented to
 * request focus on the associated text component,
 * and to set the caret position. If the shift key is held down,
 * the caret will be moved, potentially resulting in a selection,
 * otherwise the
 * caret position will be set to the new location.  If the component
 * is not enabled, there will be no request for focus.
 *
 * @param e the mouse event
 * @see MouseListener#mousePressed
 */
public void mousePressed(MouseEvent e) {
    int nclicks = SwingUtilities2.getAdjustedClickCount(getComponent(), e);

    if (SwingUtilities.isLeftMouseButton(e)) {
        if (e.isConsumed()) {
            shouldHandleRelease = true;
        } else {
            shouldHandleRelease = false;
            adjustCaretAndFocus(e);
            if (nclicks == 2
                && SwingUtilities2.canEventAccessSystemClipboard(e)) {
                selectWord(e);
            }
        }
    }
}
 
Example #15
Source File: BasicTabbedPaneUI.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) {
    Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
    int width = tabInsets.left + tabInsets.right + 3;
    Component tabComponent = tabPane.getTabComponentAt(tabIndex);
    if (tabComponent != null) {
        width += tabComponent.getPreferredSize().width;
    } else {
        Icon icon = getIconForTab(tabIndex);
        if (icon != null) {
            width += icon.getIconWidth() + textIconGap;
        }
        View v = getTextViewForTab(tabIndex);
        if (v != null) {
            // html
            width += (int) v.getPreferredSpan(View.X_AXIS);
        } else {
            // plain text
            String title = tabPane.getTitleAt(tabIndex);
            width += SwingUtilities2.stringWidth(tabPane, metrics, title);
        }
    }
    return width;
}
 
Example #16
Source File: WindowsGraphicsUtils.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Renders a text String in Windows without the mnemonic.
 * This is here because the WindowsUI hierarchy doesn't match the Component hierarchy. All
 * the overriden paintText methods of the ButtonUI delegates will call this static method.
 * <p>
 * @param g Graphics context
 * @param b Current button to render
 * @param textRect Bounding rectangle to render the text.
 * @param text String to render
 */
public static void paintText(Graphics g, AbstractButton b,
                                    Rectangle textRect, String text,
                                    int textShiftOffset) {
    FontMetrics fm = SwingUtilities2.getFontMetrics(b, g);

    int mnemIndex = b.getDisplayedMnemonicIndex();
    // W2K Feature: Check to see if the Underscore should be rendered.
    if (WindowsLookAndFeel.isMnemonicHidden() == true) {
        mnemIndex = -1;
    }

    XPStyle xp = XPStyle.getXP();
    if (xp != null && !(b instanceof JMenuItem)) {
        paintXPText(b, g, textRect.x + textShiftOffset,
                    textRect.y + fm.getAscent() + textShiftOffset,
                    text, mnemIndex);
    } else {
        paintClassicText(b, g, textRect.x + textShiftOffset,
                         textRect.y + fm.getAscent() + textShiftOffset,
                         text, mnemIndex);
    }
}
 
Example #17
Source File: FixedHeightLayoutCache.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Invoked after nodes have been removed from the tree.  Note that
 * if a subtree is removed from the tree, this method may only be
 * invoked once for the root of the removed subtree, not once for
 * each individual set of siblings removed.</p>
 *
 * <p>e.path() returns the former parent of the deleted nodes.</p>
 *
 * <p>e.childIndices() returns the indices the nodes had before they were deleted in ascending order.</p>
 */
public void treeNodesRemoved(TreeModelEvent e) {
    if(e != null) {
        int                  changedIndexs[];
        int                  maxCounter;
        TreePath             parentPath = SwingUtilities2.getTreePath(e, getModel());
        FHTreeStateNode      changedParentNode = getNodeForPath
                                   (parentPath, false, false);

        changedIndexs = e.getChildIndices();
        // PENDING(scott): make sure that changedIndexs are sorted in
        // ascending order.
        if(changedParentNode != null && changedIndexs != null &&
           (maxCounter = changedIndexs.length) > 0) {
            Object[]           children = e.getChildren();
            boolean            isVisible =
                (changedParentNode.isVisible() &&
                 changedParentNode.isExpanded());

            for(int counter = maxCounter - 1; counter >= 0; counter--) {
                changedParentNode.removeChildAtModelIndex
                                 (changedIndexs[counter], isVisible);
            }
            if(isVisible) {
                if(treeSelectionModel != null)
                    treeSelectionModel.resetRowSelection();
                if (treeModel.getChildCount(changedParentNode.
                                            getUserObject()) == 0 &&
                              changedParentNode.isLeaf()) {
                    // Node has become a leaf, collapse it.
                    changedParentNode.collapse(false);
                }
                visibleNodesChanged();
            }
            else if(changedParentNode.isVisible())
                visibleNodesChanged();
        }
    }
}
 
Example #18
Source File: WindowsLookAndFeel.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Object createValue(UIDefaults table) {
    if (nativeImage != null) {
        Image image = (Image)ShellFolder.get(nativeImage);
        if (image != null) {
            return new ImageIcon(image);
        }
    }
    return SwingUtilities2.makeIcon(getClass(),
                                    WindowsLookAndFeel.class,
                                    resource);
}
 
Example #19
Source File: BasicTableUI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void setDispatchComponent(MouseEvent e) {
    Component editorComponent = table.getEditorComponent();
    Point p = e.getPoint();
    Point p2 = SwingUtilities.convertPoint(table, p, editorComponent);
    dispatchComponent =
            SwingUtilities.getDeepestComponentAt(editorComponent,
                    p2.x, p2.y);
    SwingUtilities2.setSkipClickCount(dispatchComponent,
                                      e.getClickCount() - 1);
}
 
Example #20
Source File: BasicProgressBarUI.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Paints the progress string.
 *
 * @param g Graphics used for drawing.
 * @param x x location of bounding box
 * @param y y location of bounding box
 * @param width width of bounding box
 * @param height height of bounding box
 * @param fillStart start location, in x or y depending on orientation,
 *        of the filled portion of the progress bar.
 * @param amountFull size of the fill region, either width or height
 *        depending upon orientation.
 * @param b Insets of the progress bar.
 */
private void paintString(Graphics g, int x, int y, int width, int height,
                         int fillStart, int amountFull, Insets b) {
    if (!(g instanceof Graphics2D)) {
        return;
    }

    Graphics2D g2 = (Graphics2D)g;
    String progressString = progressBar.getString();
    g2.setFont(progressBar.getFont());
    Point renderLocation = getStringPlacement(g2, progressString,
                                              x, y, width, height);
    Rectangle oldClip = g2.getClipBounds();

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
        g2.setColor(getSelectionBackground());
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
        g2.setColor(getSelectionForeground());
        g2.clipRect(fillStart, y, amountFull, height);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
    } else { // VERTICAL
        g2.setColor(getSelectionBackground());
        AffineTransform rotate =
                AffineTransform.getRotateInstance(Math.PI/2);
        g2.setFont(progressBar.getFont().deriveFont(rotate));
        renderLocation = getStringPlacement(g2, progressString,
                                              x, y, width, height);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
        g2.setColor(getSelectionForeground());
        g2.clipRect(x, fillStart, width, amountFull);
        SwingUtilities2.drawString(progressBar, g2, progressString,
                                   renderLocation.x, renderLocation.y);
    }
    g2.setClip(oldClip);
}
 
Example #21
Source File: AbstractDocument.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Performs the actual work of inserting the text; it is assumed the
 * caller has obtained a write lock before invoking this.
 */
private void handleInsertString(int offs, String str, AttributeSet a)
        throws BadLocationException {
    if ((str == null) || (str.length() == 0)) {
        return;
    }
    UndoableEdit u = data.insertString(offs, str);
    DefaultDocumentEvent e =
        new DefaultDocumentEvent(offs, str.length(), DocumentEvent.EventType.INSERT);
    if (u != null) {
        e.addEdit(u);
    }

    // see if complex glyph layout support is needed
    if( getProperty(I18NProperty).equals( Boolean.FALSE ) ) {
        // if a default direction of right-to-left has been specified,
        // we want complex layout even if the text is all left to right.
        Object d = getProperty(TextAttribute.RUN_DIRECTION);
        if ((d != null) && (d.equals(TextAttribute.RUN_DIRECTION_RTL))) {
            putProperty( I18NProperty, Boolean.TRUE);
        } else {
            char[] chars = str.toCharArray();
            if (SwingUtilities2.isComplexLayout(chars, 0, chars.length)) {
                putProperty( I18NProperty, Boolean.TRUE);
            }
        }
    }

    insertUpdate(e, a);
    // Mark the edit as done.
    e.end();
    fireInsertUpdate(e);
    // only fire undo if Content implementation supports it
    // undo for the composed text is not supported for now
    if (u != null && (a == null || !a.isDefined(StyleConstants.ComposedTextAttribute))) {
        fireUndoableEditUpdate(new UndoableEditEvent(this, e));
    }
}
 
Example #22
Source File: BasicTreeUI.java    From openjdk-8 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 #23
Source File: BasicListUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void mouseDragged(MouseEvent e) {
    if (SwingUtilities2.shouldIgnore(e, list)) {
        return;
    }

    if (list.getDragEnabled()) {
        DragRecognitionSupport.mouseDragged(e, this);
        return;
    }

    if (e.isShiftDown() || BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
        return;
    }

    int row = locationToIndex(list, e.getPoint());
    if (row != -1) {
        // 4835633.  Dragging onto a File should not select it.
        if (isFileList) {
            return;
        }
        Rectangle cellBounds = getCellBounds(list, row, row);
        if (cellBounds != null) {
            list.scrollRectToVisible(cellBounds);
            list.setSelectionInterval(row, row);
        }
    }
}
 
Example #24
Source File: MotifFileChooserUI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected JScrollPane createFilesList() {
    fileList = new JList<File>();

    if(getFileChooser().isMultiSelectionEnabled()) {
        fileList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    } else {
        fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    }

    fileList.setModel(new MotifFileListModel());
    fileList.getSelectionModel().removeSelectionInterval(0, 0);
    fileList.setCellRenderer(new FileCellRenderer());
    fileList.addListSelectionListener(createListSelectionListener(getFileChooser()));
    fileList.addMouseListener(createDoubleClickListener(getFileChooser(), fileList));
    fileList.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            JFileChooser chooser = getFileChooser();
            if (SwingUtilities.isLeftMouseButton(e) && !chooser.isMultiSelectionEnabled()) {
                int index = SwingUtilities2.loc2IndexFileList(fileList, e.getPoint());
                if (index >= 0) {
                    File file = fileList.getModel().getElementAt(index);
                    setFileName(chooser.getName(file));
                }
            }
        }
    });
    align(fileList);
    JScrollPane scrollpane = new JScrollPane(fileList);
    scrollpane.setPreferredSize(prefListSize);
    scrollpane.setMaximumSize(MAX_SIZE);
    align(scrollpane);
    fileList.setInheritsPopupMenu(true);
    scrollpane.setInheritsPopupMenu(true);
    return scrollpane;
}
 
Example #25
Source File: BasicTreeUI.java    From JDKSourceCode1.8 with MIT License 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 #26
Source File: MetalLabelUI.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Just paint the text gray (Label.disabledForeground) rather than
 * in the labels foreground color.
 *
 * @see #paint
 * @see #paintEnabledText
 */
protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY)
{
    int mnemIndex = l.getDisplayedMnemonicIndex();
    g.setColor(UIManager.getColor("Label.disabledForeground"));
    SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemIndex,
                                               textX, textY);
}
 
Example #27
Source File: StyleSheet.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the letter or number for an ordered list.
 *
 * @param g     the graphics context
 * @param letter type of ordered list to draw
 * @param ax    x coordinate to place the bullet
 * @param ay    y coordinate to place the bullet
 * @param aw    width of the container the bullet is placed in
 * @param ah    height of the container the bullet is placed in
 * @param index position of the list item in the list
 */
void drawLetter(Graphics g, char letter, int ax, int ay, int aw,
                int ah, float align, int index) {
    String str = formatItemNum(index, letter);
    str = isLeftToRight ? str + "." : "." + str;
    FontMetrics fm = SwingUtilities2.getFontMetrics(null, g);
    int stringwidth = SwingUtilities2.stringWidth(null, fm, str);
    int gap = isLeftToRight ? - (stringwidth + bulletgap) :
                                (aw + bulletgap);
    int x = ax + gap;
    int y = Math.max(ay + fm.getAscent(), ay + (int)(ah * align));
    SwingUtilities2.drawString(null, g, str, x, y);
}
 
Example #28
Source File: FixedHeightLayoutCache.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>Invoked after a node (or a set of siblings) has changed in some
 * way. The node(s) have not changed locations in the tree or
 * altered their children arrays, but other attributes have
 * changed and may affect presentation. Example: the name of a
 * file has changed, but it is in the same location in the file
 * system.</p>
 *
 * <p>e.path() returns the path the parent of the changed node(s).</p>
 *
 * <p>e.childIndices() returns the index(es) of the changed node(s).</p>
 */
public void treeNodesChanged(TreeModelEvent e) {
    if(e != null) {
        int                 changedIndexs[];
        FHTreeStateNode     changedParent = getNodeForPath
                              (SwingUtilities2.getTreePath(e, getModel()), false, false);
        int                 maxCounter;

        changedIndexs = e.getChildIndices();
        /* Only need to update the children if the node has been
           expanded once. */
        // PENDING(scott): make sure childIndexs is sorted!
        if (changedParent != null) {
            if (changedIndexs != null &&
                (maxCounter = changedIndexs.length) > 0) {
                Object       parentValue = changedParent.getUserObject();

                for(int counter = 0; counter < maxCounter; counter++) {
                    FHTreeStateNode    child = changedParent.
                             getChildAtModelIndex(changedIndexs[counter]);

                    if(child != null) {
                        child.setUserObject(treeModel.getChild(parentValue,
                                                 changedIndexs[counter]));
                    }
                }
                if(changedParent.isVisible() && changedParent.isExpanded())
                    visibleNodesChanged();
            }
            // Null for root indicates it changed.
            else if (changedParent == root && changedParent.isVisible() &&
                     changedParent.isExpanded()) {
                visibleNodesChanged();
            }
        }
    }
}
 
Example #29
Source File: DefaultCaret.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void updateSystemSelection() {
    if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
        return;
    }
    if (this.dot != this.mark && component != null && component.hasFocus()) {
        Clipboard clip = getSystemSelection();
        if (clip != null) {
            String selectedText;
            if (component instanceof JPasswordField
                && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
                Boolean.TRUE) {
                //fix for 4793761
                StringBuilder txt = null;
                char echoChar = ((JPasswordField)component).getEchoChar();
                int p0 = Math.min(getDot(), getMark());
                int p1 = Math.max(getDot(), getMark());
                for (int i = p0; i < p1; i++) {
                    if (txt == null) {
                        txt = new StringBuilder();
                    }
                    txt.append(echoChar);
                }
                selectedText = (txt != null) ? txt.toString() : null;
            } else {
                selectedText = component.getSelectedText();
            }
            try {
                clip.setContents(
                    new StringSelection(selectedText), getClipboardOwner());

                ownsSelection = true;
            } catch (IllegalStateException ise) {
                // clipboard was unavailable
                // no need to provide error feedback to user since updating
                // the system selection is not a user invoked action
            }
        }
    }
}
 
Example #30
Source File: MotifPopupMenuUI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Dimension getPreferredSize(JComponent c) {
    LayoutManager layout = c.getLayout();
    Dimension d = layout.preferredLayoutSize(c);
    String title = ((JPopupMenu)c).getLabel();
    if (titleFont == null) {
        UIDefaults table = UIManager.getLookAndFeelDefaults();
        titleFont = table.getFont("PopupMenu.font");
    }
    FontMetrics fm = c.getFontMetrics(titleFont);
    int         stringWidth = 0;

    if (title!=null) {
        stringWidth += SwingUtilities2.stringWidth(c, fm, title);
    }

    if (d.width < stringWidth) {
        d.width = stringWidth + 8;
        Insets i = c.getInsets();
        if (i!=null) {
            d.width += i.left + i.right;
        }
        if (border != null) {
            i = border.getBorderInsets(c);
            d.width += i.left + i.right;
        }

        return d;
    }
    return null;
}