]> source.dussan.org Git - vaadin-framework.git/commitdiff
Allow editing colorpicker values in colorpicker in textfield #13469
authorJohn Ahlroos <john@vaadin.com>
Thu, 24 Apr 2014 18:12:15 +0000 (21:12 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 14 May 2014 07:25:50 +0000 (07:25 +0000)
This fix adds support for typing in color values according to
http://www.w3schools.com/cssref/css_colors_legal.asp into the
colorpicker popup input textfield.

Change-Id: If14ead791725c3052c05aa31e12e237e90c32348

server/src/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java
server/tests/src/com/vaadin/tests/server/component/colorpicker/ColorConversions.java [new file with mode: 0644]
shared/src/com/vaadin/shared/ui/colorpicker/Color.java
uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerInputFormatsTest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerTest.html
uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerTest.java [deleted file]
uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerTestUI.java [new file with mode: 0644]

index ae0f717df84307fe83578bd3e915cd8e11f4189d..ae00b267ce7dd1e34d7d31de873ac8e0a980483d 100644 (file)
@@ -19,7 +19,6 @@ import java.lang.reflect.Method;
 
 import com.vaadin.data.Property.ValueChangeEvent;
 import com.vaadin.data.Property.ValueChangeListener;
-import com.vaadin.data.validator.RegexpValidator;
 import com.vaadin.shared.ui.colorpicker.Color;
 import com.vaadin.ui.Component;
 import com.vaadin.ui.CssLayout;
@@ -67,13 +66,12 @@ public class ColorPickerPreview extends CssLayout implements ColorSelector,
         this.color = color;
 
         field = new TextField();
-        field.setReadOnly(true);
         field.setImmediate(true);
         field.setSizeFull();
         field.setStyleName("v-colorpicker-preview-textfield");
         field.setData(this);
         field.addValueChangeListener(this);
-        field.addValidator(new RegexpValidator("#[0-9a-fA-F]{6}", true, ""));
+
         addComponent(field);
 
         setColor(color);
@@ -85,7 +83,6 @@ public class ColorPickerPreview extends CssLayout implements ColorSelector,
 
         // Unregister listener
         field.removeValueChangeListener(this);
-        field.setReadOnly(false);
 
         String colorCSS = color.getCSS();
         field.setValue(colorCSS);
@@ -97,7 +94,6 @@ public class ColorPickerPreview extends CssLayout implements ColorSelector,
         }
 
         // Re-register listener
-        field.setReadOnly(true);
         field.addValueChangeListener(this);
 
         // Set the text color
@@ -130,21 +126,63 @@ public class ColorPickerPreview extends CssLayout implements ColorSelector,
     @Override
     public void valueChange(ValueChangeEvent event) {
         String value = (String) event.getProperty().getValue();
-
-        if (!field.isValid()) {
+        try {
+            if (value != null) {
+                /*
+                 * Description of supported formats see
+                 * http://www.w3schools.com/cssref/css_colors_legal.asp
+                 */
+                if (value.length() == 7 && value.startsWith("#")) {
+                    // CSS color format (e.g. #000000)
+                    int red = Integer.parseInt(value.substring(1, 3), 16);
+                    int green = Integer.parseInt(value.substring(3, 5), 16);
+                    int blue = Integer.parseInt(value.substring(5, 7), 16);
+                    color = new Color(red, green, blue);
+
+                } else if (value.startsWith("rgb")) {
+                    // RGB color format rgb/rgba(255,255,255,0.1)
+                    String[] colors = value.substring(value.indexOf("(") + 1,
+                            value.length() - 1).split(",");
+
+                    int red = Integer.parseInt(colors[0]);
+                    int green = Integer.parseInt(colors[1]);
+                    int blue = Integer.parseInt(colors[2]);
+                    if (colors.length > 3) {
+                        int alpha = (int) (Double.parseDouble(colors[3]) * 255d);
+                        color = new Color(red, green, blue, alpha);
+                    } else {
+                        color = new Color(red, green, blue);
+                    }
+
+                } else if (value.startsWith("hsl")) {
+                    // HSL color format hsl/hsla(100,50%,50%,1.0)
+                    String[] colors = value.substring(value.indexOf("(") + 1,
+                            value.length() - 1).split(",");
+
+                    int hue = Integer.parseInt(colors[0]);
+                    int saturation = Integer.parseInt(colors[1]
+                            .replace("%", ""));
+                    int lightness = Integer
+                            .parseInt(colors[2].replace("%", ""));
+                    int rgb = Color.HSLtoRGB(hue, saturation, lightness);
+
+                    if (colors.length > 3) {
+                        int alpha = (int) (Double.parseDouble(colors[3]) * 255d);
+                        color = new Color(rgb);
+                        color.setAlpha(alpha);
+                    } else {
+                        color = new Color(rgb);
+                    }
+                }
+
+                oldValue = value;
+                fireEvent(new ColorChangeEvent((Component) field.getData(),
+                        color));
+            }
+
+        } catch (NumberFormatException nfe) {
+            // Revert value
             field.setValue(oldValue);
-            return;
-        } else {
-            oldValue = value;
-        }
-
-        if (value != null && value.length() == 7) {
-            int red = Integer.parseInt(value.substring(1, 3), 16);
-            int green = Integer.parseInt(value.substring(3, 5), 16);
-            int blue = Integer.parseInt(value.substring(5, 7), 16);
-            color = new Color(red, green, blue);
-
-            fireEvent(new ColorChangeEvent((Component) field.getData(), color));
         }
     }
 
diff --git a/server/tests/src/com/vaadin/tests/server/component/colorpicker/ColorConversions.java b/server/tests/src/com/vaadin/tests/server/component/colorpicker/ColorConversions.java
new file mode 100644 (file)
index 0000000..46d72a6
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server.component.colorpicker;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.vaadin.shared.ui.colorpicker.Color;
+
+public class ColorConversions {
+
+    @Test
+    public void convertHSL2RGB() {
+
+        int rgb = Color.HSLtoRGB(100, 50, 50);
+        Color c = new Color(rgb);
+        assertEquals(106, c.getRed());
+        assertEquals(191, c.getGreen());
+        assertEquals(64, c.getBlue());
+        assertEquals("#6abf40", c.getCSS());
+
+        rgb = Color.HSLtoRGB(0, 50, 50);
+        c = new Color(rgb);
+        assertEquals(191, c.getRed());
+        assertEquals(64, c.getGreen());
+        assertEquals(64, c.getBlue());
+        assertEquals("#bf4040", c.getCSS());
+
+        rgb = Color.HSLtoRGB(50, 0, 50);
+        c = new Color(rgb);
+        assertEquals(128, c.getRed());
+        assertEquals(128, c.getGreen());
+        assertEquals(128, c.getBlue());
+        assertEquals("#808080", c.getCSS());
+
+        rgb = Color.HSLtoRGB(50, 100, 0);
+        c = new Color(rgb);
+        assertEquals(0, c.getRed(), 0);
+        assertEquals(0, c.getGreen(), 0);
+        assertEquals(0, c.getBlue(), 0);
+        assertEquals("#000000", c.getCSS());
+    }
+}
index 7fbb0ee055c645134ef2e9e367e472b0a8261e9a..86243279931abefe30f7fb2fdaae6f529f00e9a2 100644 (file)
@@ -392,4 +392,62 @@ public class Color implements Serializable {
 
         return 0xff000000 | (red << 16) | (green << 8) | (blue << 0);
     }
+
+    /**
+     * <p>
+     * Converts HSL's hue, saturation and lightness into an RGB value.
+     * 
+     * @param hue
+     *            the hue of the color. The unit of the value is degrees and
+     *            should be between 0-360.
+     * @param saturation
+     *            the saturation of the color. The unit of the value is
+     *            percentages and should be between 0-100;
+     * @param lightness
+     *            the lightness of the color. The unit of the value is
+     *            percentages and should be between 0-100;
+     * 
+     * @return the RGB value of corresponding color
+     */
+    public static int HSLtoRGB(int hue, int saturation, int lightness) {
+        int red = 0;
+        int green = 0;
+        int blue = 0;
+
+        float hueRatio = hue / 360f;
+        float saturationRatio = saturation / 100f;
+        float lightnessRatio = lightness / 100f;
+
+        if (saturationRatio == 0) {
+            red = green = blue = (int) (lightnessRatio * 255.0f + 0.5f);
+        } else {
+            float p = lightnessRatio < 0.5f ? lightnessRatio
+                    * (1f + saturationRatio) : lightnessRatio + saturationRatio
+                    - lightnessRatio * saturationRatio;
+            float q = 2 * lightnessRatio - p;
+
+            red = hslComponentToRgbComponent(p, q, hueRatio + (1f / 3f));
+            green = hslComponentToRgbComponent(p, q, hueRatio);
+            blue = hslComponentToRgbComponent(p, q, hueRatio - (1f / 3f));
+        }
+        return 0xff000000 | (red << 16) | (green << 8) | (blue << 0);
+    }
+
+    private static int hslComponentToRgbComponent(float p, float q, float ratio) {
+        if (ratio < 0) {
+            ratio += 1;
+        } else if (ratio > 1) {
+            ratio -= 1;
+        }
+
+        if (6 * ratio < 1f) {
+            return (int) ((q + (p - q) * 6f * ratio) * 255f + 0.5f);
+        } else if (2f * ratio < 1f) {
+            return (int) (p * 255f + 0.5f);
+        } else if (3f * ratio < 2f) {
+            return (int) ((q + (p - q) * ((2f / 3f) - ratio) * 6f) * 255f + 0.5f);
+        }
+
+        return (int) (q * 255f + 0.5f);
+    }
 }
