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 /**
69 * The color of the disabled color.
70 */
71 protected Color disabledTextColor;
72
73 private static final Object METAL_BUTTON_UI_KEY = new Object();
74
75 // ********************************
76 // Create PLAF
77 // ********************************
78
79 /**
80 * Returns an instance of {@code MetalButtonUI}.
81 *
82 * @param c a component
83 * @return an instance of {@code MetalButtonUI}
84 */
85 public static ComponentUI createUI(JComponent c) {
86 AppContext appContext = AppContext.getAppContext();
87 MetalButtonUI metalButtonUI =
88 (MetalButtonUI) appContext.get(METAL_BUTTON_UI_KEY);
89 if (metalButtonUI == null) {
90 metalButtonUI = new MetalButtonUI();
91 appContext.put(METAL_BUTTON_UI_KEY, metalButtonUI);
92 }
93 return metalButtonUI;
94 }
95
96 // ********************************
97 // Install
98 // ********************************
99 public void installDefaults(AbstractButton b) {
100 super.installDefaults(b);
101 }
102
103 public void uninstallDefaults(AbstractButton b) {
104 super.uninstallDefaults(b);
105 }
106
107 // ********************************
108 // Create Listeners
109 // ********************************
110 protected BasicButtonListener createButtonListener(AbstractButton b) {
111 return super.createButtonListener(b);
112 }
113
114
115 // ********************************
116 // Default Accessors
117 // ********************************
118
119 /**
120 * Returns the color of the selected button.
121 *
122 * @return the color of the selected button
123 */
124 protected Color getSelectColor() {
220 focusRect.width+1, focusRect.height+1);
221
222 }
223
224
225 protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
226 AbstractButton b = (AbstractButton) c;
227 ButtonModel model = b.getModel();
228 FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
229 int mnemIndex = b.getDisplayedMnemonicIndex();
230
231 /* Draw the Text */
232 if(model.isEnabled()) {
233 /*** paint the text normally */
234 g.setColor(b.getForeground());
235 }
236 else {
237 /*** paint the text disabled ***/
238 g.setColor(getDisabledTextColor());
239 }
240 SwingUtilities2.drawStringUnderlineCharAt(c, g,text,mnemIndex,
241 textRect.x, textRect.y + fm.getAscent());
242 }
243 }
|
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 /**
69 * The color of the disabled color.
70 */
71 protected Color disabledTextColor;
72
73 private static final Object METAL_BUTTON_UI_KEY = new Object();
74
75 private TextUIDrawing textUIDrawing;
76
77 // ********************************
78 // Create PLAF
79 // ********************************
80
81 /**
82 * Returns an instance of {@code MetalButtonUI}.
83 *
84 * @param c a component
85 * @return an instance of {@code MetalButtonUI}
86 */
87 public static ComponentUI createUI(JComponent c) {
88 AppContext appContext = AppContext.getAppContext();
89 MetalButtonUI metalButtonUI =
90 (MetalButtonUI) appContext.get(METAL_BUTTON_UI_KEY);
91 if (metalButtonUI == null) {
92 metalButtonUI = new MetalButtonUI();
93 appContext.put(METAL_BUTTON_UI_KEY, metalButtonUI);
94 }
95 return metalButtonUI;
96 }
97
98 // ********************************
99 // Install
100 // ********************************
101 public void installDefaults(AbstractButton b) {
102 super.installDefaults(b);
103 textUIDrawing = SwingUtilities2.getTextUIDrawing(textUIDrawing);
104 }
105
106 public void uninstallDefaults(AbstractButton b) {
107 super.uninstallDefaults(b);
108 if (textUIDrawing != SwingUtilities2.DEFAULT_UI_TEXT_DRAWING
109 && textUIDrawing instanceof UIResource) {
110 textUIDrawing = SwingUtilities2.DEFAULT_UI_TEXT_DRAWING;
111 }
112 }
113
114 // ********************************
115 // Create Listeners
116 // ********************************
117 protected BasicButtonListener createButtonListener(AbstractButton b) {
118 return super.createButtonListener(b);
119 }
120
121
122 // ********************************
123 // Default Accessors
124 // ********************************
125
126 /**
127 * Returns the color of the selected button.
128 *
129 * @return the color of the selected button
130 */
131 protected Color getSelectColor() {
227 focusRect.width+1, focusRect.height+1);
228
229 }
230
231
232 protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
233 AbstractButton b = (AbstractButton) c;
234 ButtonModel model = b.getModel();
235 FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
236 int mnemIndex = b.getDisplayedMnemonicIndex();
237
238 /* Draw the Text */
239 if(model.isEnabled()) {
240 /*** paint the text normally */
241 g.setColor(b.getForeground());
242 }
243 else {
244 /*** paint the text disabled ***/
245 g.setColor(getDisabledTextColor());
246 }
247 textUIDrawing.drawStringUnderlineCharAt(c, g,text,mnemIndex,
248 textRect.x, textRect.y + fm.getAscent());
249 }
250 }
|