001: // BooleanAttributeEditor.java
002: // $Id: BooleanAttributeEditor.java,v 1.7 2000/08/16 21:37:26 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1997.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigadm.editors;
007:
008: import java.awt.Component;
009:
010: import java.util.Properties;
011:
012: import org.w3c.jigsaw.admin.RemoteAccessException;
013: import org.w3c.jigsaw.admin.RemoteResource;
014:
015: import org.w3c.tools.resources.Attribute;
016: import org.w3c.tools.resources.BooleanAttribute;
017:
018: import org.w3c.tools.widgets.LabelCheckbox;
019:
020: import org.w3c.jigadm.RemoteResourceWrapper;
021:
022: public class BooleanAttributeEditor extends AttributeEditor {
023:
024: private boolean origb;
025: LabelCheckbox widget;
026:
027: /**
028: * Tells if the edited value has changed
029: * @return true if the value changed.
030: */
031:
032: public boolean hasChanged() {
033: return !(origb == widget.getState());
034: }
035:
036: /**
037: * set the current value to be the original value, ie: changed
038: * must return <strong>false</strong> after a reset.
039: */
040:
041: public void clearChanged() {
042: origb = widget.getState();
043: }
044:
045: /**
046: * reset the changes (if any)
047: */
048:
049: public void resetChanges() {
050: widget.setState(origb);
051: }
052:
053: /**
054: * Get the current value of the edited value
055: * @return an object or <strong>null</strong> if the object was not
056: * initialized
057: */
058:
059: public Object getValue() {
060: return new Boolean(widget.getState());
061: }
062:
063: /**
064: * Set the value of the edited value
065: * @param o the new value.
066: */
067:
068: public void setValue(Object o) {
069: if (o instanceof Boolean) {
070: origb = ((Boolean) o).booleanValue();
071: widget.setState(origb);
072: }
073: }
074:
075: /**
076: * get the Component created by the editor.
077: * @return a Component
078: */
079:
080: public Component getComponent() {
081: return widget;
082: }
083:
084: /**
085: * Initialize the editor
086: * @param w the ResourceWrapper father of the attribute
087: * @param a the Attribute we are editing
088: * @param o the value of the above attribute
089: * @param p some Properties, used to fine-tune the editor
090: * @exception RemoteAccessException if a remote access error occurs.
091: */
092:
093: public void initialize(RemoteResourceWrapper w, Attribute a,
094: Object o, Properties p) throws RemoteAccessException {
095: RemoteResource r = w.getResource();
096: if (o == null) {
097: if (a instanceof BooleanAttribute) {
098: Object oo = null;
099: // FIXME
100: oo = r.getValue(a.getName());
101:
102: if (oo != null) {
103: origb = ((Boolean) oo).booleanValue();
104: } else {
105: if (a.getDefault() != null) {
106: origb = ((Boolean) a.getDefault())
107: .booleanValue();
108: }
109: }
110: widget.setState(origb);
111: }
112: } else {
113: if (o instanceof Boolean) {
114: origb = (((Boolean) o).booleanValue());
115: }
116: }
117: widget.setState(origb);
118: }
119:
120: public BooleanAttributeEditor() {
121: widget = new LabelCheckbox();
122: origb = false;
123: }
124: }
|