28 import sun.swing.SwingUtilities2;
29 import sun.awt.AppContext;
30
31 import javax.swing.*;
32 import javax.swing.border.*;
33 import javax.swing.plaf.basic.*;
34 import java.awt.*;
35 import java.awt.event.*;
36 import java.beans.*;
37 import javax.swing.plaf.*;
38
39 /**
40 * MetalButtonUI implementation
41 * <p>
42 * <strong>Warning:</strong>
43 * Serialized objects of this class will not be compatible with
44 * future Swing releases. The current serialization support is
45 * appropriate for short term storage or RMI between applications running
46 * the same version of Swing. As of 1.4, support for long term storage
47 * of all JavaBeans™
48 * has been added to the <code>java.beans</code> package.
49 * Please see {@link java.beans.XMLEncoder}.
50 *
51 * @author Tom Santos
52 */
53 @SuppressWarnings("serial") // Same-version serialization only
54 public class MetalButtonUI extends BasicButtonUI {
55
56 // NOTE: These are not really needed, but at this point we can't pull
57 // them. Their values are updated purely for historical reasons.
58 /**
59 * The color of the focused button.
60 */
61 protected Color focusColor;
62
63 /**
64 * The color of the selected button.
65 */
66 protected Color selectColor;
67
68 /**
135 disabledTextColor = UIManager.getColor(getPropertyPrefix() +
136 "disabledText");
137 return disabledTextColor;
138 }
139
140 /**
141 * Returns the color of the focused button.
142 *
143 * @return the color of the focused button
144 */
145 protected Color getFocusColor() {
146 focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
147 return focusColor;
148 }
149
150 // ********************************
151 // Paint
152 // ********************************
153 /**
154 * If necessary paints the background of the component, then
155 * invokes <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, "Button.gradient", 0, 0, c.getWidth(),
174 c.getHeight(), true)) {
175 paint(g, c);
176 return;
177 }
178 }
179 else if (model.isRollover() && MetalUtils.drawGradient(
|
28 import sun.swing.SwingUtilities2;
29 import sun.awt.AppContext;
30
31 import javax.swing.*;
32 import javax.swing.border.*;
33 import javax.swing.plaf.basic.*;
34 import java.awt.*;
35 import java.awt.event.*;
36 import java.beans.*;
37 import javax.swing.plaf.*;
38
39 /**
40 * MetalButtonUI implementation
41 * <p>
42 * <strong>Warning:</strong>
43 * Serialized objects of this class will not be compatible with
44 * future Swing releases. The current serialization support is
45 * appropriate for short term storage or RMI between applications running
46 * the same version of Swing. As of 1.4, support for long term storage
47 * of all JavaBeans™
48 * has been added to the {@code java.beans} package.
49 * Please see {@link java.beans.XMLEncoder}.
50 *
51 * @author Tom Santos
52 */
53 @SuppressWarnings("serial") // Same-version serialization only
54 public class MetalButtonUI extends BasicButtonUI {
55
56 // NOTE: These are not really needed, but at this point we can't pull
57 // them. Their values are updated purely for historical reasons.
58 /**
59 * The color of the focused button.
60 */
61 protected Color focusColor;
62
63 /**
64 * The color of the selected button.
65 */
66 protected Color selectColor;
67
68 /**
135 disabledTextColor = UIManager.getColor(getPropertyPrefix() +
136 "disabledText");
137 return disabledTextColor;
138 }
139
140 /**
141 * Returns the color of the focused button.
142 *
143 * @return the color of the focused button
144 */
145 protected Color getFocusColor() {
146 focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
147 return focusColor;
148 }
149
150 // ********************************
151 // Paint
152 // ********************************
153 /**
154 * If necessary paints the background of the component, then
155 * invokes {@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, "Button.gradient", 0, 0, c.getWidth(),
174 c.getHeight(), true)) {
175 paint(g, c);
176 return;
177 }
178 }
179 else if (model.isRollover() && MetalUtils.drawGradient(
|