01: // BooleanField.java
02: // $Id: BooleanField.java,v 1.3 1998/08/13 16:24:55 bmahe Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.tools.forms;
07:
08: public class BooleanField extends OptionField {
09: private static String bools[] = { "true", "false" };
10: /**
11: * Our current value.
12: */
13: Boolean value = Boolean.TRUE;
14:
15: /**
16: * Do we accept the given change ?
17: */
18:
19: public boolean acceptChange(int idx) {
20: try {
21: setValue((idx == 0) ? Boolean.TRUE : Boolean.FALSE, true,
22: false);
23: } catch (IllegalFieldValueException ex) {
24: throw new RuntimeException("implementation bug.");
25: }
26: return true;
27: }
28:
29: /**
30: * Set this field's boolean value.
31: * @param value A Boolean object.
32: * @param udate Should we update the editor's view ?
33: * @exception IllegalFieldValueException If the field rejected the value.
34: */
35:
36: public void setValue(Object value, boolean notify, boolean update)
37: throws IllegalFieldValueException {
38: if (!(value instanceof Boolean))
39: throw new IllegalFieldValueException(value);
40: this .value = (Boolean) value;
41: super .setValue((this .value.booleanValue() ? 0 : 1), notify,
42: update);
43: }
44:
45: /**
46: * Get this field's value according to its native type.
47: */
48:
49: public Object getValue() {
50: return value;
51: }
52:
53: /**
54: * Get this field's value as a boolean.
55: */
56:
57: public Boolean getBooleanValue() {
58: return value;
59: }
60:
61: /**
62: * Create a boolean field.
63: * @exception IllegalFieldValueException If the field rejected the value.
64: */
65:
66: public BooleanField(FormManager manager, String name, String title,
67: boolean value) throws IllegalFieldValueException {
68: super (manager, name, title, bools, (value ? 0 : 1));
69: this.value = (value ? Boolean.TRUE : Boolean.FALSE);
70: }
71:
72: }
|