下面列出了javax.swing.text.View#paint ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void paintText(SynthContext ss,
Graphics g, int tabPlacement,
Font font, FontMetrics metrics, int tabIndex,
String title, Rectangle textRect,
boolean isSelected) {
g.setFont(font);
View v = getTextViewForTab(tabIndex);
if (v != null) {
// html
v.paint(g, textRect);
} else {
// plain text
int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
g.setColor(ss.getStyle().getColor(ss, ColorType.TEXT_FOREGROUND));
ss.getStyle().getGraphicsUtils(ss).paintText(ss, g, title,
textRect, mnemIndex);
}
}
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g the {@code Graphics} object used for painting
* @see #update(Graphics,JComponent)
*/
protected void paint(SynthContext context, Graphics g) {
JToolTip tip = (JToolTip)context.getComponent();
Insets insets = tip.getInsets();
View v = (View)tip.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
Rectangle paintTextR = new Rectangle(insets.left, insets.top,
tip.getWidth() - (insets.left + insets.right),
tip.getHeight() - (insets.top + insets.bottom));
v.paint(g, paintTextR);
} else {
g.setColor(context.getStyle().getColor(context,
ColorType.TEXT_FOREGROUND));
g.setFont(style.getFont(context));
context.getStyle().getGraphicsUtils(context).paintText(
context, g, tip.getTipText(), insets.left, insets.top, -1);
}
}
protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
final View v = getTextViewForTab(tabIndex);
if (v != null) {
v.paint(g2d, textRect);
return;
}
if (title == null) return;
final Color color = tabPane.getForegroundAt(tabIndex);
if (color instanceof UIResource) {
g2d.setColor(getNonSelectedTabTitleColor());
if (tabPane.getSelectedIndex() == tabIndex) {
boolean pressed = isPressedAt(tabIndex);
boolean enabled = tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex);
Color textColor = getSelectedTabTitleColor(enabled, pressed);
Color shadowColor = getSelectedTabTitleShadowColor(enabled);
AquaUtils.paintDropShadowText(g2d, tabPane, font, metrics, textRect.x, textRect.y, 0, 1, textColor, shadowColor, title);
return;
}
} else {
g2d.setColor(color);
}
g2d.setFont(font);
SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
/**
* 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);
}
}
}
}
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);
}
}
}
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);
}
}
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);
}
}
}
@Override public void paint(Graphics g, JComponent c) {
if (!(c instanceof AbstractButton)) {
return;
}
AbstractButton b = (AbstractButton) c;
Font f = b.getFont();
g.setFont(f);
// Insets i = c.getInsets();
// b.getSize(size);
// viewRect.setBounds(i.left, i.top, size.width - i.left - i.right, size.height - i.top - i.bottom);
SwingUtilities.calculateInnerArea(c, viewRect);
iconRect.setBounds(0, 0, 0, 0);
textRect.setBounds(0, 0, 0, 0);
String text = SwingUtilities.layoutCompoundLabel(
c, c.getFontMetrics(f), b.getText(), null, // altIcon != null ? altIcon : getDefaultIcon(),
b.getVerticalAlignment(), b.getHorizontalAlignment(),
b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
viewRect, iconRect, textRect,
0); // b.getText() == null ? 0 : b.getIconTextGap());
if (c.isOpaque()) {
g.setColor(b.getBackground());
g.fillRect(0, 0, c.getWidth(), c.getHeight());
}
ButtonModel model = b.getModel();
if (!model.isSelected() && !model.isPressed() && !model.isArmed() && b.isRolloverEnabled() && model.isRollover()) {
g.setColor(Color.BLUE);
g.drawLine(viewRect.x, viewRect.y + viewRect.height, viewRect.x + viewRect.width, viewRect.y + viewRect.height);
}
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if (Objects.nonNull(v)) {
v.paint(g, textRect);
} else {
paintText(g, b, textRect, text);
}
}
/**
* 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);
}
}
}
}
/**
* 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);
}
}
}
}
public void paint(final Graphics g, final JComponent c) {
final AbstractButton b = (AbstractButton)c;
final ButtonModel model = b.getModel();
final Insets i = c.getInsets();
Rectangle viewRect = new Rectangle(b.getWidth(), b.getHeight());
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
// we are overdrawing here with translucent colors so we get
// a darkening effect. How can we avoid it. Try clear rect?
if (b.isOpaque()) {
g.setColor(c.getBackground());
g.fillRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
}
AquaButtonBorder aquaBorder = null;
if (((AbstractButton)c).isBorderPainted()) {
final Border border = c.getBorder();
if (border instanceof AquaButtonBorder) {
// only do this if borders are on!
// this also takes care of focus painting.
aquaBorder = (AquaButtonBorder)border;
aquaBorder.paintButton(c, g, viewRect.x, viewRect.y, viewRect.width, viewRect.height);
}
} else {
if (b.isOpaque()) {
viewRect.x = i.left - 2;
viewRect.y = i.top - 2;
viewRect.width = b.getWidth() - (i.right + viewRect.x) + 4;
viewRect.height = b.getHeight() - (i.bottom + viewRect.y) + 4;
if (b.isContentAreaFilled() || model.isSelected()) {
if (model.isSelected()) // Toggle buttons
g.setColor(c.getBackground().darker());
else g.setColor(c.getBackground());
g.fillRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
}
}
// needs focus to be painted
// for now we don't know exactly what to do...we'll see!
if (b.isFocusPainted() && b.hasFocus()) {
// paint UI specific focus
paintFocus(g, b, viewRect, textRect, iconRect);
}
}
// performs icon and text rect calculations
final String text = layoutAndGetText(g, b, aquaBorder, i, viewRect, iconRect, textRect);
// Paint the Icon
if (b.getIcon() != null) {
paintIcon(g, b, iconRect);
}
if (textRect.width == 0) {
textRect.width = 50;
}
if (text != null && !text.equals("")) {
final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g, textRect);
} else {
paintText(g, b, textRect, text);
}
}
}
protected void paintText(Graphics g, int tabPlacement,
Font font, FontMetrics metrics, int tabIndex,
String title, Rectangle textRect,
boolean isSelected) {
g.setFont(font);
View v = getTextViewForTab(tabIndex);
if (v != null) {
// html
v.paint(g, textRect);
} else {
// plain text
int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
Color fg = tabPane.getForegroundAt(tabIndex);
if (isSelected && (fg instanceof UIResource)) {
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);
}
}
}
public void paint(final Graphics g, final JComponent c) {
final AbstractButton b = (AbstractButton)c;
final ButtonModel model = b.getModel();
final Insets i = c.getInsets();
Rectangle viewRect = new Rectangle(b.getWidth(), b.getHeight());
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
// we are overdrawing here with translucent colors so we get
// a darkening effect. How can we avoid it. Try clear rect?
if (b.isOpaque()) {
g.setColor(c.getBackground());
g.fillRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
}
AquaButtonBorder aquaBorder = null;
if (((AbstractButton)c).isBorderPainted()) {
final Border border = c.getBorder();
if (border instanceof AquaButtonBorder) {
// only do this if borders are on!
// this also takes care of focus painting.
aquaBorder = (AquaButtonBorder)border;
aquaBorder.paintButton(c, g, viewRect.x, viewRect.y, viewRect.width, viewRect.height);
}
} else {
if (b.isOpaque()) {
viewRect.x = i.left - 2;
viewRect.y = i.top - 2;
viewRect.width = b.getWidth() - (i.right + viewRect.x) + 4;
viewRect.height = b.getHeight() - (i.bottom + viewRect.y) + 4;
if (b.isContentAreaFilled() || model.isSelected()) {
if (model.isSelected()) // Toggle buttons
g.setColor(c.getBackground().darker());
else g.setColor(c.getBackground());
g.fillRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
}
}
// needs focus to be painted
// for now we don't know exactly what to do...we'll see!
if (b.isFocusPainted() && b.hasFocus()) {
// paint UI specific focus
paintFocus(g, b, viewRect, textRect, iconRect);
}
}
// performs icon and text rect calculations
final String text = layoutAndGetText(g, b, aquaBorder, i, viewRect, iconRect, textRect);
// Paint the Icon
if (b.getIcon() != null) {
paintIcon(g, b, iconRect);
}
if (textRect.width == 0) {
textRect.width = 50;
}
if (text != null && !text.equals("")) {
final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g, textRect);
} else {
paintText(g, b, textRect, text);
}
}
}
@Override
public void paint(Graphics g, JComponent c) {
AbstractButton b = (AbstractButton) c;
// boolean isOpaque = b.isOpaque();
// b.putClientProperty(SubstanceButtonUI.LOCK_OPACITY, Boolean.TRUE);
// b.setOpaque(false);
if (SubstanceCoreUtilities.isOpaque(c)) {
BackgroundPaintingUtils.update(g, c, false);
}
// b.setOpaque(isOpaque);
// b.putClientProperty(SubstanceButtonUI.LOCK_OPACITY, null);
FontMetrics fm = g.getFontMetrics();
Insets i = b.getInsets();
viewRect.x = i.left;
viewRect.y = i.top;
viewRect.width = b.getWidth() - (i.right + viewRect.x);
viewRect.height = b.getHeight() - (i.bottom + viewRect.y);
textRect.x = textRect.y = textRect.width = textRect.height = 0;
iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
Font f = b.getFont();
g.setFont(f);
Icon icon = SubstanceCoreUtilities.getOriginalIcon(b, getDefaultIcon());
// layout the text and icon
String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), icon,
b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(),
b.getHorizontalTextPosition(), viewRect, iconRect, textRect,
b.getText() == null ? 0 : b.getIconTextGap());
Graphics2D g2d = (Graphics2D) g.create();
if (text != null && !text.equals("")) {
final View v = (View) b.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g2d, textRect);
} else {
this.paintButtonText(g2d, b, textRect, text);
}
}
// Paint the Icon
if (icon != null) {
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
icon.paintIcon(c, g2d, iconRect.x, iconRect.y);
}
if (b.isFocusPainted()) {
// make sure that the focus ring is not clipped
float focusRingPadding = SubstanceSizeUtils
.getFocusRingPadding(SubstanceSizeUtils.getComponentFontSize(button)) / 2;
SubstanceCoreUtilities.paintFocus(g2d, button, button, this, null, textRect, 1.0f,
focusRingPadding);
}
// g2d.setColor(Color.red);
// g2d.draw(iconRect);
// g2d.draw(viewRect);
// g2d.draw(textRect);
// g2d.setColor(Color.blue);
// g2d.drawRect(0, 0, button.getWidth() - 1, button.getHeight() - 1);
g2d.dispose();
}
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);
}
}
private void paintView(final Graphics2D graphics2D, final View view,
final Shape allocation) {
if (graphics2D != null) {
view.paint(graphics2D, allocation);
}
}
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);
}
}
/**
* 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);
}
}
}
public void paint(final Graphics g, final JComponent c) {
final AbstractButton b = (AbstractButton)c;
final ButtonModel model = b.getModel();
final Insets i = c.getInsets();
Rectangle viewRect = new Rectangle(b.getWidth(), b.getHeight());
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
// we are overdrawing here with translucent colors so we get
// a darkening effect. How can we avoid it. Try clear rect?
if (b.isOpaque()) {
g.setColor(c.getBackground());
g.fillRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
}
AquaButtonBorder aquaBorder = null;
if (((AbstractButton)c).isBorderPainted()) {
final Border border = c.getBorder();
if (border instanceof AquaButtonBorder) {
// only do this if borders are on!
// this also takes care of focus painting.
aquaBorder = (AquaButtonBorder)border;
aquaBorder.paintButton(c, g, viewRect.x, viewRect.y, viewRect.width, viewRect.height);
}
} else {
if (b.isOpaque()) {
viewRect.x = i.left - 2;
viewRect.y = i.top - 2;
viewRect.width = b.getWidth() - (i.right + viewRect.x) + 4;
viewRect.height = b.getHeight() - (i.bottom + viewRect.y) + 4;
if (b.isContentAreaFilled() || model.isSelected()) {
if (model.isSelected()) // Toggle buttons
g.setColor(c.getBackground().darker());
else g.setColor(c.getBackground());
g.fillRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
}
}
// needs focus to be painted
// for now we don't know exactly what to do...we'll see!
if (b.isFocusPainted() && b.hasFocus()) {
// paint UI specific focus
paintFocus(g, b, viewRect, textRect, iconRect);
}
}
// performs icon and text rect calculations
final String text = layoutAndGetText(g, b, aquaBorder, i, viewRect, iconRect, textRect);
// Paint the Icon
if (b.getIcon() != null) {
paintIcon(g, b, iconRect);
}
if (textRect.width == 0) {
textRect.width = 50;
}
if (text != null && !text.equals("")) {
final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g, textRect);
} else {
paintText(g, b, textRect, text);
}
}
}