diff options
3 files changed, 109 insertions, 53 deletions
diff --git a/server/src/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java b/server/src/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java index fee52d1a24..b1eef16024 100644 --- a/server/src/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java +++ b/server/src/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java @@ -276,11 +276,9 @@ public class ColorPickerPopup extends Window implements ClickListener, sliders.setStyleName("rgb-sliders"); redSlider = createRGBSlider("Red", "red"); - - try { - redSlider.setValue(((Integer) color.getRed()).doubleValue()); - } catch (ValueOutOfBoundsException e) { - } + greenSlider = createRGBSlider("Green", "green"); + blueSlider = createRGBSlider("Blue", "blue"); + setRgbSliderValues(color); redSlider.addValueChangeListener(new ValueChangeListener() { @Override @@ -296,13 +294,6 @@ public class ColorPickerPopup extends Window implements ClickListener, sliders.addComponent(redSlider); - greenSlider = createRGBSlider("Green", "green"); - - try { - greenSlider.setValue(((Integer) color.getGreen()).doubleValue()); - } catch (ValueOutOfBoundsException e) { - } - greenSlider.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { @@ -316,13 +307,6 @@ public class ColorPickerPopup extends Window implements ClickListener, }); sliders.addComponent(greenSlider); - blueSlider = createRGBSlider("Blue", "blue"); - - try { - blueSlider.setValue(((Integer) color.getBlue()).doubleValue()); - } catch (ValueOutOfBoundsException e) { - } - blueSlider.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { @@ -368,15 +352,15 @@ public class ColorPickerPopup extends Window implements ClickListener, hsvLayout.addComponent(hsvGradient); selectors.add(hsvGradient); - 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) { - } + saturationSlider = new Slider("Saturation", 0, 100); + valueSlider = new Slider("Value", 0, 100); + + float[] hsv = color.getHSV(); + setHsvSliderValues(hsv); hueSlider.setStyleName("hsv-slider"); hueSlider.addStyleName("hue-slider"); @@ -410,13 +394,6 @@ public class ColorPickerPopup extends Window implements ClickListener, }); 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); @@ -438,13 +415,6 @@ public class ColorPickerPopup extends Window implements ClickListener, }); sliders.addComponent(saturationSlider); - valueSlider = new Slider("Value", 0, 100); - - try { - valueSlider.setValue(((Float) hsv[2]).doubleValue()); - } catch (ValueOutOfBoundsException e1) { - } - valueSlider.setStyleName("hsv-slider"); valueSlider.setWidth("220px"); valueSlider.setImmediate(true); @@ -576,23 +546,11 @@ public class ColorPickerPopup extends Window implements ClickListener, setColor(event.getColor()); updatingColors = true; - try { - redSlider - .setValue(((Integer) selectedColor.getRed()).doubleValue()); - blueSlider.setValue(((Integer) selectedColor.getBlue()) - .doubleValue()); - greenSlider.setValue(((Integer) selectedColor.getGreen()) - .doubleValue()); - - float[] hsv = selectedColor.getHSV(); - hueSlider.setValue(((Float) (hsv[0] * 360f)).doubleValue()); - saturationSlider.setValue(((Float) (hsv[1] * 100f)).doubleValue()); - valueSlider.setValue(((Float) (hsv[2] * 100f)).doubleValue()); + setRgbSliderValues(selectedColor); + float[] hsv = selectedColor.getHSV(); + setHsvSliderValues(hsv); - } catch (ValueOutOfBoundsException e) { - e.printStackTrace(); - } updatingColors = false; for (ColorSelector s : selectors) { @@ -603,6 +561,26 @@ public class ColorPickerPopup extends Window implements ClickListener, } } + private void setRgbSliderValues(Color color) { + try { + redSlider.setValue(((Integer) color.getRed()).doubleValue()); + blueSlider.setValue(((Integer) color.getBlue()).doubleValue()); + greenSlider.setValue(((Integer) color.getGreen()).doubleValue()); + } catch (ValueOutOfBoundsException e) { + e.printStackTrace(); + } + } + + private void setHsvSliderValues(float[] hsv) { + try { + hueSlider.setValue(((Float) (hsv[0] * 360f)).doubleValue()); + saturationSlider.setValue(((Float) (hsv[1] * 100f)).doubleValue()); + valueSlider.setValue(((Float) (hsv[2] * 100f)).doubleValue()); + } catch (ValueOutOfBoundsException e) { + e.printStackTrace(); + } + } + @Override public void addColorChangeListener(ColorChangeListener listener) { addListener(ColorChangeEvent.class, listener, COLOR_CHANGE_METHOD); diff --git a/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerHsvTest.html b/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerHsvTest.html new file mode 100644 index 0000000000..1c53673b41 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerHsvTest.html @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head profile="http://selenium-ide.openqa.org/profiles/test-case"> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<link rel="selenium.base" href="" /> +<title>ColorPickerTest</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3">ColorPickerTest</td></tr> +</thead><tbody> +<tr> + <td>open</td> + <td>/run/com.vaadin.tests.components.colorpicker.ColorPickerHsvTest?restartApplication</td> + <td></td> +</tr> +<!-- verify HSV sliders when initially opening the tab, ticket #7863 --> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerHsvTest::PID_Scolorpicker/domChild[1]</td> + <td>20,16</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerHsvTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/Slot[0]/VTabsheet[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]</td> + <td>16,5</td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>hsv-initial-sliders</td> +</tr> +</tbody></table> +</body> +</html> diff --git a/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerHsvTest.java b/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerHsvTest.java new file mode 100644 index 0000000000..ab77fbf2ba --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerHsvTest.java @@ -0,0 +1,41 @@ +package com.vaadin.tests.components.colorpicker; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.colorpicker.Color; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ColorPickerArea; +import com.vaadin.ui.Label; +import com.vaadin.ui.VerticalLayout; + +/** + * Tests the HSV tab slider values when initially opening the tab. + */ +public class ColorPickerHsvTest extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + + layout.addComponent(new Label( + "HSV initial values when opening the tab for the first time")); + ColorPickerArea colorpicker = new ColorPickerArea(); + colorpicker.setColor(new Color(Integer.parseInt("00b4f0", 16))); + colorpicker.setDefaultCaptionEnabled(false); + colorpicker.setId("colorpicker"); + layout.addComponent(colorpicker); + + } + + @Override + protected String getTestDescription() { + return "Tests the slider values when initially opening the HSV tab."; + } + + @Override + protected Integer getTicketNumber() { + return 7863; + } + +} |