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