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.

ColorPicker.java 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package com.itmill.toolkit.demo.colorpicker;
  2. import java.util.Map;
  3. import com.itmill.toolkit.terminal.PaintException;
  4. import com.itmill.toolkit.terminal.PaintTarget;
  5. import com.itmill.toolkit.ui.*;
  6. public class ColorPicker extends AbstractField {
  7. public ColorPicker() {
  8. super();
  9. setValue(new String("white"));
  10. }
  11. /** The property value of the field is an Integer. */
  12. public Class getType() {
  13. return String.class;
  14. }
  15. /** Tag is the UIDL element name for client-server communications. */
  16. public String getTag() {
  17. return "colorpicker";
  18. }
  19. /** Encode the property value of the field from RGB components. */
  20. public void setColor(String newcolor) {
  21. setValue(new String(newcolor));
  22. }
  23. /** Decode the property value of the field to RGB components. */
  24. public String getColor() {
  25. return (String) getValue();
  26. }
  27. /* Paint (serialize) the component for the client. */
  28. public void paintContent(PaintTarget target) throws PaintException {
  29. // Superclass writes any common attributes in the paint target.
  30. super.paintContent(target);
  31. // Set any values as variables of the paint target.
  32. target.addVariable(this, "colorname", getColor());
  33. }
  34. public void changeVariables(Object source, Map variables) {
  35. // Sets the currently selected color
  36. if (variables.containsKey("colorname") && !isReadOnly()) {
  37. String newValue = (String) variables.get("colorname");
  38. setValue(newValue, true);
  39. }
  40. }
  41. }