Remove old ColorSelector API from ColorPicker.
The various subcomponents still implement ColorSelector for now.
Change-Id: If0e30eda71c5fe30f7128056a65fb127a4953089
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;
*
* @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
public Color calculate(int x, int y);
/**
- * Calculate coordinates from color
+ * Calculates coordinates from a color.
*
* @param c
* the c
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;
/** 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;
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);
}
/**
* available.
*
* @param enabled
+ * {@code true} to enable the default caption, {@code false} to
+ * disable
*/
public void setDefaultCaptionEnabled(boolean enabled) {
getState().showDefaultCaption = enabled;
/**
* 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
}
}
- @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
}
/**
- * 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) {
}
/**
- * Gets the visibility of the RGB Tab
+ * Gets the visibility of the RGB Tab.
*
* @since 7.5.0
* @return visibility of the RGB tab
}
/**
- * 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) {
}
/**
- * 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) {
}
/**
- * 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;
}
/**
- * 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;
}
/**
- * 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;
}
/**
- * 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.
}
/**
- * 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()) {
parent = getUI();
}
- if (window == null) {
+ Color color = getValue();
- // Create the popup
+ if (window == null) {
window = new ColorPickerPopup(color);
window.setCaption(popupCaption);
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())) {
window.setColor(color);
window.getHistory().setColor(color);
window.setVisible(true);
+
parent.addWindow(window);
+ window.focus();
}
} else if (window != null) {
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);
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(
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);
result.add("popup-style");
return result;
}
+
+ @Override
+ protected void doSetValue(Color color) {
+ this.color = color;
+ getState().color = color.getCSS();
+ }
}
setPrimaryStyleName(STYLENAME_BUTTON);
addStyleName(STYLENAME_DEFAULT);
}
-
}
+ " 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);
+ " 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);
*/
package com.vaadin.shared.ui.colorpicker;
-import com.vaadin.shared.AbstractComponentState;
+import com.vaadin.shared.AbstractFieldState;
import com.vaadin.shared.annotations.DelegateToWidget;
/**
*
* @since 7.0.0
*/
-public class ColorPickerState extends AbstractComponentState {
+public class ColorPickerState extends AbstractFieldState {
{
primaryStyleName = "v-colorpicker";
}
public String color = null;
public boolean showDefaultCaption;
-
}
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.
@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
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;
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() {
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);
HorizontalLayout layout2 = createHorizontalLayout();
colorpicker3 = new ColorPicker("Foreground", foregroundColor);
- colorpicker3.addColorChangeListener(this);
+ colorpicker3.addValueChangeListener(this::colorChanged);
colorpicker3.setWidth("120px");
colorpicker3.setCaption("Foreground");
colorpicker3.setId("colorpicker3");
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");
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);
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);
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 {
*/
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
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;
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
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;
}
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;
* 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;
*/
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;
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 {
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();
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;
@Theme("tests-valo")
@Title("Valo Theme Test")
+@Widgetset("com.vaadin.DefaultWidgetSet")
@PreserveOnRefresh
public class ValoThemeUI extends UI {