001: // SlideDoubleAttributeEditor.java
002: // $Id: SlideDoubleAttributeEditor.java,v 1.4 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.Color;
009: import java.awt.Component;
010:
011: import java.util.Properties;
012:
013: import org.w3c.tools.resources.Attribute;
014:
015: import org.w3c.tools.widgets.Slider;
016:
017: import org.w3c.jigsaw.admin.RemoteAccessException;
018: import org.w3c.jigsaw.admin.RemoteResource;
019:
020: import org.w3c.jigadm.RemoteResourceWrapper;
021:
022: /**
023: * SlideDoubleAttributeEditor :
024: * @author Benoit Mahe <bmahe@sophia.inria.fr>
025: */
026:
027: public class SlideDoubleAttributeEditor extends AttributeEditor {
028:
029: /**
030: * The slider's max bound property.
031: */
032: public static final String MAX_P = "slider.max";
033:
034: /**
035: * The slider's min bound property.
036: */
037: public static final String MIN_P = "slider.min";
038:
039: /**
040: * The slider's step property.
041: */
042: public static final String STEP_P = "slider.step";
043: /**
044: * The slider border property
045: */
046: public static final String BORDER_P = "slider.border";
047:
048: private double origs;
049: Slider widget;
050:
051: /**
052: * Tells if the edited value has changed
053: * @return true if the value changed.
054: */
055: public boolean hasChanged() {
056: return (origs != widget.getValue());
057: }
058:
059: /**
060: * set the current value to be the original value, ie: changed
061: * must return <strong>false</strong> after a reset.
062: */
063: public void clearChanged() {
064: origs = (double) widget.getValue();
065: }
066:
067: /**
068: * reset the changes (if any)
069: */
070: public void resetChanges() {
071: widget.setValue(origs);
072: }
073:
074: /**
075: * Get the current value of the edited value
076: * @return an object or <strong>null</strong> if the object was not
077: * initialized
078: */
079: public Object getValue() {
080: return new Double(widget.getValue());
081: }
082:
083: /**
084: * Set the value of the edited value
085: * @param o the new value.
086: */
087: public void setValue(Object o) {
088: widget.setValue(((Double) o).doubleValue());
089: }
090:
091: /**
092: * get the Component created by the editor.
093: * @return a Component
094: */
095: public Component getComponent() {
096: return widget;
097: }
098:
099: /**
100: * Initialize the editor
101: * @param w the ResourceWrapper father of the attribute
102: * @param a the Attribute we are editing
103: * @param o the value of the above attribute
104: * @param p some Properties, used to fine-tune the editor
105: * @exception RemoteAccessException if a remote access error occurs.
106: */
107: public void initialize(RemoteResourceWrapper w, Attribute a,
108: Object o, Properties p) throws RemoteAccessException {
109: if (p != null) {
110: double min;
111: double max;
112: double step;
113:
114: try {
115: min = Double.valueOf(p.getProperty(MIN_P, "0.0"))
116: .doubleValue();
117: } catch (NumberFormatException ex) {
118: min = 0.0;
119: }
120:
121: try {
122: max = Double.valueOf(p.getProperty(MAX_P, "100.0"))
123: .doubleValue();
124: } catch (NumberFormatException ex) {
125: max = 100.0;
126: }
127:
128: try {
129: step = Double.valueOf(p.getProperty(STEP_P, "5.0"))
130: .doubleValue();
131: } catch (NumberFormatException ex) {
132: step = 5.0;
133: }
134:
135: widget.initialize(min, max, step, p.getProperty(BORDER_P,
136: "false").equals("true"));
137:
138: } else {
139: widget.initialize(0.0, 100.0, 5.0);
140: }
141:
142: RemoteResource r = w.getResource();
143: if (o == null) {
144: Double v = null;
145: // FIXME
146: v = (Double) r.getValue(a.getName());
147:
148: if (v == null)
149: if (a.getDefault() != null)
150: v = (Double) a.getDefault();
151: if (v != null) {
152: origs = v.doubleValue();
153: widget.setValue(origs);
154: }
155: } else {
156: origs = ((Double) o).doubleValue();
157: }
158: widget.setValue(origs);
159: }
160:
161: public SlideDoubleAttributeEditor() {
162: widget = new Slider(4, false);
163: widget.setColor(Color.lightGray);
164: }
165:
166: }
|