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.fxmltests.app;
  26 
  27 import com.sun.javafx.fxml.LoadListener;
  28 import com.sun.javafx.runtime.VersionInfo;
  29 import java.util.ArrayList;
  30 import java.util.List;
  31 import javafx.application.Application;
  32 import javafx.fxml.FXMLLoader;
  33 import javafx.scene.Node;
  34 import javafx.scene.Scene;
  35 import javafx.scene.layout.VBox;
  36 import javafx.scene.layout.VBoxBuilder;
  37 import javafx.scene.paint.Color;
  38 import javafx.scene.shape.Rectangle;
  39 import javafx.stage.Stage;
  40 import test.javaclient.shared.BasicButtonChooserApp;
  41 import test.javaclient.shared.PageWithSlots;
  42 import test.javaclient.shared.TestNode;
  43 
  44 public class LineNumberApp extends BasicButtonChooserApp {
  45 
  46     private static String FXML_MAIN_RESOURCE = "/test/fxmltests/resources/line_number.fxml";
  47     private static String FXML_TYPE_RESOURCE = "/test/fxmltests/resources/line_number_type.fxml";
  48     private static String FXML_PROPERTY_RESOURCE = "/test/fxmltests/resources/line_number_property.fxml";
  49     public static List<Integer> importProcessingInstruction = new ArrayList<Integer>();
  50     final public static Integer[] importProcessingInstructionMatrix = new Integer[]{3, 4, 5, 6, 7};
  51     public static List<Integer> languageProcessingInstruction = new ArrayList<Integer>();
  52     final public static Integer[] languageProcessingInstructionMatrix = new Integer[]{9};
  53     public static List<Integer> comment = new ArrayList<Integer>();
  54     final public static Integer[] commentMatrix = new Integer[]{12, 15};
  55     public static List<Integer> instanceDeclarationElement = new ArrayList<Integer>();
  56     final public static Integer[] instanceDeclarationElementMatrix = new Integer[]{25, 26, 27, 31, 32, 34, 37};
  57     public static List<Integer> includeElement = new ArrayList<Integer>();
  58     final public static Integer[] includeElementMatrix = new Integer[]{35};
  59     public static List<Integer> referenceElement = new ArrayList<Integer>();
  60     final public static Integer[] referenceElementMatrix = new Integer[]{38};
  61     public static int rootElement = 0;
  62     final public static int rootElementLine = 11;
  63     public static List<Integer> readUnknownStaticProperty = new ArrayList<Integer>();
  64     final public static Integer[] readUnknownStaticPropertyMatrix = new Integer[]{5};
  65     public static List<Integer> beginUnknowStaticElement = new ArrayList<Integer>();
  66     final public static Integer[] beginUnknowStaticElementMatrix = new Integer[]{5};
  67     public static List<Integer> beginUnknowStaticPropertyElement = new ArrayList<Integer>();
  68     final public static Integer[] beginUnknowStaticPropertyElementMatrix = new Integer[]{6};
  69     public static List<Integer> propertyElement = new ArrayList<Integer>();
  70     final public static Integer[] propertyElementMatrix = new Integer[]{28};
  71     public static List<Integer> scriptElement = new ArrayList<Integer>();
  72     final public static Integer[] scriptElementMatrix = new Integer[]{19};
  73     public static List<Integer> defineElement = new ArrayList<Integer>();
  74     final public static Integer[] defineElementMatrix = new Integer[]{16, 41};
  75     public static List<Integer> readPropertyAttribute = new ArrayList<Integer>();
  76     final public static Integer[] readPropertyAttributeMatrix = new Integer[]{11, 11, 26, 27, 27, 27, 27, 32};
  77     public static List<Integer> readInternalAttribute = new ArrayList<Integer>();
  78     final public static Integer[] readInternalAttributeMatrix = new Integer[]{11, 27, 35, 38};
  79     public static List<Integer> readEventHandlerAttribute = new ArrayList<Integer>();
  80     final public static Integer[] readEventHandlerAttributeMatrix = new Integer[]{32};
  81     public static List<Integer> endElement = new ArrayList<Integer>();
  82     final public static Integer[] endElementMatrix = new Integer[]{18, 24, 28, 29, 30, 32, 33, 35, 36, 38, 39, 40, 43, 44};
  83     public static List<Integer> copyElement = new ArrayList<Integer>();
  84     final public static Integer[] copyElementMatrix = new Integer[]{};
  85     private static int WIDTH = 300;
  86     private static int HEIGHT = 300;
  87 
  88     public enum Pages {
  89 
  90         mainPage, unknownTypePage, unknownPropertyPage
  91     }
  92 
  93     public LineNumberApp() {
  94         super(WIDTH, HEIGHT, VersionInfo.getRuntimeVersion(), false);
  95     }
  96 
  97     @Override
  98     protected TestNode setup() {
  99         TestNode root = new TestNode();
 100 
 101         PageWithSlots pageMain = new PageWithSlots(LineNumberApp.Pages.mainPage.name(), HEIGHT - 15, WIDTH - 10);
 102         pageMain.add(new FxmlLoadPage(FXML_MAIN_RESOURCE), LineNumberApp.Pages.mainPage.name());
 103 
 104         PageWithSlots pageType = new PageWithSlots(LineNumberApp.Pages.unknownTypePage.name(), HEIGHT - 15, WIDTH - 10);
 105         pageType.add(new FxmlLoadPage(FXML_TYPE_RESOURCE), LineNumberApp.Pages.mainPage.name());
 106 
 107         PageWithSlots pageProperty = new PageWithSlots(LineNumberApp.Pages.unknownPropertyPage.name(), HEIGHT - 15, WIDTH - 10);
 108         pageProperty.add(new FxmlLoadPage(FXML_PROPERTY_RESOURCE), LineNumberApp.Pages.mainPage.name());
 109 
 110         root.add(pageMain);
 111         root.add(pageType);
 112         root.add(pageProperty);
 113 
 114         return root;
 115     }
 116 
 117     private class FxmlLoadPage extends TestNode {
 118 
 119         private String resource;
 120 
 121         public FxmlLoadPage(String resource) {
 122             this.resource = resource;
 123         }
 124 
 125         @Override
 126         public Node drawNode() {
 127             LineNumberApp.reset();
 128             final FXMLLoader loader = new FXMLLoader(getClass().getResource(resource));
 129             loader.impl_setStaticLoad(true);
 130             loader.impl_setLoadListener(new LoadListener() {
 131 
 132                 @Override
 133                 public void readImportProcessingInstruction(String string) {
 134                     importProcessingInstruction.add(loader.impl_getLineNumber());
 135                 }
 136 
 137                 @Override
 138                 public void readLanguageProcessingInstruction(String string) {
 139                     languageProcessingInstruction.add(loader.impl_getLineNumber());
 140                 }
 141 
 142                 @Override
 143                 public void readComment(String string) {
 144                     comment.add(loader.impl_getLineNumber());
 145                 }
 146 
 147                 @Override
 148                 public void beginInstanceDeclarationElement(Class<?> tye) {
 149                     instanceDeclarationElement.add(loader.impl_getLineNumber());
 150                 }
 151 
 152                 @Override
 153                 public void beginUnknownTypeElement(String string) {
 154                     beginUnknowStaticElement.add(loader.impl_getLineNumber());
 155                 }
 156 
 157                 @Override
 158                 public void beginIncludeElement() {
 159                     includeElement.add(loader.impl_getLineNumber());
 160                 }
 161 
 162                 @Override
 163                 public void beginReferenceElement() {
 164                     referenceElement.add(loader.impl_getLineNumber());
 165                 }
 166 
 167                 @Override
 168                 public void beginCopyElement() {
 169                     copyElement.add(loader.impl_getLineNumber());
 170                 }
 171 
 172                 @Override
 173                 public void beginRootElement() {
 174                     rootElement = loader.impl_getLineNumber();
 175                 }
 176 
 177                 @Override
 178                 public void beginPropertyElement(String string, Class<?> type) {
 179                     propertyElement.add(loader.impl_getLineNumber());
 180                 }
 181 
 182                 @Override
 183                 public void beginUnknownStaticPropertyElement(String string) {
 184                     beginUnknowStaticPropertyElement.add(loader.impl_getLineNumber());
 185                 }
 186 
 187                 @Override
 188                 public void beginScriptElement() {
 189                     scriptElement.add(loader.impl_getLineNumber());
 190                 }
 191 
 192                 @Override
 193                 public void beginDefineElement() {
 194                     defineElement.add(loader.impl_getLineNumber());
 195                 }
 196 
 197                 @Override
 198                 public void readInternalAttribute(String string, String string1) {
 199                     readInternalAttribute.add(loader.impl_getLineNumber());
 200                 }
 201 
 202                 @Override
 203                 public void readPropertyAttribute(String string, Class<?> type, String string1) {
 204                     readPropertyAttribute.add(loader.impl_getLineNumber());
 205                 }
 206 
 207                 @Override
 208                 public void readUnknownStaticPropertyAttribute(String string, String string1) {
 209                     readUnknownStaticProperty.add(loader.impl_getLineNumber());
 210                 }
 211 
 212                 @Override
 213                 public void readEventHandlerAttribute(String string, String string1) {
 214                     readEventHandlerAttribute.add(loader.impl_getLineNumber());
 215                 }
 216 
 217                 @Override
 218                 public void endElement(Object o) {
 219                     endElement.add(loader.impl_getLineNumber());
 220                 }
 221             });
 222             try {
 223                 loader.setRoot(VBoxBuilder.create().prefHeight(200).prefWidth(200).build());
 224                 return (Node) loader.load();
 225             } catch (Exception exc) {
 226                 exc.printStackTrace();
 227                 return new Rectangle(10, 10) {
 228 
 229                     {
 230                         setFill(Color.RED);
 231                     }
 232                 };
 233             }
 234         }
 235     }
 236 
 237     public static void main(String[] args) {
 238         launch(args);
 239     }
 240 
 241     public static void reset() {
 242         importProcessingInstruction.clear();
 243         languageProcessingInstruction.clear();
 244         comment.clear();
 245         instanceDeclarationElement.clear();
 246         beginUnknowStaticElement.clear();
 247         includeElement.clear();
 248         referenceElement.clear();
 249         copyElement.clear();
 250         rootElement = 0;
 251         propertyElement.clear();
 252         beginUnknowStaticPropertyElement.clear();
 253         scriptElement.clear();
 254         defineElement.clear();
 255         readInternalAttribute.clear();
 256         readPropertyAttribute.clear();
 257         readUnknownStaticProperty.clear();
 258         readEventHandlerAttribute.clear();
 259         endElement.clear();
 260     }
 261 }