Java Code Examples for sun.swing.SwingUtilities2

The following examples show how to use sun.swing.SwingUtilities2. These examples are extracted from open source projects. 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
/**
 * 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 Project: jdk8u-dev-jdk   Source File: Utilities.java    License: 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 3
Source Project: hottub   Source File: BasicFileChooserUI.java    License: 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 4
Source Project: Java8CN   Source File: DefaultCaret.java    License: 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 5
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 6
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 7
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 8
Source Project: jdk8u-dev-jdk   Source File: DefaultCaret.java    License: 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 9
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 10
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 11
Source Project: dragonwell8_jdk   Source File: BasicTreeUI.java    License: 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 12
Source Project: openjdk-jdk9   Source File: DefaultCaret.java    License: 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 13
Source Project: openjdk-8   Source File: BasicLabelUI.java    License: 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 14
Source Project: Bytecoder   Source File: MetalToggleButtonUI.java    License: 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 15
Source Project: jdk8u60   Source File: DefaultCaret.java    License: 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 16
Source Project: JDKSourceCode1.8   Source File: WindowsGraphicsUtils.java    License: 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 17
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 18
Source Project: TencentKona-8   Source File: BasicListUI.java    License: 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 19
Source Project: openjdk-8   Source File: BasicTableUI.java    License: 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 20
public void paint(Graphics g) {
    Dimension size = getSize();
    State state = State.NORMAL;
    TableColumn draggedColumn = header.getDraggedColumn();
    if (draggedColumn != null &&
            column == SwingUtilities2.convertColumnIndexToView(
                    header.getColumnModel(), draggedColumn.getModelIndex())) {
        state = State.PRESSED;
    } else if (isSelected || hasFocus || hasRollover) {
        state = State.HOT;
    }
    /* on Vista there are more states for sorted columns */
    if (WindowsLookAndFeel.isOnVista()) {
        SortOrder sortOrder = getColumnSortOrder(header.getTable(), column);
        if (sortOrder != null) {
             switch(sortOrder) {
             case ASCENDING:
                 /* falls through */
             case DESCENDING:
                 switch (state) {
                 case NORMAL:
                     state = State.SORTEDNORMAL;
                     break;
                 case PRESSED:
                     state = State.SORTEDPRESSED;
                     break;
                 case HOT:
                     state = State.SORTEDHOT;
                     break;
                 default:
                     /* do nothing */
                 }
             default :
                 /* do nothing */
             }
        }
    }
    skin.paintSkin(g, 0, 0, size.width-1, size.height-1, state);
    super.paint(g);
}
 
Example 21
Source Project: jdk8u-jdk   Source File: GTKLookAndFeel.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void initialize() {
    /*
     * We need to call loadGTK() to ensure that the native GTK
     * libraries are loaded.  It is very unlikely that this call will
     * fail (since we've already verified native GTK support in
     * isSupportedLookAndFeel()), but we can throw an error in the
     * failure situation just in case.
     */
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    if (toolkit instanceof UNIXToolkit &&
        !((UNIXToolkit)toolkit).loadGTK())
    {
        throw new InternalError("Unable to load native GTK libraries");
    }

    super.initialize();
    inInitialize = true;
    loadStyles();
    inInitialize = false;

    /*
     * Check if system AA font settings should be used.
     * Sun's JDS (for Linux and Solaris) ships with high quality CJK
     * fonts and specifies via fontconfig that these be rendered in
     * B&W to take advantage of the embedded bitmaps.
     * If is a Sun CJK locale or remote display, indicate by the condition
     * variable that in this case the L&F recommends ignoring desktop
     * settings. On other Unixes (eg Linux) this doesn't apply.
     * REMIND 1: The isSunCJK test is really just a place holder
     * until we can properly query fontconfig and use the properties
     * set for specific fonts.
     * REMIND 2: See comment on isLocalDisplay() definition regarding
     * XRender.
     */
    gtkAAFontSettingsCond = !isSunCJK && SwingUtilities2.isLocalDisplay();
    aaTextInfo = SwingUtilities2.AATextInfo.getAATextInfo(gtkAAFontSettingsCond);
}
 
