]> source.dussan.org Git - vaadin-framework.git/commitdiff
Make ColorPicker an AbstractField<Color>
authorJohannes Dahlström <johannesd@vaadin.com>
Wed, 28 Sep 2016 12:18:44 +0000 (15:18 +0300)
committerJohannes Dahlström <johannesd@vaadin.com>
Mon, 3 Oct 2016 14:18:49 +0000 (17:18 +0300)
Remove old ColorSelector API from ColorPicker.
The various subcomponents still implement ColorSelector for now.

Change-Id: If0e30eda71c5fe30f7128056a65fb127a4953089

server/src/main/java/com/vaadin/ui/AbstractColorPicker.java
server/src/main/java/com/vaadin/ui/ColorPicker.java
server/src/test/java/com/vaadin/tests/server/component/colorpicker/AbstractColorPickerDeclarativeTest.java
shared/src/main/java/com/vaadin/shared/ui/colorpicker/ColorPickerState.java
uitest/src/main/java/com/vaadin/tests/components/colorpicker/ColorPickerHsvTest.java
uitest/src/main/java/com/vaadin/tests/components/colorpicker/ColorPickerTestUI.java
uitest/src/main/java/com/vaadin/tests/components/colorpicker/DefaultCaptionWidth.java
uitest/src/main/java/com/vaadin/tests/minitutorials/v71beta/CSSInjectWithColorpicker.java
uitest/src/main/java/com/vaadin/tests/themes/valo/ColorPickers.java
uitest/src/main/java/com/vaadin/tests/themes/valo/ValoThemeUI.java

index 695187a6eb9680fec628e46a27a012f0afd791a9..d9a668bb9a8a6e3e87f278c75c74c472f1038dc1 100644 (file)
 package com.vaadin.ui;
 
 import java.io.Serializable;
-import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.Objects;
 
 import org.jsoup.nodes.Attributes;
 import org.jsoup.nodes.Element;
 
-import com.vaadin.shared.Registration;
 import com.vaadin.shared.ui.colorpicker.Color;
 import com.vaadin.shared.ui.colorpicker.ColorPickerServerRpc;
 import com.vaadin.shared.ui.colorpicker.ColorPickerState;
-import com.vaadin.ui.Window.CloseEvent;
-import com.vaadin.ui.Window.CloseListener;
-import com.vaadin.ui.components.colorpicker.ColorChangeEvent;
-import com.vaadin.ui.components.colorpicker.ColorChangeListener;
 import com.vaadin.ui.components.colorpicker.ColorPickerPopup;
-import com.vaadin.ui.components.colorpicker.ColorSelector;
 import com.vaadin.ui.declarative.DesignAttributeHandler;
 import com.vaadin.ui.declarative.DesignContext;
 
@@ -42,27 +35,15 @@ import com.vaadin.ui.declarative.DesignContext;
  *
  * @since 7.0.0
  */
