6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
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 com.sun.javafx.css;
27
28
29 import com.sun.javafx.css.parser.CSSParser;
30
31 import java.io.IOException;
32 import javafx.css.CssMetaData;
33 import javafx.css.PseudoClass;
34 import javafx.css.StyleableProperty;
35 import javafx.scene.Group;
36 import javafx.scene.Scene;
37 import javafx.scene.paint.Color;
38 import javafx.scene.paint.Paint;
39 import javafx.scene.shape.Rectangle;
40 import static org.junit.Assert.*;
41
42 import org.junit.Before;
43 import org.junit.Ignore;
44 import org.junit.Test;
45
46 public class Node_cssStateTransition_Test {
47
48 public Node_cssStateTransition_Test() {
49 }
50
51 @Before
52 public void setUp() {
53 StyleManager sm = StyleManager.getInstance();
54 sm.userAgentStylesheetContainers.clear();
61 @Test
62 public void testPropertiesResetOnStyleclassChange() {
63
64 Rectangle rect = new Rectangle(50,50);
65 Paint defaultFill = rect.getFill();
66 Paint defaultStroke = rect.getStroke();
67 Double defaultStrokeWidth = Double.valueOf(rect.getStrokeWidth());
68
69 CssMetaData metaData = ((StyleableProperty)rect.fillProperty()).getCssMetaData();
70 assertEquals(defaultFill, metaData.getInitialValue(rect));
71 metaData = ((StyleableProperty)rect.strokeProperty()).getCssMetaData();
72 assertEquals(defaultStroke, metaData.getInitialValue(rect));
73 metaData = ((StyleableProperty)rect.strokeWidthProperty()).getCssMetaData();
74 assertEquals(defaultStrokeWidth, metaData.getInitialValue(rect));
75
76 Stylesheet stylesheet = null;
77 try {
78 // Note: setDefaultUserAgentStylesheet in StyleManager won't replace the UA stylesheet unless it has a name,
79 // and that name needs to be different from the current one, if any. This matters when running
80 // these tests from the same VM since StyleManager is a singleton.
81 stylesheet = CSSParser.getInstance().parse(
82 "testPropertiesResetOnStyleclassChange",
83 ".rect { -fx-fill: red; -fx-stroke: yellow; -fx-stroke-width: 3px; }" +
84 ".rect.green { -fx-fill: green; }" +
85 ".green { -fx-stroke: green; }"
86
87 );
88 } catch(IOException ioe) {
89 fail();
90 }
91
92 rect.getStyleClass().add("rect");
93
94 Group root = new Group();
95 root.getChildren().add(rect);
96 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
97
98 Scene scene = new Scene(root);
99
100 root.applyCss();
101
128 @Test
129 public void testPropertiesResetOnPsedudoClassStateChange() {
130
131 Rectangle rect = new Rectangle(50,50);
132 Paint defaultFill = rect.getFill();
133 Paint defaultStroke = rect.getStroke();
134 Double defaultStrokeWidth = Double.valueOf(rect.getStrokeWidth());
135
136 CssMetaData metaData = ((StyleableProperty)rect.fillProperty()).getCssMetaData();
137 assertEquals(defaultFill, metaData.getInitialValue(rect));
138 metaData = ((StyleableProperty)rect.strokeProperty()).getCssMetaData();
139 assertEquals(defaultStroke, metaData.getInitialValue(rect));
140 metaData = ((StyleableProperty)rect.strokeWidthProperty()).getCssMetaData();
141 assertEquals(defaultStrokeWidth, metaData.getInitialValue(rect));
142
143 Stylesheet stylesheet = null;
144 try {
145 // Note: setDefaultUserAgentStylesheet in StyleManager won't replace the UA stylesheet unless it has a name,
146 // and that name needs to be different from the current one, if any. This matters when running
147 // these tests from the same VM since StyleManager is a singleton.
148 stylesheet = CSSParser.getInstance().parse(
149 "testPropertiesResetOnPsedudoClassStateChange",
150 ".rect:hover { -fx-fill: red; -fx-stroke: yellow; -fx-stroke-width: 3px; }" +
151 ".rect:hover:focused { -fx-fill: green; }" +
152 ".rect:focused { -fx-stroke: green; }"
153
154 );
155 } catch(IOException ioe) {
156 fail();
157 }
158
159 rect.getStyleClass().add("rect");
160
161 Group root = new Group();
162 root.getChildren().add(rect);
163 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
164
165 Scene scene = new Scene(root);
166
167 root.applyCss();
168
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
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 javafx.css;
27
28
29 import com.sun.javafx.css.StyleManager;
30
31 import java.io.IOException;
32 import javafx.scene.Group;
33 import javafx.scene.Scene;
34 import javafx.scene.paint.Color;
35 import javafx.scene.paint.Paint;
36 import javafx.scene.shape.Rectangle;
37 import static org.junit.Assert.*;
38
39 import org.junit.Before;
40 import org.junit.Ignore;
41 import org.junit.Test;
42
43 public class Node_cssStateTransition_Test {
44
45 public Node_cssStateTransition_Test() {
46 }
47
48 @Before
49 public void setUp() {
50 StyleManager sm = StyleManager.getInstance();
51 sm.userAgentStylesheetContainers.clear();
58 @Test
59 public void testPropertiesResetOnStyleclassChange() {
60
61 Rectangle rect = new Rectangle(50,50);
62 Paint defaultFill = rect.getFill();
63 Paint defaultStroke = rect.getStroke();
64 Double defaultStrokeWidth = Double.valueOf(rect.getStrokeWidth());
65
66 CssMetaData metaData = ((StyleableProperty)rect.fillProperty()).getCssMetaData();
67 assertEquals(defaultFill, metaData.getInitialValue(rect));
68 metaData = ((StyleableProperty)rect.strokeProperty()).getCssMetaData();
69 assertEquals(defaultStroke, metaData.getInitialValue(rect));
70 metaData = ((StyleableProperty)rect.strokeWidthProperty()).getCssMetaData();
71 assertEquals(defaultStrokeWidth, metaData.getInitialValue(rect));
72
73 Stylesheet stylesheet = null;
74 try {
75 // Note: setDefaultUserAgentStylesheet in StyleManager won't replace the UA stylesheet unless it has a name,
76 // and that name needs to be different from the current one, if any. This matters when running
77 // these tests from the same VM since StyleManager is a singleton.
78 stylesheet = new CssParser().parse(
79 "testPropertiesResetOnStyleclassChange",
80 ".rect { -fx-fill: red; -fx-stroke: yellow; -fx-stroke-width: 3px; }" +
81 ".rect.green { -fx-fill: green; }" +
82 ".green { -fx-stroke: green; }"
83
84 );
85 } catch(IOException ioe) {
86 fail();
87 }
88
89 rect.getStyleClass().add("rect");
90
91 Group root = new Group();
92 root.getChildren().add(rect);
93 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
94
95 Scene scene = new Scene(root);
96
97 root.applyCss();
98
125 @Test
126 public void testPropertiesResetOnPsedudoClassStateChange() {
127
128 Rectangle rect = new Rectangle(50,50);
129 Paint defaultFill = rect.getFill();
130 Paint defaultStroke = rect.getStroke();
131 Double defaultStrokeWidth = Double.valueOf(rect.getStrokeWidth());
132
133 CssMetaData metaData = ((StyleableProperty)rect.fillProperty()).getCssMetaData();
134 assertEquals(defaultFill, metaData.getInitialValue(rect));
135 metaData = ((StyleableProperty)rect.strokeProperty()).getCssMetaData();
136 assertEquals(defaultStroke, metaData.getInitialValue(rect));
137 metaData = ((StyleableProperty)rect.strokeWidthProperty()).getCssMetaData();
138 assertEquals(defaultStrokeWidth, metaData.getInitialValue(rect));
139
140 Stylesheet stylesheet = null;
141 try {
142 // Note: setDefaultUserAgentStylesheet in StyleManager won't replace the UA stylesheet unless it has a name,
143 // and that name needs to be different from the current one, if any. This matters when running
144 // these tests from the same VM since StyleManager is a singleton.
145 stylesheet = new CssParser().parse(
146 "testPropertiesResetOnPsedudoClassStateChange",
147 ".rect:hover { -fx-fill: red; -fx-stroke: yellow; -fx-stroke-width: 3px; }" +
148 ".rect:hover:focused { -fx-fill: green; }" +
149 ".rect:focused { -fx-stroke: green; }"
150
151 );
152 } catch(IOException ioe) {
153 fail();
154 }
155
156 rect.getStyleClass().add("rect");
157
158 Group root = new Group();
159 root.getChildren().add(rect);
160 StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
161
162 Scene scene = new Scene(root);
163
164 root.applyCss();
165
|