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.

HasStyleNames.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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.ui;
  17. import java.io.Serializable;
  18. /**
  19. * Implemented by components which support style names.
  20. *
  21. * <p>
  22. * Each style name will occur only once as specified and it is not prefixed with
  23. * the style name of the component.
  24. * </p>
  25. *
  26. * @since 8.7
  27. */
  28. public interface HasStyleNames extends Serializable {
  29. /**
  30. * Gets all user-defined CSS style names of a component. If the component
  31. * has multiple style names defined, the return string is a space-separated
  32. * list of style names. Built-in style names defined in Vaadin or GWT are
  33. * not returned.
  34. *
  35. * <p>
  36. * The style names are returned only in the basic form in which they were
  37. * added.
  38. * </p>
  39. *
  40. * @since 8.7
  41. * @return the style name or a space-separated list of user-defined style
  42. * names of the component
  43. * @see #setStyleName(String)
  44. * @see #addStyleName(String)
  45. * @see #removeStyleName(String)
  46. */
  47. String getStyleName();
  48. /**
  49. * Sets one or more user-defined style names of the component, replacing any
  50. * previous user-defined styles. Multiple styles can be specified as a
  51. * space-separated list of style names. The style names must be valid CSS
  52. * class names.
  53. *
  54. * <p>
  55. * It is normally a good practice to use {@link #addStyleName(String)
  56. * addStyleName()} rather than this setter, as different software
  57. * abstraction layers can then add their own styles without accidentally
  58. * removing those defined in other layers.
  59. * </p>
  60. *
  61. * @since 8.7
  62. * @param style
  63. * the new style or styles of the component as a space-separated
  64. * list
  65. * @see #getStyleName()
  66. * @see #addStyleName(String)
  67. * @see #removeStyleName(String)
  68. */
  69. void setStyleName(String style);
  70. /**
  71. * Adds or removes a style name. Multiple styles can be specified as a
  72. * space-separated list of style names.
  73. *
  74. * If the {@code add} parameter is true, the style name is added to the
  75. * component. If the {@code add} parameter is false, the style name is
  76. * removed from the component.
  77. * <p>
  78. * Functionally this is equivalent to using {@link #addStyleName(String)} or
  79. * {@link #removeStyleName(String)}
  80. *
  81. * @since 8.7
  82. * @param style
  83. * the style name to be added or removed
  84. * @param add
  85. * <code>true</code> to add the given style, <code>false</code>
  86. * to remove it
  87. * @see #addStyleName(String)
  88. * @see #removeStyleName(String)
  89. */
  90. default void setStyleName(String style, boolean add) {
  91. if (add) {
  92. addStyleName(style);
  93. } else {
  94. removeStyleName(style);
  95. }
  96. }
  97. /**
  98. * Adds one or more style names to this component. Multiple styles can be
  99. * specified as a space-separated list of style names. The style name will
  100. * be rendered as a HTML class name, which can be used in a CSS definition.
  101. *
  102. *
  103. * @since 8.7
  104. * @param style
  105. * the new style to be added to the component
  106. * @see #getStyleName()
  107. * @see #setStyleName(String)
  108. * @see #removeStyleName(String)
  109. */
  110. void addStyleName(String style);
  111. /**
  112. * Adds one or more style names to this component by using one or multiple
  113. * parameters.
  114. *
  115. * @since 8.7
  116. * @param styles
  117. * the style name or style names to be added to the component
  118. * @see #addStyleName(String)
  119. * @see #setStyleName(String)
  120. * @see #removeStyleName(String)
  121. */
  122. default void addStyleNames(String... styles) {
  123. for (String style : styles) {
  124. addStyleName(style);
  125. }
  126. }
  127. /**
  128. * Removes one or more style names from component. Multiple styles can be
  129. * specified as a space-separated list of style names.
  130. *
  131. * <p>
  132. * The parameter must be a valid CSS style name. Only user-defined style
  133. * names added with {@link #addStyleName(String) addStyleName()} or
  134. * {@link #setStyleName(String) setStyleName()} can be removed; built-in
  135. * style names defined in Vaadin or GWT can not be removed.
  136. * </p>
  137. *
  138. * @since 8.7
  139. * @param style
  140. * the style name or style names to be removed
  141. * @see #getStyleName()
  142. * @see #setStyleName(String)
  143. * @see #addStyleName(String)
  144. */
  145. void removeStyleName(String style);
  146. /**
  147. * Removes one or more style names from component. Multiple styles can be
  148. * specified by using multiple parameters.
  149. *
  150. * <p>
  151. * The parameter must be a valid CSS style name. Only user-defined style
  152. * names added with {@link #addStyleName(String) addStyleName()} or
  153. * {@link #setStyleName(String) setStyleName()} can be removed; built-in
  154. * style names defined in Vaadin or GWT can not be removed.
  155. * </p>
  156. *
  157. * @since 8.7
  158. * @param styles
  159. * the style name or style names to be removed
  160. * @see #removeStyleName(String)
  161. * @see #setStyleName(String)
  162. * @see #addStyleName(String)
  163. */
  164. default void removeStyleNames(String... styles) {
  165. for (String style : styles) {
  166. removeStyleName(style);
  167. }
  168. }
  169. }