summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui/Slider.java
diff options
context:
space:
mode:
authorSauli Tähkäpää <sauli@vaadin.com>2015-02-25 16:54:59 +0200
committerVaadin Code Review <review@vaadin.com>2015-02-27 16:28:43 +0000
commitf0a04197be3b536b23889bcce3178962b5e10733 (patch)
tree24e323e9f07c3eaedf1e7de7a64775a283db36d7 /server/src/com/vaadin/ui/Slider.java
parentc9586c93b93987d9b5942c38ef0b536c091092a5 (diff)
downloadvaadin-framework-f0a04197be3b536b23889bcce3178962b5e10733.tar.gz
vaadin-framework-f0a04197be3b536b23889bcce3178962b5e10733.zip
Ensure that slider min is always smaller or equal to max. (#16776)
- Set slider min to max if max is being set to a smaller value than min, and vice-versa. - Set also an informative message to Slider.ValueOutOfBoundsException. Change-Id: I06b6b05dd0ef2c1fb862cf4acc7df3e235db59ba
Diffstat (limited to 'server/src/com/vaadin/ui/Slider.java')
-rw-r--r--server/src/com/vaadin/ui/Slider.java18
1 files changed, 15 insertions, 3 deletions
diff --git a/server/src/com/vaadin/ui/Slider.java b/server/src/com/vaadin/ui/Slider.java
index 66ed1a48f4..dad4d295bf 100644
--- a/server/src/com/vaadin/ui/Slider.java
+++ b/server/src/com/vaadin/ui/Slider.java
@@ -161,6 +161,11 @@ public class Slider extends AbstractField<Double> {
*/
public void setMax(double max) {
getState().maxValue = max;
+
+ if (getMin() > max) {
+ getState().minValue = max;
+ }
+
if (getValue() > max) {
setValue(max);
}
@@ -179,11 +184,16 @@ public class Slider extends AbstractField<Double> {
* Set the minimum slider value. If the current value of the slider is
* smaller than this, the value is set to the new minimum.
*
- * @param max
+ * @param min
* The new minimum slider value
*/
public void setMin(double min) {
getState().minValue = min;
+
+ if (getMax() < min) {
+ getState().maxValue = min;
+ }
+
if (getValue() < min) {
setValue(min);
}
@@ -260,12 +270,12 @@ public class Slider extends AbstractField<Double> {
newValue = (int) (v * Math.pow(10, resolution));
newValue = newValue / Math.pow(10, resolution);
if (getMin() > newValue || getMax() < newValue) {
- throw new ValueOutOfBoundsException(value);
+ throw new ValueOutOfBoundsException(newValue);
}
} else {
newValue = (int) v;
if (getMin() > newValue || getMax() < newValue) {
- throw new ValueOutOfBoundsException(value);
+ throw new ValueOutOfBoundsException(newValue);
}
}
@@ -313,6 +323,8 @@ public class Slider extends AbstractField<Double> {
* @param valueOutOfBounds
*/
public ValueOutOfBoundsException(Double valueOutOfBounds) {
+ super(String.format("Value %s is out of bounds: [%s, %s]",
+ valueOutOfBounds, getMin(), getMax()));
value = valueOutOfBounds;
}