001: // BooleanAttributeEditor.java
002: // $Id: BooleanAttributeEditor.java,v 1.4 2000/08/16 21:37:29 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.jigadmin.attributes;
007:
008: import java.awt.Component;
009:
010: import javax.swing.JCheckBox;
011: import javax.swing.ImageIcon;
012:
013: import java.util.Properties;
014:
015: import org.w3c.jigsaw.admin.RemoteAccessException;
016: import org.w3c.jigsaw.admin.RemoteResource;
017:
018: import org.w3c.jigadm.RemoteResourceWrapper;
019: import org.w3c.jigadm.editors.AttributeEditor;
020:
021: import org.w3c.tools.resources.Attribute;
022: import org.w3c.tools.resources.BooleanAttribute;
023:
024: /**
025: * Editor for BooleanAttribute.
026: */
027: public class BooleanAttributeEditor extends AttributeEditor {
028:
029: class MyJCheckBox extends JCheckBox {
030:
031: protected static final String SELECTED_STRING = "True";
032: protected static final String UNSELECTED_STRING = "False";
033:
034: protected void setSelectedText(boolean onoff) {
035: if (onoff)
036: setText(SELECTED_STRING);
037: else
038: setText(UNSELECTED_STRING);
039: }
040:
041: protected void fireStateChanged() {
042: setSelectedText(isSelected());
043: super .fireStateChanged();
044: }
045:
046: MyJCheckBox(boolean onoff) {
047: setSelected(onoff);
048: setSelectedText(onoff);
049: }
050: }
051:
052: private boolean origb;
053: MyJCheckBox widget;
054:
055: /**
056: * Tells if the edited value has changed
057: * @return true if the value changed.
058: */
059:
060: public boolean hasChanged() {
061: return !(origb == widget.isSelected());
062: }
063:
064: /**
065: * set the current value to be the original value, ie: changed
066: * must return <strong>false</strong> after a reset.
067: */
068:
069: public void clearChanged() {
070: origb = widget.isSelected();
071: }
072:
073: /**
074: * reset the changes (if any)
075: */
076:
077: public void resetChanges() {
078: widget.setSelected(origb);
079: }
080:
081: /**
082: * Get the current value of the edited value
083: * @return an object or <strong>null</strong> if the object was not
084: * initialized
085: */
086:
087: public Object getValue() {
088: return new Boolean(widget.isSelected());
089: }
090:
091: /**
092: * Set the value of the edited value
093: * @param o the new value.
094: */
095:
096: public void setValue(Object o) {
097: if (o instanceof Boolean) {
098: origb = ((Boolean) o).booleanValue();
099: widget.setSelected(origb);
100: }
101: }
102:
103: /**
104: * get the Component created by the editor.
105: * @return a Component
106: */
107:
108: public Component getComponent() {
109: return widget;
110: }
111:
112: /**
113: * Initialize the editor
114: * @param w the ResourceWrapper father of the attribute
115: * @param a the Attribute we are editing
116: * @param o the value of the above attribute
117: * @param p some Properties, used to fine-tune the editor
118: * @exception RemoteAccessException if a remote access error occurs.
119: */
120:
121: public void initialize(RemoteResourceWrapper w, Attribute a,
122: Object o, Properties p) throws RemoteAccessException {
123: RemoteResource r = w.getResource();
124: if (o == null) {
125: if (a instanceof BooleanAttribute) {
126: Object oo = r.getValue(a.getName());
127: if (oo != null) {
128: origb = ((Boolean) oo).booleanValue();
129: } else {
130: if (a.getDefault() != null) {
131: origb = ((Boolean) a.getDefault())
132: .booleanValue();
133: }
134: }
135: widget.setSelected(origb);
136: }
137: } else {
138: if (o instanceof Boolean) {
139: origb = (((Boolean) o).booleanValue());
140: }
141: }
142: widget.setSelected(origb);
143: }
144:
145: public BooleanAttributeEditor() {
146: widget = new MyJCheckBox(false);
147: origb = false;
148: }
149: }
|