Search in sources :

Example 46 with View

use of javax.swing.text.View in project jdk8u_jdk by JetBrains.

the class BasicButtonUI method paint.

// ********************************
//          Paint Methods
// ********************************
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);
    }
}
Also used : View(javax.swing.text.View)

Example 47 with View

use of javax.swing.text.View in project jdk8u_jdk by JetBrains.

the class BasicLabelUI method paint.

/**
     * Paints the label text with the foreground color, if the label is opaque
     * then paints the entire background with the background color. The Label
     * text is drawn by {@link #paintEnabledText} or {@link #paintDisabledText}.
     * The locations of the label parts are computed by {@link #layoutCL}.
     *
     * @see #paintEnabledText
     * @see #paintDisabledText
     * @see #layoutCL
     */
public void paint(Graphics g, JComponent c) {
    JLabel label = (JLabel) c;
    String text = label.getText();
    Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();
    if ((icon == null) && (text == null)) {
        return;
    }
    FontMetrics fm = SwingUtilities2.getFontMetrics(label, g);
    String clippedText = layout(label, fm, c.getWidth(), c.getHeight());
    if (icon != null) {
        icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
    }
    if (text != null) {
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
        if (v != null) {
            v.paint(g, paintTextR);
        } else {
            int textX = paintTextR.x;
            int textY = paintTextR.y + fm.getAscent();
            if (label.isEnabled()) {
                paintEnabledText(label, g, clippedText, textX, textY);
            } else {
                paintDisabledText(label, g, clippedText, textX, textY);
            }
        }
    }
}
Also used : FontMetrics(java.awt.FontMetrics) View(javax.swing.text.View)

Example 48 with View

use of javax.swing.text.View in project jdk8u_jdk by JetBrains.

the class BasicLabelUI method getMinimumSize.

/**
     * @return getPreferredSize(c)
     */
public Dimension getMinimumSize(JComponent c) {
    Dimension d = getPreferredSize(c);
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
        d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS);
    }
    return d;
}
Also used : Dimension(java.awt.Dimension) View(javax.swing.text.View)

Example 49 with View

use of javax.swing.text.View in project jdk8u_jdk by JetBrains.

the class AquaMenuPainter method paintMenuItem.

