summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/ui/slider/SliderConnector.java89
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/ui/slider/VSlider.java251
-rw-r--r--server/src/com/vaadin/ui/Slider.java172
-rw-r--r--shared/src/com/vaadin/shared/ui/slider/SliderOrientation.java5
-rw-r--r--shared/src/com/vaadin/shared/ui/slider/SliderServerRpc.java14
-rw-r--r--shared/src/com/vaadin/shared/ui/slider/SliderState.java60
-rw-r--r--tests/testbench/com/vaadin/tests/components/slider/SliderTest.java11
-rw-r--r--tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java5
8 files changed, 359 insertions, 248 deletions
diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/slider/SliderConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/slider/SliderConnector.java
index 7e0617b7dc..53f3b8874b 100644
--- a/client/src/com/vaadin/terminal/gwt/client/ui/slider/SliderConnector.java
+++ b/client/src/com/vaadin/terminal/gwt/client/ui/slider/SliderConnector.java
@@ -15,70 +15,61 @@
*/
package com.vaadin.terminal.gwt.client.ui.slider;
-import com.google.gwt.core.client.Scheduler;
-import com.google.gwt.user.client.Command;
+import com.google.gwt.event.logical.shared.ValueChangeEvent;
+import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.vaadin.shared.ui.Connect;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.Paintable;
-import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.shared.ui.slider.SliderServerRpc;
+import com.vaadin.shared.ui.slider.SliderState;
+import com.vaadin.terminal.gwt.client.communication.RpcProxy;
+import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
import com.vaadin.terminal.gwt.client.ui.AbstractFieldConnector;
import com.vaadin.ui.Slider;
@Connect(Slider.class)
public class SliderConnector extends AbstractFieldConnector implements
- Paintable {
+ ValueChangeHandler<Double> {
- @Override
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-
- getWidget().client = client;
- getWidget().id = uidl.getId();
-
- if (!isRealUpdate(uidl)) {
- return;
- }
+ protected SliderServerRpc rpc = RpcProxy
+ .create(SliderServerRpc.class, this);
- getWidget().immediate = getState().isImmediate();
- getWidget().disabled = !isEnabled();
- getWidget().readonly = isReadOnly();
+ @Override
+ public void init() {
+ super.init();
+ getWidget().setConnection(getConnection());
+ getWidget().addValueChangeHandler(this);
+ }
- getWidget().vertical = uidl.hasAttribute("vertical");
+ @Override
+ public VSlider getWidget() {
+ return (VSlider) super.getWidget();
+ }
- // TODO should style names be used?
+ @Override
+ public SliderState getState() {
+ return (SliderState) super.getState();
+ }
- if (getWidget().vertical) {
- getWidget().addStyleName(VSlider.CLASSNAME + "-vertical");
- } else {
- getWidget().removeStyleName(VSlider.CLASSNAME + "-vertical");
- }
+ @Override
+ public void onValueChange(ValueChangeEvent<Double> event) {
+ rpc.valueChanged(event.getValue());
+ }
- getWidget().min = uidl.getDoubleAttribute("min");
- getWidget().max = uidl.getDoubleAttribute("max");
- getWidget().resolution = uidl.getIntAttribute("resolution");
- getWidget().value = new Double(uidl.getDoubleVariable("value"));
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
- getWidget().setFeedbackValue(getWidget().value);
+ getWidget().setId(getConnectorId());
+ getWidget().setImmediate(getState().isImmediate());
+ getWidget().setDisabled(!isEnabled());
+ getWidget().setReadOnly(isReadOnly());
+ getWidget().setOrientation(getState().getOrientation());
+ getWidget().setMinValue(getState().getMinValue());
+ getWidget().setMaxValue(getState().getMaxValue());
+ getWidget().setResolution(getState().getResolution());
+ getWidget().setValue(getState().getValue(), false);
+ getWidget().setFeedbackValue(getState().getValue());
getWidget().buildBase();
-
- if (!getWidget().vertical) {
- // Draw handle with a delay to allow base to gain maximum width
- Scheduler.get().scheduleDeferred(new Command() {
- @Override
- public void execute() {
- getWidget().buildHandle();
- getWidget().setValue(getWidget().value, false);
- }
- });
- } else {
- getWidget().buildHandle();
- getWidget().setValue(getWidget().value, false);
- }
- }
-
- @Override
- public VSlider getWidget() {
- return (VSlider) super.getWidget();
}
}
diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/slider/VSlider.java b/client/src/com/vaadin/terminal/gwt/client/ui/slider/VSlider.java
index 9667522eb3..d9801626b4 100644
--- a/client/src/com/vaadin/terminal/gwt/client/ui/slider/VSlider.java
+++ b/client/src/com/vaadin/terminal/gwt/client/ui/slider/VSlider.java
@@ -19,12 +19,17 @@ package com.vaadin.terminal.gwt.client.ui.slider;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.dom.client.KeyCodes;
+import com.google.gwt.event.logical.shared.ValueChangeEvent;
+import com.google.gwt.event.logical.shared.ValueChangeHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.HasValue;
+import com.vaadin.shared.ui.slider.SliderOrientation;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.ContainerResizedListener;
@@ -36,7 +41,7 @@ import com.vaadin.terminal.gwt.client.ui.VLazyExecutor;
import com.vaadin.terminal.gwt.client.ui.VOverlay;
public class VSlider extends SimpleFocusablePanel implements Field,
- ContainerResizedListener {
+ ContainerResizedListener, HasValue<Double> {
public static final String CLASSNAME = "v-slider";
@@ -46,20 +51,22 @@ public class VSlider extends SimpleFocusablePanel implements Field,
*/
private static final int MIN_SIZE = 50;
- ApplicationConnection client;
+ protected ApplicationConnection client;
- String id;
+ protected String id;
- boolean immediate;
- boolean disabled;
- boolean readonly;
+ protected boolean immediate;
+ protected boolean disabled;
+ protected boolean readonly;
private int acceleration = 1;
- double min;
- double max;
- int resolution;
- Double value;
- boolean vertical;
+ protected double min;
+ protected double max;
+ protected int resolution;
+ protected Double value;
+ protected SliderOrientation orientation = SliderOrientation.HORIZONTAL;
+
+ private boolean valueChangeHandlerInitialized = false;
private final HTML feedback = new HTML("", false);
private final VOverlay feedbackPopup = new VOverlay(true, false, true) {
@@ -92,7 +99,7 @@ public class VSlider extends SimpleFocusablePanel implements Field,
@Override
public void execute() {
- updateValueToServer();
+ fireValueChanged();
acceleration = 1;
}
});
@@ -137,7 +144,7 @@ public class VSlider extends SimpleFocusablePanel implements Field,
}
private void updateFeedbackPosition() {
- if (vertical) {
+ if (isVertical()) {
feedbackPopup.setPopupPosition(
DOM.getAbsoluteLeft(handle) + handle.getOffsetWidth(),
DOM.getAbsoluteTop(handle) + handle.getOffsetHeight() / 2
@@ -152,16 +159,17 @@ public class VSlider extends SimpleFocusablePanel implements Field,
}
void buildBase() {
- final String styleAttribute = vertical ? "height" : "width";
- final String oppositeStyleAttribute = vertical ? "width" : "height";
- final String domProperty = vertical ? "offsetHeight" : "offsetWidth";
+ final String styleAttribute = isVertical() ? "height" : "width";
+ final String oppositeStyleAttribute = isVertical() ? "width" : "height";
+ final String domProperty = isVertical() ? "offsetHeight"
+ : "offsetWidth";
// clear unnecessary opposite style attribute
DOM.setStyleAttribute(base, oppositeStyleAttribute, "");
final Element p = DOM.getParent(getElement());
if (DOM.getElementPropertyInt(p, domProperty) > 50) {
- if (vertical) {
+ if (isVertical()) {
setHeight();
} else {
DOM.setStyleAttribute(base, styleAttribute, "");
@@ -176,7 +184,7 @@ public class VSlider extends SimpleFocusablePanel implements Field,
public void execute() {
final Element p = DOM.getParent(getElement());
if (DOM.getElementPropertyInt(p, domProperty) > (MIN_SIZE + 5)) {
- if (vertical) {
+ if (isVertical()) {
setHeight();
} else {
DOM.setStyleAttribute(base, styleAttribute, "");
@@ -188,12 +196,27 @@ public class VSlider extends SimpleFocusablePanel implements Field,
});
}
+ if (!isVertical()) {
+ // Draw handle with a delay to allow base to gain maximum width
+ Scheduler.get().scheduleDeferred(new Command() {
+ @Override
+ public void execute() {
+ buildHandle();
+ setValue(value, false);
+ }
+ });
+ } else {
+ buildHandle();
+ setValue(value, false);
+ }
+
// TODO attach listeners for focusing and arrow keys
}
void buildHandle() {
- final String handleAttribute = vertical ? "marginTop" : "marginLeft";
- final String oppositeHandleAttribute = vertical ? "marginLeft"
+ final String handleAttribute = isVertical() ? "marginTop"
+ : "marginLeft";
+ final String oppositeHandleAttribute = isVertical() ? "marginLeft"
: "marginTop";
DOM.setStyleAttribute(handle, handleAttribute, "0");
@@ -206,59 +229,6 @@ public class VSlider extends SimpleFocusablePanel implements Field,
}
- void setValue(Double value, boolean updateToServer) {
- if (value == null) {
- return;
- }
-
- if (value < min) {
- value = min;
- } else if (value > max) {
- value = max;
- }
-
- // Update handle position
- final String styleAttribute = vertical ? "marginTop" : "marginLeft";
- final String domProperty = vertical ? "offsetHeight" : "offsetWidth";
- final int handleSize = Integer.parseInt(DOM.getElementProperty(handle,
- domProperty));
- final int baseSize = Integer.parseInt(DOM.getElementProperty(base,
- domProperty)) - (2 * BASE_BORDER_WIDTH);
-
- final int range = baseSize - handleSize;
- double v = value.doubleValue();
-
- // Round value to resolution
- if (resolution > 0) {
- v = Math.round(v * Math.pow(10, resolution));
- v = v / Math.pow(10, resolution);
- } else {
- v = Math.round(v);
- }
- final double valueRange = max - min;
- double p = 0;
- if (valueRange > 0) {
- p = range * ((v - min) / valueRange);
- }
- if (p < 0) {
- p = 0;
- }
- if (vertical) {
- p = range - p;
- }
- final double pos = p;
-
- DOM.setStyleAttribute(handle, styleAttribute, (Math.round(pos)) + "px");
-
- // Update value
- this.value = new Double(v);
- setFeedbackValue(v);
-
- if (updateToServer) {
- updateValueToServer();
- }
- }
-
@Override
public void onBrowserEvent(Event event) {
if (disabled || readonly) {
@@ -386,7 +356,7 @@ public class VSlider extends SimpleFocusablePanel implements Field,
final int coord = getEventPosition(event);
final int handleSize, baseSize, baseOffset;
- if (vertical) {
+ if (isVertical()) {
handleSize = handle.getOffsetHeight();
baseSize = base.getOffsetHeight();
baseOffset = base.getAbsoluteTop() - Window.getScrollTop()
@@ -398,7 +368,7 @@ public class VSlider extends SimpleFocusablePanel implements Field,
+ handleSize / 2;
}
- if (vertical) {
+ if (isVertical()) {
v = ((baseSize - (coord - baseOffset)) / (double) (baseSize - handleSize))
* (max - min) + min;
} else {
@@ -423,7 +393,7 @@ public class VSlider extends SimpleFocusablePanel implements Field,
* @return
*/
protected int getEventPosition(Event event) {
- if (vertical) {
+ if (isVertical()) {
return Util.getTouchOrMouseClientY(event);
} else {
return Util.getTouchOrMouseClientX(event);
@@ -432,7 +402,7 @@ public class VSlider extends SimpleFocusablePanel implements Field,
@Override
public void iLayout() {
- if (vertical) {
+ if (isVertical()) {
setHeight();
}
// Update handle position
@@ -451,8 +421,8 @@ public class VSlider extends SimpleFocusablePanel implements Field,
DOM.setStyleAttribute(base, "overflow", "");
}
- private void updateValueToServer() {
- client.updateVariable(id, "value", value.doubleValue(), immediate);
+ private void fireValueChanged() {
+ ValueChangeEvent.fire(VSlider.this, value);
}
/**
@@ -469,8 +439,8 @@ public class VSlider extends SimpleFocusablePanel implements Field,
return false;
}
- if ((keycode == getNavigationUpKey() && vertical)
- || (keycode == getNavigationRightKey() && !vertical)) {
+ if ((keycode == getNavigationUpKey() && isVertical())
+ || (keycode == getNavigationRightKey() && !isVertical())) {
if (shift) {
for (int a = 0; a < acceleration; a++) {
increaseValue(false);
@@ -480,8 +450,8 @@ public class VSlider extends SimpleFocusablePanel implements Field,
increaseValue(false);
}
return true;
- } else if (keycode == getNavigationDownKey() && vertical
- || (keycode == getNavigationLeftKey() && !vertical)) {
+ } else if (keycode == getNavigationDownKey() && isVertical()
+ || (keycode == getNavigationLeftKey() && !isVertical())) {
if (shift) {
for (int a = 0; a < acceleration; a++) {
decreaseValue(false);
@@ -539,4 +509,119 @@ public class VSlider extends SimpleFocusablePanel implements Field,
protected int getNavigationRightKey() {
return KeyCodes.KEY_RIGHT;
}
+
+ public void setConnection(ApplicationConnection client) {
+ this.client = client;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setImmediate(boolean immediate) {
+ this.immediate = immediate;
+ }
+
+ public void setDisabled(boolean disabled) {
+ this.disabled = disabled;
+ }
+
+ public void setReadOnly(boolean readonly) {
+ this.readonly = readonly;
+ }
+
+ private boolean isVertical() {
+ return orientation == SliderOrientation.VERTICAL;
+ }
+
+ public void setOrientation(SliderOrientation orientation) {
+ if (this.orientation != orientation) {
+ this.orientation = orientation;
+
+ if (isVertical()) {
+ addStyleName(VSlider.CLASSNAME + "-vertical");
+ } else {
+ removeStyleName(VSlider.CLASSNAME + "-vertical");
+ }
+ }
+ }
+
+ public void setMinValue(double value) {
+ min = value;
+ }
+
+ public void setMaxValue(double value) {
+ max = value;
+ }
+
+ public void setResolution(int resolution) {
+ this.resolution = resolution;
+ }
+
+ public HandlerRegistration addValueChangeHandler(
+ ValueChangeHandler<Double> handler) {
+ return addHandler(handler, ValueChangeEvent.getType());
+ }
+
+ public Double getValue() {
+ return value;
+ }
+
+ public void setValue(Double value) {
+ if (value < min) {
+ value = min;
+ } else if (value > max) {
+ value = max;
+ }
+
+ // Update handle position
+ final String styleAttribute = isVertical() ? "marginTop" : "marginLeft";
+ final String domProperty = isVertical() ? "offsetHeight"
+ : "offsetWidth";
+ final int handleSize = Integer.parseInt(DOM.getElementProperty(handle,
+ domProperty));
+ final int baseSize = Integer.parseInt(DOM.getElementProperty(base,
+ domProperty)) - (2 * BASE_BORDER_WIDTH);
+
+ final int range = baseSize - handleSize;
+ double v = value.doubleValue();
+
+ // Round value to resolution
+ if (resolution > 0) {
+ v = Math.round(v * Math.pow(10, resolution));
+ v = v / Math.pow(10, resolution);
+ } else {
+ v = Math.round(v);
+ }
+ final double valueRange = max - min;
+ double p = 0;
+ if (valueRange > 0) {
+ p = range * ((v - min) / valueRange);
+ }
+ if (p < 0) {
+ p = 0;
+ }
+ if (isVertical()) {
+ p = range - p;
+ }
+ final double pos = p;
+
+ DOM.setStyleAttribute(handle, styleAttribute, (Math.round(pos)) + "px");
+
+ // Update value
+ this.value = new Double(v);
+ setFeedbackValue(v);
+ }
+
+ public void setValue(Double value, boolean fireEvents) {
+ if (value == null) {
+ return;
+ }
+
+ setValue(value);
+
+ if (fireEvents) {
+ fireValueChanged();
+ }
+ }
}
diff --git a/server/src/com/vaadin/ui/Slider.java b/server/src/com/vaadin/ui/Slider.java
index d4e2db4853..a0b1d01b01 100644
--- a/server/src/com/vaadin/ui/Slider.java
+++ b/server/src/com/vaadin/ui/Slider.java
@@ -16,11 +16,9 @@
package com.vaadin.ui;
-import java.util.Map;
-
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.Vaadin6Component;
+import com.vaadin.shared.ui.slider.SliderOrientation;
+import com.vaadin.shared.ui.slider.SliderServerRpc;
+import com.vaadin.shared.ui.slider.SliderState;
/**
* A component for selecting a numerical value within a range.
@@ -41,9 +39,9 @@ import com.vaadin.terminal.Vaadin6Component;
* vl.addComponent(volumeIndicator);
* volumeIndicator.setValue("Current volume:" + 50.0);
* slider.addListener(this);
- *
+ *
* }
- *
+ *
* public void setVolume(double d) {
* volumeIndicator.setValue("Current volume: " + d);
* }
@@ -58,28 +56,29 @@ import com.vaadin.terminal.Vaadin6Component;
*
* @author Vaadin Ltd.
*/
-public class Slider extends AbstractField<Double> implements Vaadin6Component {
-
- public static final int ORIENTATION_HORIZONTAL = 0;
-
- public static final int ORIENTATION_VERTICAL = 1;
+public class Slider extends AbstractField<Double> {
- /** Minimum value of slider */
- private double min = 0;
+ private SliderServerRpc rpc = new SliderServerRpc() {
- /** Maximum value of slider */
- private double max = 100;
+ @Override
+ public void valueChanged(double value) {
- /**
- * Resolution, how many digits are considered relevant after the decimal
- * point. Must be a non-negative value
- */
- private int resolution = 0;
+ try {
+ setValue(value, true);
+ } catch (final ValueOutOfBoundsException e) {
+ // Convert to nearest bound
+ double out = e.getValue().doubleValue();
+ if (out < getState().getMinValue()) {
+ out = getState().getMinValue();
+ }
+ if (out > getState().getMaxValue()) {
+ out = getState().getMaxValue();
+ }
+ Slider.super.setValue(new Double(out), false);
+ }
+ }
- /**
- * Slider orientation (horizontal/vertical), defaults .
- */
- private int orientation = ORIENTATION_HORIZONTAL;
+ };
/**
* Default slider constructor. Sets all values to defaults and the slide
@@ -88,7 +87,8 @@ public class Slider extends AbstractField<Double> implements Vaadin6Component {
*/
public Slider() {
super();
- super.setValue(new Double(min));
+ registerRpc(rpc);
+ super.setValue(new Double(getState().getMinValue()));
}
/**
@@ -153,13 +153,18 @@ public class Slider extends AbstractField<Double> implements Vaadin6Component {
setCaption(caption);
}
+ @Override
+ public SliderState getState() {
+ return (SliderState) super.getState();
+ }
+
/**
* Gets the maximum slider value
*
* @return the largest value the slider can have
*/
public double getMax() {
- return max;
+ return getState().getMaxValue();
}
/**
@@ -170,11 +175,10 @@ public class Slider extends AbstractField<Double> implements Vaadin6Component {
* The new maximum slider value
*/
public void setMax(double max) {
- this.max = max;
+ getState().setMaxValue(max);
if (getValue() > max) {
setValue(max);
}
- markAsDirty();
}
/**
@@ -183,7 +187,7 @@ public class Slider extends AbstractField<Double> implements Vaadin6Component {
* @return the smallest value the slider can have
*/
public double getMin() {
- return min;
+ return getState().getMinValue();
}
/**
@@ -194,33 +198,32 @@ public class Slider extends AbstractField<Double> implements Vaadin6Component {
* The new minimum slider value
*/
public void setMin(double min) {
- this.min = min;
+ getState().setMinValue(min);
if (getValue() < min) {
setValue(min);
}
- markAsDirty();
}
/**
* Get the current orientation of the slider (horizontal or vertical).
*
- * @return {@link #ORIENTATION_HORIZONTAL} or
- * {@link #ORIENTATION_HORIZONTAL}
+ * @return {@link SliderOrientation#HORIZONTAL} or
+ * {@link SliderOrientation#VERTICAL}
*/
- public int getOrientation() {
- return orientation;
+ public SliderOrientation getOrientation() {
+ return getState().getOrientation();
}
/**
* Set the orientation of the slider.
*
- * @param The
- * new orientation, either {@link #ORIENTATION_HORIZONTAL} or
- * {@link #ORIENTATION_VERTICAL}
+ * @param orientation
+ * The new orientation, either
+ * {@link SliderOrientation#HORIZONTAL} or
+ * {@link SliderOrientation#VERTICAL}
*/
- public void setOrientation(int orientation) {
- this.orientation = orientation;
- markAsDirty();
+ public void setOrientation(SliderOrientation orientation) {
+ getState().setOrientation(orientation);
}
/**
@@ -230,21 +233,24 @@ public class Slider extends AbstractField<Double> implements Vaadin6Component {
* @return resolution
*/
public int getResolution() {
- return resolution;
+ return getState().getResolution();
}
/**
* Set a new resolution for the slider. The resolution is the number of
* digits after the decimal point.
*
+ * @throws IllegalArgumentException
+ * if resolution is negative.
+ *
* @param resolution
*/
public void setResolution(int resolution) {
if (resolution < 0) {
- return;
+ throw new IllegalArgumentException(
+ "Cannot set a negative resolution to Slider");
}
- this.resolution = resolution;
- markAsDirty();
+ getState().setResolution(resolution);
}
/**
@@ -261,87 +267,36 @@ public class Slider extends AbstractField<Double> implements Vaadin6Component {
@Override
protected void setValue(Double value, boolean repaintIsNotNeeded) {
final double v = value.doubleValue();
+ final int resolution = getResolution();
double newValue;
+
if (resolution > 0) {
// Round up to resolution
newValue = (int) (v * Math.pow(10, resolution));
newValue = newValue / Math.pow(10, resolution);
- if (min > newValue || max < newValue) {
+ if (getMin() > newValue || getMax() < newValue) {
throw new ValueOutOfBoundsException(value);
}
} else {
newValue = (int) v;
- if (min > newValue || max < newValue) {
+ if (getMin() > newValue || getMax() < newValue) {
throw new ValueOutOfBoundsException(value);
}
}
+
+ getState().setValue(newValue);
super.setValue(newValue, repaintIsNotNeeded);
}
@Override
- public void setValue(Object newFieldValue)
- throws com.vaadin.data.Property.ReadOnlyException {
- if (newFieldValue != null && newFieldValue instanceof Number
- && !(newFieldValue instanceof Double)) {
+ public void setValue(Object newFieldValue) {
+ if (newFieldValue instanceof Number) {
// Support setting all types of Numbers
newFieldValue = ((Number) newFieldValue).doubleValue();
}
-
- super.setValue(newFieldValue);
- }
-
- @Override
- public void paintContent(PaintTarget target) throws PaintException {
-
- target.addAttribute("min", min);
- if (max > min) {
- target.addAttribute("max", max);
- } else {
- target.addAttribute("max", min);
- }
- target.addAttribute("resolution", resolution);
-
- if (resolution > 0) {
- target.addVariable(this, "value", getValue().doubleValue());
- } else {
- target.addVariable(this, "value", getValue().intValue());
- }
-
- if (orientation == ORIENTATION_VERTICAL) {
- target.addAttribute("vertical", true);
- }
-
- }
-
- /**
- * Invoked when the value of a variable has changed. Slider listeners are
- * notified if the slider value has changed.
- *
- * @param source
- * @param variables
- */
- @Override
- public void changeVariables(Object source, Map<String, Object> variables) {
- if (variables.containsKey("value")) {
- final Object value = variables.get("value");
- final Double newValue = new Double(value.toString());
- if (newValue != null && newValue != getValue()
- && !newValue.equals(getValue())) {
- try {
- setValue(newValue, true);
- } catch (final ValueOutOfBoundsException e) {
- // Convert to nearest bound
- double out = e.getValue().doubleValue();
- if (out < min) {
- out = min;
- }
- if (out > max) {
- out = max;
- }
- super.setValue(new Double(out), false);
- }
- }
- }
+ setValue(newFieldValue);
+ // The cast is safe if the above call returned without throwing
+ getState().setValue((Double) newFieldValue);
}
/**
@@ -373,7 +328,6 @@ public class Slider extends AbstractField<Double> implements Vaadin6Component {
public Double getValue() {
return value;
}
-
}
@Override
diff --git a/shared/src/com/vaadin/shared/ui/slider/SliderOrientation.java b/shared/src/com/vaadin/shared/ui/slider/SliderOrientation.java
new file mode 100644
index 0000000000..d130550946
--- /dev/null
+++ b/shared/src/com/vaadin/shared/ui/slider/SliderOrientation.java
@@ -0,0 +1,5 @@
+package com.vaadin.shared.ui.slider;
+
+public enum SliderOrientation {
+ HORIZONTAL, VERTICAL;
+}
diff --git a/shared/src/com/vaadin/shared/ui/slider/SliderServerRpc.java b/shared/src/com/vaadin/shared/ui/slider/SliderServerRpc.java
new file mode 100644
index 0000000000..6ea02f0a95
--- /dev/null
+++ b/shared/src/com/vaadin/shared/ui/slider/SliderServerRpc.java
@@ -0,0 +1,14 @@
+package com.vaadin.shared.ui.slider;
+
+import com.vaadin.shared.communication.ServerRpc;
+
+public interface SliderServerRpc extends ServerRpc {
+
+ /**
+ * Invoked when the value of a variable has changed. Slider listeners are
+ * notified if the slider value has changed.
+ *
+ * @param value
+ */
+ public void valueChanged(double value);
+}
diff --git a/shared/src/com/vaadin/shared/ui/slider/SliderState.java b/shared/src/com/vaadin/shared/ui/slider/SliderState.java
new file mode 100644
index 0000000000..98168b80af
--- /dev/null
+++ b/shared/src/com/vaadin/shared/ui/slider/SliderState.java
@@ -0,0 +1,60 @@
+package com.vaadin.shared.ui.slider;
+
+import com.vaadin.shared.AbstractFieldState;
+
+public class SliderState extends AbstractFieldState {
+
+ protected double value;
+
+ protected double maxValue;
+ protected double minValue;
+
+ /**
+ * The number of fractional digits that are considered significant. Must be
+ * non-negative.
+ */
+ protected int resolution;
+
+ protected SliderOrientation orientation;
+
+ public double getValue() {
+ return value;
+ }
+
+ public void setValue(double value) {
+ this.value = value;
+ }
+
+ public double getMaxValue() {
+ return maxValue;
+ }
+
+ public void setMaxValue(double maxValue) {
+ this.maxValue = maxValue;
+ }
+
+ public double getMinValue() {
+ return minValue;
+ }
+
+ public void setMinValue(double minValue) {
+ this.minValue = minValue;
+ }
+
+ public int getResolution() {
+ return resolution;
+ }
+
+ public void setResolution(int resolution) {
+ this.resolution = resolution;
+ }
+
+ public SliderOrientation getOrientation() {
+ return orientation;
+ }
+
+ public void setOrientation(SliderOrientation orientation) {
+ this.orientation = orientation;
+ }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/components/slider/SliderTest.java b/tests/testbench/com/vaadin/tests/components/slider/SliderTest.java
index 9be1fea987..0b9c2d6c5a 100644
--- a/tests/testbench/com/vaadin/tests/components/slider/SliderTest.java
+++ b/tests/testbench/com/vaadin/tests/components/slider/SliderTest.java
@@ -2,6 +2,7 @@ package com.vaadin.tests.components.slider;
import java.util.LinkedHashMap;
+import com.vaadin.shared.ui.slider.SliderOrientation;
import com.vaadin.tests.components.abstractfield.AbstractFieldTest;
import com.vaadin.ui.Slider;
@@ -21,9 +22,9 @@ public class SliderTest extends AbstractFieldTest<Slider> {
}
};
- private Command<Slider, Integer> orientationCommand = new Command<Slider, Integer>() {
+ private Command<Slider, SliderOrientation> orientationCommand = new Command<Slider, SliderOrientation>() {
@Override
- public void execute(Slider c, Integer value, Object data) {
+ public void execute(Slider c, SliderOrientation value, Object data) {
c.setOrientation(value);
}
};
@@ -56,9 +57,9 @@ public class SliderTest extends AbstractFieldTest<Slider> {
}
private void createOrientationSelect(String category) {
- LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
- options.put("Horizontal", Slider.ORIENTATION_HORIZONTAL);
- options.put("Vertical", Slider.ORIENTATION_VERTICAL);
+ LinkedHashMap<String, SliderOrientation> options = new LinkedHashMap<String, SliderOrientation>();
+ options.put("Horizontal", SliderOrientation.HORIZONTAL);
+ options.put("Vertical", SliderOrientation.VERTICAL);
createSelectAction("Orientation", category, options, "Horizontal",
orientationCommand);
diff --git a/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java b/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java
index 41a3d18f9f..a233191070 100644
--- a/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java
+++ b/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java
@@ -10,6 +10,7 @@ import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.event.Action;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.shared.ui.label.ContentMode;
+import com.vaadin.shared.ui.slider.SliderOrientation;
import com.vaadin.terminal.ExternalResource;
import com.vaadin.terminal.Page;
import com.vaadin.terminal.Resource;
@@ -39,7 +40,6 @@ import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Panel;
import com.vaadin.ui.PopupView;
-import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.Slider;
import com.vaadin.ui.Slider.ValueOutOfBoundsException;
import com.vaadin.ui.TabSheet;
@@ -50,6 +50,7 @@ import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Tree;
import com.vaadin.ui.TwinColSelect;
+import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.VerticalSplitPanel;
import com.vaadin.ui.Window;
@@ -534,7 +535,7 @@ public class LiferayThemeDemo extends Application.LegacyApplication {
l.addComponent(new Label("Vertical Slider", ContentMode.XHTML));
s = new Slider();
- s.setOrientation(Slider.ORIENTATION_VERTICAL);
+ s.setOrientation(SliderOrientation.VERTICAL);
s.setHeight("200px");
try {
s.setValue(50);