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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.demo.colorpicker;
  5. import com.itmill.toolkit.data.Property.ValueChangeEvent;
  6. import com.itmill.toolkit.data.Property.ValueChangeListener;
  7. import com.itmill.toolkit.ui.Button;
  8. import com.itmill.toolkit.ui.Label;
  9. import com.itmill.toolkit.ui.Window;
  10. import com.itmill.toolkit.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.itmill.toolkit.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. public void init() {
  22. setMainWindow(main);
  23. // Listen for value change events in the custom component,
  24. // triggered when user clicks a button to select another color.
  25. colorselector.addListener(new ValueChangeListener() {
  26. public void valueChange(ValueChangeEvent event) {
  27. // Provide some server-side feedback
  28. colorname.setValue("Selected color: "
  29. + colorselector.getColor());
  30. }
  31. });
  32. main.addComponent(colorselector);
  33. // Add another component to give feedback from server-side code
  34. colorname = new Label("Selected color: " + colorselector.getColor());
  35. main.addComponent(colorname);
  36. // Server-side manipulation of the component state
  37. final Button button = new Button("Set to white");
  38. button.addListener(new Button.ClickListener() {
  39. public void buttonClick(ClickEvent event) {
  40. colorselector.setColor("white");
  41. }
  42. });
  43. main.addComponent(button);
  44. }
  45. }