]> source.dussan.org Git - vaadin-framework.git/commitdiff
Split Slider into paintable + widget
authorArtur Signell <artur@vaadin.com>
Mon, 30 Jan 2012 07:59:35 +0000 (09:59 +0200)
committerArtur Signell <artur@vaadin.com>
Mon, 30 Jan 2012 07:59:35 +0000 (09:59 +0200)
src/com/vaadin/terminal/gwt/client/ui/VSlider.java
src/com/vaadin/terminal/gwt/client/ui/VSliderPaintable.java [new file with mode: 0644]

index 3632e90956f5034d1454867428a11a21f893f7dc..9fbbeb71817f00915e0dcc89e9b11bc985c8634a 100644 (file)
@@ -17,13 +17,11 @@ import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
 import com.vaadin.terminal.gwt.client.BrowserInfo;\r
 import com.vaadin.terminal.gwt.client.ContainerResizedListener;\r
-import com.vaadin.terminal.gwt.client.VPaintableWidget;\r
-import com.vaadin.terminal.gwt.client.UIDL;\r
 import com.vaadin.terminal.gwt.client.Util;\r
 import com.vaadin.terminal.gwt.client.VConsole;\r
 \r
-public class VSlider extends SimpleFocusablePanel implements VPaintableWidget,\r
-        Field, ContainerResizedListener {\r
+public class VSlider extends SimpleFocusablePanel implements Field,\r
+        ContainerResizedListener {\r
 \r
     public static final String CLASSNAME = "v-slider";\r
 \r
@@ -37,16 +35,16 @@ public class VSlider extends SimpleFocusablePanel implements VPaintableWidget,
 \r
     String id;\r
 \r
-    private boolean immediate;\r
-    private boolean disabled;\r
-    private boolean readonly;\r
+    boolean immediate;\r
+    boolean disabled;\r
+    boolean readonly;\r
 \r
     private int acceleration = 1;\r
-    private double min;\r
-    private double max;\r
-    private int resolution;\r
-    private Double value;\r
-    private boolean vertical;\r
+    double min;\r
+    double max;\r
+    int resolution;\r
+    Double value;\r
+    boolean vertical;\r
 \r
     private final HTML feedback = new HTML("", false);\r
     private final VOverlay feedbackPopup = new VOverlay(true, false, true) {\r
@@ -113,57 +111,7 @@ public class VSlider extends SimpleFocusablePanel implements VPaintableWidget,
         feedbackPopup.setWidget(feedback);\r
     }\r
 \r
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
-\r
-        this.client = client;\r
-        id = uidl.getId();\r
-\r
-        // Ensure correct implementation\r
-        if (client.updateComponent(this, uidl, true)) {\r
-            return;\r
-        }\r
-\r
-        immediate = uidl.getBooleanAttribute("immediate");\r
-        disabled = uidl.getBooleanAttribute("disabled");\r
-        readonly = uidl.getBooleanAttribute("readonly");\r
-\r
-        vertical = uidl.hasAttribute("vertical");\r
-\r
-        String style = "";\r
-        if (uidl.hasAttribute("style")) {\r
-            style = uidl.getStringAttribute("style");\r
-        }\r
-\r
-        if (vertical) {\r
-            addStyleName(CLASSNAME + "-vertical");\r
-        } else {\r
-            removeStyleName(CLASSNAME + "-vertical");\r
-        }\r
-\r
-        min = uidl.getDoubleAttribute("min");\r
-        max = uidl.getDoubleAttribute("max");\r
-        resolution = uidl.getIntAttribute("resolution");\r
-        value = new Double(uidl.getDoubleVariable("value"));\r
-\r
-        setFeedbackValue(value);\r
-\r
-        buildBase();\r
-\r
-        if (!vertical) {\r
-            // Draw handle with a delay to allow base to gain maximum width\r
-            Scheduler.get().scheduleDeferred(new Command() {\r
-                public void execute() {\r
-                    buildHandle();\r
-                    setValue(value, false);\r
-                }\r
-            });\r
-        } else {\r
-            buildHandle();\r
-            setValue(value, false);\r
-        }\r
-    }\r
-\r
-    private void setFeedbackValue(double value) {\r
+    void setFeedbackValue(double value) {\r
         String currentValue = "" + value;\r
         if (resolution == 0) {\r
             currentValue = "" + new Double(value).intValue();\r
@@ -186,7 +134,7 @@ public class VSlider extends SimpleFocusablePanel implements VPaintableWidget,
         }\r
     }\r
 \r
-    private void buildBase() {\r
+    void buildBase() {\r
         final String styleAttribute = vertical ? "height" : "width";\r
         final String domProperty = vertical ? "offsetHeight" : "offsetWidth";\r
 \r
@@ -220,7 +168,7 @@ public class VSlider extends SimpleFocusablePanel implements VPaintableWidget,
         // TODO attach listeners for focusing and arrow keys\r
     }\r
 \r
-    private void buildHandle() {\r
+    void buildHandle() {\r
         final String handleAttribute = vertical ? "marginTop" : "marginLeft";\r
 \r
         DOM.setStyleAttribute(handle, handleAttribute, "0");\r
@@ -230,7 +178,7 @@ public class VSlider extends SimpleFocusablePanel implements VPaintableWidget,
 \r
     }\r
 \r
-    private void setValue(Double value, boolean updateToServer) {\r
+    void setValue(Double value, boolean updateToServer) {\r
         if (value == null) {\r
             return;\r
         }\r
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VSliderPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VSliderPaintable.java
new file mode 100644 (file)
index 0000000..f5b8c8a
--- /dev/null
@@ -0,0 +1,78 @@
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.core.client.Scheduler;\r
+import com.google.gwt.user.client.Command;\r
+import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+\r
+public class VSliderPaintable extends VAbstractPaintableWidget {\r
+\r
+    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+\r
+        getWidgetForPaintable().client = client;\r
+        getWidgetForPaintable().id = uidl.getId();\r
+\r
+        // Ensure correct implementation\r
+        if (client.updateComponent(this, uidl, true)) {\r
+            return;\r
+        }\r
+\r
+        getWidgetForPaintable().immediate = uidl\r
+                .getBooleanAttribute("immediate");\r
+        getWidgetForPaintable().disabled = uidl.getBooleanAttribute("disabled");\r
+        getWidgetForPaintable().readonly = uidl.getBooleanAttribute("readonly");\r
+\r
+        getWidgetForPaintable().vertical = uidl.hasAttribute("vertical");\r
+\r
+        String style = "";\r
+        if (uidl.hasAttribute("style")) {\r
+            style = uidl.getStringAttribute("style");\r
+        }\r
+\r
+        if (getWidgetForPaintable().vertical) {\r
+            getWidgetForPaintable().addStyleName(\r
+                    VSlider.CLASSNAME + "-vertical");\r
+        } else {\r
+            getWidgetForPaintable().removeStyleName(\r
+                    VSlider.CLASSNAME + "-vertical");\r
+        }\r
+\r
+        getWidgetForPaintable().min = uidl.getDoubleAttribute("min");\r
+        getWidgetForPaintable().max = uidl.getDoubleAttribute("max");\r
+        getWidgetForPaintable().resolution = uidl.getIntAttribute("resolution");\r
+        getWidgetForPaintable().value = new Double(\r
+                uidl.getDoubleVariable("value"));\r
+\r
+        getWidgetForPaintable().setFeedbackValue(getWidgetForPaintable().value);\r
+\r
+        getWidgetForPaintable().buildBase();\r
+\r
+        if (!getWidgetForPaintable().vertical) {\r
+            // Draw handle with a delay to allow base to gain maximum width\r
+            Scheduler.get().scheduleDeferred(new Command() {\r
+                public void execute() {\r
+                    getWidgetForPaintable().buildHandle();\r
+                    getWidgetForPaintable().setValue(\r
+                            getWidgetForPaintable().value, false);\r
+                }\r
+            });\r
+        } else {\r
+            getWidgetForPaintable().buildHandle();\r
+            getWidgetForPaintable().setValue(getWidgetForPaintable().value,\r
+                    false);\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public VSlider getWidgetForPaintable() {\r
+        return (VSlider) super.getWidgetForPaintable();\r
+    }\r
+\r
+    @Override\r
+    protected Widget createWidget() {\r
+        return GWT.create(VSlider.class);\r
+    }\r
+\r
+}\r