1 /*
   2  * Copyright (c) 2014, 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
  23  * questions.
  24  */
  25 package test.css.stylesheets;
  26 
  27 import com.sun.javafx.runtime.VersionInfo;
  28 import javafx.application.Application;
  29 import javafx.event.EventHandler;
  30 import javafx.geometry.Pos;
  31 import javafx.scene.Scene;
  32 import javafx.scene.input.MouseEvent;
  33 import javafx.scene.layout.Pane;
  34 import javafx.scene.layout.StackPane;
  35 import javafx.scene.layout.VBox;
  36 import javafx.scene.text.Text;
  37 import javafx.stage.Stage;
  38 import test.javaclient.shared.Utils;
  39 
  40 /**
  41  *
  42  * @author sergey.lugovoy@oracle.com
  43  */
  44 public class StylesheetApp extends Application {
  45     public final static String EXAMPLE_ID = "example";
  46     private static int WIDTH = 300;
  47     private static int HEIGHT = 300;
  48 
  49 
  50     private static String[] styles = new String[]{
  51         StylesheetApp.class.getResource("/test/css/resources/rt-17348_1.css").toExternalForm(),
  52         StylesheetApp.class.getResource("/test/css/resources/rt-17348_2.css").toExternalForm()
  53     };
  54 
  55     private int styleIndex = 0;
  56 
  57     @Override
  58     public void start(Stage stage) throws Exception {
  59         StackPane  pane = new StackPane();
  60         Pane golden = new Pane();
  61         golden.setId(EXAMPLE_ID);
  62         golden.setMinSize(WIDTH, 120);
  63         Text button  = new Text("Change CSS");
  64         final Scene scene = new Scene(pane, HEIGHT, WIDTH);
  65         button.setOnMouseClicked(new EventHandler<MouseEvent>() {
  66 
  67             @Override
  68             public void handle(MouseEvent t) {
  69                 styleIndex = styleIndex == 0 ? 1 : 0;
  70                 scene.getStylesheets().set(0, styles[styleIndex]);
  71             }
  72         });
  73         scene.getStylesheets().add(styles[styleIndex]);
  74         VBox temp = new VBox(golden, button);
  75         temp.setAlignment(Pos.CENTER);
  76         temp.setSpacing(50);
  77         pane.getChildren().add(temp);
  78         stage.setScene(scene);
  79         stage.setTitle("Test for RT-17348." + VersionInfo.getRuntimeVersion());
  80         stage.show();
  81     }
  82 
  83     public static void main(String[] args) {
  84         Utils.launch(StylesheetApp.class, null);
  85     }
  86 }
--- EOF ---