1 package javax
.swing
.plaf
.basic
;
4 import javax
.swing
.plaf
.*;
8 public class BasicButtonUI
extends ButtonUI
11 // int y_text_space = 2, x_text_space + 5;
13 Color textColor
, disabledTextColor
;
14 Color pressedBackgroundColor
;
15 Color normalBackgroundColor
;
18 public static ComponentUI
createUI(final JComponent c
)
20 return new BasicButtonUI();
24 public void installUI(final JComponent c
)
28 textColor
= new Color(0,0,0);
29 disabledTextColor
= new Color(130, 130, 130);
30 pressedBackgroundColor
= new Color(150,150,150);
31 pressedBackgroundColor
= new Color(150,150,150);
32 normalBackgroundColor
= new Color(192,192,192);
36 public Dimension
getPreferredSize(JComponent c
)
38 AbstractButton b
= (AbstractButton
)c
;
39 Dimension d
= BasicGraphicsUtils
.getPreferredSize(b
,
43 b
.getVerticalAlignment(),
44 b
.getHorizontalAlignment(),
45 b
.getHorizontalTextPosition(),
46 b
.getVerticalTextPosition());
47 // System.out.println("^^^^^^^^^^^^^^^^^^^^^^ BASIC-PREF="+d + ",T="+b.text);
52 public void paint(Graphics g
, JComponent c
)
54 AbstractButton b
= (AbstractButton
) c
;
56 Rectangle tr
= new Rectangle();
57 Rectangle ir
= new Rectangle();
58 Rectangle vr
= new Rectangle();
64 FontMetrics fm
= SwingUtilities
.getFontMetrics(f
);
66 Insets i
= c
.getInsets();
70 vr
.width
= b
.getWidth() - (i
.right
+ vr
.x
);
71 vr
.height
= b
.getHeight() - (i
.bottom
+ vr
.y
);
73 //System.out.println(" VIEW-RECT-BUTTON="+vr+", insets="+i+", FONTM="+fm);
75 String text
= SwingUtilities
.layoutCompoundLabel(c
,
79 b
.getVerticalAlignment(),
80 b
.getHorizontalAlignment(),
81 b
.getVerticalTextPosition(),
82 b
.getHorizontalTextPosition(),
88 if (b
.getModel().isPressed() ||
89 b
.getModel().isSelected())
91 //System.out.println("paint pressed");
92 paintButtonPressed(g
, c
);
96 //System.out.println("paint normal");
97 paintButtonNormal(g
, c
);
101 paintText(g
, c
, tr
, b
.getText());
102 paintFocus(g
, c
, vr
, tr
, ir
);
106 protected void paintFocus(Graphics g
,
114 protected void paintIcon(Graphics g
,
118 AbstractButton b
= (AbstractButton
) c
;
119 if (b
.getIcon() != null)
124 System
.out
.println("WE HAVE AN ICON: " + b
.getIcon());
126 b
.getIcon().paintIcon(c
, g
, x
, y
);
130 //System.out.println("NO ICON FOR BUTTON:" + b.text);
134 protected void paintButtonPressed(Graphics g
,
137 Dimension size
= b
.getSize();
139 g
.setColor(pressedBackgroundColor
);
140 g
.fillRect(1,1,size
.width
-2, size
.height
-2);
144 protected void paintButtonNormal(Graphics g
,
147 Dimension size
= b
.getSize();
149 g
.setColor(normalBackgroundColor
);
150 g
.fillRect(1,1,size
.width
-2, size
.height
-2);
154 protected void paintText(Graphics g
,
159 Font f
= c
.getFont();
163 FontMetrics fm
= SwingUtilities
.getFontMetrics(f
);
165 g
.setColor(c
.isEnabled() ? textColor
: disabledTextColor
);
167 BasicGraphicsUtils
.drawString(g
,
171 textRect
.y
+ fm
.getAscent()/2);