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