Search in sources :

Example 16 with View

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

the class BasicTabbedPaneUI method getBaseline.

/**
     * Returns the baseline for the specified tab.
     *
     * @param tab index of tab to get baseline for
     * @exception IndexOutOfBoundsException if index is out of range
     *            (index < 0 || index >= tab count)
     * @return baseline or a value < 0 indicating there is no reasonable
     *                  baseline
     * @since 1.6
     */
protected int getBaseline(int tab) {
    if (tabPane.getTabComponentAt(tab) != null) {
        int offset = getBaselineOffset();
        if (offset != 0) {
            // in the tab.
            return -1;
        }
        Component c = tabPane.getTabComponentAt(tab);
        Dimension pref = c.getPreferredSize();
        Insets tabInsets = getTabInsets(tabPane.getTabPlacement(), tab);
        int cellHeight = maxTabHeight - tabInsets.top - tabInsets.bottom;
        return c.getBaseline(pref.width, pref.height) + (cellHeight - pref.height) / 2 + tabInsets.top;
    } else {
        View view = getTextViewForTab(tab);
        if (view != null) {
            int viewHeight = (int) view.getPreferredSpan(View.Y_AXIS);
            int baseline = BasicHTML.getHTMLBaseline(view, (int) view.getPreferredSpan(View.X_AXIS), viewHeight);
            if (baseline >= 0) {
                return maxTabHeight / 2 - viewHeight / 2 + baseline + getBaselineOffset();
            }
            return -1;
        }
    }
    FontMetrics metrics = getFontMetrics();
    int fontHeight = metrics.getHeight();
    int fontBaseline = metrics.getAscent();
    return maxTabHeight / 2 - fontHeight / 2 + fontBaseline + getBaselineOffset();
}
Also used : View(javax.swing.text.View)

Example 17 with View

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

the class BasicToggleButtonUI method paint.

// ********************************
//          Paint Methods
// ********************************
public void paint(Graphics g, JComponent c) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    Dimension size = b.getSize();
    FontMetrics fm = g.getFontMetrics();
    Insets i = c.getInsets();
    Rectangle viewRect = new Rectangle(size);
    viewRect.x += i.left;
    viewRect.y += i.top;
    viewRect.width -= (i.right + viewRect.x);
    viewRect.height -= (i.bottom + viewRect.y);
    Rectangle iconRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Font f = c.getFont();
    g.setFont(f);
    // layout the text and icon
    String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), b.getIcon(), b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, b.getText() == null ? 0 : b.getIconTextGap());
    g.setColor(b.getBackground());
    if (model.isArmed() && model.isPressed() || model.isSelected()) {
        paintButtonPressed(g, b);
    }
    // Paint the Icon
    if (b.getIcon() != null) {
        paintIcon(g, b, iconRect);
    }
    // Draw the Text
    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);
        }
    }
    // draw the dashed focus line.
    if (b.isFocusPainted() && b.hasFocus()) {
        paintFocus(g, b, viewRect, textRect, iconRect);
    }
}
Also used : View(javax.swing.text.View)

Example 18 with View

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

the class BasicRadioButtonUI method paint.

/**
     * paint the radio button
     */
