summaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/ui/Slider.java
diff options
context:
space:
mode:
authorJouni Koivuviita <jouni.koivuviita@itmill.com>2007-07-30 13:22:40 +0000
committerJouni Koivuviita <jouni.koivuviita@itmill.com>2007-07-30 13:22:40 +0000
commitb88e9d23a54a5e8a63272a4b4e90eb1151dbfd29 (patch)
tree9e959434192b6300b935fe7e7dd3c80b896cd290 /src/com/itmill/toolkit/ui/Slider.java
parent545e7b8034f1670232d460a1c5854adf2f348f48 (diff)
downloadvaadin-framework-b88e9d23a54a5e8a63272a4b4e90eb1151dbfd29.tar.gz
vaadin-framework-b88e9d23a54a5e8a63272a4b4e90eb1151dbfd29.zip
Slider component updated with proper implementation and styles.
svn changeset:1925/svn branch:trunk
Diffstat (limited to 'src/com/itmill/toolkit/ui/Slider.java')
-rw-r--r--src/com/itmill/toolkit/ui/Slider.java169
1 files changed, 85 insertions, 84 deletions
diff --git a/src/com/itmill/toolkit/ui/Slider.java b/src/com/itmill/toolkit/ui/Slider.java
index 2d7e253821..41ecb63d10 100644
--- a/src/com/itmill/toolkit/ui/Slider.java
+++ b/src/com/itmill/toolkit/ui/Slider.java
@@ -1,7 +1,6 @@
package com.itmill.toolkit.ui;
import java.util.Map;
-import java.util.Set;
import com.itmill.toolkit.terminal.PaintException;
import com.itmill.toolkit.terminal.PaintTarget;
@@ -12,9 +11,9 @@ public class Slider extends AbstractField {
public static final int ORIENTATION_VERTICAL = 1;
/** Minimum value of slider */
- private float min = 0;
+ private double min = 0;
/** Maximum value of slider */
- private float max = 100;
+ private double max = 100;
/**
* Resolution, how many digits are considered relevant after desimal point.
@@ -22,12 +21,6 @@ public class Slider extends AbstractField {
*/
private int resolution = 0;
- /**
- * Object values for slider in stead of numeric (usually strings).
- * If this is set, min, max and resolution values are ignored.
- */
- private Set values;
-
/**
* Slider orientation (horizontal==default/vertical).
*/
@@ -44,15 +37,45 @@ public class Slider extends AbstractField {
* Handle size in percents related to base size.
* Must be a value between 1-100.
*/
- private int handleSize = 20;
+ private int handleSize = -1;
+ /**
+ * Show arrows that can be pressed to slide the
+ * handle in some increments (client-side
+ * implementation decides the increment).
+ */
+ private boolean arrows = true;
public Slider() {
super();
- super.setValue(new Float(min));
+ super.setValue(new Double(min));
+ }
+
+ public Slider(String caption) {
+ this();
+ setCaption(caption);
+ }
+
+ public Slider(double min, double max, int resolution) {
+ this();
+ setMin(min);
+ setMax(max);
+ setResolution(resolution);
+ }
+
+ public Slider(int min, int max) {
+ this();
+ setMin(min);
+ setMax(max);
+ setResolution(0);
+ }
+
+ public Slider(String caption, int min, int max) {
+ this(min, max);
+ setCaption(caption);
}
- public float getMax() {
+ public double getMax() {
return max;
}
@@ -60,19 +83,20 @@ public class Slider extends AbstractField {
* Set the maximum value of the Slider. As a side-effect nullifies the "values" Set.
* @param max
*/
- public void setMax(float max) {
+ public void setMax(double max) {
this.max = max;
- this.values = null;
try {
if((new Float(getValue().toString())).floatValue() > max)
super.setValue(new Float(min));
} catch(ClassCastException e) {
super.setValue(new Float(max));
}
+ if(handleSize == -1)
+ handleSize = (int) ((max-min)/max*10 + (max-min)/10);
requestRepaint();
}
- public float getMin() {
+ public double getMin() {
return min;
}
@@ -80,15 +104,16 @@ public class Slider extends AbstractField {
* Set the minimum value of the Slider. As a side-effect nullifies the "values" Set.
* @param max
*/
- public void setMin(float min) {
+ public void setMin(double min) {
this.min = min;
- this.values = null;
try {
- if((new Float(getValue().toString())).floatValue() < min)
- super.setValue(new Float(min));
+ if((new Double(getValue().toString())).doubleValue() < min)
+ super.setValue(new Double(min));
} catch(ClassCastException e) {
- super.setValue(new Float(min));
+ super.setValue(new Double(min));
}
+ if(handleSize == -1)
+ handleSize = (int) ((max-min)/max*10 + (max-min)/10);
requestRepaint();
}
@@ -112,47 +137,24 @@ public class Slider extends AbstractField {
requestRepaint();
}
- public Set getValues() {
- return values;
- }
-
- public void setValues(Set values) {
- this.values = values;
- requestRepaint();
- }
-
- public void setValue(Float value, boolean repaintIsNotNeeded) throws ValueOutOfBoundsException {
- float v = new Float(value.toString()).floatValue();
- Object newValue;
+ public void setValue(Double value, boolean repaintIsNotNeeded) throws ValueOutOfBoundsException {
+ double v = new Double(value.toString()).doubleValue();
+ double newValue;
if(resolution>0) {
// Round up to resolution
- newValue = new Float(v * (resolution*10) / (resolution*10));
- if(min > ((Float)newValue).floatValue() || max < ((Float)newValue).floatValue())
+ newValue = (int) (v * (double) Math.pow(10, resolution));
+ newValue = newValue / (double) Math.pow(10, resolution);
+ if(min > newValue || max < newValue)
throw new ValueOutOfBoundsException(value);
} else {
- newValue = new Float((int) v);
- if(min > ((Float)newValue).intValue() || max < ((Float)newValue).intValue())
+ newValue = (int) v;
+ if(min > newValue || max < newValue)
throw new ValueOutOfBoundsException(value);
}
- super.setValue(newValue, repaintIsNotNeeded);
+ super.setValue(new Double(newValue), repaintIsNotNeeded);
}
- public void setValue(Float value)throws ValueOutOfBoundsException {
- setValue(value, false);
- }
-
- public void setValue(String value, boolean repaintIsNotNeeded) throws ValueOutOfBoundsException {
- if(this.values != null) {
- String v = new String(value.toString());
- if(this.values.contains(v))
- super.setValue(v, repaintIsNotNeeded);
- else throw new ValueOutOfBoundsException(value);
- } else {
- // TODO
- }
- }
-
- public void setValue(String value) throws ValueOutOfBoundsException {
+ public void setValue(Double value) throws ValueOutOfBoundsException {
setValue(value, false);
}
@@ -175,6 +177,15 @@ public class Slider extends AbstractField {
this.handleSize = handleSize;
requestRepaint();
}
+
+ public void setArrows(boolean visible) {
+ arrows = visible;
+ requestRepaint();
+ }
+
+ public boolean arrowsVisible() {
+ return arrows;
+ }
public String getTag() {
return "slider";
@@ -182,26 +193,22 @@ public class Slider extends AbstractField {
public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);
-
- if(values == null) {
-
- target.addAttribute("min", (long) min);
- target.addAttribute("max", (long) max);
- target.addAttribute("resolution", resolution);
-
- if(resolution > 0)
- target.addVariable(this, "value", ((Float)getValue()).floatValue());
- else
- target.addVariable(this, "value", ((Float)getValue()).intValue());
- } else {
- target.addVariable(this, "value", getValue().toString());
- target.addAttribute("values", values.toArray(new String[values.size()]));
- }
+ target.addAttribute("min", min);
+ target.addAttribute("max", max);
+ target.addAttribute("resolution", resolution);
+ if(resolution > 0)
+ target.addVariable(this, "value", ((Double)getValue()).doubleValue());
+ else
+ target.addVariable(this, "value", ((Double)getValue()).intValue());
+
if(orientation == ORIENTATION_VERTICAL)
target.addAttribute("vertical", true);
+ if(arrows)
+ target.addAttribute("arrows", true);
+
if(size > -1)
target.addAttribute("size", size);
@@ -219,16 +226,12 @@ public class Slider extends AbstractField {
public void changeVariables(Object source, Map variables) {
if (variables.containsKey("value")) {
Object newValue = variables.get("value");
- if(values == null) {
- if(resolution >0)
- newValue = new Long(newValue.toString());
- else
- newValue = new Integer(newValue.toString());
- if(newValue != null && newValue != getValue() && !newValue.equals(getValue())) {
- setValue(newValue);
- }
- } else {
- // TODO
+ if(resolution > 0)
+ newValue = new Double(newValue.toString());
+ else
+ newValue = new Integer(newValue.toString());
+ if(newValue != null && newValue != getValue() && !newValue.equals(getValue())) {
+ setValue(newValue, true);
}
}
}
@@ -240,7 +243,7 @@ public class Slider extends AbstractField {
*/
private static final long serialVersionUID = -6451298598644446340L;
- private Object value;
+ private Double value;
/**
* Constructs an <code>ValueOutOfBoundsException</code> with the specified
@@ -248,20 +251,18 @@ public class Slider extends AbstractField {
*
* @param valueOutOfBounds
*/
- public ValueOutOfBoundsException(Object valueOutOfBounds) {
+ public ValueOutOfBoundsException(Double valueOutOfBounds) {
this.value = valueOutOfBounds;
}
- public Object getValue() {
+ public Double getValue() {
return this.value;
}
}
public Class getType() {
- if(values == null)
- return Float.class;
- return String.class;
+ return Double.class;
}
}