Example 22
Source Project: openjdk-jdk9   Source File: RepaintManager.java    License: GNU General Public License v2.0 5 votes vote down vote up
private boolean isPixelsCopying(JComponent c, Graphics g) {

            AffineTransform tx = getTransform(g);
            GraphicsConfiguration gc = c.getGraphicsConfiguration();

            if (tx == null || gc == null
                    || !SwingUtilities2.isFloatingPointScale(tx)) {
                return false;
            }

            AffineTransform gcTx = gc.getDefaultTransform();

            return gcTx.getScaleX() == tx.getScaleX()
                    && gcTx.getScaleY() == tx.getScaleY();
        }
 
Example 23
Source Project: Java8CN   Source File: BasicButtonUI.java    License: Apache License 2.0 5 votes vote down vote up
public void paint(Graphics g, JComponent c)
{
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();

    String text = layout(b, SwingUtilities2.getFontMetrics(b, g),
           b.getWidth(), b.getHeight());

    clearTextShiftOffset();

    // perform UI specific press action, e.g. Windows L&F shifts text
    if (model.isArmed() && model.isPressed()) {
        paintButtonPressed(g,b);
    }

    // Paint the Icon
    if(b.getIcon() != null) {
        paintIcon(g,c,iconRect);
    }

    if (text != null && !text.equals("")){
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
        if (v != null) {
            v.paint(g, textRect);
        } else {
            paintText(g, b, textRect, text);
        }
    }

    if (b.isFocusPainted() && b.hasFocus()) {
        // paint UI specific focus
        paintFocus(g,b,viewRect,textRect,iconRect);
    }
}
 
Example 24
protected void paintEnabledText(JLabel l, Graphics g, String s,
                                int textX, int textY) {
    int mnemonicIndex = l.getDisplayedMnemonicIndex();
    // W2K Feature: Check to see if the Underscore should be rendered.
    if (WindowsLookAndFeel.isMnemonicHidden() == true) {
        mnemonicIndex = -1;
    }

    g.setColor(l.getForeground());
    SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemonicIndex,
                                                 textX, textY);
}
 
Example 25
Source Project: jdk8u-jdk   Source File: BasicLabelUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Paint clippedText at textX, textY with background.lighter() and then
 * shifted down and to the right by one pixel with background.darker().
 *
 * @see #paint
 * @see #paintEnabledText
 */
protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY)
{
    int accChar = l.getDisplayedMnemonicIndex();
    Color background = l.getBackground();
    g.setColor(background.brighter());
    SwingUtilities2.drawStringUnderlineCharAt(l, g, s, accChar,
                                               textX + 1, textY + 1);
    g.setColor(background.darker());
    SwingUtilities2.drawStringUnderlineCharAt(l, g, s, accChar,
                                               textX, textY);
}
 
Example 26
Source Project: JDKSourceCode1.8   Source File: BasicTableUI.java    License: MIT License 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 27
Source Project: Bytecoder   Source File: MetalLabelUI.java    License: Apache License 2.0 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 28
public void propertyChange(PropertyChangeEvent pce) {
    LookAndFeel laf = get();
    if (laf == null || laf != UIManager.getLookAndFeel()) {
        dispose();
        return;
    }
    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    boolean lafCond = SwingUtilities2.isLocalDisplay();
    Object aaTextInfo =
        SwingUtilities2.AATextInfo.getAATextInfo(lafCond);
    defaults.put(SwingUtilities2.AA_TEXT_PROPERTY_KEY, aaTextInfo);
    updateUI();
}
 
Example 29
/**
 * <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 30
Source Project: jdk8u-jdk   Source File: BasicListUI.java    License: 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);
        }
    }
}