Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / src / org / w3c / jigadm / editors / SlideDoubleAttributeEditor.java
diff --git a/JMCR-Stable/real-world application/jigsaw/src/org/w3c/jigadm/editors/SlideDoubleAttributeEditor.java b/JMCR-Stable/real-world application/jigsaw/src/org/w3c/jigadm/editors/SlideDoubleAttributeEditor.java
new file mode 100644 (file)
index 0000000..84fde0c
--- /dev/null
@@ -0,0 +1,161 @@
+// SlideDoubleAttributeEditor.java\r
+// $Id: SlideDoubleAttributeEditor.java,v 1.1 2010/06/15 12:22:40 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1997.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.jigadm.editors;\r
+\r
+import java.awt.Color;\r
+import java.awt.Component;\r
+\r
+import java.util.Properties;\r
+\r
+import org.w3c.tools.resources.Attribute;\r
+\r
+import org.w3c.tools.widgets.Slider;\r
+\r
+import org.w3c.jigsaw.admin.RemoteAccessException;\r
+import org.w3c.jigsaw.admin.RemoteResource;\r
+\r
+import org.w3c.jigadm.RemoteResourceWrapper;\r
+\r
+/**\r
+ * SlideDoubleAttributeEditor :\r
+ * @author Benoit Mahe <bmahe@sophia.inria.fr>\r
+ */\r
+\r
+public class SlideDoubleAttributeEditor extends AttributeEditor {\r
+\r
+    /**\r
+     * The slider's max bound property.\r
+     */\r
+    public static final String MAX_P = "slider.max";\r
+\r
+    /**\r
+     * The slider's min bound property.\r
+     */\r
+    public static final String MIN_P = "slider.min";\r
+\r
+    /**\r
+     * The slider's step property.\r
+     */\r
+    public static final String STEP_P = "slider.step";\r
+    /**\r
+     * The slider border property\r
+     */\r
+    public static final String BORDER_P = "slider.border";\r
+\r
+    private double origs;\r
+    Slider widget;\r
+\r
+    /**\r
+     * Tells if the edited value has changed\r
+     * @return true if the value changed.\r
+     */\r
+    public boolean hasChanged(){\r
+       return (origs != widget.getValue());\r
+    }\r
+\r
+    /**\r
+     * set the current value to be the original value, ie: changed\r
+     * must return <strong>false</strong> after a reset.\r
+     */\r
+    public void clearChanged(){\r
+       origs = (double)widget.getValue();\r
+    }\r
+\r
+    /**\r
+     * reset the changes (if any)\r
+     */\r
+    public void resetChanges(){\r
+       widget.setValue(origs);\r
+    }\r
+\r
+    /**\r
+     * Get the current value of the edited value\r
+     * @return an object or <strong>null</strong> if the object was not\r
+     * initialized\r
+     */\r
+    public Object getValue(){\r
+       return new Double(widget.getValue());\r
+    }\r
+\r
+    /**\r
+     * Set the value of the edited value\r
+     * @param o the new value.\r
+     */\r
+    public void setValue(Object o){\r
+       widget.setValue(((Double)o).doubleValue());\r
+    }\r
+\r
+    /**\r
+     * get the Component created by the editor.\r
+     * @return a Component\r
+     */\r
+    public Component getComponent() {\r
+       return widget;\r
+    }\r
+\r
+    /**\r
+     * Initialize the editor\r
+     * @param w the ResourceWrapper father of the attribute\r
+     * @param a the Attribute we are editing\r
+     * @param o the value of the above attribute\r
+     * @param p some Properties, used to fine-tune the editor\r
+     * @exception RemoteAccessException if a remote access error occurs.\r
+     */\r
+    public void initialize(RemoteResourceWrapper w, Attribute a, Object o,\r
+                          Properties p)\r
+       throws RemoteAccessException\r
+    {\r
+       if (p != null) {\r
+           double min; double max; double step;\r
+\r
+           try { \r
+               min = \r
+                   Double.valueOf(p.getProperty(MIN_P,"0.0")).doubleValue(); \r
+           } catch (NumberFormatException ex) { min = 0.0; }\r
+\r
+           try { \r
+               max = \r
+                   Double.valueOf(p.getProperty(MAX_P,\r
+                                                "100.0")).doubleValue(); \r
+           } catch (NumberFormatException ex) { max = 100.0; }\r
+\r
+           try { \r
+               step = Double.valueOf(p.getProperty(STEP_P,\r
+                                                   "5.0")).doubleValue(); \r
+           } catch (NumberFormatException ex) { step = 5.0; }\r
+       \r
+           widget.initialize(min,max,step,\r
+                             p.getProperty(BORDER_P,"false").equals("true"));\r
+\r
+       } else {\r
+           widget.initialize(0.0,100.0,5.0);\r
+       }\r
+\r
+       RemoteResource r = w.getResource();\r
+       if(o == null) {\r
+           Double v = null;\r
+           // FIXME\r
+           v = (Double) r.getValue(a.getName());\r
+          \r
+           if(v == null)\r
+               if(a.getDefault() != null)\r
+                   v = (Double)a.getDefault();\r
+           if ( v != null ) {\r
+               origs = v.doubleValue();\r
+               widget.setValue(origs);\r
+           } \r
+       } else {\r
+           origs = ((Double)o).doubleValue();\r
+       }\r
+       widget.setValue(origs);\r
+    }\r
+\r
+    public SlideDoubleAttributeEditor () {\r
+       widget = new Slider(4, false);\r
+       widget.setColor(Color.lightGray);\r
+    }\r
+\r
+}\r