modules/controls/src/test/java/com/sun/javafx/scene/control/LabeledImplTest.java

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


   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.scene.control.skin;
  27 
  28 import com.sun.javafx.pgstub.StubImageLoaderFactory;
  29 import com.sun.javafx.pgstub.StubPlatformImageInfo;
  30 import com.sun.javafx.pgstub.StubToolkit;


  31 import com.sun.javafx.tk.Toolkit;
  32 import javafx.css.StyleConverter;
  33 import javafx.css.CssMetaData;
  34 import java.util.ArrayList;
  35 
  36 import java.util.Arrays;
  37 import java.util.Collection;
  38 import java.util.List;
  39 import javafx.beans.value.WritableValue;
  40 import javafx.css.Styleable;
  41 import javafx.geometry.Insets;
  42 import javafx.geometry.Pos;
  43 import javafx.scene.Cursor;
  44 import javafx.scene.Node;
  45 import javafx.scene.control.ContentDisplay;
  46 import javafx.scene.control.Label;
  47 import javafx.scene.control.Labeled;
  48 import javafx.scene.control.OverrunStyle;
  49 import javafx.scene.effect.BlendMode;
  50 import javafx.scene.effect.ColorAdjust;
  51 import javafx.scene.paint.Color;
  52 import javafx.scene.text.Font;
  53 import javafx.scene.text.TextAlignment;
  54 import javax.swing.GroupLayout;
  55 
  56 import org.junit.BeforeClass;
  57 import org.junit.runner.RunWith;
  58 import org.junit.runners.Parameterized;
  59 import org.junit.runners.Parameterized.Parameters;
  60 
  61 import org.junit.Before;
  62 import org.junit.Ignore;
  63 import org.junit.Test;
  64 import static org.junit.Assert.*;
  65 
  66 @RunWith(Parameterized.class)
  67 public class LabeledImplTest {
  68 
  69     @BeforeClass
  70     public static void configureImageLoaderFactory() {
  71         final StubImageLoaderFactory imageLoaderFactory =
  72                 ((StubToolkit) Toolkit.getToolkit()).getImageLoaderFactory();
  73         imageLoaderFactory.reset();
  74         imageLoaderFactory.registerImage(LabeledImpl.class.getResource("caspian/center-btn.png").toExternalForm(),
  75                 new StubPlatformImageInfo(32, 32));
  76     }
  77 
  78     private static final Labeled LABELED = new Label("label");
  79     private static final LabeledImpl LABELED_IMPL = new LabeledImpl(LABELED);
  80     
  81     private static class Configuration {
  82         final WritableValue source;
  83         final WritableValue mirror;
  84         final Object value;
  85         Configuration(WritableValue source, WritableValue mirror, Object value) {
  86             this.source = source;
  87             this.mirror = mirror;
  88             this.value = value;
  89         }        
  90     }
  91     
  92     private static Configuration config(CssMetaData styleable) {
  93         WritableValue source = styleable.getStyleableProperty(LABELED);
  94         WritableValue mirror   = styleable.getStyleableProperty(LABELED_IMPL);


 117                 value = .5;
 118             } else if ("-fx-translate-y".equals(prop)) {
 119                 value = .5;
 120             } else if ("-fx-translate-z".equals(prop)) {
 121                 value = .5;
 122             } else if ("visibility".equals(prop)) {
 123                 value = Boolean.FALSE;
 124             } else if ("-fx-font".equals(prop)) {
 125                 value = Font.font("Amble", 15);
 126             } else if ("-fx-alignment".equals(prop)) {
 127                 value = Pos.TOP_CENTER;
 128             } else if ("-fx-text-alignment".equals(prop)) {
 129                 value = TextAlignment.RIGHT;
 130             } else if ("-fx-text-fill".equals(prop)) {
 131                 value = Color.RED;
 132             } else if ("-fx-text-overrun".equals(prop)) {
 133                 value = OverrunStyle.LEADING_WORD_ELLIPSIS;
 134             } else if ("-fx-wrap-text".equals(prop)) {
 135                 value = Boolean.TRUE;
 136             } else if ("-fx-graphic".equals(prop)) {
 137                 value = LabeledImpl.class.getResource("caspian/center-btn.png").toExternalForm();


 138             } else if ("-fx-underline".equals(prop)) {
 139                 value = Boolean.TRUE;
 140             } else if ("-fx-content-display".equals(prop)) {
 141                 value = ContentDisplay.GRAPHIC_ONLY;
 142             } else if ("-fx-label-padding".equals(prop)) {
 143                 value = new Insets(1,2,3,4);
 144             } else if ("-fx-graphic-text-gap".equals(prop)) {
 145                 value = .5;
 146             } else if ("-fx-ellipsis-string".equals(prop)) {
 147                 value = "...";
 148             } else if ("-fx-line-spacing".equals(prop)) {
 149                 value = 0.0;
 150             } else {
 151                 fail(prop + " not accounted for");
 152                 return null;
 153             }          
 154             
 155             return new Configuration(source, mirror, value);
 156         }
 157 




   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.scene.control;
  27 
  28 import com.sun.javafx.pgstub.StubImageLoaderFactory;
  29 import com.sun.javafx.pgstub.StubPlatformImageInfo;
  30 import com.sun.javafx.pgstub.StubToolkit;
  31 import com.sun.javafx.scene.control.LabeledImpl;
  32 import com.sun.javafx.scene.control.skin.FXVK;
  33 import com.sun.javafx.tk.Toolkit;

  34 import javafx.css.CssMetaData;
  35 import java.util.ArrayList;
  36 

  37 import java.util.Collection;
  38 import java.util.List;
  39 import javafx.beans.value.WritableValue;
  40 import javafx.css.Styleable;
  41 import javafx.geometry.Insets;
  42 import javafx.geometry.Pos;
  43 import javafx.scene.Cursor;

  44 import javafx.scene.control.ContentDisplay;
  45 import javafx.scene.control.Label;
  46 import javafx.scene.control.Labeled;
  47 import javafx.scene.control.OverrunStyle;
  48 import javafx.scene.effect.BlendMode;
  49 import javafx.scene.effect.ColorAdjust;
  50 import javafx.scene.paint.Color;
  51 import javafx.scene.text.Font;
  52 import javafx.scene.text.TextAlignment;

  53 
  54 import org.junit.BeforeClass;
  55 import org.junit.runner.RunWith;
  56 import org.junit.runners.Parameterized;
  57 import org.junit.runners.Parameterized.Parameters;
  58 


  59 import org.junit.Test;
  60 import static org.junit.Assert.*;
  61 
  62 @RunWith(Parameterized.class)
  63 public class LabeledImplTest {
  64 
  65     @BeforeClass
  66     public static void configureImageLoaderFactory() {
  67         final StubImageLoaderFactory imageLoaderFactory =
  68                 ((StubToolkit) Toolkit.getToolkit()).getImageLoaderFactory();
  69         imageLoaderFactory.reset();
  70         imageLoaderFactory.registerImage(FXVK.class.getResource("caspian/center-btn.png").toExternalForm(),
  71                 new StubPlatformImageInfo(32, 32));
  72     }
  73 
  74     private static final Labeled LABELED = new Label("label");
  75     private static final LabeledImpl LABELED_IMPL = new LabeledImpl(LABELED);
  76     
  77     private static class Configuration {
  78         final WritableValue source;
  79         final WritableValue mirror;
  80         final Object value;
  81         Configuration(WritableValue source, WritableValue mirror, Object value) {
  82             this.source = source;
  83             this.mirror = mirror;
  84             this.value = value;
  85         }        
  86     }
  87     
  88     private static Configuration config(CssMetaData styleable) {
  89         WritableValue source = styleable.getStyleableProperty(LABELED);
  90         WritableValue mirror   = styleable.getStyleableProperty(LABELED_IMPL);


 113                 value = .5;
 114             } else if ("-fx-translate-y".equals(prop)) {
 115                 value = .5;
 116             } else if ("-fx-translate-z".equals(prop)) {
 117                 value = .5;
 118             } else if ("visibility".equals(prop)) {
 119                 value = Boolean.FALSE;
 120             } else if ("-fx-font".equals(prop)) {
 121                 value = Font.font("Amble", 15);
 122             } else if ("-fx-alignment".equals(prop)) {
 123                 value = Pos.TOP_CENTER;
 124             } else if ("-fx-text-alignment".equals(prop)) {
 125                 value = TextAlignment.RIGHT;
 126             } else if ("-fx-text-fill".equals(prop)) {
 127                 value = Color.RED;
 128             } else if ("-fx-text-overrun".equals(prop)) {
 129                 value = OverrunStyle.LEADING_WORD_ELLIPSIS;
 130             } else if ("-fx-wrap-text".equals(prop)) {
 131                 value = Boolean.TRUE;
 132             } else if ("-fx-graphic".equals(prop)) {
 133                 // FXVK is used here as it is located within com.sun.javafx.scene.control.skin,
 134                 // which is useful when trying to load caspian / modena resources.
 135                 value = FXVK.class.getResource("caspian/center-btn.png").toExternalForm();
 136             } else if ("-fx-underline".equals(prop)) {
 137                 value = Boolean.TRUE;
 138             } else if ("-fx-content-display".equals(prop)) {
 139                 value = ContentDisplay.GRAPHIC_ONLY;
 140             } else if ("-fx-label-padding".equals(prop)) {
 141                 value = new Insets(1,2,3,4);
 142             } else if ("-fx-graphic-text-gap".equals(prop)) {
 143                 value = .5;
 144             } else if ("-fx-ellipsis-string".equals(prop)) {
 145                 value = "...";
 146             } else if ("-fx-line-spacing".equals(prop)) {
 147                 value = 0.0;
 148             } else {
 149                 fail(prop + " not accounted for");
 150                 return null;
 151             }          
 152             
 153             return new Configuration(source, mirror, value);
 154         }
 155