float[] hsv = color.getHSV();
VerticalLayout sliders = new VerticalLayout();
sliders.setStyleName("hsv-sliders");
hueSlider = new Slider("Hue", 0, 360);
try {
hueSlider.setValue(((Float) hsv[0]).doubleValue());
} catch (ValueOutOfBoundsException e1) {
}
hueSlider.setStyleName("hsv-slider");
hueSlider.addStyleName("hue-slider");
hueSlider.setWidth("220px");
hueSlider.setImmediate(true);
hueSlider.addValueChangeListener(new ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
if (!updatingColors) {
float hue = (Float.parseFloat(event.getProperty()
.getValue().toString())) / 360f;
float saturation = (Float.parseFloat(saturationSlider
.getValue().toString())) / 100f;
float value = (Float.parseFloat(valueSlider.getValue()
.toString())) / 100f;
// Set the color
Color color = new Color(Color.HSVtoRGB(hue, saturation,
value));
setColor(color);
/*
* Set the background color of the hue gradient. This has to
* be done here since in the conversion the base color
* information is lost when color is black/white
*/
Color bgColor = new Color(Color.HSVtoRGB(hue, 1f, 1f));
hsvGradient.setBackgroundColor(bgColor);
}
}
});
sliders.addComponent(hueSlider);
saturationSlider = new Slider("Saturation", 0, 100);
try {
saturationSlider.setValue(((Float) hsv[1]).doubleValue());
} catch (ValueOutOfBoundsException e1) {
}
saturationSlider.setStyleName("hsv-slider");
saturationSlider.setWidth("220px");
saturationSlider.setImmediate(true);
saturationSlider.addValueChangeListener(new ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
if (!updatingColors) {
float hue = (Float.parseFloat(hueSlider.getValue()
.toString())) / 360f;
float saturation = (Float.parseFloat(event.getProperty()
.getValue().toString())) / 100f;
float value = (Float.parseFloat(valueSlider.getValue()
.toString())) / 100f;
Color color = new Color(Color.HSVtoRGB(hue, saturation,
value));
setColor(color);
}
}
});
sliders.addComponent(saturationSlider);
valueSlider = new Slider("Value", 0, 100);
try {
valueSlider.setValue(((Float) hsv[2]).doubleValue());
} catch (ValueOutOfBoundsException e1) {
}