modules/graphics/src/test/java/javafx/scene/Node_effectiveOrientation_Css_Test.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


   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.scene;
  27 
  28 import com.sun.javafx.css.StyleManager;
  29 import com.sun.javafx.css.Stylesheet;
  30 import com.sun.javafx.css.parser.CSSParser;
  31 import com.sun.javafx.tk.Toolkit;
  32 import static javafx.geometry.NodeOrientation.*;
  33 import javafx.scene.paint.Color;
  34 import javafx.scene.shape.Rectangle;
  35 import javafx.stage.Stage;
  36 import org.junit.After;
  37 import org.junit.Ignore;
  38 import org.junit.Test;
  39 import static org.junit.Assert.*;
  40 import org.junit.Before;
  41 
  42 /**
  43  * Test :dir functional pseudo-class 
  44  */
  45 @Ignore
  46 public class Node_effectiveOrientation_Css_Test {
  47     
  48     private Group root;
  49     private Scene scene;
  50     private Stage stage;
  51 
  52     @Before
  53     public void setUp() {
  54         root = new Group();
  55         scene = new Scene(root);
  56         stage = new Stage();
  57         stage.setScene(scene);
  58         stage.show();
  59         stage.requestFocus();
  60     }
  61 
  62     @After
  63     public void tearDown() {
  64         stage.hide();
  65     }
  66     
  67     public Node_effectiveOrientation_Css_Test() {}
  68     
  69     @Test
  70     public void test_SimpleSelector_dir_pseudoClass_with_scene_effective_orientation_ltr() {
  71         Stylesheet stylesheet = CSSParser.getInstance().parse(
  72                 ".rect:dir(rtl) { -fx-fill: #ff0000; }" +
  73                 ".rect:dir(ltr) { -fx-fill: #00ff00; }" +
  74                 ".rect { -fx-fill: #0000ff; }" 
  75         );
  76         StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
  77 
  78         Rectangle rect = new Rectangle();
  79         rect.getStyleClass().add("rect");
  80         root.getChildren().add(rect);
  81 
  82         // CSS is applied on next pulse after child is added
  83         root.applyCss();
  84         
  85         assertEquals(scene.getEffectiveNodeOrientation(), LEFT_TO_RIGHT);
  86         assertEquals(Color.web("#00ff00"), rect.getFill());
  87     }
  88     
  89     @Test
  90     public void test_SimpleSelector_dir_pseudoClass_with_scene_effective_orientation_rtl() {
  91         Stylesheet stylesheet = CSSParser.getInstance().parse(
  92                 ".rect:dir(rtl) { -fx-fill: #ff0000; }" +
  93                 ".rect:dir(ltr) { -fx-fill: #00ff00; }" +
  94                 ".rect { -fx-fill: #0000ff; }" 
  95         );
  96         StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
  97 
  98         Rectangle rect = new Rectangle();
  99         rect.getStyleClass().add("rect");
 100         root.getChildren().add(rect);
 101 
 102         scene.setNodeOrientation(RIGHT_TO_LEFT);
 103         // CSS is applied on next pulse after child is added
 104         root.applyCss();
 105         
 106         assertEquals(scene.getEffectiveNodeOrientation(), RIGHT_TO_LEFT);
 107         assertEquals(Color.web("#ff0000"), rect.getFill());
 108     }
 109 
 110     @Test
 111     public void test_CompounSelector_dir_pseudoClass_on_parent_with_scene_effective_orientation_ltr() {
 112         Stylesheet stylesheet = CSSParser.getInstance().parse(
 113                 ".root:dir(rtl) .rect { -fx-fill: #ff0000; }" +
 114                 ".root:dir(ltr) .rect { -fx-fill: #00ff00; }" +
 115                 ".root .rect { -fx-fill: #0000ff; }" 
 116         );
 117         StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
 118 
 119         Rectangle rect = new Rectangle();
 120         rect.getStyleClass().add("rect");
 121         root.getChildren().add(rect);
 122 
 123         // CSS is applied on next pulse after child is added
 124         root.applyCss();
 125         
 126         assertEquals(scene.getEffectiveNodeOrientation(), LEFT_TO_RIGHT);
 127         assertEquals(Color.web("#00ff00"), rect.getFill());
 128     }
 129     
 130     @Test
 131     public void test_CompoundSelector_dir_pseudoClass_on_parent_with_scene_effective_orientation_rtl() {
 132         Stylesheet stylesheet = CSSParser.getInstance().parse(
 133                 ".root:dir(rtl) .rect { -fx-fill: #ff0000; }" +
 134                 ".root:dir(ltr) .rect { -fx-fill: #00ff00; }" +
 135                 ".root .rect { -fx-fill: #0000ff; }" 
 136         );
 137         StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
 138 
 139         Rectangle rect = new Rectangle();
 140         rect.getStyleClass().add("rect");
 141         root.getChildren().add(rect);
 142 
 143         scene.setNodeOrientation(RIGHT_TO_LEFT);
 144         // CSS is applied on next pulse after child is added
 145         root.applyCss();
 146         
 147         assertEquals(scene.getEffectiveNodeOrientation(), RIGHT_TO_LEFT);
 148         assertEquals(Color.web("#ff0000"), rect.getFill());
 149     }
 150 
 151     @Test
 152     public void test_CompounSelector_dir_pseudoClass_on_child_with_scene_effective_orientation_ltr() {
 153         Stylesheet stylesheet = CSSParser.getInstance().parse(
 154                 ".root .rect:dir(rtl) { -fx-fill: #ff0000; }" +
 155                 ".root .rect:dir(ltr) { -fx-fill: #00ff00; }" +
 156                 ".root .rect { -fx-fill: #0000ff; }" 
 157         );
 158         StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
 159 
 160         Rectangle rect = new Rectangle();
 161         rect.getStyleClass().add("rect");
 162         root.getChildren().add(rect);
 163 
 164         // CSS is applied on next pulse after child is added
 165         root.applyCss();
 166         
 167         assertEquals(scene.getEffectiveNodeOrientation(), LEFT_TO_RIGHT);
 168         assertEquals(Color.web("#00ff00"), rect.getFill());
 169     }
 170     
 171     @Test
 172     public void test_CompoundSelector_dir_pseudoClass_on_child_with_scene_effective_orientation_rtl() {
 173         Stylesheet stylesheet = CSSParser.getInstance().parse(
 174                 ".root .rect:dir(rtl) { -fx-fill: #ff0000; }" +
 175                 ".root .rect:dir(ltr) { -fx-fill: #00ff00; }" +
 176                 ".root .rect { -fx-fill: #0000ff; }" 
 177         );
 178         StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
 179 
 180         Rectangle rect = new Rectangle();
 181         rect.getStyleClass().add("rect");
 182         root.getChildren().add(rect);
 183 
 184         scene.setNodeOrientation(RIGHT_TO_LEFT);
 185         // CSS is applied on next pulse after child is added
 186         root.applyCss();
 187         
 188         assertEquals(scene.getEffectiveNodeOrientation(), RIGHT_TO_LEFT);
 189         assertEquals(Color.web("#ff0000"), rect.getFill());
 190     }
 191     
 192     @Test
 193     public void test_dir_pseudoClass_functions_on_scene_effective_orientation_not_node() {
 194         Stylesheet stylesheet = CSSParser.getInstance().parse(
 195                 ".rect:dir(rtl) { -fx-fill: #ff0000; }" +
 196                 ".rect:dir(ltr) { -fx-fill: #00ff00; }" +
 197                 ".rect { -fx-fill: #0000ff; }" 
 198         );
 199         StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
 200 
 201         Rectangle rect = new Rectangle();
 202         rect.getStyleClass().add("rect");
 203         root.getChildren().add(rect);
 204         
 205         rect.setNodeOrientation(RIGHT_TO_LEFT);
 206 
 207         // CSS is applied on next pulse after child is added
 208         root.applyCss();
 209         
 210         assertEquals(scene.getEffectiveNodeOrientation(), LEFT_TO_RIGHT);
 211         assertEquals(rect.getEffectiveNodeOrientation(), RIGHT_TO_LEFT);
 212         // :dir() pseudo-class functions on scene effective orientation, not node
 213         assertEquals(Color.web("#00ff00"), rect.getFill());
 214         


   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.scene;
  27 
  28 import com.sun.javafx.css.StyleManager;
  29 import javafx.css.Stylesheet;
  30 import javafx.css.CssParser;
  31 import com.sun.javafx.tk.Toolkit;
  32 import static javafx.geometry.NodeOrientation.*;
  33 import javafx.scene.paint.Color;
  34 import javafx.scene.shape.Rectangle;
  35 import javafx.stage.Stage;
  36 import org.junit.After;
  37 import org.junit.Ignore;
  38 import org.junit.Test;
  39 import static org.junit.Assert.*;
  40 import org.junit.Before;
  41 
  42 /**
  43  * Test :dir functional pseudo-class 
  44  */
  45 @Ignore
  46 public class Node_effectiveOrientation_Css_Test {
  47     
  48     private Group root;
  49     private Scene scene;
  50     private Stage stage;
  51 
  52     @Before
  53     public void setUp() {
  54         root = new Group();
  55         scene = new Scene(root);
  56         stage = new Stage();
  57         stage.setScene(scene);
  58         stage.show();
  59         stage.requestFocus();
  60     }
  61 
  62     @After
  63     public void tearDown() {
  64         stage.hide();
  65     }
  66     
  67     public Node_effectiveOrientation_Css_Test() {}
  68     
  69     @Test
  70     public void test_SimpleSelector_dir_pseudoClass_with_scene_effective_orientation_ltr() {
  71         Stylesheet stylesheet = new CssParser().parse(
  72                 ".rect:dir(rtl) { -fx-fill: #ff0000; }" +
  73                 ".rect:dir(ltr) { -fx-fill: #00ff00; }" +
  74                 ".rect { -fx-fill: #0000ff; }" 
  75         );
  76         StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
  77 
  78         Rectangle rect = new Rectangle();
  79         rect.getStyleClass().add("rect");
  80         root.getChildren().add(rect);
  81 
  82         // CSS is applied on next pulse after child is added
  83         root.applyCss();
  84         
  85         assertEquals(scene.getEffectiveNodeOrientation(), LEFT_TO_RIGHT);
  86         assertEquals(Color.web("#00ff00"), rect.getFill());
  87     }
  88     
  89     @Test
  90     public void test_SimpleSelector_dir_pseudoClass_with_scene_effective_orientation_rtl() {
  91         Stylesheet stylesheet = new CssParser().parse(
  92                 ".rect:dir(rtl) { -fx-fill: #ff0000; }" +
  93                 ".rect:dir(ltr) { -fx-fill: #00ff00; }" +
  94                 ".rect { -fx-fill: #0000ff; }" 
  95         );
  96         StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
  97 
  98         Rectangle rect = new Rectangle();
  99         rect.getStyleClass().add("rect");
 100         root.getChildren().add(rect);
 101 
 102         scene.setNodeOrientation(RIGHT_TO_LEFT);
 103         // CSS is applied on next pulse after child is added
 104         root.applyCss();
 105         
 106         assertEquals(scene.getEffectiveNodeOrientation(), RIGHT_TO_LEFT);
 107         assertEquals(Color.web("#ff0000"), rect.getFill());
 108     }
 109 
 110     @Test
 111     public void test_CompounSelector_dir_pseudoClass_on_parent_with_scene_effective_orientation_ltr() {
 112         Stylesheet stylesheet = new CssParser().parse(
 113                 ".root:dir(rtl) .rect { -fx-fill: #ff0000; }" +
 114                 ".root:dir(ltr) .rect { -fx-fill: #00ff00; }" +
 115                 ".root .rect { -fx-fill: #0000ff; }" 
 116         );
 117         StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
 118 
 119         Rectangle rect = new Rectangle();
 120         rect.getStyleClass().add("rect");
 121         root.getChildren().add(rect);
 122 
 123         // CSS is applied on next pulse after child is added
 124         root.applyCss();
 125         
 126         assertEquals(scene.getEffectiveNodeOrientation(), LEFT_TO_RIGHT);
 127         assertEquals(Color.web("#00ff00"), rect.getFill());
 128     }
 129     
 130     @Test
 131     public void test_CompoundSelector_dir_pseudoClass_on_parent_with_scene_effective_orientation_rtl() {
 132         Stylesheet stylesheet = new CssParser().parse(
 133                 ".root:dir(rtl) .rect { -fx-fill: #ff0000; }" +
 134                 ".root:dir(ltr) .rect { -fx-fill: #00ff00; }" +
 135                 ".root .rect { -fx-fill: #0000ff; }" 
 136         );
 137         StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
 138 
 139         Rectangle rect = new Rectangle();
 140         rect.getStyleClass().add("rect");
 141         root.getChildren().add(rect);
 142 
 143         scene.setNodeOrientation(RIGHT_TO_LEFT);
 144         // CSS is applied on next pulse after child is added
 145         root.applyCss();
 146         
 147         assertEquals(scene.getEffectiveNodeOrientation(), RIGHT_TO_LEFT);
 148         assertEquals(Color.web("#ff0000"), rect.getFill());
 149     }
 150 
 151     @Test
 152     public void test_CompounSelector_dir_pseudoClass_on_child_with_scene_effective_orientation_ltr() {
 153         Stylesheet stylesheet = new CssParser().parse(
 154                 ".root .rect:dir(rtl) { -fx-fill: #ff0000; }" +
 155                 ".root .rect:dir(ltr) { -fx-fill: #00ff00; }" +
 156                 ".root .rect { -fx-fill: #0000ff; }" 
 157         );
 158         StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
 159 
 160         Rectangle rect = new Rectangle();
 161         rect.getStyleClass().add("rect");
 162         root.getChildren().add(rect);
 163 
 164         // CSS is applied on next pulse after child is added
 165         root.applyCss();
 166         
 167         assertEquals(scene.getEffectiveNodeOrientation(), LEFT_TO_RIGHT);
 168         assertEquals(Color.web("#00ff00"), rect.getFill());
 169     }
 170     
 171     @Test
 172     public void test_CompoundSelector_dir_pseudoClass_on_child_with_scene_effective_orientation_rtl() {
 173         Stylesheet stylesheet = new CssParser().parse(
 174                 ".root .rect:dir(rtl) { -fx-fill: #ff0000; }" +
 175                 ".root .rect:dir(ltr) { -fx-fill: #00ff00; }" +
 176                 ".root .rect { -fx-fill: #0000ff; }" 
 177         );
 178         StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
 179 
 180         Rectangle rect = new Rectangle();
 181         rect.getStyleClass().add("rect");
 182         root.getChildren().add(rect);
 183 
 184         scene.setNodeOrientation(RIGHT_TO_LEFT);
 185         // CSS is applied on next pulse after child is added
 186         root.applyCss();
 187         
 188         assertEquals(scene.getEffectiveNodeOrientation(), RIGHT_TO_LEFT);
 189         assertEquals(Color.web("#ff0000"), rect.getFill());
 190     }
 191     
 192     @Test
 193     public void test_dir_pseudoClass_functions_on_scene_effective_orientation_not_node() {
 194         Stylesheet stylesheet = new CssParser().parse(
 195                 ".rect:dir(rtl) { -fx-fill: #ff0000; }" +
 196                 ".rect:dir(ltr) { -fx-fill: #00ff00; }" +
 197                 ".rect { -fx-fill: #0000ff; }" 
 198         );
 199         StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
 200 
 201         Rectangle rect = new Rectangle();
 202         rect.getStyleClass().add("rect");
 203         root.getChildren().add(rect);
 204         
 205         rect.setNodeOrientation(RIGHT_TO_LEFT);
 206 
 207         // CSS is applied on next pulse after child is added
 208         root.applyCss();
 209         
 210         assertEquals(scene.getEffectiveNodeOrientation(), LEFT_TO_RIGHT);
 211         assertEquals(rect.getEffectiveNodeOrientation(), RIGHT_TO_LEFT);
 212         // :dir() pseudo-class functions on scene effective orientation, not node
 213         assertEquals(Color.web("#00ff00"), rect.getFill());
 214