< prev index next >

modules/javafx.graphics/src/test/java/test/javafx/css/CssMetaDataTest.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   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


  27 
  28 import java.io.File;
  29 import java.lang.reflect.InvocationTargetException;
  30 import java.lang.reflect.Method;
  31 import java.lang.reflect.Modifier;
  32 import java.net.URL;
  33 import java.util.ArrayList;
  34 import java.util.Arrays;
  35 import java.util.Collections;
  36 import java.util.List;
  37 import java.util.Set;
  38 
  39 import com.sun.javafx.css.CascadingStyle;
  40 import com.sun.javafx.css.ParsedValueImpl;
  41 import com.sun.javafx.css.PseudoClassState;
  42 import com.sun.javafx.css.StyleManager;
  43 import test.com.sun.javafx.css.TestNode;
  44 import test.com.sun.javafx.css.TestNodeBase;
  45 import com.sun.javafx.sg.prism.NGNode;
  46 import javafx.beans.value.WritableValue;

  47 import javafx.scene.Group;
  48 import javafx.scene.Node;
  49 import javafx.scene.Scene;
  50 import javafx.scene.paint.Color;
  51 import javafx.scene.shape.Rectangle;
  52 import javafx.scene.text.Font;
  53 import javafx.scene.text.Text;
  54 import javafx.stage.Stage;
  55 import javafx.css.converter.BooleanConverter;
  56 import com.sun.javafx.geom.BaseBounds;
  57 import com.sun.javafx.geom.transform.BaseTransform;
  58 import com.sun.javafx.scene.NodeHelper;
  59 import javafx.css.CompoundSelector;
  60 import javafx.css.CssMetaData;
  61 import javafx.css.CssParser;
  62 import javafx.css.CssParserShim;
  63 import javafx.css.Declaration;
  64 import javafx.css.DeclarationShim;
  65 import javafx.css.FontCssMetaData;
  66 import javafx.css.ParsedValue;
  67 import javafx.css.PseudoClass;
  68 import javafx.css.Rule;
  69 import javafx.css.RuleShim;
  70 import javafx.css.Selector;
  71 import javafx.css.SelectorShim;
  72 import javafx.css.SimpleSelector;
  73 import javafx.css.SimpleSelectorShim;
  74 import javafx.css.Style;
  75 import javafx.css.StyleConverter;
  76 import javafx.css.StyleOrigin;
  77 import javafx.css.Styleable;
  78 import javafx.css.StyleableProperty;
  79 import javafx.css.Stylesheet;
  80 import javafx.css.StylesheetShim;
  81 import org.junit.Test;
  82 
  83 import static org.junit.Assert.*;
  84 






  85 
  86 public class CssMetaDataTest {
  87 
  88     public CssMetaDataTest() {
  89     }
  90 
  91     private static CssMetaData get(List<CssMetaData<? extends Styleable, ?>> list, String prop) {
  92         for (CssMetaData styleable : list) {
  93             if (prop.equals(styleable.getProperty())) return styleable;
  94         }
  95         return null;
  96     }
  97 
  98     /**
  99      * Test of getCssMetaData method of class Styleable.
 100      */
 101     @Test
 102     public void testGetCssMetaData_Styleable() {
 103         Styleable styleable = new TestNode();
 104         List<CssMetaData<? extends Styleable, ?>> expResult = TestNode.getClassCssMetaData();


1269         text.getStyleClass().add("text");
1270         text.setFill(Color.BLUE);
1271 
1272         final Group group = new Group();
1273         group.getStyleClass().add("group");
1274         group.getChildren().add(text);
1275 
1276         final Group root = new Group();
1277         root.getChildren().add(group);
1278 
1279         Scene scene = new Scene(root);
1280         Stage stage = new Stage();
1281         stage.setScene(scene);
1282         stage.show();
1283 
1284         CssMetaData prop = ((StyleableProperty)text.fillProperty()).getCssMetaData();
1285         List list = NodeHelper.getMatchingStyles(prop, text);
1286 
1287         assertEquals(3, list.size(), 0);
1288 
















1289     }
1290 
1291 }
   1 /*
   2  * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   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


  27 
  28 import java.io.File;
  29 import java.lang.reflect.InvocationTargetException;
  30 import java.lang.reflect.Method;
  31 import java.lang.reflect.Modifier;
  32 import java.net.URL;
  33 import java.util.ArrayList;
  34 import java.util.Arrays;
  35 import java.util.Collections;
  36 import java.util.List;
  37 import java.util.Set;
  38 
  39 import com.sun.javafx.css.CascadingStyle;
  40 import com.sun.javafx.css.ParsedValueImpl;
  41 import com.sun.javafx.css.PseudoClassState;
  42 import com.sun.javafx.css.StyleManager;
  43 import test.com.sun.javafx.css.TestNode;
  44 import test.com.sun.javafx.css.TestNodeBase;
  45 import com.sun.javafx.sg.prism.NGNode;
  46 import javafx.beans.value.WritableValue;
  47 import javafx.scene.control.Labeled;
  48 import javafx.scene.Group;
  49 import javafx.scene.Node;
  50 import javafx.scene.Scene;
  51 import javafx.scene.paint.Color;
  52 import javafx.scene.shape.Rectangle;
  53 import javafx.scene.text.Font;
  54 import javafx.scene.text.Text;
  55 import javafx.stage.Stage;
  56 import javafx.css.converter.BooleanConverter;
  57 import com.sun.javafx.geom.BaseBounds;
  58 import com.sun.javafx.geom.transform.BaseTransform;
  59 import com.sun.javafx.scene.NodeHelper;
  60 import javafx.css.CompoundSelector;
  61 import javafx.css.CssMetaData;
  62 import javafx.css.CssParser;
  63 import javafx.css.CssParserShim;
  64 import javafx.css.Declaration;
  65 import javafx.css.DeclarationShim;
  66 import javafx.css.FontCssMetaData;
  67 import javafx.css.ParsedValue;
  68 import javafx.css.PseudoClass;
  69 import javafx.css.Rule;
  70 import javafx.css.RuleShim;
  71 import javafx.css.Selector;
  72 import javafx.css.SelectorShim;
  73 import javafx.css.SimpleSelector;
  74 import javafx.css.SimpleSelectorShim;
  75 import javafx.css.Style;
  76 import javafx.css.StyleConverter;
  77 import javafx.css.StyleOrigin;
  78 import javafx.css.Styleable;
  79 import javafx.css.StyleableProperty;
  80 import javafx.css.Stylesheet;
  81 import javafx.css.StylesheetShim;
  82 import org.junit.Test;
  83 
  84 import static org.junit.Assert.*;
  85 
  86 enum TestEnum {
  87     LEFT,
  88     CENTER,
  89     RIGHT,
  90     JUSTIFY
  91 }
  92 
  93 public class CssMetaDataTest {
  94 
  95     public CssMetaDataTest() {
  96     }
  97 
  98     private static CssMetaData get(List<CssMetaData<? extends Styleable, ?>> list, String prop) {
  99         for (CssMetaData styleable : list) {
 100             if (prop.equals(styleable.getProperty())) return styleable;
 101         }
 102         return null;
 103     }
 104 
 105     /**
 106      * Test of getCssMetaData method of class Styleable.
 107      */
 108     @Test
 109     public void testGetCssMetaData_Styleable() {
 110         Styleable styleable = new TestNode();
 111         List<CssMetaData<? extends Styleable, ?>> expResult = TestNode.getClassCssMetaData();


1276         text.getStyleClass().add("text");
1277         text.setFill(Color.BLUE);
1278 
1279         final Group group = new Group();
1280         group.getStyleClass().add("group");
1281         group.getChildren().add(text);
1282 
1283         final Group root = new Group();
1284         root.getChildren().add(group);
1285 
1286         Scene scene = new Scene(root);
1287         Stage stage = new Stage();
1288         stage.setScene(scene);
1289         stage.show();
1290 
1291         CssMetaData prop = ((StyleableProperty)text.fillProperty()).getCssMetaData();
1292         List list = NodeHelper.getMatchingStyles(prop, text);
1293 
1294         assertEquals(3, list.size(), 0);
1295 
1296     }
1297 
1298     @Test
1299     public void testStyleConverterReturnType() {
1300         final CssMetaData<Labeled, TestEnum> TEST_ENUM =
1301                 new CssMetaData<Labeled, TestEnum> ("-my-enum", StyleConverter.getEnumConverter(TestEnum.class), TestEnum.LEFT, false) {
1302                     @Override
1303                     public boolean isSettable(Labeled styleable) {
1304                         return false;
1305                     }
1306 
1307                     @Override
1308                     public StyleableProperty<TestEnum> getStyleableProperty(Labeled styleable) {
1309                         return null;
1310                     }
1311         };
1312     }
1313 
1314 }
< prev index next >