diff --git a/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerInputFormatsTest.java b/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerInputFormatsTest.java
new file mode 100644 (file)
index 0000000..90c0111
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.colorpicker;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Test legal color values according to
+ * http://www.w3schools.com/cssref/css_colors_legal.asp
+ */
+public class ColorPickerInputFormatsTest extends MultiBrowserTest {
+
+    @Override
+    protected Class<?> getUIClass() {
+        return ColorPickerTestUI.class;
+    }
+
+    @Test
+    public void testRGBValue() throws Exception {
+        openTestURL();
+
+        setColorpickerValue("rgb(100,100,100)");
+
+        assertEquals("#646464", getColorpickerValue());
+    }
+
+    @Test
+    public void testRGBAValue() {
+        openTestURL();
+
+        setColorpickerValue("rgba(100,100,100, 0.5)");
+
+        assertEquals("#646464", getColorpickerValue());
+    }
+
+    @Test
+    public void testHSLValue() {
+        openTestURL();
+
+        setColorpickerValue("hsl(120,100%,50%)");
+
+        assertEquals("#00ff00", getColorpickerValue());
+    }
+
+    @Test
+    public void testHSLAValue() {
+        openTestURL();
+
+        setColorpickerValue("hsla(120,100%,50%, 0.3)");
+
+        assertEquals("#00ff00", getColorpickerValue());
+    }
+
+    private void setColorpickerValue(String value) {
+
+        // Open colorpicker
+        getDriver().findElement(By.id("colorpicker1")).click();
+
+        // Add RGB value
+        WebElement field = getDriver().findElement(
+                By.className("v-colorpicker-preview-textfield"));
+
+        // Select all text
+        field.sendKeys(Keys.chord(Keys.CONTROL, "a"));
+
+        // Replace with rgb value
+        field.sendKeys(value);
+
+        // Submit
+        field.sendKeys(Keys.ENTER);
+    }
+
+    private String getColorpickerValue() {
+        WebElement field = getDriver().findElement(
+                By.className("v-colorpicker-preview-textfield"));
+        return field.getAttribute("value");
+    }
+}
index 23c44d3cc0dc1757841a79a469e067327c80eb65..48a4219c8773b7afe05de3f90007f84a1b5048fd 100644 (file)
@@ -4,16 +4,16 @@
 <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>
+<title>ColorPickerTestUI</title>
 </head>
 <body>
 <table cellpadding="1" cellspacing="1" border="1">
 <thead>
-<tr><td rowspan="1" colspan="3">ColorPickerTest</td></tr>
+<tr><td rowspan="1" colspan="3">ColorPickerTestUI</td></tr>
 </thead><tbody>
 <tr>
        <td>open</td>
