001: // SelectFileEditor.java
002: // $Id: SelectFileEditor.java,v 1.6 2000/08/16 21:37:28 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.BorderLayout;
009: import java.awt.Button;
010: import java.awt.Component;
011: import java.awt.Container;
012: import java.awt.Dialog;
013: import java.awt.FileDialog;
014: import java.awt.Frame;
015: import java.awt.Panel;
016: import java.awt.TextComponent;
017: import java.awt.TextField;
018:
019: import java.io.File;
020:
021: import java.awt.event.ActionEvent;
022: import java.awt.event.ActionListener;
023:
024: import java.util.Properties;
025:
026: import org.w3c.tools.resources.Attribute;
027:
028: import org.w3c.jigsaw.admin.RemoteAccessException;
029: import org.w3c.jigsaw.admin.RemoteResource;
030:
031: import org.w3c.jigadm.RemoteResourceWrapper;
032:
033: public class SelectFileEditor extends AttributeEditor {
034:
035: class FComponent extends Panel implements ActionListener {
036: SelectFileEditor editor = null;
037: TextField text = null;
038: Button select = null;
039:
040: public String getFile() {
041: return text.getText();
042: }
043:
044: public void setFile(String file) {
045: text.setText(file);
046: }
047:
048: public void actionPerformed(ActionEvent e) {
049: String command = e.getActionCommand();
050: if (command != null) {
051: if (command.equals("select")) {
052: FileDialog fileD = new FileDialog(new Frame(),
053: "Select a file");
054: //FIXME
055: String file = getFile();
056: String dir = null;
057: if (file != null) {
058: dir = new File(file).getParent();
059: fileD.setDirectory(dir);
060: }
061: fileD.show();
062: file = fileD.getFile();
063: dir = fileD.getDirectory();
064: String selected = null;
065: if ((file != null) && (file.length() > 0)) {
066: selected = (new File(dir, file))
067: .getAbsolutePath();
068: setFile(selected);
069: }
070: }
071: }
072: }
073:
074: FComponent(SelectFileEditor editor) {
075: this .editor = editor;
076: this .text = new TextField();
077: this .select = new Button("Select");
078: select.setActionCommand("select");
079: select.addActionListener(this );
080: setLayout(new BorderLayout());
081: add(text, "Center");
082: add(select, "East");
083: }
084: }
085:
086: private String origs;
087: protected FComponent widget;
088:
089: /**
090: * Tells if the edited value has changed
091: * @return true if the value changed.
092: */
093:
094: public boolean hasChanged() {
095: return !origs.equals(widget.getFile());
096: }
097:
098: /**
099: * set the current value to be the original value, ie: changed
100: * must return <strong>false</strong> after a reset.
101: */
102:
103: public void clearChanged() {
104: origs = widget.getFile();
105: }
106:
107: /**
108: * reset the changes (if any)
109: */
110:
111: public void resetChanges() {
112: widget.setFile(origs);
113: }
114:
115: /**
116: * Get the current value of the edited value
117: * @return an object or <strong>null</strong> if the object was not
118: * initialized
119: */
120:
121: public Object getValue() {
122: return widget.getFile();
123: }
124:
125: /**
126: * Set the value of the edited value
127: * @param o the new value.
128: */
129:
130: public void setValue(Object o) {
131: widget.setFile(o.toString());
132: }
133:
134: /**
135: * get the Component created by the editor.
136: * @return a Component
137: */
138:
139: public Component getComponent() {
140: return widget;
141: }
142:
143: /**
144: * Initialize the editor
145: * @param w the ResourceWrapper father of the attribute
146: * @param a the Attribute we are editing
147: * @param o the value of the above attribute
148: * @param p some Properties, used to fine-tune the editor
149: * @exception RemoteAccessException if a remote access error occurs.
150: */
151:
152: public void initialize(RemoteResourceWrapper w, Attribute a,
153: Object o, Properties p) throws RemoteAccessException {
154: RemoteResource r = w.getResource();
155: if (o == null) {
156: String v = null;
157: // FIXME
158: v = (String) r.getValue(a.getName());
159:
160: if (v == null)
161: if (a.getDefault() != null)
162: v = a.getDefault().toString();
163: if (v != null) {
164: origs = v;
165: widget.setFile(origs);
166: }
167: } else {
168: origs = o.toString();
169: }
170: widget.setFile(origs);
171: }
172:
173: public void createComponent() {
174: widget = new FComponent(this );
175: }
176:
177: public SelectFileEditor() {
178: createComponent();
179: origs = "";
180: }
181:
182: }
|