001: // SlideLongAttributeEditor.java
002: // $Id: SlideLongAttributeEditor.java,v 1.10 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: * SlideLongAttributeEditor :
024: * @author Benoit Mahe <bmahe@sophia.inria.fr>
025: */
026:
027: public class SlideLongAttributeEditor 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: /**
045: * The slider border property
046: */
047: public static final String BORDER_P = "slider.border";
048:
049: private long origs;
050: Slider widget;
051:
052: /**
053: * Tells if the edited value has changed
054: * @return true if the value changed.
055: */
056: public boolean hasChanged() {
057: return (origs != widget.getValue());
058: }
059:
060: /**
061: * set the current value to be the original value, ie: changed
062: * must return <strong>false</strong> after a reset.
063: */
064: public void clearChanged() {
065: origs = (long) widget.getValue();
066: }
067:
068: /**
069: * reset the changes (if any)
070: */
071: public void resetChanges() {
072: widget.setValue(origs);
073: }
074:
075: /**
076: * Get the current value of the edited value
077: * @return an object or <strong>null</strong> if the object was not
078: * initialized
079: */
080: public Object getValue() {
081: return new Long((long) widget.getValue());
082: }
083:
084: /**
085: * Set the value of the edited value
086: * @param o the new value.
087: */
088: public void setValue(Object o) {
089: widget.setValue(((Long) o).longValue());
090: }
091:
092: /**
093: * get the Component created by the editor.
094: * @return a Component
095: */
096: public Component getComponent() {
097: return widget;
098: }
099:
100: /**
101: * Initialize the editor
102: * @param w the ResourceWrapper father of the attribute
103: * @param a the Attribute we are editing
104: * @param o the value of the above attribute
105: * @param p some Properties, used to fine-tune the editor
106: * @exception RemoteAccessException if a remote access error occurs.
107: */
108: public void initialize(RemoteResourceWrapper w, Attribute a,
109: Object o, Properties p) throws RemoteAccessException {
110: if (p != null) {
111: long min;
112: long max;
113: long step;
114:
115: try {
116: min = Long.parseLong(p.getProperty(MIN_P, "0"));
117: } catch (NumberFormatException ex) {
118: min = 0;
119: }
120:
121: try {
122: max = Long.parseLong(p.getProperty(MAX_P, "100"));
123: } catch (NumberFormatException ex) {
124: max = 100;
125: }
126:
127: try {
128: step = Long.parseLong(p.getProperty(STEP_P, "5"));
129: } catch (NumberFormatException ex) {
130: step = 5;
131: }
132:
133: widget.initialize(min, max, step, p.getProperty(BORDER_P,
134: "false").equals("true"));
135:
136: } else {
137: widget.initialize((long) 0, (long) 100, (long) 5);
138: }
139:
140: RemoteResource r = w.getResource();
141: if (o == null) {
142: Long v = null;
143: // FIXME
144: v = (Long) r.getValue(a.getName());
145:
146: if (v == null)
147: if (a.getDefault() != null)
148: v = (Long) a.getDefault();
149: if (v != null) {
150: origs = v.intValue();
151: widget.setValue(origs);
152: }
153: } else {
154: origs = ((Long) o).longValue();
155: }
156: widget.setValue(origs);
157: }
158:
159: public SlideLongAttributeEditor() {
160: widget = new Slider(4, false);
161: widget.setColor(Color.lightGray);
162: }
163:
164: }
|