55 |
import javax.swing.plaf.basic.BasicToggleButtonUI; |
import javax.swing.plaf.basic.BasicToggleButtonUI; |
56 |
|
|
57 |
/** |
/** |
58 |
* A UI delegate for {@link JToggleButton} components. |
* A UI delegate for the {@link JToggleButton} component. |
59 |
*/ |
*/ |
60 |
public class MetalToggleButtonUI |
public class MetalToggleButtonUI |
61 |
extends BasicToggleButtonUI |
extends BasicToggleButtonUI |
71 |
protected Color disabledTextColor; |
protected Color disabledTextColor; |
72 |
|
|
73 |
/** |
/** |
74 |
* Returns an instance of MetalToggleButtonUI. |
* Returns a new instance of <code>MetalToggleButtonUI</code>. |
75 |
* |
* |
76 |
* @param component the component for which we return an UI instance |
* @param component the component for which we return an UI instance |
77 |
* |
* |
78 |
* @return an instance of MetalToggleButtonUI |
* @return A new instance of <code>MetalToggleButtonUI</code>. |
79 |
*/ |
*/ |
80 |
public static ComponentUI createUI(JComponent component) |
public static ComponentUI createUI(JComponent component) |
81 |
{ |
{ |
83 |
} |
} |
84 |
|
|
85 |
/** |
/** |
86 |
* Constructs a new instance of MetalToggleButtonUI. |
* Constructs a new instance of <code>MetalToggleButtonUI</code>. |
87 |
*/ |
*/ |
88 |
public MetalToggleButtonUI() |
public MetalToggleButtonUI() |
89 |
{ |
{ |
90 |
super(); |
super(); |
|
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
|
|
focusColor = defaults.getColor(getPropertyPrefix() + "focus"); |
|
|
selectColor = defaults.getColor(getPropertyPrefix() + "select"); |
|
|
disabledTextColor = defaults.getColor(getPropertyPrefix() + "disabledText"); |
|
91 |
} |
} |
92 |
|
|
93 |
/** |
/** |
111 |
} |
} |
112 |
|
|
113 |
/** |
/** |
114 |
* Returns the color for the text label of disabled buttons. |
* Returns the color for the text label of disabled buttons. The value |
115 |
|
* is initialised in the {@link #installDefaults(AbstractButton)} method |
116 |
|
* by reading the <code>ToggleButton.disabledText</code> item from the UI |
117 |
|
* defaults. |
118 |
* |
* |
119 |
* @return the color for the text label of disabled buttons |
* @return The color for the text label of disabled buttons. |
120 |
*/ |
*/ |
121 |
protected Color getDisabledTextColor() |
protected Color getDisabledTextColor() |
122 |
{ |
{ |
130 |
*/ |
*/ |
131 |
public void installDefaults(AbstractButton b) |
public void installDefaults(AbstractButton b) |
132 |
{ |
{ |
|
// FIXME: for now, this override just changes the visibility of the method |
|
|
// in the super-class, to satisfy japi...but there must be something else. |
|
133 |
super.installDefaults(b); |
super.installDefaults(b); |
134 |
|
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
135 |
|
focusColor = defaults.getColor(getPropertyPrefix() + "focus"); |
136 |
|
selectColor = defaults.getColor(getPropertyPrefix() + "select"); |
137 |
|
disabledTextColor = defaults.getColor(getPropertyPrefix() + "disabledText"); |
138 |
} |
} |
139 |
|
|
140 |
/** |
/** |
145 |
*/ |
*/ |
146 |
protected void paintButtonPressed(Graphics g, AbstractButton b) |
protected void paintButtonPressed(Graphics g, AbstractButton b) |
147 |
{ |
{ |
148 |
Color saved = g.getColor(); |
if (b.isContentAreaFilled() && b.isOpaque()) |
149 |
Rectangle bounds = SwingUtilities.getLocalBounds(b); |
{ |
150 |
g.setColor(selectColor); |
Color saved = g.getColor(); |
151 |
g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); |
Rectangle bounds = SwingUtilities.getLocalBounds(b); |
152 |
g.setColor(saved); |
g.setColor(selectColor); |
153 |
|
g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); |
154 |
|
g.setColor(saved); |
155 |
|
} |
156 |
} |
} |
157 |
|
|
158 |
/** |
/** |