01: package net.xoetrope.swing;
02:
03: import javax.swing.JButton;
04:
05: import net.xoetrope.xui.XValueHolder;
06: import net.xoetrope.xui.XAttributedComponent;
07: import net.xoetrope.xui.XTextHolder;
08:
09: /**
10: * <p>A wrapper for the Swing JButton class. In addition to wrapping the button this
11: * object can hold a value. </p>
12: * <p>Copyright (c) Xoetrope Ltd., 1998-2004<br>
13: * License: see license.txt
14: * @version 1.0
15: */
16: public class XButton extends JButton implements XTextHolder,
17: XValueHolder, XAttributedComponent {
18: protected Object value;
19:
20: public XButton() {
21: }
22:
23: /**
24: * Set one or more attributes of the component.
25: * <OL>
26: * <LI>alignment, value=(Left|Right|Center|Leading|Trailing)</LI>
27: * </OL>
28: * @param attribName the name of the attribute
29: * @param attribValue the value of the attribute
30: */
31: public void setAttribute(String attribName, String attribValue) {
32: String attribNameLwr = attribName.toLowerCase();
33: String attribValueLwr = attribValue.toLowerCase();
34: if (attribNameLwr.compareTo("alignment") == 0)
35: setHorizontalAlignment(XAlignmentHelper
36: .getAlignmentOption(attribValue));
37: }
38:
39: /**
40: * Get the radiobutton's value if it has one or else get the text
41: * @return the value for this button
42: */
43: public Object getValue() {
44: if (value != null)
45: return value;
46:
47: return getText();
48: }
49:
50: /**
51: * Set the value associated with this button
52: * @param newValue the new button value
53: */
54: public void setValue(Object newValue) {
55: value = newValue;
56: }
57: }
|