-       <td>/run/com.vaadin.tests.components.colorpicker.ColorPickerTest?restartApplication</td>
+       <td>/run/com.vaadin.tests.components.colorpicker.ColorPickerTestUI?restartApplication</td>
        <td></td>
 </tr>
 
 </tr>
 <tr>
        <td>waitForElementPresent</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/Slot[1]/VColorPickerGradient[0]#clicklayer</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/Slot[1]/VColorPickerGradient[0]#clicklayer</td>
        <td></td>
 </tr>
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/Slot[1]/VColorPickerGradient[0]#clicklayer</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/Slot[1]/VColorPickerGradient[0]#clicklayer</td>
        <td>190,87</td>
 </tr>
 <tr>
        <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
        <td></td>
 </tr>
 
 </tr>
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/Slot[1]/VColorPickerGradient[0]#clicklayer</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/Slot[1]/VColorPickerGradient[0]#clicklayer</td>
        <td>51,33</td>
 </tr>
 <tr>
        <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
        <td></td>
 </tr>
 <tr>
 <!-- change foreground color with area button -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_Scolorpicker5/domChild[1]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_Scolorpicker5/domChild[1]</td>
        <td>10,15</td>
 </tr>
 <!-- expand history -->
 <tr>
        <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VButton[0]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VButton[0]/domChild[0]</td>
        <td></td>
 </tr>
 <!-- choose from history -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomComponent[0]/VColorPickerGrid[0]/domChild[0]/domChild[1]/domChild[0]/domChild[3]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomComponent[0]/VColorPickerGrid[0]/domChild[0]/domChild[1]/domChild[0]/domChild[3]</td>
        <td>9,9</td>
 </tr>
 <tr>
        <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
        <td></td>
 </tr>
 
 <!-- change background color with area button -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_Scolorpicker6/domChild[1]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_Scolorpicker6/domChild[1]</td>
        <td>12,24</td>
 </tr>
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomComponent[0]/VColorPickerGrid[0]/domChild[0]/domChild[1]/domChild[0]/domChild[1]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomComponent[0]/VColorPickerGrid[0]/domChild[0]/domChild[1]/domChild[0]/domChild[1]</td>
        <td>9,12</td>
 </tr>
 <!-- choose from history -->
 <tr>
        <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]</td>
        <td></td>
 </tr>
 <tr>
 <!-- open and close using area button -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_Scolorpicker5/domChild[1]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_Scolorpicker5/domChild[1]</td>
        <td>11,17</td>
 </tr>
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_Scolorpicker5/domChild[1]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_Scolorpicker5/domChild[1]</td>
        <td>11,17</td>
 </tr>
 
 <!-- open background (using area button) to display HSV effects -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_Scolorpicker6/domChild[1]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_Scolorpicker6/domChild[1]</td>
        <td>21,15</td>
 </tr>
 <!-- HSV tab -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VTabsheet[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VTabsheet[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]</td>
        <td>12,6</td>
 </tr>
 <!-- hue slider -->
 <tr>
        <td>dragAndDrop</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VSlider[0]/domChild[2]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VSlider[0]/domChild[2]/domChild[0]</td>
        <td>136,0</td>
 </tr>
 <!-- saturation slider -->
 <tr>
        <td>dragAndDrop</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VSlider[0]/domChild[2]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VSlider[0]/domChild[2]/domChild[0]</td>
        <td>100,0</td>
 </tr>
 <!-- value slider -->
 <tr>
        <td>dragAndDrop</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VSlider[0]/domChild[2]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VVerticalLayout[0]/VOrderedLayout$Slot[2]/VSlider[0]/domChild[2]/domChild[0]</td>
        <td>-60,0</td>
 </tr>
 <!-- Swatches tab (choose color) -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VTabsheet[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[2]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VTabsheet[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[2]/domChild[0]/domChild[0]/domChild[0]</td>
        <td>43,8</td>
 </tr>
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VCustomComponent[0]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VColorPickerGrid[0]/domChild[0]/domChild[1]/domChild[11]/domChild[9]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VCustomComponent[0]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VColorPickerGrid[0]/domChild[0]/domChild[1]/domChild[11]/domChild[9]</td>
        <td>12,10</td>
 </tr>
 <tr>
        <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
        <td></td>
 </tr>
 <tr>
 <!-- open foreground (using area button) to display checkbox effects -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_Scolorpicker5/domChild[1]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_Scolorpicker5/domChild[1]</td>
        <td>14,25</td>
 </tr>
 <!-- remove Swatches tab -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_SswaBox/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_SswaBox/domChild[0]</td>
        <td>9,6</td>
 </tr>
 <!-- remove css field -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_StxtBox/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_StxtBox/domChild[0]</td>
        <td>6,9</td>
 </tr>
 <!-- remove history -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_ShisBox/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_ShisBox/domChild[0]</td>
        <td>6,7</td>
 </tr>
 <!-- remove RGB tab -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_SrgbBox/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_SrgbBox/domChild[0]</td>
        <td>6,7</td>
 </tr>
 <!-- return RGB tab -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_SrgbBox/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_SrgbBox/domChild[0]</td>
        <td>6,7</td>
 </tr>
 <!-- remove HSV tab -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_ShsvBox/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_ShsvBox/domChild[0]</td>
        <td>6,9</td>
 </tr>
 <!-- return HSV tab -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_ShsvBox/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_ShsvBox/domChild[0]</td>
        <td>6,9</td>
 </tr>
 <!-- return css field -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_StxtBox/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_StxtBox/domChild[0]</td>
        <td>8,8</td>
 </tr>
 <!-- return history -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_ShisBox/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_ShisBox/domChild[0]</td>
        <td>6,8</td>
 </tr>
 <!-- return Swatches tab -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_SswaBox/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_SswaBox/domChild[0]</td>
        <td>4,8</td>
 </tr>
 <!-- close without choosing a new color -->
 <tr>
        <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]</td>
        <td></td>
 </tr>
 
 </tr>
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/Slot[1]/VColorPickerGradient[0]#clicklayer</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/Slot[1]/VColorPickerGradient[0]#clicklayer</td>
        <td>148,127</td>
 </tr>
 <tr>
        <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
        <td></td>
 </tr>
 <tr>
 </tr>
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomComponent[0]/VColorPickerGrid[0]/domChild[0]/domChild[1]/domChild[0]/domChild[6]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomComponent[0]/VColorPickerGrid[0]/domChild[0]/domChild[1]/domChild[0]/domChild[6]</td>
        <td>10,7</td>
 </tr>
 <tr>
        <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
        <td></td>
 </tr>
 
 <!-- change color of the last shade area -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_Sshadearea_16/domChild[1]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_Sshadearea_16/domChild[1]</td>
        <td>10,-65</td>
 </tr>
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/Slot[1]/VColorPickerGradient[0]#clicklayer</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/Slot[0]/VTabsheet[0]/VTabsheetPanel[0]/VVerticalLayout[0]/Slot[1]/VColorPickerGradient[0]#clicklayer</td>
        <td>36,93</td>
 </tr>
 <tr>
        <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
        <td></td>
 </tr>
 <tr>
 <!-- reset the color back to white -->
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_Sshadearea_16/domChild[1]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::PID_Sshadearea_16/domChild[1]</td>
        <td>19,-65</td>
 </tr>
 <tr>
        <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomComponent[0]/VColorPickerGrid[0]/domChild[0]/domChild[1]/domChild[0]/domChild[4]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomComponent[0]/VColorPickerGrid[0]/domChild[0]/domChild[1]/domChild[0]/domChild[4]</td>
        <td>6,7</td>
 </tr>
 <tr>
        <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]</td>
+       <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTestUI::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/VOrderedLayout$Slot[3]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]</td>
        <td></td>
 </tr>
 <tr>
