01: package net.xoetrope.awt;
02:
03: import java.awt.Checkbox;
04:
05: import net.xoetrope.xui.XAttributedComponent;
06: import net.xoetrope.xui.XValueHolder;
07: import net.xoetrope.xui.XStateHolder;
08: import net.xoetrope.xui.XTextHolder;
09: import net.xoetrope.xui.XStateHolder;
10: import java.awt.Component;
11:
12: /**
13: * A wrapper for the AWT Checkbox class
14: * <p>Copyright (c) Xoetrope Ltd., 1998-2004<br>
15: * License: see license.txt
16: * @version $Revision: 1.14 $
17: */
18: public class XCheckbox extends Checkbox implements XStateHolder,
19: XTextHolder, XValueHolder, XAttributedComponent {
20: protected Object value;
21:
22: public XCheckbox() {
23: }
24:
25: public void setText(String s) {
26: setLabel(s);
27: }
28:
29: /**
30: * Gets the text/caption
31: * @return the text value
32: */
33: public String getText() {
34: return getLabel();
35: }
36:
37: /**
38: * Set one or more attributes of the component. Currently this handles the
39: * attributes
40: * <OL>
41: * <LI>selected, value=true|false</LI>
42: * </OL>
43: * @param attribName the attribute name
44: * @param attribValue the attribute value
45: */
46: public void setAttribute(String attribName, String attribValue) {
47: if (attribName.compareTo("selected") == 0)
48: setState(attribValue.compareTo("true") == 0);
49: }
50:
51: /**
52: * Get the component state
53: * @param the new component state
54: */
55: public Object getComponentState() {
56: return new Boolean(getState());
57: }
58:
59: /**
60: * Set the component state
61: * @return the object state
62: */
63: public void setComponentState(Object o) {
64: if (o != null) {
65: String objValue = o.toString();
66: boolean value = objValue.equals("1");
67: if (!value)
68: value |= objValue.equals("true");
69: setState(value);
70: }
71: }
72:
73: /**
74: * Get the checkbox's value if it has one or else get the text
75: * @return the value for this button
76: */
77: public Object getValue() {
78: if (value != null)
79: return value;
80:
81: return getText();
82: }
83:
84: /**
85: * Set the value associated with this button
86: * @param newValue the new button value
87: */
88: public void setValue(Object newValue) {
89: value = newValue;
90: }
91: }
|