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