diff options
author | Anna Koskinen <anna@vaadin.com> | 2012-11-27 10:33:53 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2012-12-10 13:11:13 +0000 |
commit | 97834440254dcb03ed267fbf5f453f4dc435a291 (patch) | |
tree | 69ce018cfdec938dcc01d1bf1cfe5dff06bff8f8 /uitest | |
parent | d2b69dbee663bc2607a9d268e4c751e9dbdc53a5 (diff) | |
download | vaadin-framework-97834440254dcb03ed267fbf5f453f4dc435a291.tar.gz vaadin-framework-97834440254dcb03ed267fbf5f453f4dc435a291.zip |
Vaadin 7 compatible ColorPicker (#9201)
Change-Id: I44962ceedd5ef607e2fbe2af0d96808e0aef9cc5
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerTest.html | 339 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerTest.java | 492 |
2 files changed, 831 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerTest.html b/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerTest.html new file mode 100644 index 0000000000..fb8669b9f0 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerTest.html @@ -0,0 +1,339 @@ +<?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="http://localhost:8888/run/com.vaadin.tests.components.colorpicker.ColorPickerTest?restartApplication" /> +<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.ColorPickerTest?restartApplication</td> + <td></td> +</tr> + +<!-- change foreground color --> +<tr> + <td>click</td> + <td>colorpicker1</td> + <td></td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_Srgb-gradient/domChild[1]/domChild[4]</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></td> +</tr> + +<!-- change background color --> +<tr> + <td>click</td> + <td>colorpicker2</td> + <td></td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_Srgb-gradient/domChild[1]/domChild[4]</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></td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>pink-on-yellow</td> +</tr> + +<!-- change foreground color with area button --> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::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></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>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></td> +</tr> + +<!-- change background color with area button --> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::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>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></td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>black-on-white</td> +</tr> + +<!-- open and close --> +<tr> + <td>click</td> + <td>colorpicker1</td> + <td></td> +</tr> +<tr> + <td>click</td> + <td>colorpicker1</td> + <td></td> +</tr> + +<!-- open and close using area button --> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_Scolorpicker5/domChild[1]</td> + <td>11,17</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::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>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>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>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>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>-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>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>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></td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>black-on-purple</td> +</tr> + +<!-- open foreground (using area button) to display checkbox effects --> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::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>9,6</td> +</tr> +<!-- remove css field --> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::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>6,7</td> +</tr> +<!-- remove RGB tab --> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::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>6,7</td> +</tr> +<!-- remove HSV tab --> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::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>6,9</td> +</tr> +<!-- return css field --> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::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>6,8</td> +</tr> +<!-- return Swatches tab --> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::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></td> +</tr> + +<!-- change color of the first shade button --> +<tr> + <td>click</td> + <td>shadebutton_1</td> + <td></td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_Srgb-gradient/domChild[1]/domChild[4]</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></td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>blue-first-button</td> +</tr> + +<!-- reset the color back to black --> +<tr> + <td>click</td> + <td>shadebutton_1</td> + <td></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[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></td> +</tr> + +<!-- change color of the last shade area --> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_Sshadearea_16/domChild[1]</td> + <td>10,-65</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::PID_Srgb-gradient/domChild[1]/domChild[4]</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></td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>yellow-last-area</td> +</tr> + +<!-- reset the color back to white --> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentscolorpickerColorPickerTest::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>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></td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>final</td> +</tr> +</tbody></table> +</body> +</html> diff --git a/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerTest.java b/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerTest.java new file mode 100644 index 0000000000..0f7e639725 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/colorpicker/ColorPickerTest.java @@ -0,0 +1,492 @@ +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); + } +} |