199 |
/** The text displayed in the button. */ |
/** The text displayed in the button. */ |
200 |
String text; |
String text; |
201 |
|
|
202 |
/** The gap between icon and text, if both icon and text are non-<code>null</code>. */ |
/** |
203 |
|
* The gap between icon and text, if both icon and text are |
204 |
|
* non-<code>null</code>. |
205 |
|
*/ |
206 |
int iconTextGap; |
int iconTextGap; |
207 |
|
|
208 |
/** The vertical alignment of the button's text and icon. */ |
/** The vertical alignment of the button's text and icon. */ |
238 |
/** The margin between the button's border and its label. */ |
/** The margin between the button's border and its label. */ |
239 |
Insets margin; |
Insets margin; |
240 |
|
|
241 |
/** A hint to the look and feel class, suggesting which character in the |
/** |
242 |
* button's label should be underlined when drawing the label. */ |
* A hint to the look and feel class, suggesting which character in the |
243 |
|
* button's label should be underlined when drawing the label. |
244 |
|
*/ |
245 |
int mnemonicIndex; |
int mnemonicIndex; |
246 |
|
|
247 |
/** Listener the button uses to receive ActionEvents from its model. */ |
/** Listener the button uses to receive ActionEvents from its model. */ |
253 |
/** Listener the button uses to receive ChangeEvents from its model. */ |
/** Listener the button uses to receive ChangeEvents from its model. */ |
254 |
protected ChangeListener changeListener; |
protected ChangeListener changeListener; |
255 |
|
|
256 |
/** The time in miliseconds in which clicks get coalesced into a single |
/** |
257 |
* <code>ActionEvent</code>. */ |
* The time in miliseconds in which clicks get coalesced into a single |
258 |
|
* <code>ActionEvent</code>. |
259 |
|
*/ |
260 |
long multiClickThreshhold; |
long multiClickThreshhold; |
261 |
|
|
262 |
/** Listener the button uses to receive PropertyChangeEvents from its |
/** |
263 |
Action. */ |
* Listener the button uses to receive PropertyChangeEvents from its |
264 |
|
* Action. |
265 |
|
*/ |
266 |
PropertyChangeListener actionPropertyChangeListener; |
PropertyChangeListener actionPropertyChangeListener; |
267 |
|
|
268 |
/** ChangeEvent that is fired to button's ChangeEventListeners */ |
/** ChangeEvent that is fired to button's ChangeEventListeners */ |
269 |
protected ChangeEvent changeEvent = new ChangeEvent(this); |
protected ChangeEvent changeEvent = new ChangeEvent(this); |
270 |
|
|
271 |
/** Fired in a PropertyChangeEvent when the "borderPainted" property changes. */ |
/** |
272 |
|
* Fired in a PropertyChangeEvent when the "borderPainted" property changes. |
273 |
|
*/ |
274 |
public static final String BORDER_PAINTED_CHANGED_PROPERTY = "borderPainted"; |
public static final String BORDER_PAINTED_CHANGED_PROPERTY = "borderPainted"; |
275 |
|
|
276 |
/** Fired in a PropertyChangeEvent when the "contentAreaFilled" property changes. */ |
/** |
277 |
public static final String CONTENT_AREA_FILLED_CHANGED_PROPERTY = "contentAreaFilled"; |
* Fired in a PropertyChangeEvent when the "contentAreaFilled" property |
278 |
|
* changes. |
279 |
|
*/ |
280 |
|
public static final String CONTENT_AREA_FILLED_CHANGED_PROPERTY = |
281 |
|
"contentAreaFilled"; |
282 |
|
|
283 |
/** Fired in a PropertyChangeEvent when the "disabledIcon" property changes. */ |
/** |
284 |
|
* Fired in a PropertyChangeEvent when the "disabledIcon" property changes. |
285 |
|
*/ |
286 |
public static final String DISABLED_ICON_CHANGED_PROPERTY = "disabledIcon"; |
public static final String DISABLED_ICON_CHANGED_PROPERTY = "disabledIcon"; |
287 |
|
|
288 |
/** Fired in a PropertyChangeEvent when the "disabledSelectedIcon" property changes. */ |
/** |
289 |
public static final String DISABLED_SELECTED_ICON_CHANGED_PROPERTY = "disabledSelectedIcon"; |
* Fired in a PropertyChangeEvent when the "disabledSelectedIcon" property |
290 |
|
* changes. |
291 |
|
*/ |
292 |
|
public static final String DISABLED_SELECTED_ICON_CHANGED_PROPERTY = |
293 |
|
"disabledSelectedIcon"; |
294 |
|
|
295 |
/** Fired in a PropertyChangeEvent when the "focusPainted" property changes. */ |
/** |
296 |
|
* Fired in a PropertyChangeEvent when the "focusPainted" property changes. |
297 |
|
*/ |
298 |
public static final String FOCUS_PAINTED_CHANGED_PROPERTY = "focusPainted"; |
public static final String FOCUS_PAINTED_CHANGED_PROPERTY = "focusPainted"; |
299 |
|
|
300 |
/** Fired in a PropertyChangeEvent when the "horizontalAlignment" property changes. */ |
/** |
301 |
public static final String HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY = "horizontalAlignment"; |
* Fired in a PropertyChangeEvent when the "horizontalAlignment" property |
302 |
|
* changes. |
303 |
|
*/ |
304 |
|
public static final String HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY = |
305 |
|
"horizontalAlignment"; |
306 |
|
|
307 |
/** Fired in a PropertyChangeEvent when the "horizontalTextPosition" property changes. */ |
/** |
308 |
public static final String HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY = "horizontalTextPosition"; |
* Fired in a PropertyChangeEvent when the "horizontalTextPosition" property |
309 |
|
* changes. |
310 |
|
*/ |
311 |
|
public static final String HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY = |
312 |
|
"horizontalTextPosition"; |
313 |
|
|
314 |
/** Fired in a PropertyChangeEvent when the "icon" property changes. */ |
/** |
315 |
|
* Fired in a PropertyChangeEvent when the "icon" property changes. */ |
316 |
public static final String ICON_CHANGED_PROPERTY = "icon"; |
public static final String ICON_CHANGED_PROPERTY = "icon"; |
317 |
|
|
318 |
/** Fired in a PropertyChangeEvent when the "margin" property changes. */ |
/** Fired in a PropertyChangeEvent when the "margin" property changes. */ |
327 |
/** Fired in a PropertyChangeEvent when the "pressedIcon" property changes. */ |
/** Fired in a PropertyChangeEvent when the "pressedIcon" property changes. */ |
328 |
public static final String PRESSED_ICON_CHANGED_PROPERTY = "pressedIcon"; |
public static final String PRESSED_ICON_CHANGED_PROPERTY = "pressedIcon"; |
329 |
|
|
330 |
/** Fired in a PropertyChangeEvent when the "rolloverEnabled" property changes. */ |
/** |
331 |
public static final String ROLLOVER_ENABLED_CHANGED_PROPERTY = "rolloverEnabled"; |
* Fired in a PropertyChangeEvent when the "rolloverEnabled" property |
332 |
|
* changes. |
333 |
|
*/ |
334 |
|
public static final String ROLLOVER_ENABLED_CHANGED_PROPERTY = |
335 |
|
"rolloverEnabled"; |
336 |
|
|
337 |
/** Fired in a PropertyChangeEvent when the "rolloverIcon" property changes. */ |
/** |
338 |
|
* Fired in a PropertyChangeEvent when the "rolloverIcon" property changes. |
339 |
|
*/ |
340 |
public static final String ROLLOVER_ICON_CHANGED_PROPERTY = "rolloverIcon"; |
public static final String ROLLOVER_ICON_CHANGED_PROPERTY = "rolloverIcon"; |
341 |
|
|
342 |
/** Fired in a PropertyChangeEvent when the "rolloverSelectedIcon" property changes. */ |
/** |
343 |
public static final String ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY = "rolloverSelectedIcon"; |
* Fired in a PropertyChangeEvent when the "rolloverSelectedIcon" property |
344 |
|
* changes. |
345 |
|
*/ |
346 |
|
public static final String ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY = |
347 |
|
"rolloverSelectedIcon"; |
348 |
|
|
349 |
/** Fired in a PropertyChangeEvent when the "selectedIcon" property changes. */ |
/** |
350 |
|
* Fired in a PropertyChangeEvent when the "selectedIcon" property changes. |
351 |
|
*/ |
352 |
public static final String SELECTED_ICON_CHANGED_PROPERTY = "selectedIcon"; |
public static final String SELECTED_ICON_CHANGED_PROPERTY = "selectedIcon"; |
353 |
|
|
354 |
/** Fired in a PropertyChangeEvent when the "text" property changes. */ |
/** Fired in a PropertyChangeEvent when the "text" property changes. */ |
355 |
public static final String TEXT_CHANGED_PROPERTY = "text"; |
public static final String TEXT_CHANGED_PROPERTY = "text"; |
356 |
|
|
357 |
/** Fired in a PropertyChangeEvent when the "verticalAlignment" property changes. */ |
/** |
358 |
public static final String VERTICAL_ALIGNMENT_CHANGED_PROPERTY = "verticalAlignment"; |
* Fired in a PropertyChangeEvent when the "verticalAlignment" property |
359 |
|
* changes. |
360 |
|
*/ |
361 |
|
public static final String VERTICAL_ALIGNMENT_CHANGED_PROPERTY = |
362 |
|
"verticalAlignment"; |
363 |
|
|
364 |
/** Fired in a PropertyChangeEvent when the "verticalTextPosition" property changes. */ |
/** |
365 |
public static final String VERTICAL_TEXT_POSITION_CHANGED_PROPERTY = "verticalTextPosition"; |
* Fired in a PropertyChangeEvent when the "verticalTextPosition" property |
366 |
|
* changes. |
367 |
|
*/ |
368 |
|
public static final String VERTICAL_TEXT_POSITION_CHANGED_PROPERTY = |
369 |
|
"verticalTextPosition"; |
370 |
|
|
371 |
/** |
/** |
372 |
* A Java Accessibility extension of the AbstractButton. |
* A Java Accessibility extension of the AbstractButton. |
806 |
|
|
807 |
if (old != mne) |
if (old != mne) |
808 |
{ |
{ |
809 |
getModel().setMnemonic(mne); |
getModel().setMnemonic(mne); |
810 |
|
|
811 |
|
if (text != null && !text.equals("")) |
812 |
|
{ |
813 |
|
// Since lower case char = upper case char for |
814 |
|
// mnemonic, we will convert both text and mnemonic |
815 |
|
// to upper case before checking if mnemonic character occurs |
816 |
|
// in the menu item text. |
817 |
|
int upperCaseMne = Character.toUpperCase((char) mne); |
818 |
|
String upperCaseText = text.toUpperCase(); |
819 |
|
setDisplayedMnemonicIndex(upperCaseText.indexOf(upperCaseMne)); |
820 |
|
} |
821 |
|
|
822 |
if (text != null && ! text.equals("")) |
firePropertyChange(MNEMONIC_CHANGED_PROPERTY, old, mne); |
823 |
{ |
revalidate(); |
824 |
// Since lower case char = upper case char for |
repaint(); |
|
// mnemonic, we will convert both text and mnemonic |
|
|
// to upper case before checking if mnemonic character occurs |
|
|
// in the menu item text. |
|
|
int upperCaseMne = Character.toUpperCase((char) mne); |
|
|
String upperCaseText = text.toUpperCase(); |
|
|
setDisplayedMnemonicIndex(upperCaseText.indexOf(upperCaseMne)); |
|
|
} |
|
|
|
|
|
firePropertyChange(MNEMONIC_CHANGED_PROPERTY, old, mne); |
|
|
revalidate(); |
|
|
repaint(); |
|
825 |
} |
} |
826 |
} |
} |
827 |
|
|
1336 |
*/ |
*/ |
1337 |
public Icon getDisabledIcon() |
public Icon getDisabledIcon() |
1338 |
{ |
{ |
1339 |
if (disabeldIcon == null |
if (disabeldIcon == null && default_icon instanceof ImageIcon) |
1340 |
&& default_icon instanceof ImageIcon) |
{ |
1341 |
disabeldIcon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon) default_icon).getImage())); |
Image iconImage = ((ImageIcon) default_icon).getImage(); |
1342 |
|
Image grayImage = GrayFilter.createDisabledImage(iconImage); |
1343 |
|
disabeldIcon = new ImageIcon(grayImage); |
1344 |
|
} |
1345 |
|
|
1346 |
return disabeldIcon; |
return disabeldIcon; |
1347 |
} |
} |
1486 |
* |
* |
1487 |
* @param a An Action to configure the button from |
* @param a An Action to configure the button from |
1488 |
*/ |
*/ |
1489 |
protected void configurePropertiesFromAction(Action a) |
protected void configurePropertiesFromAction(Action a) |
1490 |
{ |
{ |
1491 |
if (a == null) |
if (a == null) |
1492 |
{ |
{ |
1497 |
} |
} |
1498 |
else |
else |
1499 |
{ |
{ |
1500 |
setText((String)(a.getValue(Action.NAME))); |
setText((String) (a.getValue(Action.NAME))); |
1501 |
setIcon((Icon)(a.getValue(Action.SMALL_ICON))); |
setIcon((Icon) (a.getValue(Action.SMALL_ICON))); |
1502 |
setEnabled(a.isEnabled()); |
setEnabled(a.isEnabled()); |
1503 |
setToolTipText((String)(a.getValue(Action.SHORT_DESCRIPTION))); |
setToolTipText((String) (a.getValue(Action.SHORT_DESCRIPTION))); |
1504 |
if (a.getValue(Action.MNEMONIC_KEY) != null) |
if (a.getValue(Action.MNEMONIC_KEY) != null) |
1505 |
setMnemonic(((Integer)(a.getValue(Action.MNEMONIC_KEY))).intValue()); |
setMnemonic(((Integer) (a.getValue(Action.MNEMONIC_KEY))).intValue()); |
1506 |
String actionCommand = (String)(a.getValue(Action.ACTION_COMMAND_KEY)); |
String actionCommand = (String) (a.getValue(Action.ACTION_COMMAND_KEY)); |
1507 |
|
|
1508 |
// Set actionCommand to button's text by default if it is not specified |
// Set actionCommand to button's text by default if it is not specified |
1509 |
if (actionCommand != null) |
if (actionCommand != null) |
1510 |
setActionCommand((String)(a.getValue(Action.ACTION_COMMAND_KEY))); |
setActionCommand((String) (a.getValue(Action.ACTION_COMMAND_KEY))); |
1511 |
else |
else |
1512 |
setActionCommand(getText()); |
setActionCommand(getText()); |
1513 |
} |
} |
1514 |
} |
} |
1515 |
|
|
1565 |
{ |
{ |
1566 |
public void propertyChange(PropertyChangeEvent e) |
public void propertyChange(PropertyChangeEvent e) |
1567 |
{ |
{ |
1568 |
Action act = (Action) (e.getSource()); |
Action act = (Action) (e.getSource()); |
1569 |
if (e.getPropertyName().equals("enabled")) |
if (e.getPropertyName().equals("enabled")) |
1570 |
setEnabled(act.isEnabled()); |
setEnabled(act.isEnabled()); |
1571 |
else if (e.getPropertyName().equals(Action.NAME)) |
else if (e.getPropertyName().equals(Action.NAME)) |
1572 |
setText((String)(act.getValue(Action.NAME))); |
setText((String) (act.getValue(Action.NAME))); |
1573 |
else if (e.getPropertyName().equals(Action.SMALL_ICON)) |
else if (e.getPropertyName().equals(Action.SMALL_ICON)) |
1574 |
setIcon((Icon)(act.getValue(Action.SMALL_ICON))); |
setIcon((Icon) (act.getValue(Action.SMALL_ICON))); |
1575 |
else if (e.getPropertyName().equals(Action.SHORT_DESCRIPTION)) |
else if (e.getPropertyName().equals(Action.SHORT_DESCRIPTION)) |
1576 |
setToolTipText((String)(act.getValue(Action.SHORT_DESCRIPTION))); |
setToolTipText((String) (act.getValue(Action.SHORT_DESCRIPTION))); |
1577 |
else if (e.getPropertyName().equals(Action.MNEMONIC_KEY)) |
else if (e.getPropertyName().equals(Action.MNEMONIC_KEY)) |
1578 |
if (act.getValue(Action.MNEMONIC_KEY) != null) |
if (act.getValue(Action.MNEMONIC_KEY) != null) |
1579 |
setMnemonic(((Integer)(act.getValue(Action.MNEMONIC_KEY))).intValue()); |
setMnemonic(((Integer) (act.getValue(Action.MNEMONIC_KEY))) |
1580 |
else if (e.getPropertyName().equals(Action.ACTION_COMMAND_KEY)) |
.intValue()); |
1581 |
setActionCommand((String)(act.getValue(Action.ACTION_COMMAND_KEY))); |
else if (e.getPropertyName().equals(Action.ACTION_COMMAND_KEY)) |
1582 |
} |
setActionCommand((String) (act.getValue(Action.ACTION_COMMAND_KEY))); |
1583 |
|
} |
1584 |
}; |
}; |
1585 |
} |
} |
1586 |
|
|
1825 |
return objs; |
return objs; |
1826 |
} |
} |
1827 |
else |
else |
1828 |
{ |
{ |
1829 |
return null; |
return null; |
1830 |
} |
} |
1831 |
} |
} |
1834 |
* Called when image data becomes available for one of the button's icons. |
* Called when image data becomes available for one of the button's icons. |
1835 |
* |
* |
1836 |
* @param img The image being updated |
* @param img The image being updated |
1837 |
* @param infoflags One of the constant codes in {@link ImageObserver} used to describe |
* @param infoflags One of the constant codes in {@link ImageObserver} used |
1838 |
* updated portions of an image. |
* to describe updated portions of an image. |
1839 |
* @param x X coordinate of the region being updated |
* @param x X coordinate of the region being updated |
1840 |
* @param y Y coordinate of the region being updated |
* @param y Y coordinate of the region being updated |
1841 |
* @param w Width of the region beign updated |
* @param w Width of the region beign updated |
1842 |
* @param h Height of the region being updated |
* @param h Height of the region being updated |
1843 |
* |
* |
1844 |
* @return <code>true</code> if img is equal to the button's current |
* @return <code>true</code> if img is equal to the button's current icon, |
1845 |
* icon, otherwise <code>false</code> |
* otherwise <code>false</code> |
1846 |
*/ |
*/ |
1847 |
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, |
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, |
1848 |
int h) |
int h) |