33 import java.lang.ref.*;
34 import java.util.*;
35 import javax.swing.plaf.basic.BasicToggleButtonUI;
36
37 import javax.swing.*;
38 import javax.swing.border.*;
39 import javax.swing.plaf.*;
40 import javax.swing.*;
41
42 import java.io.Serializable;
43
44 /**
45 * MetalToggleButton implementation
46 * <p>
47 * <strong>Warning:</strong>
48 * Serialized objects of this class will not be compatible with
49 * future Swing releases. The current serialization support is
50 * appropriate for short term storage or RMI between applications running
51 * the same version of Swing. As of 1.4, support for long term storage
52 * of all JavaBeans™
53 * has been added to the <code>java.beans</code> package.
54 * Please see {@link java.beans.XMLEncoder}.
55 *
56 * @author Tom Santos
57 */
58 @SuppressWarnings("serial") // Same-version serialization only
59 public class MetalToggleButtonUI extends BasicToggleButtonUI {
60
61 private static final Object METAL_TOGGLE_BUTTON_UI_KEY = new Object();
62
63 /**
64 * The color of a focused toggle button.
65 */
66 protected Color focusColor;
67
68 /**
69 * The color of a selected button.
70 */
71 protected Color selectColor;
72
73 /**
135 */
136 protected Color getDisabledTextColor() {
137 return disabledTextColor;
138 }
139
140 /**
141 * Returns the color of a focused toggle button.
142 *
143 * @return the color of a focused toggle button
144 */
145 protected Color getFocusColor() {
146 return focusColor;
147 }
148
149
150 // ********************************
151 // Paint Methods
152 // ********************************
153 /**
154 * If necessary paints the background of the component, then invokes
155 * <code>paint</code>.
156 *
157 * @param g Graphics to paint to
158 * @param c JComponent painting on
159 * @throws NullPointerException if <code>g</code> or <code>c</code> is
160 * null
161 * @see javax.swing.plaf.ComponentUI#update
162 * @see javax.swing.plaf.ComponentUI#paint
163 * @since 1.5
164 */
165 public void update(Graphics g, JComponent c) {
166 AbstractButton button = (AbstractButton)c;
167 if ((c.getBackground() instanceof UIResource) &&
168 button.isContentAreaFilled() && c.isEnabled()) {
169 ButtonModel model = button.getModel();
170 if (!MetalUtils.isToolBarButton(c)) {
171 if (!model.isArmed() && !model.isPressed() &&
172 MetalUtils.drawGradient(
173 c, g, "ToggleButton.gradient", 0, 0, c.getWidth(),
174 c.getHeight(), true)) {
175 paint(g, c);
176 return;
177 }
178 }
179 else if ((model.isRollover() || model.isSelected()) &&
227 if ( text != null && !text.equals( "" ) ) {
228 if ( !isIcon ) {
229 focusRect.setBounds( textRect );
230 }
231 else {
232 focusRect.setBounds( iconRect.union( textRect ) );
233 }
234 }
235 // If there is an icon and no text
236 else if ( isIcon ) {
237 focusRect.setBounds( iconRect );
238 }
239
240 g.setColor(getFocusColor());
241 g.drawRect((focusRect.x-1), (focusRect.y-1),
242 focusRect.width+1, focusRect.height+1);
243
244 }
245
246 /**
247 * Paints the appropriate icon of the button <code>b</code> in the
248 * space <code>iconRect</code>.
249 *
250 * @param g Graphics to paint to
251 * @param b Button to render for
252 * @param iconRect space to render in
253 * @throws NullPointerException if any of the arguments are null.
254 * @since 1.5
255 */
256 protected void paintIcon(Graphics g, AbstractButton b, Rectangle iconRect) {
257 super.paintIcon(g, b, iconRect);
258 }
259 }
|
33 import java.lang.ref.*;
34 import java.util.*;
35 import javax.swing.plaf.basic.BasicToggleButtonUI;
36
37 import javax.swing.*;
38 import javax.swing.border.*;
39 import javax.swing.plaf.*;
40 import javax.swing.*;
41
42 import java.io.Serializable;
43
44 /**
45 * MetalToggleButton implementation
46 * <p>
47 * <strong>Warning:</strong>
48 * Serialized objects of this class will not be compatible with
49 * future Swing releases. The current serialization support is
50 * appropriate for short term storage or RMI between applications running
51 * the same version of Swing. As of 1.4, support for long term storage
52 * of all JavaBeans™
53 * has been added to the {@code java.beans} package.
54 * Please see {@link java.beans.XMLEncoder}.
55 *
56 * @author Tom Santos
57 */
58 @SuppressWarnings("serial") // Same-version serialization only
59 public class MetalToggleButtonUI extends BasicToggleButtonUI {
60
61 private static final Object METAL_TOGGLE_BUTTON_UI_KEY = new Object();
62
63 /**
64 * The color of a focused toggle button.
65 */
66 protected Color focusColor;
67
68 /**
69 * The color of a selected button.
70 */
71 protected Color selectColor;
72
73 /**
135 */
136 protected Color getDisabledTextColor() {
137 return disabledTextColor;
138 }
139
140 /**
141 * Returns the color of a focused toggle button.
142 *
143 * @return the color of a focused toggle button
144 */
145 protected Color getFocusColor() {
146 return focusColor;
147 }
148
149
150 // ********************************
151 // Paint Methods
152 // ********************************
153 /**
154 * If necessary paints the background of the component, then invokes
155 * {@code paint}.
156 *
157 * @param g Graphics to paint to
158 * @param c JComponent painting on
159 * @throws NullPointerException if {@code g} or {@code c} is
160 * null
161 * @see javax.swing.plaf.ComponentUI#update
162 * @see javax.swing.plaf.ComponentUI#paint
163 * @since 1.5
164 */
165 public void update(Graphics g, JComponent c) {
166 AbstractButton button = (AbstractButton)c;
167 if ((c.getBackground() instanceof UIResource) &&
168 button.isContentAreaFilled() && c.isEnabled()) {
169 ButtonModel model = button.getModel();
170 if (!MetalUtils.isToolBarButton(c)) {
171 if (!model.isArmed() && !model.isPressed() &&
172 MetalUtils.drawGradient(
173 c, g, "ToggleButton.gradient", 0, 0, c.getWidth(),
174 c.getHeight(), true)) {
175 paint(g, c);
176 return;
177 }
178 }
179 else if ((model.isRollover() || model.isSelected()) &&
227 if ( text != null && !text.equals( "" ) ) {
228 if ( !isIcon ) {
229 focusRect.setBounds( textRect );
230 }
231 else {
232 focusRect.setBounds( iconRect.union( textRect ) );
233 }
234 }
235 // If there is an icon and no text
236 else if ( isIcon ) {
237 focusRect.setBounds( iconRect );
238 }
239
240 g.setColor(getFocusColor());
241 g.drawRect((focusRect.x-1), (focusRect.y-1),
242 focusRect.width+1, focusRect.height+1);
243
244 }
245
246 /**
247 * Paints the appropriate icon of the button {@code b} in the
248 * space {@code iconRect}.
249 *
250 * @param g Graphics to paint to
251 * @param b Button to render for
252 * @param iconRect space to render in
253 * @throws NullPointerException if any of the arguments are null.
254 * @since 1.5
255 */
256 protected void paintIcon(Graphics g, AbstractButton b, Rectangle iconRect) {
257 super.paintIcon(g, b, iconRect);
258 }
259 }
|