Skip to content

Commit

Permalink
Make ColorPicker an AbstractField<Color>
Browse files Browse the repository at this point in the history
Remove old ColorSelector API from ColorPicker.
The various subcomponents still implement ColorSelector for now.

Change-Id: If0e30eda71c5fe30f7128056a65fb127a4953089
  • Loading branch information
jdahlstrom committed Oct 3, 2016
1 parent 9583be4 commit ac84fe6
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 260 deletions.
246 changes: 97 additions & 149 deletions server/src/main/java/com/vaadin/ui/AbstractColorPicker.java

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion server/src/main/java/com/vaadin/ui/ColorPicker.java
Expand Up @@ -63,5 +63,4 @@ protected void setDefaultStyles() {
setPrimaryStyleName(STYLENAME_BUTTON); setPrimaryStyleName(STYLENAME_BUTTON);
addStyleName(STYLENAME_DEFAULT); addStyleName(STYLENAME_DEFAULT);
} }

} }
Expand Up @@ -34,7 +34,7 @@ public void testAllAbstractColorPickerFeatures() {
+ " history-visibility=false textfield-visibility=false />"; + " history-visibility=false textfield-visibility=false />";
ColorPicker colorPicker = new ColorPicker(); ColorPicker colorPicker = new ColorPicker();
int colorInt = Integer.parseInt("fafafa", 16); int colorInt = Integer.parseInt("fafafa", 16);
colorPicker.setColor(new Color(colorInt)); colorPicker.setValue(new Color(colorInt));
colorPicker.setDefaultCaptionEnabled(true); colorPicker.setDefaultCaptionEnabled(true);
colorPicker.setPosition(100, 100); colorPicker.setPosition(100, 100);
colorPicker.setPopupStyle(PopupStyle.POPUP_SIMPLE); colorPicker.setPopupStyle(PopupStyle.POPUP_SIMPLE);
Expand Down Expand Up @@ -63,7 +63,7 @@ public void testAllAbstractColorPickerAreaFeatures() {
+ " history-visibility=false textfield-visibility=false />"; + " history-visibility=false textfield-visibility=false />";
AbstractColorPicker colorPicker = new ColorPickerArea(); AbstractColorPicker colorPicker = new ColorPickerArea();
int colorInt = Integer.parseInt("fafafa", 16); int colorInt = Integer.parseInt("fafafa", 16);
colorPicker.setColor(new Color(colorInt)); colorPicker.setValue(new Color(colorInt));
colorPicker.setDefaultCaptionEnabled(true); colorPicker.setDefaultCaptionEnabled(true);
colorPicker.setPosition(100, 100); colorPicker.setPosition(100, 100);
colorPicker.setPopupStyle(PopupStyle.POPUP_SIMPLE); colorPicker.setPopupStyle(PopupStyle.POPUP_SIMPLE);
Expand Down
Expand Up @@ -15,15 +15,15 @@
*/ */
package com.vaadin.shared.ui.colorpicker; package com.vaadin.shared.ui.colorpicker;


import com.vaadin.shared.AbstractComponentState; import com.vaadin.shared.AbstractFieldState;
import com.vaadin.shared.annotations.DelegateToWidget; import com.vaadin.shared.annotations.DelegateToWidget;


/** /**
* Default shared state implementation for AbstractColorPicker. * Default shared state implementation for AbstractColorPicker.
* *
* @since 7.0.0 * @since 7.0.0
*/ */
public class ColorPickerState extends AbstractComponentState { public class ColorPickerState extends AbstractFieldState {
{ {
primaryStyleName = "v-colorpicker"; primaryStyleName = "v-colorpicker";
} }
Expand All @@ -35,5 +35,4 @@ public class ColorPickerState extends AbstractComponentState {
public String color = null; public String color = null;


public boolean showDefaultCaption; public boolean showDefaultCaption;

} }
Expand Up @@ -4,8 +4,6 @@
import com.vaadin.shared.ui.colorpicker.Color; import com.vaadin.shared.ui.colorpicker.Color;
import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.ColorPickerArea; 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. * Tests the HSV tab slider values when initially opening the tab.
Expand All @@ -14,18 +12,11 @@ public class ColorPickerHsvTest extends AbstractTestUI {


@Override @Override
protected void setup(VaadinRequest request) { 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(); ColorPickerArea colorpicker = new ColorPickerArea();
colorpicker.setColor(new Color(Integer.parseInt("00b4f0", 16))); colorpicker.setValue(new Color(Integer.parseInt("00b4f0", 16)));
colorpicker.setDefaultCaptionEnabled(false); colorpicker.setDefaultCaptionEnabled(false);
colorpicker.setId("colorpicker"); colorpicker.setId("colorpicker");
layout.addComponent(colorpicker); addComponent(colorpicker);

} }


@Override @Override
Expand Down
Expand Up @@ -26,6 +26,8 @@


import javax.imageio.ImageIO; import javax.imageio.ImageIO;


import com.vaadin.annotations.Widgetset;
import com.vaadin.data.HasValue.ValueChange;
import com.vaadin.server.StreamResource; import com.vaadin.server.StreamResource;
import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.ui.colorpicker.Color; import com.vaadin.shared.ui.colorpicker.Color;
Expand All @@ -42,11 +44,9 @@
import com.vaadin.ui.Label; import com.vaadin.ui.Label;
import com.vaadin.ui.Panel; import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.components.colorpicker.ColorChangeEvent;
import com.vaadin.ui.components.colorpicker.ColorChangeListener;


public class ColorPickerTestUI extends AbstractTestUI @Widgetset("com.vaadin.DefaultWidgetSet")
implements ColorChangeListener { public class ColorPickerTestUI extends AbstractTestUI {


@Override @Override
public String getTestDescription() { public String getTestDescription() {
Expand Down Expand Up @@ -274,14 +274,14 @@ protected void setup(VaadinRequest request) {
HorizontalLayout layout1 = createHorizontalLayout(); HorizontalLayout layout1 = createHorizontalLayout();


colorpicker1 = new ColorPicker("Foreground", foregroundColor); colorpicker1 = new ColorPicker("Foreground", foregroundColor);
colorpicker1.setHtmlContentAllowed(true); colorpicker1.setCaptionAsHtml(true);
colorpicker1.addColorChangeListener(this); colorpicker1.addValueChangeListener(this::colorChanged);
colorpicker1.setId("colorpicker1"); colorpicker1.setId("colorpicker1");
layout1.addComponent(colorpicker1); layout1.addComponent(colorpicker1);
layout1.setComponentAlignment(colorpicker1, Alignment.MIDDLE_CENTER); layout1.setComponentAlignment(colorpicker1, Alignment.MIDDLE_CENTER);


colorpicker2 = new ColorPicker("Background", backgroundColor); colorpicker2 = new ColorPicker("Background", backgroundColor);
colorpicker2.addColorChangeListener(this); colorpicker2.addValueChangeListener(this::colorChanged);
colorpicker2.setId("colorpicker2"); colorpicker2.setId("colorpicker2");
layout1.addComponent(colorpicker2); layout1.addComponent(colorpicker2);
layout1.setComponentAlignment(colorpicker2, Alignment.MIDDLE_CENTER); layout1.setComponentAlignment(colorpicker2, Alignment.MIDDLE_CENTER);
Expand All @@ -294,15 +294,15 @@ protected void setup(VaadinRequest request) {
HorizontalLayout layout2 = createHorizontalLayout(); HorizontalLayout layout2 = createHorizontalLayout();


colorpicker3 = new ColorPicker("Foreground", foregroundColor); colorpicker3 = new ColorPicker("Foreground", foregroundColor);
colorpicker3.addColorChangeListener(this); colorpicker3.addValueChangeListener(this::colorChanged);
colorpicker3.setWidth("120px"); colorpicker3.setWidth("120px");
colorpicker3.setCaption("Foreground"); colorpicker3.setCaption("Foreground");
colorpicker3.setId("colorpicker3"); colorpicker3.setId("colorpicker3");
layout2.addComponent(colorpicker3); layout2.addComponent(colorpicker3);
layout2.setComponentAlignment(colorpicker3, Alignment.MIDDLE_CENTER); layout2.setComponentAlignment(colorpicker3, Alignment.MIDDLE_CENTER);


colorpicker4 = new ColorPicker("Background", backgroundColor); colorpicker4 = new ColorPicker("Background", backgroundColor);
colorpicker4.addColorChangeListener(this); colorpicker4.addValueChangeListener(this::colorChanged);
colorpicker4.setWidth("120px"); colorpicker4.setWidth("120px");
colorpicker4.setCaption("Background"); colorpicker4.setCaption("Background");
colorpicker4.setId("colorpicker4"); colorpicker4.setId("colorpicker4");
Expand All @@ -318,15 +318,15 @@ protected void setup(VaadinRequest request) {


colorpicker5 = new ColorPickerArea("Foreground", foregroundColor); colorpicker5 = new ColorPickerArea("Foreground", foregroundColor);
colorpicker5.setCaption("Foreground"); colorpicker5.setCaption("Foreground");
colorpicker5.addColorChangeListener(this); colorpicker5.addValueChangeListener(this::colorChanged);
colorpicker5.setId("colorpicker5"); colorpicker5.setId("colorpicker5");
layout3.addComponent(colorpicker5); layout3.addComponent(colorpicker5);
layout3.setComponentAlignment(colorpicker5, Alignment.MIDDLE_CENTER); layout3.setComponentAlignment(colorpicker5, Alignment.MIDDLE_CENTER);


colorpicker6 = new ColorPickerArea("Background", backgroundColor); colorpicker6 = new ColorPickerArea("Background", backgroundColor);
colorpicker6.setCaption("Background"); colorpicker6.setCaption("Background");
colorpicker6.setDefaultCaptionEnabled(false); colorpicker6.setDefaultCaptionEnabled(false);
colorpicker6.addColorChangeListener(this); colorpicker6.addValueChangeListener(this::colorChanged);
colorpicker6.setId("colorpicker6"); colorpicker6.setId("colorpicker6");
layout3.addComponent(colorpicker6); layout3.addComponent(colorpicker6);
layout3.setComponentAlignment(colorpicker6, Alignment.MIDDLE_CENTER); layout3.setComponentAlignment(colorpicker6, Alignment.MIDDLE_CENTER);
Expand Down Expand Up @@ -451,36 +451,35 @@ public void updateDisplay(Color fg, Color bg) {
display.setSource(imageresource); display.setSource(imageresource);
} }


@Override private void colorChanged(ValueChange<Color> event) {
public void colorChanged(ColorChangeEvent event) {
if (event.getSource() == colorpicker1 if (event.getSource() == colorpicker1
|| event.getSource() == colorpicker3 || event.getSource() == colorpicker3
|| event.getSource() == colorpicker5) { || event.getSource() == colorpicker5) {
foregroundColor = event.getColor(); foregroundColor = event.getValue();


if (event.getSource() != colorpicker1) { if (event.getSource() != colorpicker1) {
colorpicker1.setColor(event.getColor()); colorpicker1.setValue(event.getValue());
} }
if (event.getSource() != colorpicker3) { if (event.getSource() != colorpicker3) {
colorpicker3.setColor(event.getColor()); colorpicker3.setValue(event.getValue());
} }
if (event.getSource() != colorpicker5) { if (event.getSource() != colorpicker5) {
colorpicker5.setColor(event.getColor()); colorpicker5.setValue(event.getValue());
} }


} else if (event.getSource() == colorpicker2 } else if (event.getSource() == colorpicker2
|| event.getSource() == colorpicker4 || event.getSource() == colorpicker4
|| event.getSource() == colorpicker6) { || event.getSource() == colorpicker6) {
backgroundColor = event.getColor(); backgroundColor = event.getValue();


if (event.getSource() != colorpicker2) { if (event.getSource() != colorpicker2) {
colorpicker2.setColor(event.getColor()); colorpicker2.setValue(event.getValue());
} }
if (event.getSource() != colorpicker4) { if (event.getSource() != colorpicker4) {
colorpicker4.setColor(event.getColor()); colorpicker4.setValue(event.getValue());
} }
if (event.getSource() != colorpicker6) { if (event.getSource() != colorpicker6) {
colorpicker6.setColor(event.getColor()); colorpicker6.setValue(event.getValue());
} }


} else { } else {
Expand Down
Expand Up @@ -15,17 +15,19 @@
*/ */
package com.vaadin.tests.components.colorpicker; package com.vaadin.tests.components.colorpicker;


import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Button; import com.vaadin.ui.Button;
import com.vaadin.ui.ColorPicker;
import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.ColorPicker;


/** /**
* Test for color picker with default caption. * Test for color picker with default caption.
* *
* @author Vaadin Ltd * @author Vaadin Ltd
*/ */
@Widgetset("com.vaadin.DefaultWidgetSet")
public class DefaultCaptionWidth extends AbstractTestUI { public class DefaultCaptionWidth extends AbstractTestUI {


@Override @Override
Expand Down

0 comments on commit ac84fe6

Please sign in to comment.