diff --git a/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerTest.java b/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerTest.java
deleted file mode 100644 (file)
index 0f7e639..0000000
+++ /dev/null
@@ -1,492 +0,0 @@
-package com.vaadin.tests.components.colorpicker;
-
-import java.awt.Graphics;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import javax.imageio.ImageIO;
-
-import com.vaadin.data.Property.ValueChangeEvent;
-import com.vaadin.server.StreamResource;
-import com.vaadin.shared.ui.colorpicker.Color;
-import com.vaadin.shared.ui.label.ContentMode;
-import com.vaadin.tests.components.TestBase;
-import com.vaadin.ui.AbstractColorPicker;
-import com.vaadin.ui.Alignment;
-import com.vaadin.ui.CheckBox;
-import com.vaadin.ui.ColorPicker;
-import com.vaadin.ui.ColorPickerArea;
-import com.vaadin.ui.Embedded;
-import com.vaadin.ui.GridLayout;
-import com.vaadin.ui.HorizontalLayout;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.Panel;
-import com.vaadin.ui.VerticalLayout;
-import com.vaadin.ui.components.colorpicker.ColorChangeEvent;
-import com.vaadin.ui.components.colorpicker.ColorChangeListener;
-
-public class ColorPickerTest extends TestBase implements ColorChangeListener {
-
-    @Override
-    protected String getDescription() {
-        return "Vaadin 7 compatible ColorPicker";
-    }
-
-    @Override
-    protected Integer getTicketNumber() {
-        return 9201;
-    }
-
-    /** The foreground color. */
-    private Color foregroundColor = Color.BLACK; // The currently selected
-
-    /** The background color. */
-    private Color backgroundColor = Color.WHITE; // The currently selected
-
-    // The display box where the image is rendered
-    /** The display. */
-    private Embedded display;
-
-    private AbstractColorPicker colorpicker1;
-    private AbstractColorPicker colorpicker2;
-    private AbstractColorPicker colorpicker3;
-    private AbstractColorPicker colorpicker4;
-    private AbstractColorPicker colorpicker5;
-    private AbstractColorPicker colorpicker6;
-
-    private boolean rgbVisible = true;
-    private boolean hsvVisible = true;
-    private boolean swaVisible = true;
-    private boolean historyVisible = true;
-    private boolean txtfieldVisible = true;
-
-    private final CheckBox rgbBox = new CheckBox("RGB tab visible");
-    private final CheckBox hsvBox = new CheckBox("HSV tab visible");
-    private final CheckBox swaBox = new CheckBox("Swatches tab visible");
-    private final CheckBox hisBox = new CheckBox("History visible");
-    private final CheckBox txtBox = new CheckBox("CSS field visible");
-
-    /**
-     * This class is used to represent the preview of the color selection.
-     */
-    public class MyImageSource implements StreamResource.StreamSource {
-
-        /** The imagebuffer. */
-        private java.io.ByteArrayOutputStream imagebuffer = null;
-
-        /** The bg color. */
-        private final java.awt.Color bgColor;
-
-        /** The fg color. */
-        private final java.awt.Color fgColor;
-
-        /**
-         * Instantiates a new my image source.
-         * 
-         * @param fg
-         *            the foreground
-         * @param bg
-         *            the background
-         */
-        public MyImageSource(java.awt.Color fg, java.awt.Color bg) {
-            fgColor = fg;
-            bgColor = bg;
-        }
-
-        /* Must implement this method that returns the resource as a stream. */
-        @Override
-        public InputStream getStream() {
-
-            /* Create an image and draw something on it. */
-            BufferedImage image = new BufferedImage(270, 270,
-                    BufferedImage.TYPE_INT_RGB);
-            Graphics drawable = image.getGraphics();
-            drawable.setColor(bgColor);
-            drawable.fillRect(0, 0, 270, 270);
-            drawable.setColor(fgColor);
-            drawable.fillOval(25, 25, 220, 220);
-            drawable.setColor(java.awt.Color.blue);
-            drawable.drawRect(0, 0, 269, 269);
-            drawable.setColor(java.awt.Color.black);
-            drawable.drawString(
-                    "r=" + String.valueOf(fgColor.getRed()) + ",g="
-                            + String.valueOf(fgColor.getGreen()) + ",b="
-                            + String.valueOf(fgColor.getBlue()), 50, 100);
-            drawable.drawString(
-                    "r=" + String.valueOf(bgColor.getRed()) + ",g="
-                            + String.valueOf(bgColor.getGreen()) + ",b="
-                            + String.valueOf(bgColor.getBlue()), 5, 15);
-
-            try {
-                /* Write the image to a buffer. */
-                imagebuffer = new ByteArrayOutputStream();
-                ImageIO.write(image, "png", imagebuffer);
-
-                /* Return a stream from the buffer. */
-                return new ByteArrayInputStream(imagebuffer.toByteArray());
-            } catch (IOException e) {
-                return null;
-            }
-        }
-    }
-
-    private void setPopupVisibilities() {
-
-        rgbBox.setEnabled(!(rgbVisible && !hsvVisible && !swaVisible));
-        hsvBox.setEnabled(!(!rgbVisible && hsvVisible && !swaVisible));
-        swaBox.setEnabled(!(!rgbVisible && !hsvVisible && swaVisible));
-
-        colorpicker1.setRGBVisibility(rgbVisible);
-        colorpicker2.setRGBVisibility(rgbVisible);
-        colorpicker3.setRGBVisibility(rgbVisible);
-        colorpicker4.setRGBVisibility(rgbVisible);
-        colorpicker5.setRGBVisibility(rgbVisible);
-        colorpicker6.setRGBVisibility(rgbVisible);
-
-        colorpicker1.setHSVVisibility(hsvVisible);
-        colorpicker2.setHSVVisibility(hsvVisible);
-        colorpicker3.setHSVVisibility(hsvVisible);
-        colorpicker4.setHSVVisibility(hsvVisible);
-        colorpicker5.setHSVVisibility(hsvVisible);
-        colorpicker6.setHSVVisibility(hsvVisible);
-
-        colorpicker1.setSwatchesVisibility(swaVisible);
-        colorpicker2.setSwatchesVisibility(swaVisible);
-        colorpicker3.setSwatchesVisibility(swaVisible);
-        colorpicker4.setSwatchesVisibility(swaVisible);
-        colorpicker5.setSwatchesVisibility(swaVisible);
-        colorpicker6.setSwatchesVisibility(swaVisible);
-
-        colorpicker1.setHistoryVisibility(historyVisible);
-        colorpicker2.setHistoryVisibility(historyVisible);
-        colorpicker3.setHistoryVisibility(historyVisible);
-        colorpicker4.setHistoryVisibility(historyVisible);
-        colorpicker5.setHistoryVisibility(historyVisible);
-        colorpicker6.setHistoryVisibility(historyVisible);
-
-        colorpicker1.setTextfieldVisibility(txtfieldVisible);
-        colorpicker2.setTextfieldVisibility(txtfieldVisible);
-        colorpicker3.setTextfieldVisibility(txtfieldVisible);
-        colorpicker4.setTextfieldVisibility(txtfieldVisible);
-        colorpicker5.setTextfieldVisibility(txtfieldVisible);
-        colorpicker6.setTextfieldVisibility(txtfieldVisible);
-    }
-
-    @Override
-    protected void setup() {
-        getLayout().setWidth("1000px");
-        getLayout().setHeight(null);
-        getLayout().addStyleName("colorpicker-mainwindow-content");
-
-        // Create an instance of the preview and add it to the window
-        display = new Embedded("Color preview");
-        display.setWidth("270px");
-        display.setHeight("270px");
-
-        // Add the foreground and background colorpickers to a layout
-        HorizontalLayout mainLayout = new HorizontalLayout();
-        mainLayout.addStyleName("colorpicker-mainlayout");
-        mainLayout.setWidth("100%");
-        mainLayout.setHeight(null);
-        mainLayout.setMargin(true);
-        mainLayout.setSpacing(true);
-        getLayout().addComponent(mainLayout);
-
-        VerticalLayout layoutLeft = new VerticalLayout();
-        layoutLeft.setWidth("450px");
-        layoutLeft.setHeight(null);
-        layoutLeft.setSpacing(true);
-
-        GridLayout optLayout = new GridLayout(3, 2);
-        optLayout.setWidth("100%");
-        optLayout.setHeight(null);
-        optLayout.setMargin(true);
-        optLayout.setSpacing(true);
-
-        rgbBox.setValue(rgbVisible);
-        rgbBox.addValueChangeListener(new CheckBox.ValueChangeListener() {
-            @Override
-            public void valueChange(ValueChangeEvent event) {
-                rgbVisible = (Boolean) event.getProperty().getValue();
-                setPopupVisibilities();
-            }
-        });
-        rgbBox.setImmediate(true);
-        rgbBox.setId("rgbBox");
-        optLayout.addComponent(rgbBox);
-
-        hsvBox.setValue(hsvVisible);
-        hsvBox.addValueChangeListener(new CheckBox.ValueChangeListener() {
-            @Override
-            public void valueChange(ValueChangeEvent event) {
-                hsvVisible = (Boolean) event.getProperty().getValue();
-                setPopupVisibilities();
-            }
-        });
-        hsvBox.setImmediate(true);
-        hsvBox.setId("hsvBox");
-        optLayout.addComponent(hsvBox);
-
-        swaBox.setValue(swaVisible);
-        swaBox.addValueChangeListener(new CheckBox.ValueChangeListener() {
-            @Override
-            public void valueChange(ValueChangeEvent event) {
-                swaVisible = (Boolean) event.getProperty().getValue();
-                setPopupVisibilities();
-            }
-        });
-        swaBox.setImmediate(true);
-        swaBox.setId("swaBox");
-        optLayout.addComponent(swaBox);
-
-        hisBox.setValue(historyVisible);
-        hisBox.addValueChangeListener(new CheckBox.ValueChangeListener() {
-            @Override
-            public void valueChange(ValueChangeEvent event) {
-                historyVisible = (Boolean) event.getProperty().getValue();
-                setPopupVisibilities();
-            }
-        });
-        hisBox.setImmediate(true);
-        hisBox.setId("hisBox");
-        optLayout.addComponent(hisBox);
-
-        txtBox.setValue(txtfieldVisible);
-        txtBox.addValueChangeListener(new CheckBox.ValueChangeListener() {
-            @Override
-            public void valueChange(ValueChangeEvent event) {
-                txtfieldVisible = (Boolean) event.getProperty().getValue();
-                setPopupVisibilities();
-            }
-        });
-        txtBox.setImmediate(true);
-        txtBox.setId("txtBox");
-        optLayout.addComponent(txtBox);
-
-        Panel optPanel = new Panel("Customize the color picker popup window",
-                optLayout);
-        layoutLeft.addComponent(optPanel);
-
-        HorizontalLayout layout1 = createHorizontalLayout();
-
-        colorpicker1 = new ColorPicker("Foreground", foregroundColor);
-        colorpicker1.setHtmlContentAllowed(true);
-        colorpicker1.addColorChangeListener(this);
-        colorpicker1.setId("colorpicker1");
-        layout1.addComponent(colorpicker1);
-        layout1.setComponentAlignment(colorpicker1, Alignment.MIDDLE_CENTER);
-
-        colorpicker2 = new ColorPicker("Background", backgroundColor);
-        colorpicker2.addColorChangeListener(this);
-        colorpicker2.setId("colorpicker2");
-        layout1.addComponent(colorpicker2);
-        layout1.setComponentAlignment(colorpicker2, Alignment.MIDDLE_CENTER);
-
-        Panel panel1 = new Panel(
-                "Button-like colorpicker with current color and CSS code",
-                layout1);
-        layoutLeft.addComponent(panel1);
-
-        HorizontalLayout layout2 = createHorizontalLayout();
-
-        colorpicker3 = new ColorPicker("Foreground", foregroundColor);
-        colorpicker3.addColorChangeListener(this);
-        colorpicker3.setWidth("120px");
-        colorpicker3.setCaption("Foreground");
-        colorpicker3.setId("colorpicker3");
-        layout2.addComponent(colorpicker3);
-        layout2.setComponentAlignment(colorpicker3, Alignment.MIDDLE_CENTER);
-
-        colorpicker4 = new ColorPicker("Background", backgroundColor);
-        colorpicker4.addColorChangeListener(this);
-        colorpicker4.setWidth("120px");
-        colorpicker4.setCaption("Background");
-        colorpicker4.setId("colorpicker4");
-        layout2.addComponent(colorpicker4);
-        layout2.setComponentAlignment(colorpicker4, Alignment.MIDDLE_CENTER);
-
-        Panel panel2 = new Panel(
-                "Button-like colorpicker with current color and custom caption",
-                layout2);
-        layoutLeft.addComponent(panel2);
-
-        HorizontalLayout layout3 = createHorizontalLayout();
-
-        colorpicker5 = new ColorPickerArea("Foreground", foregroundColor);
-        colorpicker5.setCaption("Foreground");
-        colorpicker5.addColorChangeListener(this);
-        colorpicker5.setId("colorpicker5");
-        layout3.addComponent(colorpicker5);
-        layout3.setComponentAlignment(colorpicker5, Alignment.MIDDLE_CENTER);
-
-        colorpicker6 = new ColorPickerArea("Background", backgroundColor);
-        colorpicker6.setCaption("Background");
-        colorpicker6.setDefaultCaptionEnabled(false);
-        colorpicker6.addColorChangeListener(this);
-        colorpicker6.setId("colorpicker6");
-        layout3.addComponent(colorpicker6);
-        layout3.setComponentAlignment(colorpicker6, Alignment.MIDDLE_CENTER);
-
-        Panel panel3 = new Panel("Color area colorpicker with caption", layout3);
-        panel3.setWidth("100%");
-        panel3.setHeight(null);
-        layoutLeft.addComponent(panel3);
-
-        Label divider1 = new Label("<hr>", ContentMode.HTML);
-        layoutLeft.addComponent(divider1);
-
-        Label divider2 = new Label("<hr>", ContentMode.HTML);
-        layoutLeft.addComponent(divider2);
-
-        HorizontalLayout layout4 = createHorizontalLayout();
-
-        addShadeButton(new Color(Integer.parseInt("000000", 16)), layout4);
-        addShadeButton(new Color(Integer.parseInt("333333", 16)), layout4);
-        addShadeButton(new Color(Integer.parseInt("666666", 16)), layout4);
-        addShadeButton(new Color(Integer.parseInt("999999", 16)), layout4);
-        addShadeButton(new Color(Integer.parseInt("cccccc", 16)), layout4);
-        addShadeButton(new Color(Integer.parseInt("ffffff", 16)), layout4);
-
-        Panel panel4 = new Panel(
-                "Button-like colorpickers with disabled caption (no effect on fg/bg colors)",
-                layout4);
-        layoutLeft.addComponent(panel4);
-
-        HorizontalLayout layout5 = createHorizontalLayout();
-
-        addShadeArea(new Color(Integer.parseInt("000000", 16)), layout5);
-        addShadeArea(new Color(Integer.parseInt("111111", 16)), layout5);
-        addShadeArea(new Color(Integer.parseInt("222222", 16)), layout5);
-        addShadeArea(new Color(Integer.parseInt("333333", 16)), layout5);
-        addShadeArea(new Color(Integer.parseInt("444444", 16)), layout5);
-        addShadeArea(new Color(Integer.parseInt("555555", 16)), layout5);
-        addShadeArea(new Color(Integer.parseInt("666666", 16)), layout5);
-        addShadeArea(new Color(Integer.parseInt("777777", 16)), layout5);
-        addShadeArea(new Color(Integer.parseInt("888888", 16)), layout5);
-        addShadeArea(new Color(Integer.parseInt("999999", 16)), layout5);
-        addShadeArea(new Color(Integer.parseInt("aaaaaa", 16)), layout5);
-        addShadeArea(new Color(Integer.parseInt("bbbbbb", 16)), layout5);
-        addShadeArea(new Color(Integer.parseInt("cccccc", 16)), layout5);
-        addShadeArea(new Color(Integer.parseInt("dddddd", 16)), layout5);
-        addShadeArea(new Color(Integer.parseInt("eeeeee", 16)), layout5);
-        addShadeArea(new Color(Integer.parseInt("ffffff", 16)), layout5);
-
-        Panel panel5 = new Panel(
-                "Area colorpickers with no given caption (no effect on fg/bg colors)",
-                layout5);
-        layoutLeft.addComponent(panel5);
-
-        mainLayout.addComponent(layoutLeft);
-
-        mainLayout.addComponent(display);
-
-        updateDisplay(foregroundColor, backgroundColor);
-    }
-
-    private HorizontalLayout createHorizontalLayout() {
-        HorizontalLayout layout = new HorizontalLayout();
-        layout.setWidth("100%");
-        layout.setHeight(null);
-        layout.setMargin(true);
-        return layout;
-    }
-
-    private int shadeButtonCounter = 1;
-
-    private void addShadeButton(Color color, HorizontalLayout layout) {
-        AbstractColorPicker colorPicker = new ColorPicker(color.toString(),
-                color);
-        colorPicker.setDefaultCaptionEnabled(false);
-        colorPicker.setWidth("41px");
-        colorPicker.setId("shadebutton_" + shadeButtonCounter);
-        layout.addComponent(colorPicker);
-        layout.setComponentAlignment(colorPicker, Alignment.MIDDLE_CENTER);
-
-        ++shadeButtonCounter;
-    }
-
-    private int shadeAreaCounter = 1;
-
-    private void addShadeArea(Color color, HorizontalLayout layout) {
-        AbstractColorPicker colorPicker = new ColorPickerArea(color.toString(),
-                color);
-        colorPicker.setWidth("20px");
-        colorPicker.setHeight("20px");
-        colorPicker.setId("shadearea_" + shadeAreaCounter);
-        layout.addComponent(colorPicker);
-        layout.setComponentAlignment(colorPicker, Alignment.MIDDLE_CENTER);
-
-        ++shadeAreaCounter;
-    }
-
-    // This is called whenever a colorpicker popup is closed
-    /**
-     * Update display.
-     * 
-     * @param fg
-     *            the fg
-     * @param bg
-     *            the bg
-     */
-    public void updateDisplay(Color fg, Color bg) {
-        java.awt.Color awtFg = new java.awt.Color(fg.getRed(), fg.getGreen(),
-                fg.getBlue());
-        java.awt.Color awtBg = new java.awt.Color(bg.getRed(), bg.getGreen(),
-                bg.getBlue());
-        StreamResource.StreamSource imagesource = new MyImageSource(awtFg,
-                awtBg);
-
-        Date now = new Date();
-        SimpleDateFormat format = new SimpleDateFormat("hhmmss");
-
-        StreamResource imageresource = new StreamResource(imagesource,
-                "myimage" + format.format(now) + ".png");
-        imageresource.setCacheTime(0);
-
-        display.setSource(imageresource);
-    }
-
-    @Override
-    public void colorChanged(ColorChangeEvent event) {
-        if (event.getSource() == colorpicker1
-                || event.getSource() == colorpicker3
-                || event.getSource() == colorpicker5) {
-            foregroundColor = event.getColor();
-
-            if (event.getSource() != colorpicker1) {
-                colorpicker1.setColor(event.getColor());
-            }
-            if (event.getSource() != colorpicker3) {
-                colorpicker3.setColor(event.getColor());
-            }
-            if (event.getSource() != colorpicker5) {
-                colorpicker5.setColor(event.getColor());
-            }
-
-        } else if (event.getSource() == colorpicker2
-                || event.getSource() == colorpicker4
-                || event.getSource() == colorpicker6) {
-            backgroundColor = event.getColor();
-
-            if (event.getSource() != colorpicker2) {
-                colorpicker2.setColor(event.getColor());
-            }
-            if (event.getSource() != colorpicker4) {
-                colorpicker4.setColor(event.getColor());
-            }
-            if (event.getSource() != colorpicker6) {
-                colorpicker6.setColor(event.getColor());
-            }
-
-        } else {
-            return;
-        }
-
-        updateDisplay(foregroundColor, backgroundColor);
-    }
-}
diff --git a/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerTestUI.java b/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerTestUI.java
new file mode 100644 (file)
index 0000000..544cdaf
--- /dev/null
@@ -0,0 +1,509 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.colorpicker;
+
+import java.awt.Graphics;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.imageio.ImageIO;
+
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.server.StreamResource;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.colorpicker.Color;
+import com.vaadin.shared.ui.label.ContentMode;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.AbstractColorPicker;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.ColorPicker;
+import com.vaadin.ui.ColorPickerArea;
+import com.vaadin.ui.Embedded;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.components.colorpicker.ColorChangeEvent;
+import com.vaadin.ui.components.colorpicker.ColorChangeListener;
+
+public class ColorPickerTestUI extends AbstractTestUI implements
+        ColorChangeListener {
+
+    @Override
+    public String getTestDescription() {
+        return "Vaadin 7 compatible ColorPicker";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 9201;
+    }
+
+    /** The foreground color. */
+    private Color foregroundColor = Color.BLACK; // The currently selected
+
+    /** The background color. */
+    private Color backgroundColor = Color.WHITE; // The currently selected
+
+    // The display box where the image is rendered
+    /** The display. */
+    private Embedded display;
+
+    private AbstractColorPicker colorpicker1;
+    private AbstractColorPicker colorpicker2;
+    private AbstractColorPicker colorpicker3;
+    private AbstractColorPicker colorpicker4;
+    private AbstractColorPicker colorpicker5;
+    private AbstractColorPicker colorpicker6;
+
+    private boolean rgbVisible = true;
+    private boolean hsvVisible = true;
+    private boolean swaVisible = true;
+    private boolean historyVisible = true;
+    private boolean txtfieldVisible = true;
+
+    private final CheckBox rgbBox = new CheckBox("RGB tab visible");
+    private final CheckBox hsvBox = new CheckBox("HSV tab visible");
+    private final CheckBox swaBox = new CheckBox("Swatches tab visible");
+    private final CheckBox hisBox = new CheckBox("History visible");
+    private final CheckBox txtBox = new CheckBox("CSS field visible");
+
+    /**
+     * This class is used to represent the preview of the color selection.
+     */
+    public class MyImageSource implements StreamResource.StreamSource {
+
+        /** The imagebuffer. */
+        private java.io.ByteArrayOutputStream imagebuffer = null;
+
+        /** The bg color. */
+        private final java.awt.Color bgColor;
+
+        /** The fg color. */
+        private final java.awt.Color fgColor;
+
+        /**
+         * Instantiates a new my image source.
+         * 
+         * @param fg
+         *            the foreground
+         * @param bg
+         *            the background
+         */
+        public MyImageSource(java.awt.Color fg, java.awt.Color bg) {
+            fgColor = fg;
+            bgColor = bg;
+        }
+
+        /* Must implement this method that returns the resource as a stream. */
+        @Override
+        public InputStream getStream() {
+
+            /* Create an image and draw something on it. */
+            BufferedImage image = new BufferedImage(270, 270,
+                    BufferedImage.TYPE_INT_RGB);
+            Graphics drawable = image.getGraphics();
+            drawable.setColor(bgColor);
+            drawable.fillRect(0, 0, 270, 270);
+            drawable.setColor(fgColor);
+            drawable.fillOval(25, 25, 220, 220);
+            drawable.setColor(java.awt.Color.blue);
+            drawable.drawRect(0, 0, 269, 269);
+            drawable.setColor(java.awt.Color.black);
+            drawable.drawString(
+                    "r=" + String.valueOf(fgColor.getRed()) + ",g="
+                            + String.valueOf(fgColor.getGreen()) + ",b="
+                            + String.valueOf(fgColor.getBlue()), 50, 100);
+            drawable.drawString(
+                    "r=" + String.valueOf(bgColor.getRed()) + ",g="
+                            + String.valueOf(bgColor.getGreen()) + ",b="
+                            + String.valueOf(bgColor.getBlue()), 5, 15);
+
+            try {
+                /* Write the image to a buffer. */
+                imagebuffer = new ByteArrayOutputStream();
+                ImageIO.write(image, "png", imagebuffer);
+
+                /* Return a stream from the buffer. */
+                return new ByteArrayInputStream(imagebuffer.toByteArray());
+            } catch (IOException e) {
+                return null;
+            }
+        }
+    }
+
+    private void setPopupVisibilities() {
+
+        rgbBox.setEnabled(!(rgbVisible && !hsvVisible && !swaVisible));
+        hsvBox.setEnabled(!(!rgbVisible && hsvVisible && !swaVisible));
+        swaBox.setEnabled(!(!rgbVisible && !hsvVisible && swaVisible));
+
+        colorpicker1.setRGBVisibility(rgbVisible);
+        colorpicker2.setRGBVisibility(rgbVisible);
+        colorpicker3.setRGBVisibility(rgbVisible);
+        colorpicker4.setRGBVisibility(rgbVisible);
+        colorpicker5.setRGBVisibility(rgbVisible);
+        colorpicker6.setRGBVisibility(rgbVisible);
+
+        colorpicker1.setHSVVisibility(hsvVisible);
+        colorpicker2.setHSVVisibility(hsvVisible);
+        colorpicker3.setHSVVisibility(hsvVisible);
+        colorpicker4.setHSVVisibility(hsvVisible);
+        colorpicker5.setHSVVisibility(hsvVisible);
+        colorpicker6.setHSVVisibility(hsvVisible);
+
+        colorpicker1.setSwatchesVisibility(swaVisible);
+        colorpicker2.setSwatchesVisibility(swaVisible);
+        colorpicker3.setSwatchesVisibility(swaVisible);
+        colorpicker4.setSwatchesVisibility(swaVisible);
+        colorpicker5.setSwatchesVisibility(swaVisible);
+        colorpicker6.setSwatchesVisibility(swaVisible);
+
+        colorpicker1.setHistoryVisibility(historyVisible);
+        colorpicker2.setHistoryVisibility(historyVisible);
+        colorpicker3.setHistoryVisibility(historyVisible);
+        colorpicker4.setHistoryVisibility(historyVisible);
+        colorpicker5.setHistoryVisibility(historyVisible);
+        colorpicker6.setHistoryVisibility(historyVisible);
+
+        colorpicker1.setTextfieldVisibility(txtfieldVisible);
+        colorpicker2.setTextfieldVisibility(txtfieldVisible);
+        colorpicker3.setTextfieldVisibility(txtfieldVisible);
+        colorpicker4.setTextfieldVisibility(txtfieldVisible);
+        colorpicker5.setTextfieldVisibility(txtfieldVisible);
+        colorpicker6.setTextfieldVisibility(txtfieldVisible);
+    }
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        getLayout().setWidth("1000px");
+        getLayout().setHeight(null);
+        getLayout().addStyleName("colorpicker-mainwindow-content");
+
+        // Create an instance of the preview and add it to the window
+        display = new Embedded("Color preview");
+        display.setWidth("270px");
+        display.setHeight("270px");
+
+        // Add the foreground and background colorpickers to a layout
+        HorizontalLayout mainLayout = new HorizontalLayout();
+        mainLayout.addStyleName("colorpicker-mainlayout");
+        mainLayout.setWidth("100%");
+        mainLayout.setHeight(null);
+        mainLayout.setMargin(true);
+        mainLayout.setSpacing(true);
+        getLayout().addComponent(mainLayout);
+
+        VerticalLayout layoutLeft = new VerticalLayout();
+        layoutLeft.setWidth("450px");
+        layoutLeft.setHeight(null);
+        layoutLeft.setSpacing(true);
+
+        GridLayout optLayout = new GridLayout(3, 2);
+        optLayout.setWidth("100%");
+        optLayout.setHeight(null);
+        optLayout.setMargin(true);
+        optLayout.setSpacing(true);
+
+        rgbBox.setValue(rgbVisible);
+        rgbBox.addValueChangeListener(new CheckBox.ValueChangeListener() {
+            @Override
+            public void valueChange(ValueChangeEvent event) {
+                rgbVisible = (Boolean) event.getProperty().getValue();
+                setPopupVisibilities();
+            }
+        });
+        rgbBox.setImmediate(true);
+        rgbBox.setId("rgbBox");
+        optLayout.addComponent(rgbBox);
+
+        hsvBox.setValue(hsvVisible);
+        hsvBox.addValueChangeListener(new CheckBox.ValueChangeListener() {
+            @Override
+            public void valueChange(ValueChangeEvent event) {
+                hsvVisible = (Boolean) event.getProperty().getValue();
+                setPopupVisibilities();
+            }
+        });
+        hsvBox.setImmediate(true);
+        hsvBox.setId("hsvBox");
+        optLayout.addComponent(hsvBox);
+
+        swaBox.setValue(swaVisible);
+        swaBox.addValueChangeListener(new CheckBox.ValueChangeListener() {
+            @Override
+            public void valueChange(ValueChangeEvent event) {
+                swaVisible = (Boolean) event.getProperty().getValue();
+                setPopupVisibilities();
+            }
+        });
+        swaBox.setImmediate(true);
+        swaBox.setId("swaBox");
+        optLayout.addComponent(swaBox);
+
+        hisBox.setValue(historyVisible);
+        hisBox.addValueChangeListener(new CheckBox.ValueChangeListener() {
+            @Override
+            public void valueChange(ValueChangeEvent event) {
+                historyVisible = (Boolean) event.getProperty().getValue();
+                setPopupVisibilities();
+            }
+        });
+        hisBox.setImmediate(true);
+        hisBox.setId("hisBox");
+        optLayout.addComponent(hisBox);
+
+        txtBox.setValue(txtfieldVisible);
+        txtBox.addValueChangeListener(new CheckBox.ValueChangeListener() {
+            @Override
+            public void valueChange(ValueChangeEvent event) {
+                txtfieldVisible = (Boolean) event.getProperty().getValue();
+                setPopupVisibilities();
+            }
+        });
+        txtBox.setImmediate(true);
+        txtBox.setId("txtBox");
+        optLayout.addComponent(txtBox);
+
+        Panel optPanel = new Panel("Customize the color picker popup window",
+                optLayout);
+        layoutLeft.addComponent(optPanel);
+
+        HorizontalLayout layout1 = createHorizontalLayout();
+
+        colorpicker1 = new ColorPicker("Foreground", foregroundColor);
+        colorpicker1.setHtmlContentAllowed(true);
+        colorpicker1.addColorChangeListener(this);
+        colorpicker1.setId("colorpicker1");
+        layout1.addComponent(colorpicker1);
+        layout1.setComponentAlignment(colorpicker1, Alignment.MIDDLE_CENTER);
+
+        colorpicker2 = new ColorPicker("Background", backgroundColor);
+        colorpicker2.addColorChangeListener(this);
+        colorpicker2.setId("colorpicker2");
+        layout1.addComponent(colorpicker2);
+        layout1.setComponentAlignment(colorpicker2, Alignment.MIDDLE_CENTER);
+
+        Panel panel1 = new Panel(
+                "Button-like colorpicker with current color and CSS code",
+                layout1);
+        layoutLeft.addComponent(panel1);
+
+        HorizontalLayout layout2 = createHorizontalLayout();
+
+        colorpicker3 = new ColorPicker("Foreground", foregroundColor);
+        colorpicker3.addColorChangeListener(this);
+        colorpicker3.setWidth("120px");
+        colorpicker3.setCaption("Foreground");
+        colorpicker3.setId("colorpicker3");
+        layout2.addComponent(colorpicker3);
+        layout2.setComponentAlignment(colorpicker3, Alignment.MIDDLE_CENTER);
+
+        colorpicker4 = new ColorPicker("Background", backgroundColor);
+        colorpicker4.addColorChangeListener(this);
+        colorpicker4.setWidth("120px");
+        colorpicker4.setCaption("Background");
+        colorpicker4.setId("colorpicker4");
+        layout2.addComponent(colorpicker4);
+        layout2.setComponentAlignment(colorpicker4, Alignment.MIDDLE_CENTER);
+
+        Panel panel2 = new Panel(
+                "Button-like colorpicker with current color and custom caption",
+                layout2);
+        layoutLeft.addComponent(panel2);
+
+        HorizontalLayout layout3 = createHorizontalLayout();
+
+        colorpicker5 = new ColorPickerArea("Foreground", foregroundColor);
+        colorpicker5.setCaption("Foreground");
+        colorpicker5.addColorChangeListener(this);
+        colorpicker5.setId("colorpicker5");
+        layout3.addComponent(colorpicker5);
+        layout3.setComponentAlignment(colorpicker5, Alignment.MIDDLE_CENTER);
+
+        colorpicker6 = new ColorPickerArea("Background", backgroundColor);
+        colorpicker6.setCaption("Background");
+        colorpicker6.setDefaultCaptionEnabled(false);
+        colorpicker6.addColorChangeListener(this);
+        colorpicker6.setId("colorpicker6");
+        layout3.addComponent(colorpicker6);
+        layout3.setComponentAlignment(colorpicker6, Alignment.MIDDLE_CENTER);
+
+        Panel panel3 = new Panel("Color area colorpicker with caption", layout3);
+        panel3.setWidth("100%");
+        panel3.setHeight(null);
+        layoutLeft.addComponent(panel3);
+
+        Label divider1 = new Label("<hr>", ContentMode.HTML);
+        layoutLeft.addComponent(divider1);
+
+        Label divider2 = new Label("<hr>", ContentMode.HTML);
+        layoutLeft.addComponent(divider2);
+
+        HorizontalLayout layout4 = createHorizontalLayout();
+
+        addShadeButton(new Color(Integer.parseInt("000000", 16)), layout4);
+        addShadeButton(new Color(Integer.parseInt("333333", 16)), layout4);
+        addShadeButton(new Color(Integer.parseInt("666666", 16)), layout4);
+        addShadeButton(new Color(Integer.parseInt("999999", 16)), layout4);
+        addShadeButton(new Color(Integer.parseInt("cccccc", 16)), layout4);
+        addShadeButton(new Color(Integer.parseInt("ffffff", 16)), layout4);
+
+        Panel panel4 = new Panel(
+                "Button-like colorpickers with disabled caption (no effect on fg/bg colors)",
+                layout4);
+        layoutLeft.addComponent(panel4);
+
+        HorizontalLayout layout5 = createHorizontalLayout();
+
+        addShadeArea(new Color(Integer.parseInt("000000", 16)), layout5);
+        addShadeArea(new Color(Integer.parseInt("111111", 16)), layout5);
+        addShadeArea(new Color(Integer.parseInt("222222", 16)), layout5);
+        addShadeArea(new Color(Integer.parseInt("333333", 16)), layout5);
+        addShadeArea(new Color(Integer.parseInt("444444", 16)), layout5);
+        addShadeArea(new Color(Integer.parseInt("555555", 16)), layout5);
+        addShadeArea(new Color(Integer.parseInt("666666", 16)), layout5);
+        addShadeArea(new Color(Integer.parseInt("777777", 16)), layout5);
+        addShadeArea(new Color(Integer.parseInt("888888", 16)), layout5);
+        addShadeArea(new Color(Integer.parseInt("999999", 16)), layout5);
+        addShadeArea(new Color(Integer.parseInt("aaaaaa", 16)), layout5);
+        addShadeArea(new Color(Integer.parseInt("bbbbbb", 16)), layout5);
+        addShadeArea(new Color(Integer.parseInt("cccccc", 16)), layout5);
+        addShadeArea(new Color(Integer.parseInt("dddddd", 16)), layout5);
+        addShadeArea(new Color(Integer.parseInt("eeeeee", 16)), layout5);
+        addShadeArea(new Color(Integer.parseInt("ffffff", 16)), layout5);
+
+        Panel panel5 = new Panel(
+                "Area colorpickers with no given caption (no effect on fg/bg colors)",
+                layout5);
+        layoutLeft.addComponent(panel5);
+
+        mainLayout.addComponent(layoutLeft);
+
+        mainLayout.addComponent(display);
+
+        updateDisplay(foregroundColor, backgroundColor);
+    }
+
+    private HorizontalLayout createHorizontalLayout() {
+        HorizontalLayout layout = new HorizontalLayout();
+        layout.setWidth("100%");
+        layout.setHeight(null);
+        layout.setMargin(true);
+        return layout;
+    }
+
+    private int shadeButtonCounter = 1;
+
+    private void addShadeButton(Color color, HorizontalLayout layout) {
+        AbstractColorPicker colorPicker = new ColorPicker(color.toString(),
+                color);
+        colorPicker.setDefaultCaptionEnabled(false);
+        colorPicker.setWidth("41px");
+        colorPicker.setId("shadebutton_" + shadeButtonCounter);
+        layout.addComponent(colorPicker);
+        layout.setComponentAlignment(colorPicker, Alignment.MIDDLE_CENTER);
+
+        ++shadeButtonCounter;
+    }
+
+    private int shadeAreaCounter = 1;
+
+    private void addShadeArea(Color color, HorizontalLayout layout) {
+        AbstractColorPicker colorPicker = new ColorPickerArea(color.toString(),
+                color);
+        colorPicker.setWidth("20px");
+        colorPicker.setHeight("20px");
+        colorPicker.setId("shadearea_" + shadeAreaCounter);
+        layout.addComponent(colorPicker);
+        layout.setComponentAlignment(colorPicker, Alignment.MIDDLE_CENTER);
+
+        ++shadeAreaCounter;
+    }
+
+    // This is called whenever a colorpicker popup is closed
+    /**
+     * Update display.
+     * 
+     * @param fg
+     *            the fg
+     * @param bg
+     *            the bg
+     */
+    public void updateDisplay(Color fg, Color bg) {
+        java.awt.Color awtFg = new java.awt.Color(fg.getRed(), fg.getGreen(),
+                fg.getBlue());
+        java.awt.Color awtBg = new java.awt.Color(bg.getRed(), bg.getGreen(),
+                bg.getBlue());
+        StreamResource.StreamSource imagesource = new MyImageSource(awtFg,
+                awtBg);
+
+        Date now = new Date();
+        SimpleDateFormat format = new SimpleDateFormat("hhmmss");
+
+        StreamResource imageresource = new StreamResource(imagesource,
+                "myimage" + format.format(now) + ".png");
+        imageresource.setCacheTime(0);
+
+        display.setSource(imageresource);
+    }
+
+    @Override
+    public void colorChanged(ColorChangeEvent event) {
+        if (event.getSource() == colorpicker1
+                || event.getSource() == colorpicker3
+                || event.getSource() == colorpicker5) {
+            foregroundColor = event.getColor();
+
+            if (event.getSource() != colorpicker1) {
+                colorpicker1.setColor(event.getColor());
+            }
+            if (event.getSource() != colorpicker3) {
+                colorpicker3.setColor(event.getColor());
+            }
+            if (event.getSource() != colorpicker5) {
+                colorpicker5.setColor(event.getColor());
+            }
+
+        } else if (event.getSource() == colorpicker2
+                || event.getSource() == colorpicker4
+                || event.getSource() == colorpicker6) {
+            backgroundColor = event.getColor();
+
+            if (event.getSource() != colorpicker2) {
+                colorpicker2.setColor(event.getColor());
+            }
+            if (event.getSource() != colorpicker4) {
+                colorpicker4.setColor(event.getColor());
+            }
+            if (event.getSource() != colorpicker6) {
+                colorpicker6.setColor(event.getColor());
+            }
+
+        } else {
+            return;
+        }
+
+        updateDisplay(foregroundColor, backgroundColor);
+    }
+}