modules/controls/src/test/java/com/sun/javafx/scene/control/LabeledTextTest.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 javafx.css.CssMetaData;
  29 import com.sun.javafx.css.Stylesheet;
  30 import javafx.scene.Cursor;
  31 import javafx.scene.Group;
  32 import javafx.scene.Scene;
  33 import javafx.scene.control.Label;


  34 import javafx.scene.effect.BlendMode;
  35 import javafx.scene.layout.VBox;
  36 import javafx.scene.paint.Color;
  37 import javafx.scene.text.Font;
  38 import javafx.scene.text.TextAlignment;
  39 import javafx.stage.Stage;
  40 import org.junit.*;
  41 import static org.junit.Assert.*;
  42 
  43 /**
  44  *
  45  * @author dgrieve
  46  */
  47 public class LabeledTextTest {
  48     
  49     Label label;
  50     LabeledText labeledText;
  51     Stage stage;
  52     Scene scene;
  53     Stylesheet stylesheet;
  54     
  55     public LabeledTextTest() {
  56     }
  57     
  58     @Before public void setup() {
  59         label = 
  60             new Label("\"A computer once beat me at chess, "
  61                 + "but it was no match for me at kick boxing.\" Emo Philips");
  62         stage = new Stage();
  63         stage.setScene(scene = new Scene(label));
  64         scene.getStylesheets().add(LabeledTextTest.class.getResource("LabeledTextTest.css").toExternalForm());
  65         label.impl_processCSS(true);
  66         labeledText = ((com.sun.javafx.scene.control.skin.LabeledSkinBase)label.getSkin()).text; 
  67     }
  68 
  69     @Test
  70     public void testLabeledTextAlignmentStyleAffectsLabeledText() {
  71         
  72         label.setStyle("-fx-text-alignment: right;");
  73         label.impl_processCSS(true);
  74         assertEquals(TextAlignment.RIGHT, label.getTextAlignment());
  75         assertEquals(TextAlignment.RIGHT, labeledText.getTextAlignment());
  76     
  77     }
  78     
  79     @Test
  80     public void testLabeledTextAlignmentIsBound() {
  81         try {
  82             labeledText.setTextAlignment(TextAlignment.RIGHT);
  83             fail();
  84         } catch (RuntimeException re) {
  85         }
  86     }


 296     }
 297     
 298     @Test
 299     public void testCanStyleUnderlineOnLabeledText() {
 300         assertTrue(labeledText.isUnderline());
 301     }
 302     
 303     @Test
 304     public void testLabeledSetTextFillNotOverridenByUAStyleOnLabeledText() {
 305         label = 
 306             new Label("\"A computer once beat me at chess, "
 307                 + "but it was no match for me at kick boxing.\" Emo Philips") {
 308                     @Override public String getUserAgentStylesheet() {
 309                         return LabeledTextTest.class.getResource("LabeledTextTest.css").toExternalForm();
 310                     }
 311                 };
 312         label.setTextFill(Color.YELLOW);
 313         stage.setScene(scene = new Scene(label));
 314         stage.show();
 315 //        label.impl_processCSS(true);
 316         labeledText = ((com.sun.javafx.scene.control.skin.LabeledSkinBase)label.getSkin()).text; 
 317         assertEquals(Color.YELLOW, labeledText.getFill());
 318     }
 319     
 320     @Test
 321     public void testLabeledSetFontNotOverridenByUAStyleOnLabeledText() {
 322         label = 
 323             new Label("\"A computer once beat me at chess, "
 324                 + "but it was no match for me at kick boxing.\" Emo Philips") {
 325                     @Override public String getUserAgentStylesheet() {
 326                         return LabeledTextTest.class.getResource("LabeledTextTest.css").toExternalForm();
 327                     }
 328                 };
 329         Font font = Font.font("Amble", 30);
 330         label.setFont(font);
 331         stage.setScene(scene = new Scene(label));
 332         stage.show();
 333 //        label.impl_processCSS(true);
 334         labeledText = ((com.sun.javafx.scene.control.skin.LabeledSkinBase)label.getSkin()).text; 
 335         assertEquals(font, labeledText.getFont());
 336     }
 337     
 338     @Test
 339     public void testLabeledSetTextAlignmentNotOverridenByUAStyleOnLabeledText() {
 340         label = 
 341             new Label("\"A computer once beat me at chess, "
 342                 + "but it was no match for me at kick boxing.\" Emo Philips") {
 343                     @Override public String getUserAgentStylesheet() {
 344                         return LabeledTextTest.class.getResource("LabeledTextTest.css").toExternalForm();
 345                     }
 346                 };
 347         label.setTextAlignment(TextAlignment.JUSTIFY);
 348         stage.setScene(scene = new Scene(label));
 349         stage.show();
 350 //        label.impl_processCSS(true);
 351         labeledText = ((com.sun.javafx.scene.control.skin.LabeledSkinBase)label.getSkin()).text; 
 352         assertEquals(TextAlignment.JUSTIFY, labeledText.getTextAlignment());
 353     }
 354     
 355     @Test
 356     public void testLabeledSetUnderlineNotOverridenByUAStyleOnLabeledText() {
 357         label = 
 358             new Label("\"A computer once beat me at chess, "
 359                 + "but it was no match for me at kick boxing.\" Emo Philips") {
 360                     @Override public String getUserAgentStylesheet() {
 361                         return LabeledTextTest.class.getResource("LabeledTextTest.css").toExternalForm();
 362                     }
 363                 };
 364         label.setUnderline(true);
 365         stage.setScene(scene = new Scene(label));
 366         stage.show();
 367 //        label.impl_processCSS(true);
 368         labeledText = ((com.sun.javafx.scene.control.skin.LabeledSkinBase)label.getSkin()).text; 
 369         assertTrue(labeledText.isUnderline());
 370     }
 371 
 372 
 373     @Test public void test_RT_37787() {
 374 
 375         label = new Label("test_RT_37787");
 376         label.getStyleClass().clear();
 377         label.setId("test-rt-37787");
 378 
 379         scene = new Scene(new Group(label));
 380         String url = getClass().getResource("LabeledTextTest.css").toExternalForm();
 381         scene.getStylesheets().add(url);
 382 
 383         label.setFont(Font.font(10));
 384         assertEquals(10, label.getFont().getSize(), .1);
 385 
 386         stage.setScene(scene);
 387         stage.show();
 388 




   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.scene.control.LabeledText;
  29 import javafx.css.CssMetaData;
  30 import javafx.css.Stylesheet;
  31 import javafx.scene.Cursor;
  32 import javafx.scene.Group;
  33 import javafx.scene.Scene;
  34 import javafx.scene.control.Label;
  35 import javafx.scene.control.skin.LabelSkinBaseRetriever;
  36 import javafx.scene.control.skin.LabeledSkinBase;
  37 import javafx.scene.effect.BlendMode;
  38 import javafx.scene.layout.VBox;
  39 import javafx.scene.paint.Color;
  40 import javafx.scene.text.Font;
  41 import javafx.scene.text.TextAlignment;
  42 import javafx.stage.Stage;
  43 import org.junit.*;
  44 import static org.junit.Assert.*;
  45 
  46 /**
  47  *
  48  * @author dgrieve
  49  */
  50 public class LabeledTextTest {
  51     
  52     Label label;
  53     LabeledText labeledText;
  54     Stage stage;
  55     Scene scene;
  56     Stylesheet stylesheet;
  57     
  58     public LabeledTextTest() {
  59     }
  60     
  61     @Before public void setup() {
  62         label = 
  63             new Label("\"A computer once beat me at chess, "
  64                 + "but it was no match for me at kick boxing.\" Emo Philips");
  65         stage = new Stage();
  66         stage.setScene(scene = new Scene(label));
  67         scene.getStylesheets().add(LabeledTextTest.class.getResource("LabeledTextTest.css").toExternalForm());
  68         label.impl_processCSS(true);
  69         labeledText = LabelSkinBaseRetriever.getText(label);
  70     }
  71 
  72     @Test
  73     public void testLabeledTextAlignmentStyleAffectsLabeledText() {
  74         
  75         label.setStyle("-fx-text-alignment: right;");
  76         label.impl_processCSS(true);
  77         assertEquals(TextAlignment.RIGHT, label.getTextAlignment());
  78         assertEquals(TextAlignment.RIGHT, labeledText.getTextAlignment());
  79     
  80     }
  81     
  82     @Test
  83     public void testLabeledTextAlignmentIsBound() {
  84         try {
  85             labeledText.setTextAlignment(TextAlignment.RIGHT);
  86             fail();
  87         } catch (RuntimeException re) {
  88         }
  89     }


 299     }
 300     
 301     @Test
 302     public void testCanStyleUnderlineOnLabeledText() {
 303         assertTrue(labeledText.isUnderline());
 304     }
 305     
 306     @Test
 307     public void testLabeledSetTextFillNotOverridenByUAStyleOnLabeledText() {
 308         label = 
 309             new Label("\"A computer once beat me at chess, "
 310                 + "but it was no match for me at kick boxing.\" Emo Philips") {
 311                     @Override public String getUserAgentStylesheet() {
 312                         return LabeledTextTest.class.getResource("LabeledTextTest.css").toExternalForm();
 313                     }
 314                 };
 315         label.setTextFill(Color.YELLOW);
 316         stage.setScene(scene = new Scene(label));
 317         stage.show();
 318 //        label.impl_processCSS(true);
 319         labeledText = LabelSkinBaseRetriever.getText(label);
 320         assertEquals(Color.YELLOW, labeledText.getFill());
 321     }
 322     
 323     @Test
 324     public void testLabeledSetFontNotOverridenByUAStyleOnLabeledText() {
 325         label = 
 326             new Label("\"A computer once beat me at chess, "
 327                 + "but it was no match for me at kick boxing.\" Emo Philips") {
 328                     @Override public String getUserAgentStylesheet() {
 329                         return LabeledTextTest.class.getResource("LabeledTextTest.css").toExternalForm();
 330                     }
 331                 };
 332         Font font = Font.font("Amble", 30);
 333         label.setFont(font);
 334         stage.setScene(scene = new Scene(label));
 335         stage.show();
 336 //        label.impl_processCSS(true);
 337         labeledText = LabelSkinBaseRetriever.getText(label);
 338         assertEquals(font, labeledText.getFont());
 339     }
 340     
 341     @Test
 342     public void testLabeledSetTextAlignmentNotOverridenByUAStyleOnLabeledText() {
 343         label = 
 344             new Label("\"A computer once beat me at chess, "
 345                 + "but it was no match for me at kick boxing.\" Emo Philips") {
 346                     @Override public String getUserAgentStylesheet() {
 347                         return LabeledTextTest.class.getResource("LabeledTextTest.css").toExternalForm();
 348                     }
 349                 };
 350         label.setTextAlignment(TextAlignment.JUSTIFY);
 351         stage.setScene(scene = new Scene(label));
 352         stage.show();
 353 //        label.impl_processCSS(true);
 354         labeledText = LabelSkinBaseRetriever.getText(label);
 355         assertEquals(TextAlignment.JUSTIFY, labeledText.getTextAlignment());
 356     }
 357     
 358     @Test
 359     public void testLabeledSetUnderlineNotOverridenByUAStyleOnLabeledText() {
 360         label = 
 361             new Label("\"A computer once beat me at chess, "
 362                 + "but it was no match for me at kick boxing.\" Emo Philips") {
 363                     @Override public String getUserAgentStylesheet() {
 364                         return LabeledTextTest.class.getResource("LabeledTextTest.css").toExternalForm();
 365                     }
 366                 };
 367         label.setUnderline(true);
 368         stage.setScene(scene = new Scene(label));
 369         stage.show();
 370 //        label.impl_processCSS(true);
 371         labeledText = LabelSkinBaseRetriever.getText(label);
 372         assertTrue(labeledText.isUnderline());
 373     }
 374 
 375 
 376     @Test public void test_RT_37787() {
 377 
 378         label = new Label("test_RT_37787");
 379         label.getStyleClass().clear();
 380         label.setId("test-rt-37787");
 381 
 382         scene = new Scene(new Group(label));
 383         String url = getClass().getResource("LabeledTextTest.css").toExternalForm();
 384         scene.getStylesheets().add(url);
 385 
 386         label.setFont(Font.font(10));
 387         assertEquals(10, label.getFont().getSize(), .1);
 388 
 389         stage.setScene(scene);
 390         stage.show();
 391