001: // FileAttributeEditor.java
002: // $Id: FileAttributeEditor.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.JTextField;
011: import javax.swing.BorderFactory;
012:
013: import java.util.Properties;
014:
015: import org.w3c.tools.resources.Attribute;
016:
017: import org.w3c.jigsaw.admin.RemoteAccessException;
018: import org.w3c.jigsaw.admin.RemoteResource;
019:
020: import org.w3c.jigadm.RemoteResourceWrapper;
021: import org.w3c.jigadm.editors.AttributeEditor;
022:
023: public class FileAttributeEditor extends AttributeEditor {
024:
025: private String origs;
026: JTextField widget;
027:
028: /**
029: * Tells if the edited value has changed
030: * @return true if the value changed.
031: */
032:
033: public boolean hasChanged() {
034: return !origs.equals(widget.getText());
035: }
036:
037: /**
038: * set the current value to be the original value, ie: changed
039: * must return <strong>false</strong> after a reset.
040: */
041:
042: public void clearChanged() {
043: origs = widget.getText();
044: }
045:
046: /**
047: * reset the changes (if any)
048: */
049:
050: public void resetChanges() {
051: widget.setText(origs);
052: }
053:
054: /**
055: * Get the current value of the edited value
056: * @return an object or <strong>null</strong> if the object was not
057: * initialized
058: */
059:
060: public Object getValue() {
061: String wt = widget.getText();
062: if ((wt != null) && (wt.length() > 0)) {
063: return widget.getText();
064: } else {
065: return null;
066: }
067: }
068:
069: /**
070: * Set the value of the edited value
071: * @param o the new value.
072: */
073:
074: public void setValue(Object o) {
075: widget.setText(o.toString());
076: }
077:
078: /**
079: * get the Component created by the editor.
080: * @return a Component
081: */
082:
083: public Component getComponent() {
084: return widget;
085: }
086:
087: /**
088: * Initialize the editor
089: * @param w the ResourceWrapper father of the attribute
090: * @param a the Attribute we are editing
091: * @param o the value of the above attribute
092: * @param p some Properties, used to fine-tune the editor
093: * @exception RemoteAccessException if a remote access error occurs.
094: */
095:
096: public void initialize(RemoteResourceWrapper w, Attribute a,
097: Object o, Properties p) throws RemoteAccessException {
098: RemoteResource r = w.getResource();
099: if (o == null) {
100: String v = null;
101: // FIXME
102: v = (String) r.getValue(a.getName());
103:
104: if (v == null)
105: if (a.getDefault() != null)
106: v = a.getDefault().toString();
107: if (v != null) {
108: origs = v;
109: widget.setText(origs);
110: }
111: } else {
112: origs = o.toString();
113: }
114: widget.setText(origs);
115: }
116:
117: public FileAttributeEditor() {
118: widget = new JTextField();
119: widget.setBorder(BorderFactory.createLoweredBevelBorder());
120: origs = "";
121: }
122: }
|