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.controls.api;
  26 
  27 import com.sun.javafx.runtime.VersionInfo;
  28 import java.net.URL;
  29 import javafx.application.ConditionalFeature;
  30 import javafx.application.Platform;
  31 import javafx.scene.Node;
  32 import javafx.scene.layout.Pane;
  33 import test.css.controls.ControlPage;
  34 import test.css.controls.ControlsCSSApp;
  35 import test.javaclient.shared.BasicButtonChooserApp;
  36 import test.javaclient.shared.ScrollablePageWithSlots;
  37 import test.javaclient.shared.TestNode;
  38 import test.javaclient.shared.TestNodeLeaf;
  39 import test.javaclient.shared.Utils;
  40 
  41 /**
  42  * @author sergey.lugovoy@oracle.com
  43  */
  44 public class APIStylesApp extends BasicButtonChooserApp {
  45 
  46     private static int WIDTH = 1500;
  47     private static int HEIGHT = 900;
  48 
  49     TestNode rootTestNode = new TestNode();
  50 
  51     public APIStylesApp() {
  52         this(WIDTH, HEIGHT, VersionInfo.getRuntimeVersion() + ", Background API Tests", false);
  53     }
  54 
  55     public APIStylesApp(int width, int height, String title, boolean showAdditionalActionButton) {
  56         super(width, height, title, showAdditionalActionButton);
  57     }
  58 
  59     @Override
  60     protected TestNode setup() {
  61         URL css = ControlsCSSApp.class.getResource("/test/css/resources/style.css");
  62         combinedTestChooserPresenter.getScene().getStylesheets().add(css.toExternalForm());
  63         if (showButtons) {
  64             for (ControlPage page : ControlPage.filteredValues()) {
  65                 createPages(page, rootTestNode);
  66             }
  67         }
  68         return rootTestNode;
  69     }
  70 
  71     private void createPages (ControlPage page, TestNode rootNode) {
  72         ScrollablePageWithSlots pageWithSlot = new ScrollablePageWithSlots(page.name(), width, height);
  73         createPage(page, pageWithSlot);
  74         rootNode.add(pageWithSlot);
  75     }
  76 
  77     private void createPage(ControlPage page, TestNode rootNode) {
  78         for (APIControlPage stylePage : APIControlPage.values()) {
  79             Pane slot = new Pane();
  80             slot.setPrefSize(page.slotWidth, page.slotHeight);
  81             final Node control = page.factory.createControl();
  82             Pane innerPane = new Pane();
  83             innerPane.setLayoutX(page.INNER_PANE_SHIFT);
  84             innerPane.setLayoutY(page.INNER_PANE_SHIFT);
  85             innerPane.setPrefSize(page.slotWidth - page.INNER_PANE_SHIFT, page.slotHeight - ControlPage.INNER_PANE_SHIFT);
  86             innerPane.setMaxSize(page.slotWidth - page.INNER_PANE_SHIFT, page.slotHeight - page.INNER_PANE_SHIFT);
  87             innerPane.getChildren().add(control);
  88             if (showButtons) {
  89                 stylePage.setStyle(control);
  90             }
  91             rootNode.add(new TestNodeLeaf(stylePage.name().replace("_", "-"), innerPane));
  92         }
  93     }
  94 
  95     public void open(final ControlPage page) {
  96         Platform.runLater(new Runnable() {
  97             @Override
  98             public void run() {
  99                 createPages(page, rootTestNode);
 100             }
 101         });
 102     }
 103 
 104     public static void main(String[] args) {
 105         Utils.launch(APIStylesApp.class, args);
 106     }
 107 }