31 import java.awt.event.KeyEvent; |
31 import java.awt.event.KeyEvent; |
32 import java.awt.event.ActionEvent; |
32 import java.awt.event.ActionEvent; |
33 import javax.swing.plaf.basic.*; |
33 import javax.swing.plaf.basic.*; |
34 import javax.swing.SwingUtilities; |
34 import javax.swing.SwingUtilities; |
35 import javax.swing.SwingConstants; |
35 import javax.swing.SwingConstants; |
36 |
|
37 public class XButtonPeer extends XComponentPeer implements ButtonPeer { |
36 public class XButtonPeer extends XComponentPeer implements ButtonPeer { |
38 |
37 private boolean pressed; |
39 boolean pressed; |
38 private boolean armed; |
40 boolean armed; |
|
41 |
|
42 private Insets focusInsets; |
39 private Insets focusInsets; |
43 private Insets borderInsets; |
40 private Insets borderInsets; |
44 private Insets contentAreaInsets; |
41 private Insets contentAreaInsets; |
45 |
42 |
46 private final static String propertyPrefix = "Button" + "."; |
43 private final static String propertyPrefix = "Button" + "."; |
207 * DEPRECATED |
193 * DEPRECATED |
208 */ |
194 */ |
209 public Dimension minimumSize() { |
195 public Dimension minimumSize() { |
210 return getMinimumSize(); |
196 return getMinimumSize(); |
211 } |
197 } |
212 |
198 /** |
213 |
199 * This method is called from Toolkit Thread and so it should not call any |
214 /* |
200 * client code. |
215 This method is called from Toolkit Thread and so it should not call any client code |
201 */ |
216 |
202 @Override |
217 */ |
203 void paintPeer(final Graphics g) { |
218 public void paint(Graphics g, Component c) |
204 if (!disposed) { |
219 { |
|
220 if (!disposed && (g != null)) |
|
221 { |
|
222 Dimension size = getPeerSize(); |
205 Dimension size = getPeerSize(); |
223 |
|
224 g.setColor( getPeerBackground() ); /* erase the existing button remains */ |
206 g.setColor( getPeerBackground() ); /* erase the existing button remains */ |
225 g.fillRect(0,0, size.width , size.height); |
207 g.fillRect(0,0, size.width , size.height); |
226 paintBorder(g,borderInsets.left, |
208 paintBorder(g,borderInsets.left, |
227 borderInsets.top, |
209 borderInsets.top, |
228 size.width-(borderInsets.left+borderInsets.right), |
210 size.width-(borderInsets.left+borderInsets.right), |
237 iconRect = new Rectangle(); |
219 iconRect = new Rectangle(); |
238 |
220 |
239 |
221 |
240 viewRect.width = size.width - (contentAreaInsets.left+contentAreaInsets.right); |
222 viewRect.width = size.width - (contentAreaInsets.left+contentAreaInsets.right); |
241 viewRect.height = size.height - (contentAreaInsets.top+contentAreaInsets.bottom); |
223 viewRect.height = size.height - (contentAreaInsets.top+contentAreaInsets.bottom); |
242 |
|
243 viewRect.x = contentAreaInsets.left; |
224 viewRect.x = contentAreaInsets.left; |
244 viewRect.y = contentAreaInsets.right; |
225 viewRect.y = contentAreaInsets.top; |
245 String llabel = (label != null) ? label : ""; |
226 String llabel = (label != null) ? label : ""; |
246 |
|
247 // layout the text and icon |
227 // layout the text and icon |
248 String text = SwingUtilities.layoutCompoundLabel( |
228 String text = SwingUtilities.layoutCompoundLabel( |
249 fm, llabel, null, |
229 fm, llabel, null, |
250 SwingConstants.CENTER, SwingConstants.CENTER, |
230 SwingConstants.CENTER, SwingConstants.CENTER, |
251 SwingConstants.CENTER, SwingConstants.CENTER, |
231 SwingConstants.CENTER, SwingConstants.CENTER, |
307 BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() ); |
287 BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() ); |
308 } |
288 } |
309 else { |
289 else { |
310 /*** paint the text disabled ***/ |
290 /*** paint the text disabled ***/ |
311 g.setColor(getPeerBackground().brighter()); |
291 g.setColor(getPeerBackground().brighter()); |
312 |
|
313 BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex, |
292 BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex, |
314 textRect.x, textRect.y + fm.getAscent()); |
293 textRect.x, textRect.y + fm.getAscent()); |
315 g.setColor(c.getBackground().darker()); |
294 g.setColor(getPeerBackground().darker()); |
316 BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex, |
295 BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex, |
317 textRect.x - 1, textRect.y + fm.getAscent() - 1); |
296 textRect.x - 1, textRect.y + fm.getAscent() - 1); |
318 } |
297 } |
319 } |
298 } |
320 } |
299 } |