-public abstract class AbstractColorPicker extends AbstractComponent
-        implements CloseListener, ColorSelector {
-    private static final Method COLOR_CHANGE_METHOD;
-    static {
-        try {
-            COLOR_CHANGE_METHOD = ColorChangeListener.class.getDeclaredMethod(
-                    "colorChanged", new Class[] { ColorChangeEvent.class });
-        } catch (final java.lang.NoSuchMethodException e) {
-            // This should never happen
-            throw new java.lang.RuntimeException(
-                    "Internal error finding methods in ColorPicker");
-        }
-    }
+public abstract class AbstractColorPicker extends AbstractField<Color> {
 
     /**
-     * Interface for converting 2d-coordinates to a Color
+     * Interface for converting 2d-coordinates to a Color.
      */
     public interface Coordinates2Color extends Serializable {
 
         /**
-         * Calculate color from coordinates
+         * Calculates a color from coordinates.
          *
          * @param x
          *            the x-coordinate
@@ -74,7 +55,7 @@ public abstract class AbstractColorPicker extends AbstractComponent
         public Color calculate(int x, int y);
 
         /**
-         * Calculate coordinates from color
+         * Calculates coordinates from a color.
          *
          * @param c
          *            the c
@@ -84,8 +65,15 @@ public abstract class AbstractColorPicker extends AbstractComponent
         public int[] calculate(Color c);
     }
 
+    /**
+     * The style of the color picker popup.
+     */
     public enum PopupStyle {
-        POPUP_NORMAL("normal"), POPUP_SIMPLE("simple");
+        /** A full popup with all tabs visible. */
+        POPUP_NORMAL("normal"),
+
+        /** A simple popup with only the swatches (palette) tab. */
+        POPUP_SIMPLE("simple");
 
         private String style;
 
@@ -116,13 +104,13 @@ public abstract class AbstractColorPicker extends AbstractComponent
     /** The popup window. */
     private ColorPickerPopup window;
 
-    /** The color. */
+    /** The currently selected color. */
     protected Color color;
 
     /** The UI. */
     private UI parent;
 
-    protected String popupCaption = null;
+    private String popupCaption = null;
     private int positionX = 0;
     private int positionY = 0;
 
@@ -160,25 +148,33 @@ public abstract class AbstractColorPicker extends AbstractComponent
     public AbstractColorPicker(String popupCaption, Color initialColor) {
         super();
         registerRpc(rpc);
-        setColor(initialColor);
+        setValue(initialColor);
         this.popupCaption = popupCaption;
         setDefaultStyles();
         setCaption("");
     }
 
+    /**
+     * Returns the current selected color of this color picker.
+     * 
+     * @return the selected color, not null
+     */
     @Override
-    public void setColor(Color color) {
-        this.color = color;
-
-        if (window != null) {
-            window.setColor(color);
-        }
-        getState().color = color.getCSS();
+    public Color getValue() {
+        return color;
     }
 
+    /**
+     * Sets the selected color of this color picker. If the new color is not
+     * equal to getValue(), fires a value change event.
+     * 
+     * @param color
+     *            the new selected color, not null
+     */
     @Override
-    public Color getColor() {
-        return color;
+    public void setValue(Color color) {
+        Objects.requireNonNull(color, "color cannot be null");
+        super.setValue(color);
     }
 
     /**
@@ -187,6 +183,8 @@ public abstract class AbstractColorPicker extends AbstractComponent
      * available.
      *
      * @param enabled
+     *            {@code true} to enable the default caption, {@code false} to
+     *            disable
      */
     public void setDefaultCaptionEnabled(boolean enabled) {
         getState().showDefaultCaption = enabled;
@@ -195,13 +193,16 @@ public abstract class AbstractColorPicker extends AbstractComponent
     /**
      * Returns true if the component shows the default caption (css-code for the
      * currently selected color, e.g. #ffffff) if no other caption is available.
+     * 
+     * @return {@code true} if the default caption is enabled, {@code false}
+     *         otherwise
      */
     public boolean isDefaultCaptionEnabled() {
         return getState(false).showDefaultCaption;
     }
 
     /**
-     * Sets the position of the popup window
+     * Sets the position of the popup window.
      *
      * @param x
      *            the x-coordinate
@@ -218,75 +219,39 @@ public abstract class AbstractColorPicker extends AbstractComponent
         }
     }
 
-    @Override
-    public Registration addColorChangeListener(ColorChangeListener listener) {
-        addListener(ColorChangeEvent.class, listener, COLOR_CHANGE_METHOD);
-        return () -> removeListener(ColorChangeEvent.class, listener);
-    }
-
-    @Override
-    @Deprecated
-    public void removeColorChangeListener(ColorChangeListener listener) {
-        removeListener(ColorChangeEvent.class, listener);
-    }
-
-    @Override
-    public void windowClose(CloseEvent e) {
-        if (e.getWindow() == window) {
-            getState().popupVisible = false;
-        }
-    }
-
     /**
-     * Fired when a color change event occurs
-     *
-     * @param event
-     *            The color change event
-     */
-    protected void colorChanged(ColorChangeEvent event) {
-        setColor(event.getColor());
-        fireColorChanged();
-    }
-
-    /**
-     * Notifies the listeners that the selected color has changed
-     */
-    public void fireColorChanged() {
-        fireEvent(new ColorChangeEvent(this, color));
-    }
-
-    /**
-     * The style for the popup window
+     * Sets the style of the popup window.
      *
      * @param style
-     *            The style
+     *            the popup window style
      */
     public void setPopupStyle(PopupStyle style) {
         popupStyle = style;
 
         switch (style) {
-        case POPUP_NORMAL: {
+        case POPUP_NORMAL:
             setRGBVisibility(true);
             setHSVVisibility(true);
             setSwatchesVisibility(true);
             setHistoryVisibility(true);
             setTextfieldVisibility(true);
             break;
-        }
 
-        case POPUP_SIMPLE: {
+        case POPUP_SIMPLE:
             setRGBVisibility(false);
             setHSVVisibility(false);
             setSwatchesVisibility(true);
             setHistoryVisibility(false);
             setTextfieldVisibility(false);
             break;
-        }
+
+        default:
+            assert false : "Unknown popup style " + style;
         }
     }
 
     /**
-     * Gets the style for the popup window
+     * Gets the style for the popup window.
      *
      * @since 7.5.0
      * @return popup window style
@@ -296,10 +261,10 @@ public abstract class AbstractColorPicker extends AbstractComponent
     }
 
     /**
-     * Set the visibility of the RGB Tab
+     * Sets the visibility of the RGB tab.
      *
      * @param visible
-     *            The visibility
+     *            {@code true} to display the RGB tab, {@code false} to hide it
      */
     public void setRGBVisibility(boolean visible) {
 
@@ -314,7 +279,7 @@ public abstract class AbstractColorPicker extends AbstractComponent
     }
 
     /**
-     * Gets the visibility of the RGB Tab
+     * Gets the visibility of the RGB Tab.
      *
      * @since 7.5.0
      * @return visibility of the RGB tab
@@ -324,10 +289,10 @@ public abstract class AbstractColorPicker extends AbstractComponent
     }
 
     /**
-     * Set the visibility of the HSV Tab
+     * Sets the visibility of the HSV Tab.
      *
      * @param visible
-     *            The visibility
+     *            {@code true} to display the HSV tab, {@code false} to hide it
      */
     public void setHSVVisibility(boolean visible) {
         if (!visible && !rgbVisible && !swatchesVisible) {
@@ -341,20 +306,22 @@ public abstract class AbstractColorPicker extends AbstractComponent
     }
 
     /**
-     * Gets the visibility of the HSV Tab
+     * Gets the visibility of the HSV tab.
      *
      * @since 7.5.0
-     * @return visibility of the HSV tab
+     * @return {@code true} if the HSV tab is currently displayed, {@code false}
+     *         otherwise
      */
     public boolean getHSVVisibility() {
         return hsvVisible;
     }
 
     /**
-     * Set the visibility of the Swatches Tab
+     * Sets the visibility of the Swatches (palette) tab.
      *
      * @param visible
-     *            The visibility
+     *            {@code true} to display the Swatches tab, {@code false} to
+     *            hide it
      */
     public void setSwatchesVisibility(boolean visible) {
         if (!visible && !hsvVisible && !rgbVisible) {
@@ -368,20 +335,22 @@ public abstract class AbstractColorPicker extends AbstractComponent
     }
 
     /**
-     * Gets the visibility of the Swatches Tab
+     * Gets the visibility of the Swatches (palette) tab.
      *
      * @since 7.5.0
-     * @return visibility of the swatches tab
+     * @return {@code true} if the Swatches tab is currently displayed,
+     *         {@code false} otherwise
      */
     public boolean getSwatchesVisibility() {
         return swatchesVisible;
     }
 
     /**
-     * Sets the visibility of the Color History
+     * Sets the visibility of the color history, displaying recently picked
+     * colors.
      *
      * @param visible
-     *            The visibility
+     *            {@code true} to display the history, {@code false} to hide it
      */
     public void setHistoryVisibility(boolean visible) {
         historyVisible = visible;
@@ -391,20 +360,22 @@ public abstract class AbstractColorPicker extends AbstractComponent
     }
 
     /**
-     * Gets the visibility of the Color History
+     * Gets the visibility of the Color history.
      *
      * @since 7.5.0
-     * @return visibility of color history
+     * @return {@code true} if the history is currently displayed, {@code false}
+     *         otherwise
      */
     public boolean getHistoryVisibility() {
         return historyVisible;
     }
 
     /**
-     * Sets the visibility of the CSS color code text field
+     * Sets the visibility of the CSS color code text field.
      *
      * @param visible
-     *            The visibility
+     *            {@code true} to display the CSS text field, {@code false} to
+     *            hide it
      */
     public void setTextfieldVisibility(boolean visible) {
         textfieldVisible = visible;
@@ -414,10 +385,11 @@ public abstract class AbstractColorPicker extends AbstractComponent
     }
 
     /**
-     * Gets the visibility of CSS color code text field
+     * Gets the visibility of CSS color code text field.
      *
      * @since 7.5.0
-     * @return visibility of css color code text field
+     * @return {@code true} if the CSS text field is currently displayed,
+     *         {@code false} otherwise
      */
     public boolean getTextfieldVisibility() {
         return textfieldVisible;
@@ -434,10 +406,9 @@ public abstract class AbstractColorPicker extends AbstractComponent
     }
 
     /**
-     * Sets the default styles of the component
-     *
+     * Sets the default styles of the component.
      */
-    abstract protected void setDefaultStyles();
+    protected abstract void setDefaultStyles();
 
     /**
      * Shows a popup-window for color selection.
@@ -454,10 +425,11 @@ public abstract class AbstractColorPicker extends AbstractComponent
     }
 
     /**
-     * Shows or hides popup-window depending on the given parameter. If there is
-     * no such window yet, one is created.
+     * Shows or hides the popup window depending on the given parameter. If
+     * there is no such window yet, one is created.
      *
      * @param open
+     *            {@code true} to display the popup, {@code false} to hide it
      */
     protected void showPopup(boolean open) {
         if (open && !isReadOnly()) {
@@ -465,9 +437,9 @@ public abstract class AbstractColorPicker extends AbstractComponent
                 parent = getUI();
             }
 
-            if (window == null) {
+            Color color = getValue();
 
-                // Create the popup
+            if (window == null) {
                 window = new ColorPickerPopup(color);
                 window.setCaption(popupCaption);
 
@@ -478,19 +450,18 @@ public abstract class AbstractColorPicker extends AbstractComponent
                 window.setPreviewVisible(textfieldVisible);
 
                 window.setImmediate(true);
-                window.addCloseListener(this);
-                window.addColorChangeListener(new ColorChangeListener() {
-                    @Override
-                    public void colorChanged(ColorChangeEvent event) {
-                        AbstractColorPicker.this.colorChanged(event);
-                    }
-                });
+                window.addCloseListener(
+                        event -> getState().popupVisible = false);
+                window.addColorChangeListener(
+                        event -> setValue(event.getColor()));
 
                 window.getHistory().setColor(color);
-                parent.addWindow(window);
-                window.setVisible(true);
                 window.setPositionX(positionX);
                 window.setPositionY(positionY);
+                window.setVisible(true);
+
+                parent.addWindow(window);
+                window.focus();
 
             } else if (!parent.equals(window.getParent())) {
 
@@ -503,7 +474,9 @@ public abstract class AbstractColorPicker extends AbstractComponent
                 window.setColor(color);
                 window.getHistory().setColor(color);
                 window.setVisible(true);
+
                 parent.addWindow(window);
+                window.focus();
             }
 
         } else if (window != null) {
@@ -513,37 +486,6 @@ public abstract class AbstractColorPicker extends AbstractComponent
         getState().popupVisible = open;
     }
 
-    /**
-     * Set whether the caption text is rendered as HTML or not. You might need
-     * to re-theme component to allow higher content than the original text
-     * style.
-     *
-     * If set to true, the captions are passed to the browser as html and the
-     * developer is responsible for ensuring no harmful html is used. If set to
-     * false, the content is passed to the browser as plain text.
-     *
-     * @param htmlContentAllowed
-     *            <code>true</code> if caption is rendered as HTML,
-     *            <code>false</code> otherwise
-     * @deprecated as of , use {@link #setCaptionAsHtml(boolean)} instead
-     */
-    @Deprecated
-    public void setHtmlContentAllowed(boolean htmlContentAllowed) {
-        setCaptionAsHtml(htmlContentAllowed);
-    }
-
-    /**
-     * Return HTML rendering setting
-     *
-     * @return <code>true</code> if the caption text is to be rendered as HTML,
-     *         <code>false</code> otherwise
-     * @deprecated as of , use {@link #isCaptionAsHtml()} instead
-     */
-    @Deprecated
-    public boolean isHtmlContentAllowed() {
-        return isCaptionAsHtml();
-    }
-
     @Override
     public void readDesign(Element design, DesignContext designContext) {
         super.readDesign(design, designContext);
@@ -554,7 +496,7 @@ public abstract class AbstractColorPicker extends AbstractComponent
             String hexColor = DesignAttributeHandler
                     .readAttribute("color", attributes, String.class)
                     .substring(1);
-            setColor(new Color(Integer.parseInt(hexColor, 16)));
+            doSetValue(new Color(Integer.parseInt(hexColor, 16)));
         }
         if (design.hasAttr("popup-style")) {
             setPopupStyle(PopupStyle.valueOf(
@@ -573,7 +515,7 @@ public abstract class AbstractColorPicker extends AbstractComponent
 
         Attributes attribute = design.attributes();
         DesignAttributeHandler.writeAttribute("color", attribute,
-                color.getCSS(), Color.WHITE.getCSS(), String.class);
+                getValue().getCSS(), Color.WHITE.getCSS(), String.class);
         DesignAttributeHandler.writeAttribute("popup-style", attribute,
                 (popupStyle == PopupStyle.POPUP_NORMAL ? "normal" : "simple"),
                 "normal", String.class);
@@ -589,4 +531,10 @@ public abstract class AbstractColorPicker extends AbstractComponent
         result.add("popup-style");
         return result;
     }
+
+    @Override
+    protected void doSetValue(Color color) {
+        this.color = color;
+        getState().color = color.getCSS();
+    }
 }
index 67002373d0d0d55f77223906d4ca7b3256b50ae1..706fd6518ba2ef1a43b35c2cba44972a932a66fc 100644 (file)
@@ -63,5 +63,4 @@ public class ColorPicker extends AbstractColorPicker {
         setPrimaryStyleName(STYLENAME_BUTTON);
         addStyleName(STYLENAME_DEFAULT);
     }
-
 }
index 2e3b8e412ecf564eac132ed87b7c956b29b060db..8018d6603e9419b6d6d3126a2cbb33da0eded5f5 100644 (file)
@@ -34,7 +34,7 @@ public class AbstractColorPickerDeclarativeTest
                 + " history-visibility=false textfield-visibility=false />";
         ColorPicker colorPicker = new ColorPicker();
         int colorInt = Integer.parseInt("fafafa", 16);
-        colorPicker.setColor(new Color(colorInt));
+        colorPicker.setValue(new Color(colorInt));
         colorPicker.setDefaultCaptionEnabled(true);
         colorPicker.setPosition(100, 100);
         colorPicker.setPopupStyle(PopupStyle.POPUP_SIMPLE);
@@ -63,7 +63,7 @@ public class AbstractColorPickerDeclarativeTest
                 + " history-visibility=false textfield-visibility=false />";
         AbstractColorPicker colorPicker = new ColorPickerArea();
         int colorInt = Integer.parseInt("fafafa", 16);
-        colorPicker.setColor(new Color(colorInt));
+        colorPicker.setValue(new Color(colorInt));
         colorPicker.setDefaultCaptionEnabled(true);
         colorPicker.setPosition(100, 100);
         colorPicker.setPopupStyle(PopupStyle.POPUP_SIMPLE);
index 074ab0627039e2137c7a970304914729d0c8f01e..922534b8b9ca5e0ce3c31658ec3bbcb249de5887 100644 (file)
@@ -15,7 +15,7 @@
  */
 package com.vaadin.shared.ui.colorpicker;
 
-import com.vaadin.shared.AbstractComponentState;
+import com.vaadin.shared.AbstractFieldState;
 import com.vaadin.shared.annotations.DelegateToWidget;
 
 /**
@@ -23,7 +23,7 @@ import com.vaadin.shared.annotations.DelegateToWidget;
  *
  * @since 7.0.0
  */
-public class ColorPickerState extends AbstractComponentState {
+public class ColorPickerState extends AbstractFieldState {
     {
         primaryStyleName = "v-colorpicker";
     }
@@ -35,5 +35,4 @@ public class ColorPickerState extends AbstractComponentState {
     public String color = null;
 
     public boolean showDefaultCaption;
-
 }
index ab77fbf2ba4d89ae9c83d636558e3db1c90f2aa5..6e426578eba45370398644fc528bd7c85156b277 100644 (file)
@@ -4,8 +4,6 @@ import com.vaadin.server.VaadinRequest;
 import com.vaadin.shared.ui.colorpicker.Color;
 import com.vaadin.tests.components.AbstractTestUI;
 import com.vaadin.ui.ColorPickerArea;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.VerticalLayout;
 
 /**
  * Tests the HSV tab slider values when initially opening the tab.
@@ -14,18 +12,11 @@ public class ColorPickerHsvTest extends AbstractTestUI {
 
     @Override
     protected void setup(VaadinRequest request) {
-        VerticalLayout layout = new VerticalLayout();
-        layout.setMargin(true);
-        setContent(layout);
-
-        layout.addComponent(new Label(
-                "HSV initial values when opening the tab for the first time"));
         ColorPickerArea colorpicker = new ColorPickerArea();
-        colorpicker.setColor(new Color(Integer.parseInt("00b4f0", 16)));
+        colorpicker.setValue(new Color(Integer.parseInt("00b4f0", 16)));
         colorpicker.setDefaultCaptionEnabled(false);
         colorpicker.setId("colorpicker");
-        layout.addComponent(colorpicker);
-
+        addComponent(colorpicker);
     }
 
     @Override
index 9f9164d5828617f9d6718f715844c4c7d88554b4..e80633bcdf04f7da2263bb8e662d2f81e40e0f58 100644 (file)
@@ -26,6 +26,8 @@ import java.util.Date;
 
 import javax.imageio.ImageIO;
 
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.data.HasValue.ValueChange;
 import com.vaadin.server.StreamResource;
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.shared.ui.colorpicker.Color;
@@ -42,11 +44,9 @@ 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 {
+@Widgetset("com.vaadin.DefaultWidgetSet")
+public class ColorPickerTestUI extends AbstractTestUI {
 
     @Override
     public String getTestDescription() {
@@ -274,14 +274,14 @@ public class ColorPickerTestUI extends AbstractTestUI
         HorizontalLayout layout1 = createHorizontalLayout();
 
         colorpicker1 = new ColorPicker("Foreground", foregroundColor);
-        colorpicker1.setHtmlContentAllowed(true);
-        colorpicker1.addColorChangeListener(this);
+        colorpicker1.setCaptionAsHtml(true);
+        colorpicker1.addValueChangeListener(this::colorChanged);
         colorpicker1.setId("colorpicker1");
         layout1.addComponent(colorpicker1);
         layout1.setComponentAlignment(colorpicker1, Alignment.MIDDLE_CENTER);
 
         colorpicker2 = new ColorPicker("Background", backgroundColor);
-        colorpicker2.addColorChangeListener(this);
+        colorpicker2.addValueChangeListener(this::colorChanged);
         colorpicker2.setId("colorpicker2");
         layout1.addComponent(colorpicker2);
         layout1.setComponentAlignment(colorpicker2, Alignment.MIDDLE_CENTER);
@@ -294,7 +294,7 @@ public class ColorPickerTestUI extends AbstractTestUI
         HorizontalLayout layout2 = createHorizontalLayout();
 
         colorpicker3 = new ColorPicker("Foreground", foregroundColor);
-        colorpicker3.addColorChangeListener(this);
+        colorpicker3.addValueChangeListener(this::colorChanged);
         colorpicker3.setWidth("120px");
         colorpicker3.setCaption("Foreground");
         colorpicker3.setId("colorpicker3");
@@ -302,7 +302,7 @@ public class ColorPickerTestUI extends AbstractTestUI
         layout2.setComponentAlignment(colorpicker3, Alignment.MIDDLE_CENTER);
 
         colorpicker4 = new ColorPicker("Background", backgroundColor);
-        colorpicker4.addColorChangeListener(this);
+        colorpicker4.addValueChangeListener(this::colorChanged);
         colorpicker4.setWidth("120px");
         colorpicker4.setCaption("Background");
         colorpicker4.setId("colorpicker4");
@@ -318,7 +318,7 @@ public class ColorPickerTestUI extends AbstractTestUI
 
         colorpicker5 = new ColorPickerArea("Foreground", foregroundColor);
         colorpicker5.setCaption("Foreground");
-        colorpicker5.addColorChangeListener(this);
+        colorpicker5.addValueChangeListener(this::colorChanged);
         colorpicker5.setId("colorpicker5");
         layout3.addComponent(colorpicker5);
         layout3.setComponentAlignment(colorpicker5, Alignment.MIDDLE_CENTER);
@@ -326,7 +326,7 @@ public class ColorPickerTestUI extends AbstractTestUI
         colorpicker6 = new ColorPickerArea("Background", backgroundColor);
         colorpicker6.setCaption("Background");
         colorpicker6.setDefaultCaptionEnabled(false);
-        colorpicker6.addColorChangeListener(this);
+        colorpicker6.addValueChangeListener(this::colorChanged);
         colorpicker6.setId("colorpicker6");
         layout3.addComponent(colorpicker6);
         layout3.setComponentAlignment(colorpicker6, Alignment.MIDDLE_CENTER);
@@ -451,36 +451,35 @@ public class ColorPickerTestUI extends AbstractTestUI
         display.setSource(imageresource);
     }
 
-    @Override
-    public void colorChanged(ColorChangeEvent event) {
+    private void colorChanged(ValueChange<Color> event) {
         if (event.getSource() == colorpicker1
                 || event.getSource() == colorpicker3
                 || event.getSource() == colorpicker5) {
-            foregroundColor = event.getColor();
+            foregroundColor = event.getValue();
 
             if (event.getSource() != colorpicker1) {
-                colorpicker1.setColor(event.getColor());
+                colorpicker1.setValue(event.getValue());
             }
             if (event.getSource() != colorpicker3) {
-                colorpicker3.setColor(event.getColor());
+                colorpicker3.setValue(event.getValue());
             }
             if (event.getSource() != colorpicker5) {
-                colorpicker5.setColor(event.getColor());
+                colorpicker5.setValue(event.getValue());
             }
 
         } else if (event.getSource() == colorpicker2
                 || event.getSource() == colorpicker4
                 || event.getSource() == colorpicker6) {
-            backgroundColor = event.getColor();
+            backgroundColor = event.getValue();
 
             if (event.getSource() != colorpicker2) {
-                colorpicker2.setColor(event.getColor());
+                colorpicker2.setValue(event.getValue());
             }
             if (event.getSource() != colorpicker4) {
-                colorpicker4.setColor(event.getColor());
+                colorpicker4.setValue(event.getValue());
             }
             if (event.getSource() != colorpicker6) {
-                colorpicker6.setColor(event.getColor());
+                colorpicker6.setValue(event.getValue());
             }
 
         } else {
index 300bfd551f8516c82a3833614082fc82a3c0dc9c..7afa9c4d3733d951c56f8c56614328ba58ad4264 100644 (file)
  */
 package com.vaadin.tests.components.colorpicker;
 
+import com.vaadin.annotations.Widgetset;
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.tests.components.AbstractTestUI;
 import com.vaadin.ui.Button;
-import com.vaadin.ui.ColorPicker;
 import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.ColorPicker;
 
 /**
  * Test for color picker with default caption.
  *
  * @author Vaadin Ltd
  */
+@Widgetset("com.vaadin.DefaultWidgetSet")
 public class DefaultCaptionWidth extends AbstractTestUI {
 
     @Override
index 72e3e284186b999636a62176e998d8c01b4d45f5..64d0ba5e6c4948e26752e70cfc5934a257b1611e 100644 (file)
@@ -2,6 +2,7 @@ package com.vaadin.tests.minitutorials.v71beta;
 
 import java.util.Arrays;
 
+import com.vaadin.annotations.Widgetset;
 import com.vaadin.server.Page;
 import com.vaadin.server.Page.Styles;
 import com.vaadin.server.VaadinRequest;
@@ -10,19 +11,16 @@ import com.vaadin.shared.ui.colorpicker.Color;
 import com.vaadin.shared.ui.label.ContentMode;
 import com.vaadin.ui.Alignment;
 import com.vaadin.ui.ColorPicker;
+import com.vaadin.ui.ComboBox;
 import com.vaadin.ui.Component;
 import com.vaadin.ui.HorizontalLayout;
 import com.vaadin.ui.Label;
 import com.vaadin.ui.Panel;
+import com.vaadin.ui.TextArea;
 import com.vaadin.ui.UI;
 import com.vaadin.ui.VerticalLayout;
-import com.vaadin.ui.components.colorpicker.ColorChangeEvent;
-import com.vaadin.ui.components.colorpicker.ColorChangeListener;
-import com.vaadin.v7.data.Property.ValueChangeEvent;
-import com.vaadin.v7.data.Property.ValueChangeListener;
-import com.vaadin.v7.ui.ComboBox;
-import com.vaadin.v7.ui.TextArea;
 
+@Widgetset("com.vaadin.DefaultWidgetSet")
 public class CSSInjectWithColorpicker extends UI {
 
     @Override
@@ -117,22 +115,19 @@ public class CSSInjectWithColorpicker extends UI {
         ColorPicker bgColor = new ColorPicker("Background", Color.WHITE);
         bgColor.setWidth("110px");
         bgColor.setCaption("Background");
-        bgColor.addColorChangeListener(new ColorChangeListener() {
+        bgColor.addValueChangeListener(event -> {
 
-            @Override
-            public void colorChanged(ColorChangeEvent event) {
+            // Get the new background color
+            Color color = event.getValue();
 
-                // Get the new background color
-                Color color = event.getColor();
+            // Get the stylesheet of the page
+            Styles styles = Page.getCurrent().getStyles();
 
-                // Get the stylesheet of the page
-                Styles styles = Page.getCurrent().getStyles();
-
-                // inject the new background color
-                styles.add(".v-app .v-textarea.text-label { background-color:"
-                        + color.getCSS() + "; }");
-            }
+            // inject the new background color
+            styles.add(".v-app .v-textarea.text-label { background-color:"
+                    + color.getCSS() + "; }");
         });
+
         return bgColor;
     }
 
@@ -145,21 +140,17 @@ public class CSSInjectWithColorpicker extends UI {
         ColorPicker textColor = new ColorPicker("Color", Color.BLACK);
         textColor.setWidth("110px");
         textColor.setCaption("Color");
-        textColor.addColorChangeListener(new ColorChangeListener() {
+        textColor.addValueChangeListener(event -> {
 
-            @Override
-            public void colorChanged(ColorChangeEvent event) {
+            // Get the new text color
+            Color color = event.getValue();
 
-                // Get the new text color
-                Color color = event.getColor();
+            // Get the stylesheet of the page
+            Styles styles = Page.getCurrent().getStyles();
 
-                // Get the stylesheet of the page
-                Styles styles = Page.getCurrent().getStyles();
-
-                // inject the new color as a style
-                styles.add(".v-app .v-textarea.text-label { color:"
-                        + color.getCSS() + "; }");
-            }
+            // inject the new color as a style
+            styles.add(".v-app .v-textarea.text-label { color:"
+                    + color.getCSS() + "; }");
         });
 
         return textColor;
@@ -169,31 +160,26 @@ public class CSSInjectWithColorpicker extends UI {
      * Creates a font family selection dialog
      */
     private Component createFontSelect() {
-        final ComboBox select = new ComboBox(null, Arrays.asList("Arial",
-                "Helvetica", "Verdana", "Courier", "Times", "sans-serif"));
+        final ComboBox<String> select = new ComboBox<>(null, Arrays.asList(
+                "Arial", "Helvetica", "Verdana", "Courier", "Times",
+                "sans-serif"));
         select.setValue("Arial");
         select.setWidth("200px");
-        select.setInputPrompt("Font");
+        select.setPlaceholder("Font");
         select.setDescription("Font");
         select.setImmediate(true);
-        select.setNullSelectionAllowed(false);
-        select.setNewItemsAllowed(false);
-
-        select.addValueChangeListener(new ValueChangeListener() {
-
-            @Override
-            public void valueChange(ValueChangeEvent event) {
-                // Get the new font family
-                String fontFamily = select.getValue().toString();
-
-                // Get the stylesheet of the page
-                Styles styles = Page.getCurrent().getStyles();
-
-                // inject the new font size as a style. We need .v-app to
-                // override Vaadin's default styles here
-                styles.add(".v-app .v-textarea.text-label { font-family:"
-                        + fontFamily + "; }");
-            }
+        select.setEmptySelectionAllowed(false);
+        select.addValueChangeListener(event -> {
+            // Get the new font family
+            String fontFamily = select.getValue().toString();
+
+            // Get the stylesheet of the page
+            Styles styles = Page.getCurrent().getStyles();
+
+            // inject the new font size as a style. We need .v-app to
+            // override Vaadin's default styles here
+            styles.add(".v-app .v-textarea.text-label { font-family:"
+                    + fontFamily + "; }");
         });
 
         return select;
@@ -204,30 +190,25 @@ public class CSSInjectWithColorpicker extends UI {
      */
     private Component createFontSizeSelect() {
 
-        final ComboBox select = new ComboBox(null,
+        final ComboBox<Integer> select = new ComboBox<>(null,
                 Arrays.asList(8, 9, 10, 12, 14, 16, 20, 25, 30, 40, 50));
         select.setWidth("100px");
         select.setValue(12);
-        select.setInputPrompt("Font size");
+        select.setPlaceholder("Font size");
         select.setDescription("Font size");
         select.setImmediate(true);
-        select.setNullSelectionAllowed(false);
-        select.setNewItemsAllowed(false);
-        select.addValueChangeListener(new ValueChangeListener() {
-
-            @Override
-            public void valueChange(ValueChangeEvent event) {
-                // Get the new font size
-                Integer fontSize = (Integer) select.getValue();
-
-                // Get the stylesheet of the page
-                Styles styles = Page.getCurrent().getStyles();
-
-                // inject the new font size as a style. We need .v-app to
-                // override Vaadin's default styles here
-                styles.add(".v-app .v-textarea.text-label { font-size:"
-                        + String.valueOf(fontSize) + "px; }");
-            }
+        select.setEmptySelectionAllowed(false);
+        select.addValueChangeListener(event -> {
+            // Get the new font size
+            Integer fontSize = select.getValue();
+
+            // Get the stylesheet of the page
+            Styles styles = Page.getCurrent().getStyles();
+
+            // inject the new font size as a style. We need .v-app to
+            // override Vaadin's default styles here
+            styles.add(".v-app .v-textarea.text-label { font-size:"
+                    + String.valueOf(fontSize) + "px; }");
         });
 
         return select;
index 4c764e7fc66cb654ba006f281f877cf4abd7365a..b36e53d55dedf9195321d4a408e4bf4e5d9c4ced 100644 (file)
@@ -18,11 +18,11 @@ package com.vaadin.tests.themes.valo;
 import com.vaadin.navigator.View;
 import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
 import com.vaadin.shared.ui.colorpicker.Color;
+import com.vaadin.ui.AbstractColorPicker.PopupStyle;
 import com.vaadin.ui.ColorPicker;
 import com.vaadin.ui.HorizontalLayout;
 import com.vaadin.ui.Label;
 import com.vaadin.ui.VerticalLayout;
-import com.vaadin.ui.AbstractColorPicker.PopupStyle;
 import com.vaadin.ui.themes.ValoTheme;
 
 public class ColorPickers extends VerticalLayout implements View {
@@ -43,7 +43,7 @@ public class ColorPickers extends VerticalLayout implements View {
         ColorPicker cp = new ColorPicker();
         cp.setDefaultCaptionEnabled(true);
         cp.setIcon(testIcon.get());
-        cp.setColor(new Color(138, 73, 115));
+        cp.setValue(new Color(138, 73, 115));
         row.addComponent(cp);
 
         cp = new ColorPicker();
index 1a84fd87184071d76278a93596f59c9dd1e8d8c4..c4bf7e8a179a0213619a57b5a360bd993c9f6df8 100644 (file)
@@ -22,6 +22,7 @@ import java.util.Map.Entry;
 import com.vaadin.annotations.PreserveOnRefresh;
 import com.vaadin.annotations.Theme;
 import com.vaadin.annotations.Title;
+import com.vaadin.annotations.Widgetset;
 import com.vaadin.event.Action;
 import com.vaadin.event.Action.Handler;
 import com.vaadin.navigator.Navigator;
@@ -60,6 +61,7 @@ import com.vaadin.v7.ui.NativeSelect;
 
 @Theme("tests-valo")
 @Title("Valo Theme Test")
+@Widgetset("com.vaadin.DefaultWidgetSet")
 @PreserveOnRefresh
 public class ValoThemeUI extends UI {