Search in sources :

Example 51 with View

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

the class AquaTabbedPaneCopyFromBasicUI method paintText.

protected void paintText(final Graphics g, final int tabPlacement, final Font font, final FontMetrics metrics, final int tabIndex, final String title, final Rectangle textRect, final boolean isSelected) {
    g.setFont(font);
    final View v = getTextViewForTab(tabIndex);
    if (v != null) {
        // html
        v.paint(g, textRect);
    } else {
        // plain text
        final int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
        if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
            Color fg = tabPane.getForegroundAt(tabIndex);
            if (isSelected && (fg instanceof UIResource)) {
                final Color selectedFG = UIManager.getColor("TabbedPane.selectedForeground");
                if (selectedFG != null) {
                    fg = selectedFG;
                }
            }
            g.setColor(fg);
            SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
        } else {
            // tab disabled
            g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
            SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
            g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
            SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1);
        }
    }
}
Also used : View(javax.swing.text.View)

Example 52 with View

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

the class AquaTabbedPaneCopyFromBasicUI 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 &lt; 0 indicating there is no reasonable
     *                  baseline
     * @since 1.6
     */
protected int getBaseline(final int tab) {
    if (tabPane.getTabComponentAt(tab) != null) {
        final int offset = getBaselineOffset();
        if (offset != 0) {
            // in the tab.
            return -1;
        }
        final Component c = tabPane.getTabComponentAt(tab);
        final Dimension pref = c.getPreferredSize();
        final Insets tabInsets = getTabInsets(tabPane.getTabPlacement(), tab);
        final int cellHeight = maxTabHeight - tabInsets.top - tabInsets.bottom;
        return c.getBaseline(pref.width, pref.height) + (cellHeight - pref.height) / 2 + tabInsets.top;
    } else {
        final View view = getTextViewForTab(tab);
        if (view != null) {
            final int viewHeight = (int) view.getPreferredSpan(View.Y_AXIS);
            final int baseline = BasicHTML.getHTMLBaseline(view, (int) view.getPreferredSpan(View.X_AXIS), viewHeight);
            if (baseline >= 0) {
                return maxTabHeight / 2 - viewHeight / 2 + baseline + getBaselineOffset();
            }
            return -1;
        }
    }
    final FontMetrics metrics = getFontMetrics();
    final int fontHeight = metrics.getHeight();
    final int fontBaseline = metrics.getAscent();
    return maxTabHeight / 2 - fontHeight / 2 + fontBaseline + getBaselineOffset();
}
Also used : View(javax.swing.text.View)

Example 53 with View

use of javax.swing.text.View in project java-swing-tips by aterai.

the class TabButton method layoutLabel.

@Override
protected void layoutLabel(int tabPlacement, FontMetrics metrics, int tabIndex, String title, Icon icon, Rectangle tabRect, Rectangle iconRect, Rectangle textRect, boolean isSelected) {
    textRect.setLocation(0, 0);
    iconRect.setLocation(0, 0);
    View v = getTextViewForTab(tabIndex);
    if (Objects.nonNull(v)) {
        tabPane.putClientProperty("html", v);
    }
    SwingUtilities.layoutCompoundLabel((JComponent) tabPane, metrics, title, icon, SwingConstants.CENTER, //CENTER, <----
    SwingConstants.LEFT, SwingConstants.CENTER, SwingConstants.TRAILING, tabRect, iconRect, textRect, textIconGap);
    tabPane.putClientProperty("html", null);
    //<----
    textRect.translate(tabInsets.left, 0);
    textRect.width -= tabInsets.left + tabInsets.right;
    int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
    int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
    iconRect.x += xNudge;
    iconRect.y += yNudge;
    textRect.x += xNudge;
    textRect.y += yNudge;
}
Also used : View(javax.swing.text.View)

Example 54 with View

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

the class BasicToolTipUI method getPreferredSize.

public Dimension getPreferredSize(JComponent c) {
    Font font = c.getFont();
    FontMetrics fm = c.getFontMetrics(font);
    Insets insets = c.getInsets();
    Dimension prefSize = new Dimension(insets.left + insets.right, insets.top + insets.bottom);
    String text = ((JToolTip) c).getTipText();
    if ((text == null) || text.equals("")) {
        text = "";
    } else {
        View v = (c != null) ? (View) c.getClientProperty("html") : null;
        if (v != null) {
            prefSize.width += (int) v.getPreferredSpan(View.X_AXIS) + 6;
            prefSize.height += (int) v.getPreferredSpan(View.Y_AXIS);
        } else {
            prefSize.width += SwingUtilities2.stringWidth(c, fm, text) + 6;
            prefSize.height += fm.getHeight();
        }
    }
    return prefSize;
}
Also used : View(javax.swing.text.View)

Example 55 with View

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

the class BasicToolTipUI method getMaximumSize.

public Dimension getMaximumSize(JComponent c) {
    Dimension d = getPreferredSize(c);
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
        d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS);
    }
    return d;
}
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