1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/*
* Copyright 2000-2021 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.ui;
import java.io.Serializable;
/**
* Implemented by components which support style names.
*
* <p>
* Each style name will occur only once as specified and it is not prefixed with
* the style name of the component.
* </p>
*
* @since 8.7
*/
public interface HasStyleNames extends Serializable {
/**
* Gets all user-defined CSS style names of a component. If the component
* has multiple style names defined, the return string is a space-separated
* list of style names. Built-in style names defined in Vaadin or GWT are
* not returned.
*
* <p>
* The style names are returned only in the basic form in which they were
* added.
* </p>
*
* @since 8.7
* @return the style name or a space-separated list of user-defined style
* names of the component
* @see #setStyleName(String)
* @see #addStyleName(String)
* @see #removeStyleName(String)
*/
String getStyleName();
/**
* Sets one or more user-defined style names of the component, replacing any
* previous user-defined styles. Multiple styles can be specified as a
* space-separated list of style names. The style names must be valid CSS
* class names.
*
* <p>
* It is normally a good practice to use {@link #addStyleName(String)
* addStyleName()} rather than this setter, as different software
* abstraction layers can then add their own styles without accidentally
* removing those defined in other layers.
* </p>
*
* @since 8.7
* @param style
* the new style or styles of the component as a space-separated
* list
* @see #getStyleName()
* @see #addStyleName(String)
* @see #removeStyleName(String)
*/
void setStyleName(String style);
/**
* Adds or removes a style name. Multiple styles can be specified as a
* space-separated list of style names.
*
* If the {@code add} parameter is true, the style name is added to the
* component. If the {@code add} parameter is false, the style name is
* removed from the component.
* <p>
* Functionally this is equivalent to using {@link #addStyleName(String)} or
* {@link #removeStyleName(String)}
*
* @since 8.7
* @param style
* the style name to be added or removed
* @param add
* <code>true</code> to add the given style, <code>false</code>
* to remove it
* @see #addStyleName(String)
* @see #removeStyleName(String)
*/
default void setStyleName(String style, boolean add) {
if (add) {
addStyleName(style);
} else {
removeStyleName(style);
}
}
/**
* Adds one or more style names to this component. Multiple styles can be
* specified as a space-separated list of style names. The style name will
* be rendered as a HTML class name, which can be used in a CSS definition.
*
*
* @since 8.7
* @param style
* the new style to be added to the component
* @see #getStyleName()
* @see #setStyleName(String)
* @see #removeStyleName(String)
*/
void addStyleName(String style);
/**
* Adds one or more style names to this component by using one or multiple
* parameters.
*
* @since 8.7
* @param styles
* the style name or style names to be added to the component
* @see #addStyleName(String)
* @see #setStyleName(String)
* @see #removeStyleName(String)
*/
default void addStyleNames(String... styles) {
for (String style : styles) {
addStyleName(style);
}
}
/**
* Removes one or more style names from component. Multiple styles can be
* specified as a space-separated list of style names.
*
* <p>
* The parameter must be a valid CSS style name. Only user-defined style
* names added with {@link #addStyleName(String) addStyleName()} or
* {@link #setStyleName(String) setStyleName()} can be removed; built-in
* style names defined in Vaadin or GWT can not be removed.
* </p>
*
* @since 8.7
* @param style
* the style name or style names to be removed
* @see #getStyleName()
* @see #setStyleName(String)
* @see #addStyleName(String)
*/
void removeStyleName(String style);
/**
* Removes one or more style names from component. Multiple styles can be
* specified by using multiple parameters.
*
* <p>
* The parameter must be a valid CSS style name. Only user-defined style
* names added with {@link #addStyleName(String) addStyleName()} or
* {@link #setStyleName(String) setStyleName()} can be removed; built-in
* style names defined in Vaadin or GWT can not be removed.
* </p>
*
* @since 8.7
* @param styles
* the style name or style names to be removed
* @see #removeStyleName(String)
* @see #setStyleName(String)
* @see #addStyleName(String)
*/
default void removeStyleNames(String... styles) {
for (String style : styles) {
removeStyleName(style);
}
}
}
|