From f2d8308279f03e6b445eb722ddcc9b4a3a6d1ca3 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 30 Jan 2012 09:59:35 +0200 Subject: [PATCH] Split Slider into paintable + widget --- .../terminal/gwt/client/ui/VSlider.java | 80 ++++--------------- .../gwt/client/ui/VSliderPaintable.java | 78 ++++++++++++++++++ 2 files changed, 92 insertions(+), 66 deletions(-) create mode 100644 src/com/vaadin/terminal/gwt/client/ui/VSliderPaintable.java diff --git a/src/com/vaadin/terminal/gwt/client/ui/VSlider.java b/src/com/vaadin/terminal/gwt/client/ui/VSlider.java index 3632e90956..9fbbeb7181 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VSlider.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VSlider.java @@ -17,13 +17,11 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.ContainerResizedListener; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VConsole; -public class VSlider extends SimpleFocusablePanel implements VPaintableWidget, - Field, ContainerResizedListener { +public class VSlider extends SimpleFocusablePanel implements Field, + ContainerResizedListener { public static final String CLASSNAME = "v-slider"; @@ -37,16 +35,16 @@ public class VSlider extends SimpleFocusablePanel implements VPaintableWidget, String id; - private boolean immediate; - private boolean disabled; - private boolean readonly; + boolean immediate; + boolean disabled; + boolean readonly; private int acceleration = 1; - private double min; - private double max; - private int resolution; - private Double value; - private boolean vertical; + double min; + double max; + int resolution; + Double value; + boolean vertical; private final HTML feedback = new HTML("", false); private final VOverlay feedbackPopup = new VOverlay(true, false, true) { @@ -113,57 +111,7 @@ public class VSlider extends SimpleFocusablePanel implements VPaintableWidget, feedbackPopup.setWidget(feedback); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - - this.client = client; - id = uidl.getId(); - - // Ensure correct implementation - if (client.updateComponent(this, uidl, true)) { - return; - } - - immediate = uidl.getBooleanAttribute("immediate"); - disabled = uidl.getBooleanAttribute("disabled"); - readonly = uidl.getBooleanAttribute("readonly"); - - vertical = uidl.hasAttribute("vertical"); - - String style = ""; - if (uidl.hasAttribute("style")) { - style = uidl.getStringAttribute("style"); - } - - if (vertical) { - addStyleName(CLASSNAME + "-vertical"); - } else { - removeStyleName(CLASSNAME + "-vertical"); - } - - min = uidl.getDoubleAttribute("min"); - max = uidl.getDoubleAttribute("max"); - resolution = uidl.getIntAttribute("resolution"); - value = new Double(uidl.getDoubleVariable("value")); - - setFeedbackValue(value); - - buildBase(); - - if (!vertical) { - // Draw handle with a delay to allow base to gain maximum width - Scheduler.get().scheduleDeferred(new Command() { - public void execute() { - buildHandle(); - setValue(value, false); - } - }); - } else { - buildHandle(); - setValue(value, false); - } - } - - private void setFeedbackValue(double value) { + void setFeedbackValue(double value) { String currentValue = "" + value; if (resolution == 0) { currentValue = "" + new Double(value).intValue(); @@ -186,7 +134,7 @@ public class VSlider extends SimpleFocusablePanel implements VPaintableWidget, } } - private void buildBase() { + void buildBase() { final String styleAttribute = vertical ? "height" : "width"; final String domProperty = vertical ? "offsetHeight" : "offsetWidth"; @@ -220,7 +168,7 @@ public class VSlider extends SimpleFocusablePanel implements VPaintableWidget, // TODO attach listeners for focusing and arrow keys } - private void buildHandle() { + void buildHandle() { final String handleAttribute = vertical ? "marginTop" : "marginLeft"; DOM.setStyleAttribute(handle, handleAttribute, "0"); @@ -230,7 +178,7 @@ public class VSlider extends SimpleFocusablePanel implements VPaintableWidget, } - private void setValue(Double value, boolean updateToServer) { + void setValue(Double value, boolean updateToServer) { if (value == null) { return; } 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 index 0000000000..f5b8c8a45e --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VSliderPaintable.java @@ -0,0 +1,78 @@ +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.user.client.Command; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; + +public class VSliderPaintable extends VAbstractPaintableWidget { + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + + getWidgetForPaintable().client = client; + getWidgetForPaintable().id = uidl.getId(); + + // Ensure correct implementation + if (client.updateComponent(this, uidl, true)) { + return; + } + + getWidgetForPaintable().immediate = uidl + .getBooleanAttribute("immediate"); + getWidgetForPaintable().disabled = uidl.getBooleanAttribute("disabled"); + getWidgetForPaintable().readonly = uidl.getBooleanAttribute("readonly"); + + getWidgetForPaintable().vertical = uidl.hasAttribute("vertical"); + + String style = ""; + if (uidl.hasAttribute("style")) { + style = uidl.getStringAttribute("style"); + } + + if (getWidgetForPaintable().vertical) { + getWidgetForPaintable().addStyleName( + VSlider.CLASSNAME + "-vertical"); + } else { + getWidgetForPaintable().removeStyleName( + VSlider.CLASSNAME + "-vertical"); + } + + getWidgetForPaintable().min = uidl.getDoubleAttribute("min"); + getWidgetForPaintable().max = uidl.getDoubleAttribute("max"); + getWidgetForPaintable().resolution = uidl.getIntAttribute("resolution"); + getWidgetForPaintable().value = new Double( + uidl.getDoubleVariable("value")); + + getWidgetForPaintable().setFeedbackValue(getWidgetForPaintable().value); + + getWidgetForPaintable().buildBase(); + + if (!getWidgetForPaintable().vertical) { + // Draw handle with a delay to allow base to gain maximum width + Scheduler.get().scheduleDeferred(new Command() { + public void execute() { + getWidgetForPaintable().buildHandle(); + getWidgetForPaintable().setValue( + getWidgetForPaintable().value, false); + } + }); + } else { + getWidgetForPaintable().buildHandle(); + getWidgetForPaintable().setValue(getWidgetForPaintable().value, + false); + } + } + + @Override + public VSlider getWidgetForPaintable() { + return (VSlider) super.getWidgetForPaintable(); + } + + @Override + protected Widget createWidget() { + return GWT.create(VSlider.class); + } + +} -- 2.39.5