11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package test.javafx.css;
27
28 import com.sun.javafx.css.CascadingStyle;
29 import com.sun.javafx.css.ParsedValueImpl;
30 import com.sun.javafx.css.StyleManager;
31 import javafx.css.converter.FontConverter;
32 import javafx.css.converter.SizeConverter;
33
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.List;
37 import java.util.Map;
38
39 import javafx.beans.property.Property;
40 import javafx.css.CssMetaData;
41 import javafx.css.Declaration;
42 import javafx.css.DeclarationShim;
43 import javafx.css.ParsedValue;
44 import javafx.css.Rule;
45 import javafx.css.RuleShim;
46 import javafx.css.Selector;
47 import javafx.css.Size;
48 import javafx.css.SizeUnits;
49 import javafx.css.Style;
50 import javafx.css.StyleOrigin;
131 );
132
133 final List<Selector> selsDisabledState = new ArrayList<Selector>();
134 Collections.addAll(selsDisabledState,
135 Selector.createSelector(".rect:disabled")
136 );
137
138 rule = RuleShim.getRule(selsDisabledState, declsDisabledState);
139 stylesheet.getRules().add(rule);
140
141 Rectangle rect = new Rectangle(50,50);
142 rect.getStyleClass().add("rect");
143
144 Group root = new Group();
145 root.getChildren().add(rect);
146 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
147 Scene scene = new Scene(root);
148
149 rect.applyCss();
150
151 Map<StyleableProperty<?>, List<Style>> map = rect.impl_findStyles(null);
152 assert (map != null && !map.isEmpty());
153
154 checkFoundStyle(rect.fillProperty(), map, declsNoState);
155 checkFoundStyle(rect.strokeProperty(), map, declsNoState);
156 checkFoundStyle(rect.strokeWidthProperty(), map, declsNoState);
157
158 rect.setDisable(true);
159 rect.applyCss();
160
161 map = rect.impl_findStyles(null);
162 assert (map != null && !map.isEmpty());
163
164 checkFoundStyle(rect.fillProperty(), map, declsDisabledState);
165 checkFoundStyle(rect.strokeProperty(), map, declsDisabledState);
166 checkFoundStyle(rect.strokeWidthProperty(), map, declsNoState);
167
168 }
169
170 @Test
171 public void testStyleMapChildren() {
172
173 final List<Declaration> declsNoState = new ArrayList<Declaration>();
174 Collections.addAll(declsNoState,
175 DeclarationShim.getDeclaration("-fx-fill", new ParsedValueImpl<Color,Color>(Color.RED, null), false)
176 );
177
178 final List<Selector> selsNoState = new ArrayList<Selector>();
179 Collections.addAll(selsNoState,
180 Selector.createSelector(".rect")
181 );
182
183 Rule rule = RuleShim.getRule(selsNoState, declsNoState);
184
185 Stylesheet stylesheet = new StylesheetShim("testStyleMapChildren");
186 stylesheet.setOrigin(StyleOrigin.USER_AGENT);
187 stylesheet.getRules().add(rule);
188
189 Rectangle rect = new Rectangle(50,50);
190 rect.getStyleClass().add("rect");
191
192 Group root = new Group();
193 Group group = new Group();
194 root.getChildren().add(group);
195 group.getChildren().add(rect);
196 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
197 Scene scene = new Scene(root);
198
199 root.applyCss();
200
201 // Even though root and group have no styles, the styles for rect should still be found
202 Map<StyleableProperty<?>, List<Style>> map = root.impl_findStyles(null);
203 assert (map != null && !map.isEmpty());
204
205 checkFoundStyle(rect.fillProperty(), map, declsNoState);
206
207 }
208
209 @Test
210 public void testRT_21212() {
211
212 final List<Declaration> rootDecls = new ArrayList<Declaration>();
213 Collections.addAll(rootDecls,
214 DeclarationShim.getDeclaration("-fx-font-size", new ParsedValueImpl<ParsedValue<?,Size>,Number>(
215 new ParsedValueImpl<Size,Size>(new Size(12, SizeUnits.PX), null),
216 SizeConverter.getInstance()), false)
217 );
218
219 final List<Selector> rootSels = new ArrayList<Selector>();
220 Collections.addAll(rootSels,
221 Selector.createSelector(".root")
222 );
246 fontValues, FontConverter.getInstance()), false)
247 );
248
249 final List<Selector> textSels = new ArrayList<Selector>();
250 Collections.addAll(textSels,
251 Selector.createSelector(".text")
252 );
253
254 Rule textRule = RuleShim.getRule(textSels, textDecls);
255 stylesheet.getRules().add(textRule);
256
257 Text text = new Text("HelloWorld");
258 text.getStyleClass().add("text");
259 group.getChildren().add(text);
260
261 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
262 Scene scene = new Scene(group);
263
264 text.applyCss();
265
266 Map<StyleableProperty<?>, List<Style>> map = text.impl_findStyles(null);
267 assert (map != null && !map.isEmpty());
268
269 checkFoundStyle(text.fontProperty(), map, textDecls);
270
271 }
272
273 boolean containsProperty(CssMetaData key, Map<String,List<CascadingStyle>> map) {
274
275 if (map.containsKey(key)) return true;
276 List<CssMetaData> subProperties = key.getSubProperties();
277 if (subProperties != null && !subProperties.isEmpty()) {
278 for (CssMetaData subKey: subProperties) {
279 if (map.containsKey(subKey)) return true;
280 }
281 }
282 return false;
283 }
284
285 @Test
286 public void testRT_34799() {
312 }
313 }
314
315 Text text = new Text("HelloWorld");
316 text.getStyleClass().add("rt-34799");
317
318 Group group = new Group();
319 group.getStyleClass().add("root");
320
321 group.getChildren().add(text);
322
323 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
324 Scene scene = new Scene(group);
325
326 group.applyCss(); // TODO: force StyleHelper to be created, remove pending RT-34812
327
328 int nExpected = expectedStyles.size();
329 assert(nExpected > 0);
330
331 for(CssMetaData cssMetaData : text.getCssMetaData()) {
332 List<Style> styles = Node.impl_getMatchingStyles(cssMetaData, text);
333 if (styles != null && !styles.isEmpty()) {
334 assertTrue(expectedStyles.containsAll(styles));
335 assertTrue(styles.containsAll(expectedStyles));
336 nExpected -= 1;
337 }
338 }
339
340 assertEquals(nExpected, 0);
341
342 }
343
344 }
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package test.javafx.css;
27
28 import com.sun.javafx.css.CascadingStyle;
29 import com.sun.javafx.css.ParsedValueImpl;
30 import com.sun.javafx.css.StyleManager;
31 import com.sun.javafx.scene.NodeHelper;
32 import javafx.css.converter.FontConverter;
33 import javafx.css.converter.SizeConverter;
34
35 import java.util.ArrayList;
36 import java.util.Collections;
37 import java.util.List;
38 import java.util.Map;
39
40 import javafx.beans.property.Property;
41 import javafx.css.CssMetaData;
42 import javafx.css.Declaration;
43 import javafx.css.DeclarationShim;
44 import javafx.css.ParsedValue;
45 import javafx.css.Rule;
46 import javafx.css.RuleShim;
47 import javafx.css.Selector;
48 import javafx.css.Size;
49 import javafx.css.SizeUnits;
50 import javafx.css.Style;
51 import javafx.css.StyleOrigin;
132 );
133
134 final List<Selector> selsDisabledState = new ArrayList<Selector>();
135 Collections.addAll(selsDisabledState,
136 Selector.createSelector(".rect:disabled")
137 );
138
139 rule = RuleShim.getRule(selsDisabledState, declsDisabledState);
140 stylesheet.getRules().add(rule);
141
142 Rectangle rect = new Rectangle(50,50);
143 rect.getStyleClass().add("rect");
144
145 Group root = new Group();
146 root.getChildren().add(rect);
147 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
148 Scene scene = new Scene(root);
149
150 rect.applyCss();
151
152 Map<StyleableProperty<?>, List<Style>> map = NodeHelper.findStyles(rect, null);
153 assert (map != null && !map.isEmpty());
154
155 checkFoundStyle(rect.fillProperty(), map, declsNoState);
156 checkFoundStyle(rect.strokeProperty(), map, declsNoState);
157 checkFoundStyle(rect.strokeWidthProperty(), map, declsNoState);
158
159 rect.setDisable(true);
160 rect.applyCss();
161
162 map = NodeHelper.findStyles(rect, null);
163 assert (map != null && !map.isEmpty());
164
165 checkFoundStyle(rect.fillProperty(), map, declsDisabledState);
166 checkFoundStyle(rect.strokeProperty(), map, declsDisabledState);
167 checkFoundStyle(rect.strokeWidthProperty(), map, declsNoState);
168
169 }
170
171 @Test
172 public void testStyleMapChildren() {
173
174 final List<Declaration> declsNoState = new ArrayList<Declaration>();
175 Collections.addAll(declsNoState,
176 DeclarationShim.getDeclaration("-fx-fill", new ParsedValueImpl<Color,Color>(Color.RED, null), false)
177 );
178
179 final List<Selector> selsNoState = new ArrayList<Selector>();
180 Collections.addAll(selsNoState,
181 Selector.createSelector(".rect")
182 );
183
184 Rule rule = RuleShim.getRule(selsNoState, declsNoState);
185
186 Stylesheet stylesheet = new StylesheetShim("testStyleMapChildren");
187 stylesheet.setOrigin(StyleOrigin.USER_AGENT);
188 stylesheet.getRules().add(rule);
189
190 Rectangle rect = new Rectangle(50,50);
191 rect.getStyleClass().add("rect");
192
193 Group root = new Group();
194 Group group = new Group();
195 root.getChildren().add(group);
196 group.getChildren().add(rect);
197 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
198 Scene scene = new Scene(root);
199
200 root.applyCss();
201
202 // Even though root and group have no styles, the styles for rect should still be found
203 Map<StyleableProperty<?>, List<Style>> map = NodeHelper.findStyles(root, null);
204 assert (map != null && !map.isEmpty());
205
206 checkFoundStyle(rect.fillProperty(), map, declsNoState);
207
208 }
209
210 @Test
211 public void testRT_21212() {
212
213 final List<Declaration> rootDecls = new ArrayList<Declaration>();
214 Collections.addAll(rootDecls,
215 DeclarationShim.getDeclaration("-fx-font-size", new ParsedValueImpl<ParsedValue<?,Size>,Number>(
216 new ParsedValueImpl<Size,Size>(new Size(12, SizeUnits.PX), null),
217 SizeConverter.getInstance()), false)
218 );
219
220 final List<Selector> rootSels = new ArrayList<Selector>();
221 Collections.addAll(rootSels,
222 Selector.createSelector(".root")
223 );
247 fontValues, FontConverter.getInstance()), false)
248 );
249
250 final List<Selector> textSels = new ArrayList<Selector>();
251 Collections.addAll(textSels,
252 Selector.createSelector(".text")
253 );
254
255 Rule textRule = RuleShim.getRule(textSels, textDecls);
256 stylesheet.getRules().add(textRule);
257
258 Text text = new Text("HelloWorld");
259 text.getStyleClass().add("text");
260 group.getChildren().add(text);
261
262 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
263 Scene scene = new Scene(group);
264
265 text.applyCss();
266
267 Map<StyleableProperty<?>, List<Style>> map = NodeHelper.findStyles(text, null);
268 assert (map != null && !map.isEmpty());
269
270 checkFoundStyle(text.fontProperty(), map, textDecls);
271
272 }
273
274 boolean containsProperty(CssMetaData key, Map<String,List<CascadingStyle>> map) {
275
276 if (map.containsKey(key)) return true;
277 List<CssMetaData> subProperties = key.getSubProperties();
278 if (subProperties != null && !subProperties.isEmpty()) {
279 for (CssMetaData subKey: subProperties) {
280 if (map.containsKey(subKey)) return true;
281 }
282 }
283 return false;
284 }
285
286 @Test
287 public void testRT_34799() {
313 }
314 }
315
316 Text text = new Text("HelloWorld");
317 text.getStyleClass().add("rt-34799");
318
319 Group group = new Group();
320 group.getStyleClass().add("root");
321
322 group.getChildren().add(text);
323
324 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
325 Scene scene = new Scene(group);
326
327 group.applyCss(); // TODO: force StyleHelper to be created, remove pending RT-34812
328
329 int nExpected = expectedStyles.size();
330 assert(nExpected > 0);
331
332 for(CssMetaData cssMetaData : text.getCssMetaData()) {
333 List<Style> styles = NodeHelper.getMatchingStyles(cssMetaData, text);
334 if (styles != null && !styles.isEmpty()) {
335 assertTrue(expectedStyles.containsAll(styles));
336 assertTrue(styles.containsAll(expectedStyles));
337 nExpected -= 1;
338 }
339 }
340
341 assertEquals(nExpected, 0);
342
343 }
344
345 }
|