javax.swing.plaf.basic.BasicHTML#getHTMLBaseline ( )源码实例Demo

下面列出了javax.swing.plaf.basic.BasicHTML#getHTMLBaseline ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: darklaf   文件: DarkTabbedPaneUIBridge.java
/**
 * Returns the baseline for the specified tab.
 *
 * @param  tab                       index of tab to get baseline for
 * @return                           baseline or a value < 0 indicating there is no reasonable baseline
 * @throws IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count)
 * @since                            1.6
 */
protected int getBaseline(final int tab) {
    if (tabPane.getTabComponentAt(tab) != null) {
        int offset = getBaselineOffset();
        if (offset != 0) {
            // The offset is not applied to the tab component, and so
            // in general we can't get good alignment like with components
            // 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();
}
 
源代码2 项目: seaglass   文件: SeaGlassLabelUI.java
public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Component must be non-null");
    }
    if (width < 0 || height < 0) {
        throw new IllegalArgumentException("Width and height must be >= 0");
    }
    JLabel label = (JLabel) c;
    String text = label.getText();
    if (text == null || "".equals(text)) {
        return -1;
    }
    Insets i = label.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    // layout the text and icon
    SeaGlassContext context = getContext(label);
    FontMetrics fm = context.getComponent().getFontMetrics(context.getStyle().getFont(context));
    context.getStyle().getGraphicsUtils(context).layoutText(context, fm, label.getText(), label.getIcon(),
        label.getHorizontalAlignment(), label.getVerticalAlignment(), label.getHorizontalTextPosition(),
        label.getVerticalTextPosition(), viewRect, iconRect, textRect, label.getIconTextGap());
    View view = (View) label.getClientProperty(BasicHTML.propertyKey);
    int baseline;
    if (view != null) {
        baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height);
        if (baseline >= 0) {
            baseline += textRect.y;
        }
    } else {
        baseline = textRect.y + fm.getAscent();
    }
    context.dispose();
    return baseline;
}
 
源代码3 项目: jdk1.8-source-analysis   文件: MetalToolTipUI.java
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);
    }
}
 
源代码4 项目: jdk1.8-source-analysis   文件: SynthButtonUI.java
/**
 * {@inheritDoc}
 */
@Override
public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Component must be non-null");
    }
    if (width < 0 || height < 0) {
        throw new IllegalArgumentException(
                "Width and height must be >= 0");
    }
    AbstractButton b = (AbstractButton)c;
    String text = b.getText();
    if (text == null || "".equals(text)) {
        return -1;
    }
    Insets i = b.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    // layout the text and icon
    SynthContext context = getContext(b);
    FontMetrics fm = context.getComponent().getFontMetrics(
        context.getStyle().getFont(context));
    context.getStyle().getGraphicsUtils(context).layoutText(
        context, fm, b.getText(), b.getIcon(),
        b.getHorizontalAlignment(), b.getVerticalAlignment(),
        b.getHorizontalTextPosition(), b.getVerticalTextPosition(),
        viewRect, iconRect, textRect, b.getIconTextGap());
    View view = (View)b.getClientProperty(BasicHTML.propertyKey);
    int baseline;
    if (view != null) {
        baseline = BasicHTML.getHTMLBaseline(view, textRect.width,
                                             textRect.height);
        if (baseline >= 0) {
            baseline += textRect.y;
        }
    }
    else {
        baseline = textRect.y + fm.getAscent();
    }
    context.dispose();
    return baseline;
}
 
源代码5 项目: dragonwell8_jdk   文件: MetalToolTipUI.java
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);
    }
}
 
源代码6 项目: Java8CN   文件: MetalToolTipUI.java
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);
    }
}
 
源代码7 项目: jdk8u-jdk   文件: SynthButtonUI.java
/**
 * {@inheritDoc}
 */
@Override
public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Component must be non-null");
    }
    if (width < 0 || height < 0) {
        throw new IllegalArgumentException(
                "Width and height must be >= 0");
    }
    AbstractButton b = (AbstractButton)c;
    String text = b.getText();
    if (text == null || "".equals(text)) {
        return -1;
    }
    Insets i = b.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    // layout the text and icon
    SynthContext context = getContext(b);
    FontMetrics fm = context.getComponent().getFontMetrics(
        context.getStyle().getFont(context));
    context.getStyle().getGraphicsUtils(context).layoutText(
        context, fm, b.getText(), b.getIcon(),
        b.getHorizontalAlignment(), b.getVerticalAlignment(),
        b.getHorizontalTextPosition(), b.getVerticalTextPosition(),
        viewRect, iconRect, textRect, b.getIconTextGap());
    View view = (View)b.getClientProperty(BasicHTML.propertyKey);
    int baseline;
    if (view != null) {
        baseline = BasicHTML.getHTMLBaseline(view, textRect.width,
                                             textRect.height);
        if (baseline >= 0) {
            baseline += textRect.y;
        }
    }
    else {
        baseline = textRect.y + fm.getAscent();
    }
    context.dispose();
    return baseline;
}
 
