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.

VColorPicker.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.ui;
  17. import com.google.gwt.event.dom.client.ClickEvent;
  18. import com.google.gwt.event.dom.client.ClickHandler;
  19. import com.google.gwt.user.client.ui.HTML;
  20. /**
  21. * Client side implementation for ColorPicker.
  22. *
  23. * @since 7.0.0
  24. */
  25. public class VColorPicker extends VButton implements ClickHandler {
  26. private String color = null;
  27. private boolean isOpen = false;
  28. private HTML colorIcon;
  29. @Override
  30. public void onClick(ClickEvent event) {
  31. super.onClick(event);
  32. setOpen(!isOpen);
  33. }
  34. /**
  35. * Set the color of the component, e.g. #ffffff
  36. *
  37. * @param color
  38. */
  39. public void setColor(String color) {
  40. this.color = color;
  41. }
  42. /**
  43. * Mark the popup opened/closed.
  44. *
  45. * @param open
  46. */
  47. public void setOpen(boolean open) {
  48. isOpen = open;
  49. }
  50. /**
  51. * Check the popup's marked state.
  52. *
  53. * @return true if the popup has been marked being open, false otherwise.
  54. */
  55. public boolean isOpen() {
  56. return isOpen;
  57. }
  58. /**
  59. * Update color icon to show the currently selected color.
  60. */
  61. public void refreshColor() {
  62. if (color != null) {
  63. if (colorIcon == null) {
  64. colorIcon = new HTML();
  65. colorIcon.setStylePrimaryName("v-colorpicker-button-color");
  66. wrapper.insertBefore(colorIcon.getElement(), captionElement);
  67. }
  68. // Set the color
  69. colorIcon.getElement().getStyle().setProperty("background", color);
  70. }
  71. }
  72. }