]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed slider value initialization on HSV and RGB tabs of ColorPicker. (#7863)
authorTeemu Pòˆntelin <teemu@vaadin.com>
Fri, 28 Jun 2013 12:13:45 +0000 (15:13 +0300)
committerVaadin Code Review <review@vaadin.com>
Fri, 28 Jun 2013 13:04:31 +0000 (13:04 +0000)
Change-Id: I3776400d849d4ba9f76d6296603152c0a6464aaa

server/src/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java
uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerHsvTest.html [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerHsvTest.java [new file with mode: 0644]

index fee52d1a24d1ec65da459db886a9696b250b436b..b1eef16024fffaf367ea66223731cd88403b2f11 100644 (file)
@@ -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 (file)
index 0000000..1c53673
--- /dev/null
@@ -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 (file)
index 0000000..ab77fbf
--- /dev/null
@@ -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;
+    }
+
+}