/* * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.javafx.css; import com.sun.javafx.FXUnit; import com.sun.javafx.css.converters.FontConverter; import com.sun.javafx.css.converters.SizeConverter; import com.sun.javafx.tk.Toolkit; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import javafx.collections.FXCollections; import javafx.collections.MapChangeListener; import javafx.css.CssMetaData; import javafx.css.ParsedValue; import javafx.css.StyleOrigin; import javafx.css.StyleableProperty; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.Stage; import static org.junit.Assert.*; import org.junit.Ignore; import org.junit.Test; public class Node_cssStyleMap_Test { @org.junit.Rule public FXUnit fx = new FXUnit(); public Node_cssStyleMap_Test() { } boolean disabled = false; int nadds = 0; int nremoves = 0; static List createStyleList(List decls) { final List styles = new ArrayList(); for (Declaration decl : decls) { styles.add( new CascadingStyle( new Style(decl.rule.getUnobservedSelectorList().get(0), decl), new PseudoClassState(), 0, 0 ) ); } return styles; } static Map> createStyleMap(List styles) { final Map> smap = new HashMap>(); final int max = styles != null ? styles.size() : 0; for (int i=0; i list = smap.get(property); if (list == null) { list = new ArrayList(5); smap.put(property, list); } list.add(style); } return smap; } @Test @Ignore ("Pending RT-34463") public void testStyleMapTracksChanges() { final List declsNoState = new ArrayList(); Collections.addAll(declsNoState, new Declaration("-fx-fill", new ParsedValueImpl(Color.RED, null), false), new Declaration("-fx-stroke", new ParsedValueImpl(Color.YELLOW, null), false), new Declaration("-fx-stroke-width", new ParsedValueImpl,Number>( new ParsedValueImpl(new Size(3d, SizeUnits.PX), null), SizeConverter.getInstance()), false) ); final List selsNoState = new ArrayList(); Collections.addAll(selsNoState, Selector.createSelector(".rect") ); Rule rule = new Rule(selsNoState, declsNoState); Stylesheet stylesheet = new Stylesheet("testStyleMapTracksChanges"); stylesheet.setOrigin(StyleOrigin.USER_AGENT); stylesheet.getRules().add(rule); final List declsDisabledState = new ArrayList(); Collections.addAll(declsDisabledState, new Declaration("-fx-fill", new ParsedValueImpl(Color.GRAY, null), false), new Declaration("-fx-stroke", new ParsedValueImpl(Color.DARKGRAY, null), false) ); final List selsDisabledState = new ArrayList(); Collections.addAll(selsDisabledState, Selector.createSelector(".rect:disabled") ); rule = new Rule(selsDisabledState, declsDisabledState); stylesheet.getRules().add(rule); final List stylesNoState = createStyleList(declsNoState); final List stylesDisabledState = createStyleList(declsDisabledState); // add to this list on wasAdded, check bean on wasRemoved. final List> beans = new ArrayList>(); Rectangle rect = new Rectangle(50,50); rect.getStyleClass().add("rect"); rect.impl_setStyleMap(FXCollections.observableMap(new HashMap, List