1 // https://bugs.openjdk.java.net/browse/INTJDK-7624138
   2 /*
   3  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation. Oracle designates this
   9  * particular file as subject to the "Classpath" exception as provided
  10  * by Oracle in the LICENSE file that accompanied this code.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  23  * or visit www.oracle.com if you need additional information or have any
  24  * questions.
  25  */
  26 package test.fxmltests.app;
  27 
  28 import javafx.fxml.LoadListener;
  29 import com.sun.javafx.runtime.VersionInfo;
  30 import java.util.ArrayList;
  31 import java.util.List;
  32 import javafx.application.Application;
  33 import javafx.fxml.FXMLLoader;
  34 import javafx.scene.Node;
  35 import javafx.scene.Scene;
  36 import javafx.scene.layout.VBox;
  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 
 131             // The following line requires --add-exports javafx.fxml/com.sun.javafx.fxml=ALL-UNNAMED
 132             loader.setLoadListener(new LoadListener() {
 133 
 134                 @Override
 135                 public void readImportProcessingInstruction(String string) {
 136                     importProcessingInstruction.add(loader.impl_getLineNumber());
 137                 }
 138 
 139                 @Override
 140                 public void readLanguageProcessingInstruction(String string) {
 141                     languageProcessingInstruction.add(loader.impl_getLineNumber());
 142                 }
 143 
 144                 @Override
 145                 public void readComment(String string) {
 146                     comment.add(loader.impl_getLineNumber());
 147                 }
 148 
 149                 @Override
 150                 public void beginInstanceDeclarationElement(Class<?> tye) {
 151                     instanceDeclarationElement.add(loader.impl_getLineNumber());
 152                 }
 153 
 154                 @Override
 155                 public void beginUnknownTypeElement(String string) {
 156                     beginUnknowStaticElement.add(loader.impl_getLineNumber());
 157                 }
 158 
 159                 @Override
 160                 public void beginIncludeElement() {
 161                     includeElement.add(loader.impl_getLineNumber());
 162                 }
 163 
 164                 @Override
 165                 public void beginReferenceElement() {
 166                     referenceElement.add(loader.impl_getLineNumber());
 167                 }
 168 
 169                 @Override
 170                 public void beginCopyElement() {
 171                     copyElement.add(loader.impl_getLineNumber());
 172                 }
 173 
 174                 @Override
 175                 public void beginRootElement() {
 176                     rootElement = loader.impl_getLineNumber();
 177                 }
 178 
 179                 @Override
 180                 public void beginPropertyElement(String string, Class<?> type) {
 181                     propertyElement.add(loader.impl_getLineNumber());
 182                 }
 183 
 184                 @Override
 185                 public void beginUnknownStaticPropertyElement(String string) {
 186                     beginUnknowStaticPropertyElement.add(loader.impl_getLineNumber());
 187                 }
 188 
 189                 @Override
 190                 public void beginScriptElement() {
 191                     scriptElement.add(loader.impl_getLineNumber());
 192                 }
 193 
 194                 @Override
 195                 public void beginDefineElement() {
 196                     defineElement.add(loader.impl_getLineNumber());
 197                 }
 198 
 199                 @Override
 200                 public void readInternalAttribute(String string, String string1) {
 201                     readInternalAttribute.add(loader.impl_getLineNumber());
 202                 }
 203 
 204                 @Override
 205                 public void readPropertyAttribute(String string, Class<?> type, String string1) {
 206                     readPropertyAttribute.add(loader.impl_getLineNumber());
 207                 }
 208 
 209                 @Override
 210                 public void readUnknownStaticPropertyAttribute(String string, String string1) {
 211                     readUnknownStaticProperty.add(loader.impl_getLineNumber());
 212                 }
 213 
 214                 @Override
 215                 public void readEventHandlerAttribute(String string, String string1) {
 216                     readEventHandlerAttribute.add(loader.impl_getLineNumber());
 217                 }
 218 
 219                 @Override
 220                 public void endElement(Object o) {
 221                     endElement.add(loader.impl_getLineNumber());
 222                 }
 223             });
 224             try {
 225                 VBox vb = new VBox();
 226                 vb.setPrefSize(200, 200);
 227                 loader.setRoot(vb);
 228                 return (Node) loader.load();
 229             } catch (Exception exc) {
 230                 exc.printStackTrace();
 231                 return new Rectangle(10, 10) {
 232 
 233                     {
 234                         setFill(Color.RED);
 235                     }
 236                 };
 237             }
 238         }
 239     }
 240 
 241     public static void main(String[] args) {
 242         launch(args);
 243     }
 244 
 245     public static void reset() {
 246         importProcessingInstruction.clear();
 247         languageProcessingInstruction.clear();
 248         comment.clear();
 249         instanceDeclarationElement.clear();
 250         beginUnknowStaticElement.clear();
 251         includeElement.clear();
 252         referenceElement.clear();
 253         copyElement.clear();
 254         rootElement = 0;
 255         propertyElement.clear();
 256         beginUnknowStaticPropertyElement.clear();
 257         scriptElement.clear();
 258         defineElement.clear();
 259         readInternalAttribute.clear();
 260         readPropertyAttribute.clear();
 261         readUnknownStaticProperty.clear();
 262         readEventHandlerAttribute.clear();
 263         endElement.clear();
 264     }
 265 }