You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ColorPickerApplication.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.demo.colorpicker;
  5. import com.vaadin.data.Property.ValueChangeEvent;
  6. import com.vaadin.data.Property.ValueChangeListener;
  7. import com.vaadin.ui.Button;
  8. import com.vaadin.ui.Label;
  9. import com.vaadin.ui.Window;
  10. import com.vaadin.ui.Button.ClickEvent;
  11. /**
  12. * Demonstration application that shows how to use a simple custom client-side
  13. * GWT component, the ColorPicker.
  14. */
  15. public class ColorPickerApplication extends com.vaadin.Application {
  16. Window main = new Window("Color Picker Demo");
  17. /* The custom component. */
  18. ColorPicker colorselector = new ColorPicker();
  19. /* Another component. */
  20. Label colorname;
  21. @Override
  22. public void init() {
  23. setMainWindow(main);
  24. // Listen for value change events in the custom component,
  25. // triggered when user clicks a button to select another color.
  26. colorselector.addListener(new ValueChangeListener() {
  27. public void valueChange(ValueChangeEvent event) {
  28. // Provide some server-side feedback
  29. colorname.setValue("Selected color: "
  30. + colorselector.getColor());
  31. }
  32. });
  33. main.addComponent(colorselector);
  34. // Add another component to give feedback from server-side code
  35. colorname = new Label("Selected color: " + colorselector.getColor());
  36. main.addComponent(colorname);
  37. // Server-side manipulation of the component state
  38. final Button button = new Button("Set to white");
  39. button.addListener(new Button.ClickListener() {
  40. public void buttonClick(ClickEvent event) {
  41. colorselector.setColor("white");
  42. }
  43. });
  44. main.addComponent(button);
  45. }
  46. }