下面列出了javax.swing.plaf.basic.BasicHTML#getHTMLBaseline ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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();
}
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;
}
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);
}
}
/**
* {@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;
}
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);
}
}
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);
}
}
/**
* {@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;
}
/**
* {@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;
}
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);
}
}
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);
}
}
/**
* {@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;
}
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);
}
}
/**
* {@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;
}
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);
}
}
/**
* {@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;
}
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);
}
}
/**
* {@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;
}
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);
}
}
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);
}
}
/**
* @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;
}