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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. * Gets the color.
  43. *
  44. * @since 8.4
  45. * @return the color
  46. */
  47. public String getColor() {
  48. return color;
  49. }
  50. /**
  51. * Mark the popup opened/closed.
  52. *
  53. * @param open
  54. */
  55. public void setOpen(boolean open) {
  56. isOpen = open;
  57. }
  58. /**
  59. * Check the popup's marked state.
  60. *
  61. * @return true if the popup has been marked being open, false otherwise.
  62. */
  63. public boolean isOpen() {
  64. return isOpen;
  65. }
  66. /**
  67. * Update color icon to show the currently selected color.
  68. */
  69. public void refreshColor() {
  70. if (color != null) {
  71. if (colorIcon == null) {
  72. colorIcon = new HTML();
  73. colorIcon.setStylePrimaryName("v-colorpicker-button-color");
  74. wrapper.insertBefore(colorIcon.getElement(), captionElement);
  75. }
  76. // Set the color
  77. colorIcon.getElement().getStyle().setProperty("background", color);
  78. }
  79. }
  80. }