protected void paintMenuItem(final Client client, final Graphics g, final JComponent c, final Icon checkIcon, final Icon arrowIcon, final Color background, final Color foreground, final Color disabledForeground, final Color selectionForeground, final int defaultTextIconGap, final Font acceleratorFont) {
    final JMenuItem b = (JMenuItem) c;
    final ButtonModel model = b.getModel();
    //        Dimension size = b.getSize();
    final int menuWidth = b.getWidth();
    final int menuHeight = b.getHeight();
    final Insets i = c.getInsets();
    Rectangle viewRect = new Rectangle(0, 0, menuWidth, menuHeight);
    viewRect.x += i.left;
    viewRect.y += i.top;
    viewRect.width -= (i.right + viewRect.x);
    viewRect.height -= (i.bottom + viewRect.y);
    final Font holdf = g.getFont();
    final Color holdc = g.getColor();
    final Font f = c.getFont();
    g.setFont(f);
    final FontMetrics fm = g.getFontMetrics(f);
    final FontMetrics fmAccel = g.getFontMetrics(acceleratorFont);
    // Paint background (doesn't touch the Graphics object's color)
    if (c.isOpaque()) {
        client.paintBackground(g, c, menuWidth, menuHeight);
    }
    // get Accelerator text
    final KeyStroke accelerator = b.getAccelerator();
    String modifiersString = "", keyString = "";
    final boolean leftToRight = AquaUtils.isLeftToRight(c);
    if (accelerator != null) {
        final int modifiers = accelerator.getModifiers();
        if (modifiers > 0) {
            modifiersString = getKeyModifiersText(modifiers, leftToRight);
        }
        final int keyCode = accelerator.getKeyCode();
        if (keyCode != 0) {
            keyString = KeyEvent.getKeyText(keyCode);
        } else {
            keyString += accelerator.getKeyChar();
        }
    }
    Rectangle iconRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle acceleratorRect = new Rectangle();
    Rectangle checkIconRect = new Rectangle();
    Rectangle arrowIconRect = new Rectangle();
    // layout the text and icon
    final String text = layoutMenuItem(b, fm, b.getText(), fmAccel, keyString, modifiersString, b.getIcon(), checkIcon, arrowIcon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, acceleratorRect, checkIconRect, arrowIconRect, b.getText() == null ? 0 : defaultTextIconGap, defaultTextIconGap);
    // if this is in a AquaScreenMenuBar that's attached to a DialogPeer
    // the native menu will be disabled, though the awt Menu won't know about it
    // so the JPopupMenu will not have visibility set and the items should draw disabled
    // If it's not on a JPopupMenu then it should just use the model's enable state
    final Container parent = b.getParent();
    final boolean parentIsMenuBar = parent instanceof JMenuBar;
    Container ancestor = parent;
    while (ancestor != null && !(ancestor instanceof JPopupMenu)) ancestor = ancestor.getParent();
    boolean isEnabled = model.isEnabled() && (ancestor == null || ancestor.isVisible());
    // Set the accel/normal text color
    boolean isSelected = false;
    if (!isEnabled) {
        // *** paint the text disabled
        g.setColor(disabledForeground);
    } else {
        // *** paint the text normally
        if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
            g.setColor(selectionForeground);
            isSelected = true;
        } else {
            // Which is either MenuItem.foreground or the user's choice
            g.setColor(parentIsMenuBar ? parent.getForeground() : b.getForeground());
        }
    }
    // Paint the Icon
    if (b.getIcon() != null) {
        paintIcon(g, b, iconRect, isEnabled);
    }
    // Paint the Check using the current text color
    if (checkIcon != null) {
        paintCheck(g, b, checkIcon, checkIconRect);
    }
    // Draw the accelerator first in case the HTML renderer changes the color
    if (keyString != null && !keyString.equals("")) {
        final int yAccel = acceleratorRect.y + fm.getAscent();
        if (modifiersString.equals("")) {
            // just draw the keyString
            SwingUtilities2.drawString(c, g, keyString, acceleratorRect.x, yAccel);
        } else {
            final int modifiers = accelerator.getModifiers();
            int underlinedChar = 0;
            // This is a Java2 thing, we won't be getting kOptionGlyph
            if ((modifiers & ALT_GRAPH_MASK) > 0)
                underlinedChar = kUOptionGlyph;
            // The keyStrings should all line up, so always adjust the width by the same amount
            // (if they're multi-char, they won't line up but at least they won't be cut off)
            final int emWidth = Math.max(fm.charWidth('M'), SwingUtilities.computeStringWidth(fm, keyString));
            if (leftToRight) {
                g.setFont(acceleratorFont);
                drawString(g, c, modifiersString, underlinedChar, acceleratorRect.x, yAccel, isEnabled, isSelected);
                g.setFont(f);
                SwingUtilities2.drawString(c, g, keyString, acceleratorRect.x + acceleratorRect.width - emWidth, yAccel);
            } else {
                final int xAccel = acceleratorRect.x + emWidth;
                g.setFont(acceleratorFont);
                drawString(g, c, modifiersString, underlinedChar, xAccel, yAccel, isEnabled, isSelected);
                g.setFont(f);
                SwingUtilities2.drawString(c, g, keyString, xAccel - fm.stringWidth(keyString), yAccel);
            }
        }
    }
    // Draw the Text
    if (text != null && !text.equals("")) {
        final View v = (View) c.getClientProperty(BasicHTML.propertyKey);
        if (v != null) {
            v.paint(g, textRect);
        } else {
            final int mnemonic = (AquaMnemonicHandler.isMnemonicHidden() ? -1 : model.getMnemonic());
            drawString(g, c, text, mnemonic, textRect.x, textRect.y + fm.getAscent(), isEnabled, isSelected);
        }
    }
    // Paint the Arrow
    if (arrowIcon != null) {
        paintArrow(g, b, model, arrowIcon, arrowIconRect);
    }
    g.setColor(holdc);
    g.setFont(holdf);
}
Also used : View(javax.swing.text.View)

Example 50 with View

use of javax.swing.text.View in project jdk8u_jdk by JetBrains.

the class AquaTabbedPaneCopyFromBasicUI method calculateTabWidth.

protected int calculateTabWidth(final int tabPlacement, final int tabIndex, final FontMetrics metrics) {
    final Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
    int width = tabInsets.left + tabInsets.right + 3;
    final Component tabComponent = tabPane.getTabComponentAt(tabIndex);
    if (tabComponent != null) {
        width += tabComponent.getPreferredSize().width;
    } else {
        final Icon icon = getIconForTab(tabIndex);
        if (icon != null) {
            width += icon.getIconWidth() + textIconGap;
        }
        final View v = getTextViewForTab(tabIndex);
        if (v != null) {
            // html
            width += (int) v.getPreferredSpan(View.X_AXIS);
        } else {
            // plain text
            final String title = tabPane.getTitleAt(tabIndex);
            width += SwingUtilities2.stringWidth(tabPane, metrics, title);
        }
    }
    return width;
}
Also used : View(javax.swing.text.View)

Aggregations

View (javax.swing.text.View)81 Rectangle (java.awt.Rectangle)8 HTMLDocument (javax.swing.text.html.HTMLDocument)6 Dimension (java.awt.Dimension)5 Element (javax.swing.text.Element)5 FontMetrics (java.awt.FontMetrics)4 Insets (java.awt.Insets)4 UIResource (javax.swing.plaf.UIResource)4 Point (java.awt.Point)3 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)3 Color (java.awt.Color)2 Font (java.awt.Font)2 Graphics2D (java.awt.Graphics2D)2 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 Border (javax.swing.border.Border)2 BadLocationException (javax.swing.text.BadLocationException)2 ViewFactory (javax.swing.text.ViewFactory)2 JBColor (com.intellij.ui.JBColor)1 JBGradientPaint (com.intellij.ui.JBGradientPaint)1