47 |
import javax.swing.AbstractButton; |
import javax.swing.AbstractButton; |
48 |
import javax.swing.JButton; |
import javax.swing.JButton; |
49 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
50 |
import javax.swing.UIDefaults; |
import javax.swing.SwingConstants; |
51 |
import javax.swing.UIManager; |
import javax.swing.UIManager; |
52 |
import javax.swing.plaf.ComponentUI; |
import javax.swing.plaf.ComponentUI; |
53 |
import javax.swing.plaf.UIResource; |
import javax.swing.plaf.UIResource; |
78 |
public MetalButtonUI() |
public MetalButtonUI() |
79 |
{ |
{ |
80 |
super(); |
super(); |
81 |
UIDefaults def = UIManager.getLookAndFeelDefaults(); |
focusColor = UIManager.getColor(getPropertyPrefix() + "focus"); |
82 |
focusColor = def.getColor(getPropertyPrefix() + "focus"); |
selectColor = UIManager.getColor(getPropertyPrefix() + "select"); |
83 |
selectColor = def.getColor(getPropertyPrefix() + "select"); |
disabledTextColor = UIManager.getColor(getPropertyPrefix() + "disabledText"); |
|
disabledTextColor = def.getColor(getPropertyPrefix() + "disabledText"); |
|
84 |
} |
} |
85 |
|
|
86 |
/** |
/** |
134 |
public void installDefaults(AbstractButton button) |
public void installDefaults(AbstractButton button) |
135 |
{ |
{ |
136 |
super.installDefaults(button); |
super.installDefaults(button); |
137 |
if (button.isRolloverEnabled()) |
button.setRolloverEnabled(UIManager.getBoolean( |
138 |
{ |
getPropertyPrefix() + "rollover")); |
|
if (button.getBorder() instanceof UIResource) |
|
|
button.setBorder(MetalBorders.getRolloverBorder()); |
|
|
} |
|
139 |
} |
} |
140 |
|
|
141 |
/** |
/** |
144 |
public void uninstallDefaults(AbstractButton button) |
public void uninstallDefaults(AbstractButton button) |
145 |
{ |
{ |
146 |
super.uninstallDefaults(button); |
super.uninstallDefaults(button); |
147 |
if (button.getBorder() instanceof UIResource) |
button.setRolloverEnabled(false); |
|
button.setBorder(null); |
|
148 |
} |
} |
149 |
|
|
150 |
/** |
/** |
187 |
*/ |
*/ |
188 |
protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, |
protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, |
189 |
Rectangle textRect, Rectangle iconRect) { |
Rectangle textRect, Rectangle iconRect) { |
190 |
if (b.hasFocus() && b.isFocusPainted()) |
if (b.isEnabled() && b.hasFocus() && b.isFocusPainted()) |
191 |
{ |
{ |
192 |
Color savedColor = g.getColor(); |
Color savedColor = g.getColor(); |
193 |
g.setColor(getFocusColor()); |
g.setColor(getFocusColor()); |
194 |
Rectangle focusRect = iconRect.union(textRect); |
Rectangle focusRect = iconRect.union(textRect); |
195 |
g.drawRect(focusRect.x - 1, focusRect.y - 1, |
g.drawRect(focusRect.x - 1, focusRect.y, |
196 |
focusRect.width + 1, focusRect.height + 1); |
focusRect.width + 1, focusRect.height); |
197 |
g.setColor(savedColor); |
g.setColor(savedColor); |
198 |
} |
} |
199 |
} |
} |
225 |
g.drawString(text, textRect.x, textRect.y + fm.getAscent()); |
g.drawString(text, textRect.x, textRect.y + fm.getAscent()); |
226 |
} |
} |
227 |
} |
} |
228 |
|
|
229 |
|
/** |
230 |
|
* If the property <code>Button.gradient</code> is set, then a gradient is |
231 |
|
* painted as background, otherwise the normal superclass behaviour is |
232 |
|
* called. |
233 |
|
*/ |
234 |
|
public void update(Graphics g, JComponent c) |
235 |
|
{ |
236 |
|
AbstractButton b = (AbstractButton) c; |
237 |
|
if (b.isOpaque() && UIManager.get(getPropertyPrefix() + "gradient") != null |
238 |
|
&& !b.getModel().isPressed() && b.isEnabled()) |
239 |
|
{ |
240 |
|
MetalUtils.paintGradient(g, 0, 0, c.getWidth(), c.getHeight(), |
241 |
|
SwingConstants.VERTICAL, |
242 |
|
getPropertyPrefix() + "gradient"); |
243 |
|
paint(g, c); |
244 |
|
} |
245 |
|
else |
246 |
|
super.update(g, c); |
247 |
|
} |
248 |
} |
} |