Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

VColorPicker.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright 2000-2018 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.user.client.ui.HTML;
  19. /**
  20. * Client side implementation for ColorPicker.
  21. *
  22. * @since 7.0.0
  23. */
  24. public class VColorPicker extends VButton {
  25. private String color = null;
  26. private boolean isOpen = false;
  27. private HTML colorIcon;
  28. @Override
  29. public void onClick(ClickEvent event) {
  30. super.onClick(event);
  31. setOpen(!isOpen);
  32. }
  33. /**
  34. * Set the color of the component, e.g. #ffffff
  35. *
  36. * @param color
  37. */
  38. public void setColor(String color) {
  39. this.color = color;
  40. }
  41. /**
  42. * Mark the popup opened/closed.
  43. *
  44. * @param open
  45. */
  46. public void setOpen(boolean open) {
  47. isOpen = open;
  48. }
  49. /**
  50. * Check the popup's marked state.
  51. *
  52. * @return true if the popup has been marked being open, false otherwise.
  53. */
  54. public boolean isOpen() {
  55. return isOpen;
  56. }
  57. /**
  58. * Update color icon to show the currently selected color.
  59. */
  60. public void refreshColor() {
  61. if (color != null) {
  62. if (colorIcon == null) {
  63. colorIcon = new HTML();
  64. colorIcon.setStylePrimaryName("v-colorpicker-button-color");
  65. wrapper.insertBefore(colorIcon.getElement(), captionElement);
  66. }
  67. // Set the color
  68. colorIcon.getElement().getStyle().setProperty("background", color);
  69. }
  70. }
  71. }