源代码8 项目: openjdk-8-source   文件: SynthButtonUI.java
/**
 * {@inheritDoc}
 */
@Override
public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Component must be non-null");
    }
    if (width < 0 || height < 0) {
        throw new IllegalArgumentException(
                "Width and height must be >= 0");
    }
    AbstractButton b = (AbstractButton)c;
    String text = b.getText();
    if (text == null || "".equals(text)) {
        return -1;
    }
    Insets i = b.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    // layout the text and icon
    SynthContext context = getContext(b);
    FontMetrics fm = context.getComponent().getFontMetrics(
        context.getStyle().getFont(context));
    context.getStyle().getGraphicsUtils(context).layoutText(
        context, fm, b.getText(), b.getIcon(),
        b.getHorizontalAlignment(), b.getVerticalAlignment(),
        b.getHorizontalTextPosition(), b.getVerticalTextPosition(),
        viewRect, iconRect, textRect, b.getIconTextGap());
    View view = (View)b.getClientProperty(BasicHTML.propertyKey);
    int baseline;
    if (view != null) {
        baseline = BasicHTML.getHTMLBaseline(view, textRect.width,
                                             textRect.height);
        if (baseline >= 0) {
            baseline += textRect.y;
        }
    }
    else {
        baseline = textRect.y + fm.getAscent();
    }
    context.dispose();
    return baseline;
}
 
源代码9 项目: jdk8u-jdk   文件: MetalToolTipUI.java
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);
    }
}
 
源代码10 项目: JDKSourceCode1.8   文件: MetalToolTipUI.java
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);
    }
}
 
源代码11 项目: jdk8u-jdk   文件: SynthButtonUI.java
/**
 * {@inheritDoc}
 */
@Override
public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Component must be non-null");
    }
    if (width < 0 || height < 0) {
        throw new IllegalArgumentException(
                "Width and height must be >= 0");
    }
    AbstractButton b = (AbstractButton)c;
    String text = b.getText();
    if (text == null || "".equals(text)) {
        return -1;
    }
    Insets i = b.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    // layout the text and icon
    SynthContext context = getContext(b);
    FontMetrics fm = context.getComponent().getFontMetrics(
        context.getStyle().getFont(context));
    context.getStyle().getGraphicsUtils(context).layoutText(
        context, fm, b.getText(), b.getIcon(),
        b.getHorizontalAlignment(), b.getVerticalAlignment(),
        b.getHorizontalTextPosition(), b.getVerticalTextPosition(),
        viewRect, iconRect, textRect, b.getIconTextGap());
    View view = (View)b.getClientProperty(BasicHTML.propertyKey);
    int baseline;
    if (view != null) {
        baseline = BasicHTML.getHTMLBaseline(view, textRect.width,
                                             textRect.height);
        if (baseline >= 0) {
            baseline += textRect.y;
        }
    }
    else {
        baseline = textRect.y + fm.getAscent();
    }
    context.dispose();
    return baseline;
}
 
源代码12 项目: openjdk-jdk8u   文件: MetalToolTipUI.java
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);
    }
}
 
源代码13 项目: openjdk-jdk8u   文件: SynthButtonUI.java
/**
 * {@inheritDoc}
 */
@Override
public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Component must be non-null");
    }
    if (width < 0 || height < 0) {
        throw new IllegalArgumentException(
                "Width and height must be >= 0");
    }
    AbstractButton b = (AbstractButton)c;
    String text = b.getText();
    if (text == null || "".equals(text)) {
        return -1;
    }
    Insets i = b.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    // layout the text and icon
    SynthContext context = getContext(b);
    FontMetrics fm = context.getComponent().getFontMetrics(
        context.getStyle().getFont(context));
    context.getStyle().getGraphicsUtils(context).layoutText(
        context, fm, b.getText(), b.getIcon(),
        b.getHorizontalAlignment(), b.getVerticalAlignment(),
        b.getHorizontalTextPosition(), b.getVerticalTextPosition(),
        viewRect, iconRect, textRect, b.getIconTextGap());
    View view = (View)b.getClientProperty(BasicHTML.propertyKey);
    int baseline;
    if (view != null) {
        baseline = BasicHTML.getHTMLBaseline(view, textRect.width,
                                             textRect.height);
        if (baseline >= 0) {
            baseline += textRect.y;
        }
    }
    else {
        baseline = textRect.y + fm.getAscent();
    }
    context.dispose();
    return baseline;
}
 
源代码14 项目: openjdk-jdk8u-backup   文件: MetalToolTipUI.java
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);
    }
}
 
源代码15 项目: Java8CN   文件: SynthButtonUI.java
/**
 * {@inheritDoc}
 */