@Override
public synchronized void paint(Graphics g, JComponent c) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    Font f = c.getFont();
    g.setFont(f);
    FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f);
    Insets i = c.getInsets();
    size = b.getSize(size);
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = size.width - (i.right + viewRect.x);
    viewRect.height = size.height - (i.bottom + viewRect.y);
    iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
    textRect.x = textRect.y = textRect.width = textRect.height = 0;
    Icon altIcon = b.getIcon();
    Icon selectedIcon = null;
    Icon disabledIcon = null;
    String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), altIcon != null ? altIcon : getDefaultIcon(), b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, b.getText() == null ? 0 : b.getIconTextGap());
    // fill background
    if (c.isOpaque()) {
        g.setColor(b.getBackground());
        g.fillRect(0, 0, size.width, size.height);
    }
    // Paint the radio button
    if (altIcon != null) {
        if (!model.isEnabled()) {
            if (model.isSelected()) {
                altIcon = b.getDisabledSelectedIcon();
            } else {
                altIcon = b.getDisabledIcon();
            }
        } else if (model.isPressed() && model.isArmed()) {
            altIcon = b.getPressedIcon();
            if (altIcon == null) {
                // Use selected icon
                altIcon = b.getSelectedIcon();
            }
        } else if (model.isSelected()) {
            if (b.isRolloverEnabled() && model.isRollover()) {
                altIcon = b.getRolloverSelectedIcon();
                if (altIcon == null) {
                    altIcon = b.getSelectedIcon();
                }
            } else {
                altIcon = b.getSelectedIcon();
            }
        } else if (b.isRolloverEnabled() && model.isRollover()) {
            altIcon = b.getRolloverIcon();
        }
        if (altIcon == null) {
            altIcon = b.getIcon();
        }
        altIcon.paintIcon(c, g, iconRect.x, iconRect.y);
    } else {
        getDefaultIcon().paintIcon(c, g, iconRect.x, iconRect.y);
    }
    // Draw the Text
    if (text != null) {
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
        if (v != null) {
            v.paint(g, textRect);
        } else {
            paintText(g, b, textRect, text);
        }
        if (b.hasFocus() && b.isFocusPainted() && textRect.width > 0 && textRect.height > 0) {
            paintFocus(g, textRect, size);
        }
    }
}
Also used : View(javax.swing.text.View)

Example 19 with View

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

the class MetalToolTipUI method paint.

public void paint(Graphics g, JComponent c) {
    JToolTip tip = (JToolTip) c;
    Font font = c.getFont();
    FontMetrics metrics = SwingUtilities2.getFontMetrics(c, g, font);
    Dimension size = c.getSize();
    int accelBL;
    g.setColor(c.getForeground());
    // fix for bug 4153892
    String tipText = tip.getTipText();
    if (tipText == null) {
        tipText = "";
    }
    String accelString = getAcceleratorString(tip);
    FontMetrics accelMetrics = SwingUtilities2.getFontMetrics(c, g, smallFont);
    int accelSpacing = calcAccelSpacing(c, accelMetrics, accelString);
    Insets insets = tip.getInsets();
    Rectangle paintTextR = new Rectangle(insets.left + 3, insets.top, size.width - (insets.left + insets.right) - 6 - accelSpacing, size.height - (insets.top + insets.bottom));
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
        v.paint(g, paintTextR);
        accelBL = BasicHTML.getHTMLBaseline(v, paintTextR.width, paintTextR.height);
    } else {
        g.setFont(font);
        SwingUtilities2.drawString(tip, g, tipText, paintTextR.x, paintTextR.y + metrics.getAscent());
        accelBL = metrics.getAscent();
    }
    if (!accelString.equals("")) {
        g.setFont(smallFont);
        g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
        SwingUtilities2.drawString(tip, g, accelString, tip.getWidth() - 1 - insets.right - accelSpacing + padSpaceBetweenStrings - 3, paintTextR.y + accelBL);
    }
}
Also used : View(javax.swing.text.View)

Example 20 with View

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

the class BasicToolTipUI method getMinimumSize.

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 : View(javax.swing.text.View)

Aggregations

View (javax.swing.text.View)66 Dimension (java.awt.Dimension)4 Rectangle (java.awt.Rectangle)4 UIResource (javax.swing.plaf.UIResource)4 FontMetrics (java.awt.FontMetrics)3 Insets (java.awt.Insets)3 Color (java.awt.Color)2 Border (javax.swing.border.Border)2 JBColor (com.intellij.ui.JBColor)1 JBGradientPaint (com.intellij.ui.JBGradientPaint)1 Container (java.awt.Container)1 Font (java.awt.Font)1 Graphics2D (java.awt.Graphics2D)1 Point (java.awt.Point)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 PrinterException (java.awt.print.PrinterException)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 ColorUIResource (javax.swing.plaf.ColorUIResource)1