@Override
public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Component must be non-null");
    }
    if (width < 0 || height < 0) {
        throw new IllegalArgumentException(
                "Width and height must be >= 0");
    }
    AbstractButton b = (AbstractButton)c;
    String text = b.getText();
    if (text == null || "".equals(text)) {
        return -1;
    }
    Insets i = b.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    // layout the text and icon
    SynthContext context = getContext(b);
    FontMetrics fm = context.getComponent().getFontMetrics(
        context.getStyle().getFont(context));
    context.getStyle().getGraphicsUtils(context).layoutText(
        context, fm, b.getText(), b.getIcon(),
        b.getHorizontalAlignment(), b.getVerticalAlignment(),
        b.getHorizontalTextPosition(), b.getVerticalTextPosition(),
        viewRect, iconRect, textRect, b.getIconTextGap());
    View view = (View)b.getClientProperty(BasicHTML.propertyKey);
    int baseline;
    if (view != null) {
        baseline = BasicHTML.getHTMLBaseline(view, textRect.width,
                                             textRect.height);
        if (baseline >= 0) {
            baseline += textRect.y;
        }
    }
    else {
        baseline = textRect.y + fm.getAscent();
    }
    context.dispose();
    return baseline;
}
 
源代码16 项目: Bytecoder   文件: MetalToolTipUI.java
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.isEmpty()) {
        g.setFont(smallFont);
        g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
        SwingUtilities2.drawString(tip, g, accelString,
                                   tip.getWidth() - 1 - insets.right
                                       - accelSpacing
                                       + padSpaceBetweenStrings
                                       - 3,
                                   paintTextR.y + accelBL);
    }
}
 
源代码17 项目: Bytecoder   文件: SynthButtonUI.java
/**
 * {@inheritDoc}
 */
@Override
public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Component must be non-null");
    }
    if (width < 0 || height < 0) {
        throw new IllegalArgumentException(
                "Width and height must be >= 0");
    }
    AbstractButton b = (AbstractButton)c;
    String text = b.getText();
    if (text == null || text.isEmpty()) {
        return -1;
    }
    Insets i = b.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    // layout the text and icon
    SynthContext context = getContext(b);
    SynthStyle style;
    if (context.getStyle() != null) {
        style = context.getStyle();
    } else {
        style = SynthLookAndFeel.updateStyle(context, this);
    }
    FontMetrics fm = context.getComponent().getFontMetrics(
                           style.getFont(context));
    style.getGraphicsUtils(context).layoutText(
        context, fm, b.getText(), b.getIcon(),
        b.getHorizontalAlignment(), b.getVerticalAlignment(),
        b.getHorizontalTextPosition(), b.getVerticalTextPosition(),
        viewRect, iconRect, textRect, b.getIconTextGap());
    View view = (View)b.getClientProperty(BasicHTML.propertyKey);
    int baseline;
    if (view != null) {
        baseline = BasicHTML.getHTMLBaseline(view, textRect.width,
                                             textRect.height);
        if (baseline >= 0) {
            baseline += textRect.y;
        }
    }
    else {
        baseline = textRect.y + fm.getAscent();
    }
    return baseline;
}
 
源代码18 项目: openjdk-jdk9   文件: MetalToolTipUI.java
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);
    }
}
 
源代码19 项目: openjdk-8-source   文件: MetalToolTipUI.java
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);
    }
}
 
源代码20 项目: seaglass   文件: SeaGlassButtonUI.java
/**
 * @see javax.swing.plaf.basic.BasicButtonUI#getBaseline(javax.swing.JComponent,
 *      int, int)
 */
public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Component must be non-null");
    }

    if (width < 0 || height < 0) {
        throw new IllegalArgumentException("Width and height must be >= 0");
    }

    AbstractButton b    = (AbstractButton) c;
    String         text = b.getText();

    if (text == null || "".equals(text)) {
        return -1;
    }

    Insets    i        = b.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();

    viewRect.x      = i.left;
    viewRect.y      = i.top;
    viewRect.width  = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    // layout the text and icon
    SeaGlassContext context = getContext(b);
    FontMetrics     fm = context.getComponent().getFontMetrics(context.getStyle().getFont(context));

    context.getStyle().getGraphicsUtils(context).layoutText(context, fm, b.getText(), b.getIcon(), b.getHorizontalAlignment(),
                                                            b.getVerticalAlignment(), b.getHorizontalTextPosition(),
                                                            b.getVerticalTextPosition(), viewRect, iconRect, textRect,
                                                            b.getIconTextGap());
    View view     = (View) b.getClientProperty(BasicHTML.propertyKey);
    int  baseline;

    if (view != null) {
        baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height);
        if (baseline >= 0) {
            baseline += textRect.y;
        }
    } else {
        baseline = textRect.y + fm.getAscent();
    }

    context.dispose();
    return baseline;
}