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.fxml.ParseTraceElement; 29 import java.io.File; 30 import java.io.IOException; 31 import java.io.InputStream; 32 import java.net.URL; 33 import java.nio.charset.Charset; 34 import java.util.ArrayList; 35 import java.util.HashMap; 36 import java.util.LinkedList; 37 import java.util.List; 38 import java.util.Locale; 39 import java.util.ResourceBundle; 40 import java.util.logging.Level; 41 import java.util.logging.Logger; 42 import javafx.collections.FXCollections; 43 import javafx.collections.ObservableList; 44 import javafx.css.CssMetaData; 45 import javafx.css.ParsedValue; 46 import javafx.css.StyleConverter; 47 import javafx.css.Styleable; 48 import javafx.event.ActionEvent; 49 import javafx.event.EventHandler; 50 import javafx.fxml.FXMLLoader; 51 import javafx.fxml.JavaFXBuilderFactory; 52 import javafx.fxml.LoadException; 53 import javafx.scene.Group; 54 55 56 import javafx.scene.Node; 57 import javafx.scene.Scene; 58 import javafx.scene.control.Button; 59 import javafx.scene.control.Label; 60 import javafx.scene.control.Labeled; 61 import javafx.scene.control.ListView; 62 import javafx.scene.control.Menu; 63 import javafx.scene.control.MenuBar; 64 import javafx.scene.control.MenuItem; 65 import javafx.scene.control.RadioButton; 66 import javafx.scene.control.TableColumn; 67 import javafx.scene.control.TableView; 68 import javafx.scene.control.ToggleGroup; 69 import javafx.scene.control.cell.PropertyValueFactory; 70 import javafx.scene.input.KeyCombination; 71 import javafx.scene.layout.*; 72 import javafx.scene.paint.Color; 73 import javafx.scene.paint.Paint; 74 import javafx.scene.shape.Rectangle; 75 import javafx.scene.text.Font; 76 import javafx.scene.text.Text; 77 import javafx.util.Callback; 78 import javafx.util.Pair; 79 import org.jemmy.control.Wrap; 80 81 import test.javaclient.shared.BasicButtonChooserApp; 82 import test.javaclient.shared.JemmyUtils; 83 import test.javaclient.shared.PageWithSlots; 84 import test.javaclient.shared.TestNode; 85 import test.javaclient.shared.Utils; 86 87 public class staticPropertyLoadApp extends BasicButtonChooserApp { 88 89 public static final String RESOURCE_BASE = "/test/fxmltests/resources/"; 90 public static final String staticPropertyResourcePath = RESOURCE_BASE + "static-property.fxml"; 91 public static final String hashmapResourcePath = RESOURCE_BASE + "hashmap.fxml"; 92 public static final String customClassLoadResourcePath = RESOURCE_BASE + "include.fxml"; 93 public static final String factoryResourcePath = RESOURCE_BASE + "factory.fxml"; 94 public static final String builderResourcePath = RESOURCE_BASE + "builder.fxml"; 95 public static final String propertyElementsResourcePath = RESOURCE_BASE + "propertyElements.fxml"; 96 public static final String referenceResourcePath = RESOURCE_BASE + "reference.fxml"; 97 public static final String copyResourcePath = RESOURCE_BASE + "fxcopy.fxml"; 98 public static final String propertySetterResourcePath = RESOURCE_BASE + "propertySetter.fxml"; 99 public static final String roListResourcePath = RESOURCE_BASE + "rolist.fxml"; 100 public static final String roMapResourcePath = RESOURCE_BASE + "romap.fxml"; 101 public static final String defaultPropertyResourcePath = RESOURCE_BASE + "defaultProperty.fxml"; 102 public static final String fxdefineResourcePath = RESOURCE_BASE + "fxdefine.fxml"; 103 public static final String fxdefine2ResourcePath = RESOURCE_BASE + "fxdefine2.fxml"; 104 public static final String namespaceBindingResourcePath = RESOURCE_BASE + "namespaceBinding.fxml"; 105 public static final String staticPropertiesResourcePath = RESOURCE_BASE + "static-properties.fxml"; 106 public static final String rootMethodEventHandlerResourcePath = RESOURCE_BASE + "rootMethodEventHandler.fxml"; 107 public static final String scriptEventHandlerResourcePath = RESOURCE_BASE + "scriptEventHandler.fxml"; 108 public static final String scriptResourcePath = RESOURCE_BASE + "script.fxml"; 109 public static final String menuitemResourcePath = RESOURCE_BASE + "menuitem.fxml"; 110 public static final String resourceResourcePath = RESOURCE_BASE + "resourcefxml.fxml"; 111 public static final String splitpanebugResourcePath = RESOURCE_BASE + "vt1.fxml"; 112 public static final String throw1ResourcePath = RESOURCE_BASE + "throw1.fxml"; 113 public static final String throw2ResourcePath = RESOURCE_BASE + "throw2.fxml"; 114 public static final String rt19133ResourcePath = RESOURCE_BASE + "rt19133.fxml"; 115 116 public static enum Pages { 117 staticProperty,HashMap,customClassAndInclude,factory,simple, 118 propertyElements,reference,copy,prSetter,roList,roMap, 119 defaultProperty,fxdefine,namespaceBinding,staticProperties,rootMethodEventHandler, 120 scriptEventHandler,script,menuItem,resources1,resources2,namespace, 121 splitpanebug,charset, loadExceptions, 122 slotDefaultLabeled, slotDefaultListview, slotDefaultMenu, slotDefaultMenuBar, 123 slotDefaultScrollpane, slotDefaultTabpane, slotDefaultTableView, 124 slotDefaultTextinput, slotDefaultTitledpane, slotDefaultTreeview, 125 slotDefaultImageview, slotDefaultPane, slotControllerFactory, 126 specificSignatureMethod, loadfontSlot, scenebuilderSlot, 127 scenebuilderNoRoot, references2, apConstraints, coerce, listviewItems, listenerNullArg, 128 gridapplet, csspath, errorFXML, colorValueOF, escapeCharacter, collectionEventsHandlers, 129 noArgControllerMethod, overloadedControllerMethod, customIDProperty, unknownCustomType, 130 baseControllerProperty, relativeStylesheet, FXMLLoaderAPI, fullyQualifiedNames, importPI, 131 beanInstantiation, valueOf, root, fxId, fxController, noDefaultController, lateRoot, 132 lateController, variableResolution, externalScript 133 134 } 135 136 public staticPropertyLoadApp() { 137 super(800, 600, "LoadFXML", false); 138 } 139 140 Rectangle retRec = new Rectangle(10,10){{setFill(Color.GREEN);}}; 141 Rectangle redRectangle = new Rectangle(10,10){{setFill(Color.RED);}}; 142 143 abstract private class TestNodeWithIOExceptionProcessing extends TestNode { 144 145 abstract protected Node impl_drawNode() throws IOException; 146 protected String impl_getPathToResource() { return null; }; 147 protected URL resource = null; 148 protected File f = null; 149 150 @Override 151 public Node drawNode() { 152 Node result = redRectangle; 153 154 VBox vb = null; 155 156 if (null != impl_getPathToResource()) { 157 resource = getClass().getResource(impl_getPathToResource()); 158 if (null != resource && null != (f = new File(resource.getFile()))) { 159 System.out.println("loading " + f.getPath()); 160 } else { 161 String tmpMsg = "resource file error. [" + impl_getPathToResource() + "]"; 162 System.out.println(tmpMsg); 163 reportGetterFailure(tmpMsg); 164 return result; 165 } 166 } 167 try { 168 result = impl_drawNode(); 169 } catch (IOException ex) { 170 reportGetterFailure("TestNodeWithIOExceptionProcessing: IOException"); 171 Logger.getLogger(staticPropertyLoadApp.class.getName()).log(Level.SEVERE, null, ex); 172 } catch (Exception ex) { 173 reportGetterFailure("TestNodeWithIOExceptionProcessing: Exception"); 174 Logger.getLogger(staticPropertyLoadApp.class.getName()).log(Level.SEVERE, null, ex); 175 } 176 return result; 177 } 178 } 179 180 private class slotStaticProperty extends TestNodeWithIOExceptionProcessing { 181 @Override 182 protected String impl_getPathToResource() { 183 return staticPropertyResourcePath; 184 } 185 @Override 186 public Node impl_drawNode() throws IOException { 187 Node uplevelNode = null; 188 try { 189 uplevelNode = FXMLLoader.load(resource); 190 } catch (Exception e) { 191 System.out.println("message: " + e.getMessage()); 192 reportGetterFailure("message: " + e.getMessage()); 193 } 194 return uplevelNode; 195 } 196 } 197 198 private class hashmaptest extends TestNodeWithIOExceptionProcessing { 199 200 HashMap hm = null; 201 String value1; 202 String value2; 203 204 @Override 205 protected String impl_getPathToResource() { 206 return hashmapResourcePath; 207 } 208 209 @Override 210 public Node impl_drawNode() throws IOException { 211 212 try { 213 hm = FXMLLoader.load(resource); 214 value1 = (String) hm.get("foo"); 215 value2 = (String) hm.get("bar"); 216 } catch (Exception e) { 217 System.out.println("message: " + e.getMessage()); 218 reportGetterFailure("exception thrown."); 219 } 220 if (value1.equals("123") && value2.equals("456")) { 221 return retRec; 222 } else { 223 reportGetterFailure("failed."); 224 return redRectangle; 225 } 226 } 227 } 228 229 CustomClass cc; 230 private class customClassLoadSlot extends TestNodeWithIOExceptionProcessing { 231 232 @Override 233 protected String impl_getPathToResource() { 234 return customClassLoadResourcePath; 235 } 236 237 @Override 238 public Node impl_drawNode() throws IOException { 239 FXMLLoader fxmlLoader = new FXMLLoader(); 240 241 InputStream is = null; 242 try { 243 fxmlLoader.setLocation(resource); 244 is = resource.openStream(); 245 cc = (CustomClass) fxmlLoader.load(is); 246 } catch (Exception e) { 247 System.out.println("message: " + e.getMessage()); 248 e.printStackTrace(); 249 reportGetterFailure("exception thrown."); 250 } finally { 251 is.close(); 252 } 253 254 // System.out.println(" includes: " + fxmlLoader.getIncludes()); 255 System.out.println("cc.getFld(): " + cc.getFld()); 256 257 if (cc.getFld().equals("fine!")) { 258 return retRec; 259 } else { 260 reportGetterFailure("failed."); 261 return redRectangle; 262 } 263 } 264 } 265 266 private class factorySlot extends TestNodeWithIOExceptionProcessing { 267 268 ObservableList<String> ss = FXCollections.observableArrayList(); 269 270 @Override 271 protected String impl_getPathToResource() { 272 return factoryResourcePath; 273 } 274 275 @Override 276 public Node impl_drawNode() throws IOException { 277 try { 278 ss = FXMLLoader.load(resource); 279 } catch (Exception e) { 280 System.out.println("message: " + e.getMessage()); 281 reportGetterFailure("exception thrown."); 282 } 283 if (ss.get(0).equals("A") && ss.get(1).equals("B") && ss.get(2).equals("C")) { 284 return retRec; 285 } else { 286 reportGetterFailure("failed."); 287 return redRectangle; 288 } 289 } 290 } 291 292 private class simpleSlot extends TestNodeWithIOExceptionProcessing { 293 294 Color color = Color.ALICEBLUE; 295 296 @Override 297 protected String impl_getPathToResource() { 298 return builderResourcePath; 299 } 300 301 @Override 302 public Node impl_drawNode() throws IOException { 303 InputStream is = null; 304 try { 305 FXMLLoader fxmlLoader2 = new FXMLLoader(); 306 is = resource.openStream(); 307 ClassLoader defaultClassLoader = fxmlLoader2.getClassLoader(); 308 309 fxmlLoader2.setBuilderFactory(new JavaFXBuilderFactory(defaultClassLoader)); 310 color = (Color) fxmlLoader2.load(is); // see RT-18091 311 } catch (Exception e) { 312 e.printStackTrace(); 313 System.out.println("message: " + e.getMessage()); 314 reportGetterFailure("exception thrown."); 315 } finally { 316 is.close(); 317 } 318 System.out.println("color: " + color); 319 if (color.equals(Color.color(1., 0., 0.))) { 320 return retRec; 321 } else { 322 reportGetterFailure("failed."); 323 return redRectangle; 324 } 325 } 326 } 327 328 private class propertyElementsSlot extends TestNodeWithIOExceptionProcessing { 329 330 Label label; 331 332 @Override 333 protected String impl_getPathToResource() { 334 return propertyElementsResourcePath; 335 } 336 337 @Override 338 public Node impl_drawNode() { 339 try { 340 label = FXMLLoader.load(resource); 341 } catch (Exception e) { 342 System.out.println("message: " + e.getMessage()); 343 reportGetterFailure("exception thrown."); 344 } 345 if (label.getText().equals("label")) { 346 return label; 347 } else { 348 reportGetterFailure("failed."); 349 return redRectangle; 350 } 351 } 352 } 353 354 private class referenceSlot extends TestNodeWithIOExceptionProcessing { 355 356 List<Label> lst = new ArrayList(); 357 358 @Override 359 protected String impl_getPathToResource() { 360 return referenceResourcePath; 361 } 362 363 @Override 364 public Node impl_drawNode() { 365 try { 366 lst = FXMLLoader.load(resource); // was: f.toURI().toURL(). does not work with jnlp http://javafx-jira.kenai.com/browse/RT-17736 367 } catch (Exception e) { 368 System.out.println("message: " + e.getMessage()); 369 reportGetterFailure("exception thrown."); 370 } 371 if (lst.get(0).getText().equals(lst.get(1).getText())) { 372 return retRec; 373 } else { 374 reportGetterFailure("failed."); 375 return redRectangle; 376 } 377 } 378 } 379 380 private class copySlot extends TestNodeWithIOExceptionProcessing { 381 382 List<Label> lst = new ArrayList(); 383 384 @Override 385 protected String impl_getPathToResource() { 386 return copyResourcePath; 387 } 388 389 @Override 390 public Node impl_drawNode() { 391 try { 392 lst = (List<Label>) FXMLLoader.load(resource); //inputStream 393 } catch (Exception e) { 394 System.out.println("message2: " + e.getMessage()); 395 e.printStackTrace(); 396 reportGetterFailure("exception thrown."); 397 } 398 if (3 == lst.size()) { 399 return retRec; 400 } else { 401 reportGetterFailure("failed."); 402 return redRectangle; 403 } 404 } 405 } 406 407 private class propertySetterSlot extends TestNodeWithIOExceptionProcessing { 408 409 Label label; 410 411 @Override 412 protected String impl_getPathToResource() { 413 return propertySetterResourcePath; 414 } 415 416 @Override 417 public Node impl_drawNode() { 418 try { 419 label = FXMLLoader.load(resource); 420 421 } catch (Exception e) { 422 System.out.println("message: " + e.getMessage()); 423 reportGetterFailure("exception thrown."); 424 } 425 if (label.getText().equals("txt")) { 426 return retRec; 427 } else { 428 reportGetterFailure("failed."); 429 return redRectangle; 430 } 431 } 432 } 433 434 private class roListSlot extends TestNodeWithIOExceptionProcessing { 435 436 Group gr; 437 438 @Override 439 protected String impl_getPathToResource() { 440 return roListResourcePath; 441 } 442 443 @Override 444 public Node impl_drawNode() { 445 try { 446 gr = FXMLLoader.load(resource); 447 } catch (Exception e) { 448 System.out.println("message: " + e.getMessage()); 449 e.printStackTrace(); 450 reportGetterFailure("exception thrown."); 451 } 452 Node n =((Rectangle) gr.getChildren().get(0)); 453 String strId = n.getId(); 454 if (strId.equals("rectangle1")) { 455 return retRec; 456 } else { 457 reportGetterFailure("failed."); 458 return redRectangle; 459 } 460 } 461 } 462 463 private class roMapSlot extends TestNodeWithIOExceptionProcessing { 464 465 JavaFXBuilderFactory builderFactory = new JavaFXBuilderFactory(); 466 FXMLLoader fxmlLoader = new FXMLLoader(); 467 Button btn; 468 469 @Override 470 protected String impl_getPathToResource() { 471 return roMapResourcePath; 472 } 473 474 @Override 475 public Node impl_drawNode() { 476 InputStream is = getClass().getResourceAsStream(impl_getPathToResource()); 477 478 try { 479 fxmlLoader.setBuilderFactory(builderFactory); 480 btn = (Button) fxmlLoader.load(is); 481 } catch (Exception e) { 482 System.out.println("message: " + e.getMessage()); 483 reportGetterFailure("exception thrown."); 484 } 485 if (builderFactory != fxmlLoader.getBuilderFactory()) { 486 reportGetterFailure("fxmlLoader.getBuilderFactory() failed."); 487 } 488 489 if (btn.getProperties().get("foo").equals("123")) { 490 return retRec; 491 } else { 492 reportGetterFailure("failed."); 493 return redRectangle; 494 } 495 } 496 } 497 498 private class defaultPropertySlot extends TestNodeWithIOExceptionProcessing { 499 500 Group gr; 501 502 @Override 503 protected String impl_getPathToResource() { 504 return defaultPropertyResourcePath; 505 } 506 507 @Override 508 public Node impl_drawNode() { 509 try { 510 gr = FXMLLoader.load(resource); 511 } catch (Exception e) { 512 System.out.println("message: " + e.getMessage()); 513 reportGetterFailure("exception thrown."); 514 } 515 if (((Rectangle) gr.getChildren().get(1)).getId().equals("rectangle2")) { 516 return retRec; 517 } else { 518 reportGetterFailure("failed."); 519 return redRectangle; 520 } 521 } 522 } 523 524 private class fxdefineSlot extends TestNodeWithIOExceptionProcessing { 525 526 VBox vb; 527 528 @Override 529 protected String impl_getPathToResource() { 530 return fxdefineResourcePath; 531 } 532 533 @Override 534 public Node impl_drawNode() { 535 try { 536 vb = FXMLLoader.load(resource); 537 } catch (Exception e) { 538 System.out.println("message: " + e.getMessage()); 539 reportGetterFailure("exception thrown."); 540 } 541 if (((RadioButton) vb.getChildren().get(0)).getText().equals("A")) { 542 return retRec; 543 } else { 544 reportGetterFailure("failed."); 545 return redRectangle; 546 } 547 } 548 } 549 550 private class namespaceBindingSlot extends TestNodeWithIOExceptionProcessing { 551 552 public VBox vb; 553 FXMLLoader fxmlLoader2 = new FXMLLoader(); 554 555 @Override 556 protected String impl_getPathToResource() { 557 return namespaceBindingResourcePath; 558 } 559 560 @Override 561 public Node impl_drawNode() throws IOException { 562 InputStream is = null; 563 try { 564 is = resource.openStream(); 565 vb = (VBox) fxmlLoader2.load(is); 566 } catch (Exception e) { 567 System.out.println("message: " + e.getMessage()); 568 reportGetterFailure("exception thrown."); 569 } finally { 570 is.close(); 571 } 572 if (null == vb) { 573 System.out.println("Custom class instance is null"); 574 reportGetterFailure("failed 1."); 575 } 576 577 Button b = (Button) vb.getChildren().get(0); 578 579 if (null == vb.getChildren().get(0)) { 580 System.out.println("button field is null"); 581 reportGetterFailure("failed 2."); 582 } 583 if (!(null != vb && null != b && null != b.getOnAction())) { 584 reportGetterFailure("failed."); 585 } 586 587 MyRootElement mr = (MyRootElement) fxmlLoader2.getController(); 588 System.out.println("mr: " + mr.toString()); 589 System.out.println("getController(): " + fxmlLoader2.getController()); 590 591 if ((null != mr) 592 && (mr.toString().contains("MyRootElement"))) { 593 return retRec; 594 } else { 595 reportGetterFailure("failed."); 596 return redRectangle; 597 } 598 } 599 } 600 601 private class staticPropertiesSlot extends TestNodeWithIOExceptionProcessing { 602 603 @Override 604 protected String impl_getPathToResource() { 605 return staticPropertiesResourcePath; 606 } 607 608 @Override 609 public Node impl_drawNode() { 610 611 try { 612 FXMLLoader.load(resource); 613 } catch (Exception e) { 614 System.out.println("message: " + e.getMessage()); 615 reportGetterFailure("exception thrown."); 616 return redRectangle; 617 } 618 619 return retRec; 620 } 621 } 622 623 private class rootMethodEventHandlerSlot extends TestNodeWithIOExceptionProcessing { 624 625 MyRootElement2 mr; 626 627 @Override 628 protected String impl_getPathToResource() { 629 return rootMethodEventHandlerResourcePath; 630 } 631 632 @Override 633 public Node impl_drawNode() { 634 try { 635 mr = FXMLLoader.load(resource); 636 } catch (Exception e) { 637 System.out.println("message: " + e.getMessage()); 638 e.printStackTrace(); 639 reportGetterFailure("exception thrown."); 640 } 641 642 Button bbb = (Button) mr.getChildren().get(0); 643 EventHandler<ActionEvent> hndlr = bbb.getOnAction(); 644 if (null != hndlr) { 645 return retRec; 646 } else { 647 reportGetterFailure("failed."); 648 return redRectangle; 649 } 650 } 651 } 652 653 private class scriptEventHandlerSlot extends TestNodeWithIOExceptionProcessing { 654 655 MyRootElement2 mr; 656 657 @Override 658 protected String impl_getPathToResource() { 659 return scriptEventHandlerResourcePath; 660 } 661 662 @Override 663 public Node impl_drawNode() { 664 665 try { 666 mr = FXMLLoader.load(resource); 667 } catch (Exception e) { 668 System.out.println("message: " + e.getMessage()); 669 reportGetterFailure("exception thrown."); 670 } 671 Button bbb = (Button) mr.getChildren().get(0); 672 EventHandler<ActionEvent> hndlr = bbb.getOnAction(); 673 if (null != hndlr) { 674 return mr;//retRec; 675 } else { 676 reportGetterFailure("failed."); 677 return redRectangle; 678 } 679 } 680 } 681 682 private class scriptSlot extends TestNodeWithIOExceptionProcessing { 683 684 VBox vb; 685 686 @Override 687 protected String impl_getPathToResource() { 688 return scriptResourcePath; 689 } 690 691 @Override 692 public Node impl_drawNode() { 693 694 try { 695 vb = FXMLLoader.load(resource); 696 } catch (Exception e) { 697 System.out.println("message: " + e.getMessage()); 698 reportGetterFailure("exception thrown."); 699 } 700 Button bbb = (Button) vb.getChildren().get(0); 701 EventHandler<ActionEvent> hndlr = bbb.getOnAction(); 702 if (null != hndlr) { 703 return vb;//retRec; 704 } else { 705 reportGetterFailure("failed."); 706 return redRectangle; 707 } 708 } 709 } 710 711 private class menuitemSlot extends TestNodeWithIOExceptionProcessing { 712 //http://javafx-jira.kenai.com/browse/RT-17715 713 714 MenuItem mi2; 715 716 @Override 717 protected String impl_getPathToResource() { 718 return menuitemResourcePath; 719 } 720 721 @Override 722 public Node impl_drawNode() { 723 /* 724 MenuItem mi = new MenuItem(); 725 mi.setText("open..."); 726 mi.setGraphic(new ImageView()); 727 mi.setAccelerator(KeyCombination.keyCombination("CTRL+N")); 728 */ 729 730 try { 731 mi2 = FXMLLoader.load(resource); 732 } catch (Exception e) { 733 System.out.println("message: " + e.getMessage()); 734 e.printStackTrace(); 735 reportGetterFailure("exception thrown."); 736 } 737 System.out.println("DEBUG: menuItem.getText()=" + ((null != mi2) ? mi2.getText() : "(null)")); 738 if ((null != mi2) 739 && (0 == "open...".compareTo(mi2.getText())) 740 && (KeyCombination.keyCombination("CTRL+N").equals(mi2.getAccelerator()))) { 741 return retRec; 742 } else { 743 reportGetterFailure("failed."); 744 return redRectangle; 745 } 746 } 747 } 748 749 750 /* 751 * localization using setResources() 752 */ 753 private class resource1Slot extends TestNodeWithIOExceptionProcessing { 754 755 MenuItem mi2; 756 757 @Override 758 public Node impl_drawNode() { 759 try { 760 URL resourceURL = getClass().getResource(resourceResourcePath); 761 Locale currentLocale = new Locale("en", "US"); 762 ResourceBundle resourceBundle = ResourceBundle.getBundle("test.fxmltests.resources.resource1", currentLocale); 763 FXMLLoader fxmlLoader2 = new FXMLLoader(); 764 765 fxmlLoader2.setResources(resourceBundle); 766 System.out.println("resources: " + fxmlLoader2.getResources()); 767 fxmlLoader2.setBuilderFactory(new JavaFXBuilderFactory()); 768 769 System.out.println("xxx loading " + resourceURL); 770 InputStream is = null; 771 try { 772 773 is = resourceURL.openStream(); 774 mi2 = (MenuItem) fxmlLoader2.load(is); 775 776 } catch (Exception e) { 777 System.out.println("message: " + e.getMessage()); 778 e.printStackTrace(); 779 reportGetterFailure("exception thrown."); 780 } finally { 781 is.close(); 782 } 783 784 System.out.println("resources: " + fxmlLoader2.getResources()); 785 System.out.println("charset: " + fxmlLoader2.getCharset()); 786 System.out.println("location: " + fxmlLoader2.getLocation()); 787 System.out.println("bf: " + fxmlLoader2.getBuilderFactory()); 788 System.out.println("namespace: " + fxmlLoader2.getNamespace()); 789 // System.out.println("includes: " + fxmlLoader2.getIncludes()); 790 791 792 System.out.println("DEBUG: menuItem.getText()=" + ((null != mi2) ? mi2.getText() : "(null)")); 793 if ((null != mi2) 794 && (0 == "close".compareTo(mi2.getText()))) { 795 boolean pass = true; 796 } else { 797 reportGetterFailure("failed."); 798 } 799 } catch (IOException ex) { 800 Logger.getLogger(staticPropertyLoadApp.class.getName()).log(Level.SEVERE, null, ex); 801 } 802 return retRec; 803 } 804 } 805 806 807 /* 808 * localization wirh resources mentioned in load() 809 */ 810 private class resource2Slot extends TestNodeWithIOExceptionProcessing { 811 812 MenuItem mi2; 813 814 @Override 815 public Node impl_drawNode() { 816 URL resourceURL = getClass().getResource(resourceResourcePath); 817 Locale currentLocale = new Locale("en", "US"); 818 ResourceBundle resourceBundle = ResourceBundle.getBundle("test.fxmltests.resources.resource1", currentLocale); 819 820 System.out.println("xxx loading " + resourceURL); 821 try { 822 823 mi2 = (MenuItem) FXMLLoader.load(resourceURL, resourceBundle); 824 825 } catch (Exception e) { 826 System.out.println("message: " + e.getMessage()); 827 e.printStackTrace(); 828 reportGetterFailure("exception thrown."); 829 } 830 831 System.out.println("DEBUG: menuItem.getText()=" + ((null != mi2) ? mi2.getText() : "(null)")); 832 if ((null != mi2) 833 && (0 == "close".compareTo(mi2.getText()))) { 834 boolean pass = true; 835 } else { 836 reportGetterFailure("failed."); 837 } 838 return retRec; 839 } 840 } 841 842 /* 843 * getNamespace test 844 */ 845 private class namespaceSlot extends TestNodeWithIOExceptionProcessing { 846 847 @Override 848 public Node impl_drawNode() throws IOException { 849 URL resourceURL = getClass().getResource(fxdefine2ResourcePath); 850 JavaFXBuilderFactory builderFactory = new JavaFXBuilderFactory(); 851 FXMLLoader fxmlLoader = new FXMLLoader(); 852 fxmlLoader.setBuilderFactory(builderFactory); 853 854 InputStream is = null; 855 System.out.println("xxx loading " + resourceURL); 856 try { 857 is = resourceURL.openStream(); 858 fxmlLoader.load(is); 859 } catch (Exception e) { 860 System.out.println("message: " + e.getMessage()); 861 e.printStackTrace(); 862 reportGetterFailure("exception thrown."); 863 } finally { 864 is.close(); 865 } 866 867 System.out.println("namespace: " + fxmlLoader.getNamespace()); 868 System.out.println("empty: " + fxmlLoader.getNamespace().isEmpty()); 869 System.out.println("nonexisting key vb5: " + fxmlLoader.getNamespace().get("vb5")); 870 871 Node n = (Node)fxmlLoader.getNamespace().get("vb1"); 872 String xxx = (null != n)?(n.getId()):""; 873 System.out.println("existing key vb1: " + fxmlLoader.getNamespace().get("vb1") + " / id=" + xxx); 874 System.out.println("getRoot: " + fxmlLoader.getRoot()); 875 876 if ((null != (fxmlLoader.getNamespace().get("vb1"))) 877 && (null == (fxmlLoader.getNamespace().get("vb5"))) 878 && (fxmlLoader.getRoot().toString().equals("VBox[id=vb1]"))) { 879 boolean pass = true; 880 } else { 881 reportGetterFailure("failed."); 882 } 883 return retRec; 884 } 885 } 886 887 888 private class splitpanebugSlot extends TestNodeWithIOExceptionProcessing { 889 // http://javafx-jira.kenai.com/browse/RT-16977 890 @Override 891 public Node impl_drawNode() throws IOException { 892 URL resourceURL = getClass().getResource(splitpanebugResourcePath); 893 JavaFXBuilderFactory builderFactory = new JavaFXBuilderFactory(); 894 FXMLLoader fxmlLoader = new FXMLLoader(); 895 fxmlLoader.setBuilderFactory(builderFactory); 896 897 InputStream is = null; 898 System.out.println("loading " + resourceURL); 899 try { 900 // fxmlLoader.setLocation(new URL(RESOURCE_BASE)); 901 // ResourceBundle rb = new ResourceBundle(); 902 // fxmlLoader.setResources(rb); 903 is = resourceURL.openStream(); 904 fxmlLoader.load(is); 905 } catch (Exception e) { 906 System.out.println("message: " + e.getMessage()); 907 e.printStackTrace(); 908 reportGetterFailure("exception thrown."); 909 } catch (Throwable e) { 910 System.out.println("message: " + e.getMessage()); 911 e.printStackTrace(); 912 reportGetterFailure("exception thrown."); 913 } finally { 914 is.close(); 915 } 916 System.out.println("loaded. "); 917 return retRec; 918 } 919 } 920 921 private class charsetSlot extends TestNodeWithIOExceptionProcessing { 922 923 @Override 924 protected String impl_getPathToResource() { 925 return "/test/fxmltests/resources/include3.fxml"; // customClassLoadResourcePath 926 } 927 928 @Override 929 public Node impl_drawNode() throws IOException { 930 Charset encoding = Charset.forName("UTF-16"); 931 FXMLLoader fxmlLoader = new FXMLLoader(encoding); 932 fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory()); 933 934 //Locale currentLocale = new Locale("en", "US"); 935 //ResourceBundle resourceBundle = ResourceBundle.getBundle("test.fxmltests.resources.resource1", currentLocale); 936 //fxmlLoader.setResources(resourceBundle); 937 938 InputStream is = null; 939 try { 940 // fxmlLoader.setLocation(resource); 941 System.out.println(" charset: " + fxmlLoader.getCharset()); 942 is = resource.openStream(); 943 fxmlLoader.load(is); 944 945 } catch (Exception e) { 946 System.out.println("message: " + e.getMessage()); 947 e.printStackTrace(); 948 reportGetterFailure("exception thrown."); 949 } finally { 950 is.close(); 951 } 952 953 System.out.println(" location: " + fxmlLoader.getLocation()); 954 System.out.println(" charset: " + fxmlLoader.getCharset()); 955 956 if (fxmlLoader.getCharset().toString().equals("UTF-16")) { 957 return retRec; 958 } else { 959 reportGetterFailure("failed."); 960 return redRectangle; 961 } 962 963 } 964 } 965 966 /* 967 * LoadExceptions test 968 */ 969 private class loadExceptionsSlot extends TestNodeWithIOExceptionProcessing { 970 971 @Override 972 public Node impl_drawNode() throws IOException{ 973 974 URL resourceURL1 = getClass().getResource(throw1ResourcePath); 975 URL resourceURL2 = getClass().getResource(throw2ResourcePath); 976 FXMLLoader fxmlLoader = new FXMLLoader(); 977 fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory()); 978 boolean exception1Thrown = false; 979 boolean exception2Thrown = false; 980 981 InputStream is = null; 982 System.out.println("loading RES 1 / " + resourceURL1); 983 try { 984 is = resourceURL1.openStream(); 985 fxmlLoader.load(is); 986 } catch (LoadException e) { 987 System.out.println("THROWN msg: " + e.getMessage()); 988 System.out.println("THROWN cause: " + e.getCause()); 989 exception1Thrown = true; 990 991 ParseTraceElement ptes[] = fxmlLoader.impl_getParseTrace(); 992 for (ParseTraceElement pte: ptes) { 993 // see rt-19329 994 System.out.println("trace element: " + pte); 995 } 996 } catch (Exception e) { 997 System.out.println("message: " + e.getMessage()); 998 e.printStackTrace(); 999 reportGetterFailure("exception thrown."); 1000 } finally { 1001 is.close(); 1002 } 1003 1004 is = null; 1005 System.out.println("loading RES 2 / " + resourceURL2); 1006 try { 1007 is = resourceURL2.openStream(); 1008 fxmlLoader.load(is); 1009 } catch (LoadException e) { 1010 exception2Thrown = true; 1011 System.out.println("2 THROWN msg: " + e.getMessage()); 1012 System.out.println("2 THROWN cause: " + e.getCause()); 1013 } catch (Exception e) { 1014 System.out.println("message: " + e.getMessage()); 1015 e.printStackTrace(); 1016 reportGetterFailure("exception thrown."); 1017 } finally { 1018 is.close(); 1019 } 1020 1021 1022 if ((true == exception1Thrown) && (true == exception2Thrown)) { 1023 boolean pass = true; 1024 } else { 1025 reportGetterFailure("failed."); 1026 } 1027 return retRec; 1028 } 1029 } 1030 1031 1032 1033 /* 1034 * 1035 Class javafx/fxml/FXMLLoader 1036 * 1037 + getBuilderFactory()Ljavafx/util/BuilderFactory; - - - - - - - - - - - - 1038 + getCharset()Ljava/nio/charset/Charset; - - - - - - - - - - - - 1039 + getController()Ljava/lang/Object; - - - - - - - - - - - - 1040 + getIncludes()Ljava/util/List; - - - - - - - - - - - - 1041 getLoadListener()Lcom/sun/javafx/fxml/LoadListener; - - - - - - - - - - - - 1042 + getLocation()Ljava/net/URL; - - - - - - - - - - - - 1043 + getNamespace()Ljavafx/collections/ObservableMap; - - - - - - - - - - - - 1044 + getResources()Ljava/util/ResourceBundle; - - - - - - - - - - - - 1045 + getRoot()Ljava/lang/Object; - - - - - - - - - - - - 1046 isStaticLoad()Z 1047 */ 1048 // Button b; 1049 1050 public static final String defaultPropertyLabeledResourcePath = RESOURCE_BASE + "rt14879-labeled.fxml"; 1051 1052 private class slotDefaultLabeled extends TestNodeWithIOExceptionProcessing { 1053 1054 @Override 1055 protected String impl_getPathToResource() { 1056 return defaultPropertyLabeledResourcePath; 1057 } 1058 1059 @Override 1060 public Node impl_drawNode() throws IOException { 1061 Node uplevelNode = null; 1062 1063 try { 1064 uplevelNode = FXMLLoader.load(resource); 1065 } catch (Exception e) { 1066 System.out.println("message: " + e.getMessage()); 1067 reportGetterFailure("message: " + e.getMessage()); 1068 } 1069 return uplevelNode; 1070 } 1071 } 1072 1073 public static final String defaultPropertyListViewResourcePath = RESOURCE_BASE + "rt14879-listview.fxml"; 1074 1075 private class slotDefaultListview extends TestNodeWithIOExceptionProcessing { 1076 1077 @Override 1078 protected String impl_getPathToResource() { 1079 return defaultPropertyListViewResourcePath; 1080 } 1081 1082 @Override 1083 public Node impl_drawNode() throws IOException { 1084 Node uplevelNode = null; 1085 1086 try { 1087 uplevelNode = FXMLLoader.load(resource); 1088 } catch (Exception e) { 1089 System.out.println("message: " + e.getMessage()); 1090 reportGetterFailure("message: " + e.getMessage()); 1091 } 1092 1093 /* DEBUG. let it be here for a while 1094 ListView lv = new ListView(); 1095 String st = "str"; 1096 lv.getItems().add(st); 1097 lv.getItems().add(st); 1098 lv.getItems().add(st); 1099 * 1100 */ 1101 1102 return uplevelNode; 1103 } 1104 } 1105 1106 public static final String defaultPropertyMenuResourcePath = RESOURCE_BASE + "rt14879-menu.fxml"; 1107 1108 private class slotDefaultMenu extends TestNodeWithIOExceptionProcessing { 1109 1110 @Override 1111 protected String impl_getPathToResource() { 1112 return defaultPropertyMenuResourcePath; 1113 } 1114 1115 @Override 1116 public Node impl_drawNode() throws IOException { 1117 Menu uplevelNode = null; 1118 FXMLLoader fxmlLoader = new FXMLLoader(resource); 1119 try { 1120 uplevelNode = (Menu)fxmlLoader.load(); 1121 } catch (Exception e) { 1122 System.out.println("message: " + e.getMessage()); 1123 reportGetterFailure("message: " + e.getMessage()); 1124 ParseTraceElement ptes[] = fxmlLoader.impl_getParseTrace(); 1125 for (ParseTraceElement pte: ptes) { 1126 // see rt-19329 1127 System.out.println("trace element: " + pte); 1128 } 1129 1130 } 1131 MenuBar mb = new MenuBar(); 1132 mb.getMenus().add(uplevelNode); 1133 // debug: uplevelNode.getItems().add(new MenuItem("open!!")); 1134 return mb; 1135 } 1136 } 1137 1138 public static final String defaultPropertyMenuBarResourcePath = RESOURCE_BASE + "rt14879-menubar.fxml"; 1139 1140 private class slotDefaultMenuBar extends TestNodeWithIOExceptionProcessing { 1141 1142 @Override 1143 protected String impl_getPathToResource() { 1144 return defaultPropertyMenuBarResourcePath; 1145 } 1146 1147 @Override 1148 public Node impl_drawNode() throws IOException { 1149 Node uplevelNode = null; 1150 1151 try { 1152 uplevelNode = FXMLLoader.load(resource); 1153 } catch (Exception e) { 1154 System.out.println("message: " + e.getMessage()); 1155 reportGetterFailure("message: " + e.getMessage()); 1156 } 1157 1158 return uplevelNode; 1159 } 1160 } 1161 1162 public static final String defaultPropertyScrollpaneResourcePath = RESOURCE_BASE + "rt14879-scrollpane.fxml"; 1163 1164 private class slotDefaultScrollpane extends TestNodeWithIOExceptionProcessing { 1165 1166 @Override 1167 protected String impl_getPathToResource() { 1168 return defaultPropertyScrollpaneResourcePath; 1169 } 1170 1171 @Override 1172 public Node impl_drawNode() throws IOException { 1173 Node uplevelNode = null; 1174 1175 try { 1176 uplevelNode = FXMLLoader.load(resource); 1177 } catch (Exception e) { 1178 System.out.println("message: " + e.getMessage()); 1179 reportGetterFailure("message: " + e.getMessage()); 1180 } 1181 return uplevelNode; 1182 } 1183 } 1184 1185 public static final String defaultPropertyTabpaneResourcePath = RESOURCE_BASE + "rt14879-tabpane.fxml"; 1186 1187 private class slotDefaultTabpane extends TestNodeWithIOExceptionProcessing { 1188 1189 @Override 1190 protected String impl_getPathToResource() { 1191 return defaultPropertyTabpaneResourcePath; 1192 } 1193 1194 @Override 1195 public Node impl_drawNode() throws IOException { 1196 Node uplevelNode = null; 1197 1198 try { 1199 uplevelNode = FXMLLoader.load(resource); 1200 } catch (Exception e) { 1201 System.out.println("message: " + e.getMessage()); 1202 reportGetterFailure("message: " + e.getMessage()); 1203 } 1204 return uplevelNode; 1205 } 1206 } 1207 1208 public static final String defaultPropertyTableViewResourcePath = RESOURCE_BASE + "rt14879-tableview.fxml"; 1209 1210 private class slotDefaultTableview extends TestNodeWithIOExceptionProcessing { 1211 1212 @Override 1213 protected String impl_getPathToResource() { 1214 return defaultPropertyTableViewResourcePath; 1215 } 1216 1217 @Override 1218 public Node impl_drawNode() throws IOException { 1219 TableView<Text> table = new TableView<Text>(); 1220 1221 try { 1222 table = 1223 FXMLLoader.load(resource); 1224 } catch (Exception e) { 1225 System.out.println("message: " + e.getMessage()); 1226 reportGetterFailure("message: " + e.getMessage()); 1227 } 1228 1229 TableColumn<Text, String> firstNameCol = new TableColumn<Text, String>("First Name"); 1230 firstNameCol.setCellValueFactory(new PropertyValueFactory("text")); 1231 table.getColumns().setAll(firstNameCol); 1232 1233 Object o = table.getItems().get(0); 1234 System.out.println("item0 type: " + o.getClass().getName()); 1235 System.out.println("item0 text: " + table.getItems().get(0).getText()); 1236 1237 return table; 1238 } 1239 } 1240 1241 public static final String defaultPropertyTextinputResourcePath = RESOURCE_BASE + "rt14879-textinput.fxml"; 1242 1243 private class slotDefaultTextinput extends TestNodeWithIOExceptionProcessing { 1244 1245 @Override 1246 protected String impl_getPathToResource() { 1247 return defaultPropertyTextinputResourcePath; 1248 } 1249 1250 @Override 1251 public Node impl_drawNode() throws IOException { 1252 Node uplevelNode = null; 1253 1254 try { 1255 uplevelNode = FXMLLoader.load(resource); 1256 } catch (Exception e) { 1257 System.out.println("message: " + e.getMessage()); 1258 reportGetterFailure("message: " + e.getMessage()); 1259 } 1260 return uplevelNode; 1261 } 1262 } 1263 1264 public static final String defaultPropertyTitledpaneResourcePath = RESOURCE_BASE + "rt14879-titledpane.fxml"; 1265 1266 private class slotDefaultTitledpane extends TestNodeWithIOExceptionProcessing { 1267 1268 @Override 1269 protected String impl_getPathToResource() { 1270 return defaultPropertyTitledpaneResourcePath; 1271 } 1272 1273 @Override 1274 public Node impl_drawNode() throws IOException { 1275 Node uplevelNode = null; 1276 1277 try { 1278 uplevelNode = FXMLLoader.load(resource); 1279 } catch (Exception e) { 1280 System.out.println("message: " + e.getMessage()); 1281 reportGetterFailure("message: " + e.getMessage()); 1282 } 1283 return uplevelNode; 1284 } 1285 } 1286 1287 public static final String defaultPropertyTreeviewResourcePath = RESOURCE_BASE + "rt14879-treeview.fxml"; 1288 1289 private class slotDefaultTreeview extends TestNodeWithIOExceptionProcessing { 1290 1291 @Override 1292 protected String impl_getPathToResource() { 1293 return defaultPropertyTreeviewResourcePath; 1294 } 1295 1296 @Override 1297 public Node impl_drawNode() throws IOException { 1298 Node uplevelNode = null; 1299 try { 1300 uplevelNode = FXMLLoader.load(resource); 1301 } catch (Exception e) { 1302 System.out.println("message: " + e.getMessage()); 1303 reportGetterFailure("message: " + e.getMessage()); 1304 } 1305 //Font f = null; 1306 return uplevelNode; 1307 } 1308 } 1309 1310 public static final String defaultPropertyImageviewResourcePath = RESOURCE_BASE + "rt14879-imageview.fxml"; 1311 1312 private class slotDefaultImageview extends TestNodeWithIOExceptionProcessing { 1313 1314 @Override 1315 protected String impl_getPathToResource() { 1316 return defaultPropertyImageviewResourcePath; 1317 } 1318 1319 @Override 1320 public Node impl_drawNode() throws IOException { 1321 Node uplevelNode = null; 1322 1323 try { 1324 uplevelNode = FXMLLoader.load(resource); 1325 } catch (Exception e) { 1326 System.out.println("message: " + e.getMessage()); 1327 reportGetterFailure("message: " + e.getMessage()); 1328 } 1329 return uplevelNode; 1330 } 1331 } 1332 1333 public static final String defaultPropertyPaneResourcePath = RESOURCE_BASE + "rt14879-pane.fxml"; 1334 1335 private class slotDefaultPane extends TestNodeWithIOExceptionProcessing { 1336 1337 @Override 1338 protected String impl_getPathToResource() { 1339 return defaultPropertyPaneResourcePath; 1340 } 1341 1342 @Override 1343 public Node impl_drawNode() throws IOException { 1344 Node uplevelNode = null; 1345 try { 1346 uplevelNode = FXMLLoader.load(resource); 1347 } catch (Exception e) { 1348 System.out.println("message: " + e.getMessage()); 1349 reportGetterFailure("message: " + e.getMessage()); 1350 } 1351 return uplevelNode; 1352 } 1353 } 1354 1355 public static final String controllerFactoryPath = RESOURCE_BASE + "rt_16724.fxml"; 1356 1357 private class controllerFactoryPane extends TestNodeWithIOExceptionProcessing { 1358 1359 @Override 1360 protected String impl_getPathToResource() { 1361 return controllerFactoryPath; 1362 } 1363 1364 @Override 1365 public Node impl_drawNode() throws IOException { 1366 LoadableEntity uplevelNode = null; 1367 boolean cntrlrFctryInvoked = false; 1368 boolean cntrlrInvoked = false; 1369 FXMLLoader fxmlLoader2 = new FXMLLoader(); 1370 Callback cfViaGetter = null; 1371 1372 RT_16724ControllerFactory cf = new RT_16724ControllerFactory(); 1373 try { 1374 1375 uplevelNode = 1376 FXMLLoader.load(resource, null, null, cf); 1377 1378 cntrlrFctryInvoked = cf.isInvoked(); 1379 RT_16724Controller cntrlr = cf.getCntrlr(); 1380 cntrlrInvoked = cntrlr.isInvoked(); 1381 1382 fxmlLoader2.setControllerFactory(cf); 1383 cfViaGetter = fxmlLoader2.getControllerFactory(); 1384 1385 } catch (Exception e) { 1386 System.out.println("message: " + e.getMessage()); 1387 reportGetterFailure("message: " + e.getMessage()); 1388 } 1389 1390 System.out.println("name: " + uplevelNode.getName()); 1391 1392 if ( cf != cfViaGetter ){ 1393 reportGetterFailure("cf via getter failed"); 1394 } 1395 1396 if ( 0 != "nameLoadedViaDefaultProperty".compareTo(uplevelNode.getName())) { 1397 reportGetterFailure("load using defaultProperty in custom class failed"); 1398 } 1399 if ( false == cntrlrFctryInvoked || false == cntrlrInvoked ) { 1400 reportGetterFailure("failed."); 1401 return redRectangle; 1402 } else { 1403 return retRec; 1404 } 1405 1406 } 1407 } 1408 1409 1410 public static final String specificSignatureMethodPath = RESOURCE_BASE + "rt_18229.fxml"; 1411 1412 private class specificSignatureMethodPane extends TestNodeWithIOExceptionProcessing { 1413 1414 @Override 1415 protected String impl_getPathToResource() { 1416 return specificSignatureMethodPath; 1417 } 1418 1419 @Override 1420 public Node impl_drawNode() throws IOException { 1421 FXMLLoader fxmlLoader = new FXMLLoader(resource); 1422 try { 1423 fxmlLoader.load(); 1424 } catch (Exception e) { 1425 System.out.println("message: " + e.getMessage()); 1426 reportGetterFailure("message: " + e.getMessage()); 1427 } 1428 1429 RT_18229Controller controller = (RT_18229Controller)fxmlLoader.getController(); 1430 if ( 0 != "abc".compareTo(controller.getRootName1())) { 1431 reportGetterFailure("compare 1"); 1432 } 1433 if ( 0 != "def".compareTo(controller.getRootName2())) { 1434 reportGetterFailure("compare 2"); 1435 } 1436 1437 final String rootName1 = "123"; 1438 controller.getRoot().setName1(rootName1); 1439 if ( 0 != rootName1.compareTo(controller.getRootName1())) { 1440 reportGetterFailure("compare 3"); 1441 } 1442 1443 final String rootName2 = "456"; 1444 controller.getRoot().setName2(rootName2); 1445 1446 if ( 0 != rootName2.compareTo(controller.getRootName2())) { 1447 reportGetterFailure("compare 4"); 1448 } 1449 1450 return retRec; 1451 } 1452 } 1453 1454 public static final String loadfontPath = RESOURCE_BASE + "fontload.fxml"; 1455 1456 private class loadfontSlot extends TestNodeWithIOExceptionProcessing { 1457 1458 @Override 1459 protected String impl_getPathToResource() { 1460 return loadfontPath ; 1461 } 1462 1463 @Override 1464 public Node impl_drawNode() throws IOException { 1465 Font fnt = null; 1466 FXMLLoader fxmlLoader = new FXMLLoader(resource); 1467 try { 1468 fnt = (Font) fxmlLoader.load(); 1469 } catch (Exception e) { 1470 System.out.println("message: " + e.getMessage()); 1471 reportGetterFailure("message: " + e.getMessage()); 1472 } 1473 1474 System.out.println("font name: " + fnt.getName()); 1475 if ( 0 != "Lucida Bright Demibold".compareTo(fnt.getName())) { 1476 reportGetterFailure("font name check failed"); 1477 } 1478 1479 return retRec; 1480 } 1481 } 1482 1483 public static final String scenebuilderPath = RESOURCE_BASE + "scenebuilder.fxml"; 1484 1485 private class scenebuilderSlot extends TestNodeWithIOExceptionProcessing { 1486 1487 @Override 1488 protected String impl_getPathToResource() { 1489 return scenebuilderPath ; 1490 } 1491 1492 @Override 1493 public Node impl_drawNode() throws IOException { 1494 Scene tmpScene = null; 1495 FXMLLoader fxmlLoader = new FXMLLoader(resource); 1496 try { 1497 tmpScene = (Scene) fxmlLoader.load(); 1498 } catch (Exception e) { 1499 System.out.println("message: " + e.getMessage()); 1500 reportGetterFailure("message: " + e.getMessage()); 1501 } 1502 1503 if ( 150 != tmpScene.getHeight()) { 1504 reportGetterFailure("sceneHeight check failed"); 1505 } 1506 if ( 100 != tmpScene.getWidth()) { 1507 reportGetterFailure("sceneWidth check failed"); 1508 } 1509 1510 return tmpScene.getRoot(); 1511 } 1512 } 1513 1514 1515 public static final String rt18299ResourcePath = RESOURCE_BASE + "rt18299-scene-without-root.fxml"; 1516 private class scenebuilderNoRootSlot extends scenebuilderSlot 1517 { 1518 1519 @Override 1520 protected String impl_getPathToResource() 1521 { 1522 return rt18299ResourcePath; 1523 } 1524 1525 } 1526 1527 public static final String rt19329ResourcePath = RESOURCE_BASE + "rt19329-error-FXML.fxml"; 1528 public static final String ERROR_INFO_ID = "error_info"; 1529 //public static final String FXML_ERROR_LOCATION = "<ErrorTag is not a valid type.>fxml:12"; 1530 private class errorFXMLLoader extends TestNodeWithIOExceptionProcessing 1531 { 1532 1533 @Override 1534 protected String impl_getPathToResource() 1535 { 1536 return rt19329ResourcePath; 1537 } 1538 1539 @Override 1540 protected Node impl_drawNode() throws IOException 1541 { 1542 final Label label = new Label(); 1543 label.setId(ERROR_INFO_ID); 1544 FXMLLoader fxmlLoader = new FXMLLoader(resource); 1545 try 1546 { 1547 fxmlLoader.load(); 1548 } 1549 catch(IOException e) 1550 { 1551 boolean lineNumberPresentAndCorrect = false; 1552 System.out.println("Exception text=" + e.getMessage()); 1553 if (e.getMessage().contains("ErrorTag") && 1554 e.getMessage().contains("fxml:12")) 1555 { 1556 return retRec; 1557 } 1558 } 1559 reportGetterFailure("wrong error message"); 1560 return label; 1561 } 1562 1563 } 1564 1565 public static final String rt18218ResourcePath = RESOURCE_BASE + "rt18218-unknown-custom-type.fxml"; 1566 public static final String LOADER_LOG_ID = "loader_log"; 1567 public static final String SUCCESSFUL_STATIC_LOAD = "success"; 1568 private class UnknownCustomType extends TestNodeWithIOExceptionProcessing 1569 { 1570 @Override 1571 protected String impl_getPathToResource() 1572 { 1573 return rt18218ResourcePath; 1574 } 1575 1576 @Override 1577 protected Node impl_drawNode() throws IOException 1578 { 1579 final Label label = new Label(); 1580 label.setId(LOADER_LOG_ID); 1581 FXMLLoader fxmlLoader = new FXMLLoader(resource); 1582 fxmlLoader.impl_setStaticLoad(true); 1583 try 1584 { 1585 fxmlLoader.load(); 1586 label.setText(SUCCESSFUL_STATIC_LOAD); 1587 } 1588 catch(LoadException e) 1589 { 1590 e.printStackTrace(); 1591 for(ParseTraceElement trace: fxmlLoader.impl_getParseTrace()) 1592 { 1593 label.setText(label.getText() + trace.toString() + '\n'); 1594 } 1595 } 1596 1597 return label; 1598 } 1599 1600 } 1601 1602 public static final String rt14345ResourcePath = RESOURCE_BASE + "rt14345-color-valueOf.fxml"; 1603 private class ColorValueOf extends TestNodeWithIOExceptionProcessing 1604 { 1605 1606 @Override 1607 protected String impl_getPathToResource() 1608 { 1609 return rt14345ResourcePath; 1610 } 1611 1612 @Override 1613 protected Node impl_drawNode() throws IOException 1614 { 1615 FXMLLoader fxmlLoader = new FXMLLoader(resource); 1616 Node node = null; 1617 try 1618 { 1619 node = (Node) fxmlLoader.load(); 1620 } 1621 catch(Exception e) 1622 { 1623 System.out.println("message: " + e.getMessage()); 1624 reportGetterFailure("message: " + e.getMessage()); 1625 } 1626 1627 return node; 1628 } 1629 1630 } 1631 1632 public static final String rt18680ResourcePath = RESOURCE_BASE + "rt18680-escape-character.fxml"; 1633 private class EscapeCharacter extends TestNodeWithIOExceptionProcessing 1634 { 1635 1636 @Override 1637 protected String impl_getPathToResource() 1638 { 1639 return rt18680ResourcePath; 1640 } 1641 1642 @Override 1643 protected Node impl_drawNode() throws IOException 1644 { 1645 FXMLLoader fxmlLoader = new FXMLLoader(resource); 1646 VBox node = null; 1647 try 1648 { 1649 node = (VBox) fxmlLoader.load(); 1650 for(Node child: node.getChildren()) 1651 { 1652 if((child.getId().equals("label_1") 1653 || child.getId().equals("label_2")) 1654 && !((Label) child).getText().equals("${foo}")) 1655 { 1656 reportGetterFailure(child.getId() + " text check failed"); 1657 } 1658 if((child.getId().equals("label_3") 1659 || child.getId().equals("label_4")) 1660 && !((Label) child).getText().equals("@{foo}")) 1661 { 1662 reportGetterFailure(child.getId() + " text check failed"); 1663 } 1664 if((child.getId().equals("label_5") 1665 || child.getId().equals("label_6")) 1666 && !((Label) child).getText().equals("%{foo}")) 1667 { 1668 reportGetterFailure(child.getId() + " text check failed"); 1669 } 1670 } 1671 } 1672 catch(Exception e) 1673 { 1674 System.out.println("message: " + e.getMessage()); 1675 reportGetterFailure("message: " + e.getMessage()); 1676 } 1677 1678 return node; 1679 } 1680 1681 } 1682 1683 public static final String rt17714ResourcePath = RESOURCE_BASE + "rt17714-collection-events-handlers.fxml"; 1684 private class CollectionEventsHandlers extends TestNodeWithIOExceptionProcessing 1685 { 1686 1687 @Override 1688 protected String impl_getPathToResource() 1689 { 1690 return rt17714ResourcePath; 1691 } 1692 1693 @Override 1694 protected Node impl_drawNode() throws IOException 1695 { 1696 FXMLLoader fxmlLoader = new FXMLLoader(resource); 1697 ObservableList<String> observableArrayList = null; 1698 //javafx.collections.FXCollections.observableArrayList(); 1699 try 1700 { 1701 observableArrayList = (ObservableList<String>) fxmlLoader.load(); 1702 System.out.println(fxmlLoader.getController().getClass()); 1703 observableArrayList.add("New added string"); 1704 } 1705 catch(Exception e) 1706 { 1707 System.out.println("message: " + e.getMessage()); 1708 reportGetterFailure("message: " + e.getMessage()); 1709 } 1710 1711 if(1 != CollectionController.callCount) 1712 { 1713 reportGetterFailure("Controller didn't handle event"); 1714 } 1715 1716 return new Label(observableArrayList.get(0).toString()); 1717 } 1718 1719 } 1720 1721 public static final String rt18229ResourcePath = RESOURCE_BASE + "rt18229-no-args-controller-method.fxml"; 1722 private class NoArgsControllerMethod extends TestNodeWithIOExceptionProcessing 1723 { 1724 @Override 1725 protected String impl_getPathToResource() 1726 { 1727 return rt18229ResourcePath; 1728 } 1729 1730 @Override 1731 public Node impl_drawNode() throws IOException 1732 { 1733 FXMLLoader loader = new FXMLLoader(resource); 1734 Button button = null; 1735 try 1736 { 1737 button = (Button) loader.load(); 1738 System.out.println(button.getId()); 1739 } 1740 catch(Exception e) 1741 { 1742 e.printStackTrace(); 1743 System.out.println("message: " + e.getMessage()); 1744 reportGetterFailure("message: " + e.getMessage()); 1745 } 1746 return button; 1747 } 1748 } 1749 1750 public static final String rt18229OverloadedResourcePath = RESOURCE_BASE + "rt18229-overloaded-controller-method.fxml"; 1751 private class OverloadedControllerMethod extends TestNodeWithIOExceptionProcessing 1752 { 1753 1754 @Override 1755 protected String impl_getPathToResource() 1756 { 1757 return rt18229OverloadedResourcePath; 1758 } 1759 1760 @Override 1761 public Node impl_drawNode() throws IOException 1762 { 1763 FXMLLoader loader = new FXMLLoader(resource); 1764 Button button = null; 1765 try 1766 { 1767 button = (Button) loader.load(); 1768 } 1769 catch(Exception e) 1770 { 1771 e.printStackTrace(); 1772 System.out.println("message: " + e.getMessage()); 1773 reportGetterFailure("message: " + e.getMessage()); 1774 } 1775 return button; 1776 } 1777 1778 } 1779 1780 public static final String rt17657ResourcePath = RESOURCE_BASE + "rt17657-custom-id-property.fxml"; 1781 private class CustomIDProperty extends TestNodeWithIOExceptionProcessing 1782 { 1783 1784 @Override 1785 protected String impl_getPathToResource() 1786 { 1787 return rt17657ResourcePath; 1788 } 1789 1790 @Override 1791 public Node impl_drawNode() throws IOException 1792 { 1793 FXMLLoader loader = new FXMLLoader(resource); 1794 CustomIDButton button = null; 1795 try 1796 { 1797 button = (CustomIDButton) loader.load(); 1798 System.out.println(button.getCustomID()); 1799 } 1800 catch(Exception e) 1801 { 1802 e.printStackTrace(); 1803 System.out.println("message: " + e.getMessage()); 1804 reportGetterFailure("message: " + e.getMessage()); 1805 } 1806 return button; 1807 1808 } 1809 1810 } 1811 1812 public static final String rt16722ResourcePath = RESOURCE_BASE + "rt16722-base-controller-properties.fxml"; 1813 private class BaseColntrollerProperty extends TestNodeWithIOExceptionProcessing 1814 { 1815 1816 @Override 1817 protected String impl_getPathToResource() 1818 { 1819 return rt16722ResourcePath; 1820 } 1821 1822 @Override 1823 public Node impl_drawNode() throws IOException 1824 { 1825 FXMLLoader loader = new FXMLLoader(resource); 1826 VBox vBox = null; 1827 try 1828 { 1829 vBox = (VBox) loader.load(); 1830 } 1831 catch(Exception e) 1832 { 1833 e.printStackTrace(); 1834 System.out.println("message: " + e.getMessage()); 1835 reportGetterFailure("message: " + e.getMessage()); 1836 } 1837 return vBox; 1838 1839 } 1840 1841 } 1842 1843 public static final String rt18956ResourcePath = RESOURCE_BASE + "rt18956-relative-stylesheets.fxml"; 1844 private class RelativeStylesheet extends TestNodeWithIOExceptionProcessing 1845 { 1846 @Override 1847 protected String impl_getPathToResource() 1848 { 1849 return rt18956ResourcePath; 1850 } 1851 1852 @Override 1853 public Node impl_drawNode() throws IOException 1854 { 1855 FXMLLoader loader = new FXMLLoader(resource); 1856 Label label = null; 1857 try 1858 { 1859 label = (Label) loader.load(); 1860 System.out.println("font:" + label.getFont().toString()); 1861 1862 System.out.println("Style:"); 1863 System.out.println(label.getStyle()); 1864 final ObservableList<String> sheets = label.getStylesheets(); 1865 for (String str : sheets) 1866 System.out.println("sheet:" + str); 1867 if (null != label.getBackground()) { 1868 final List<BackgroundFill> lbf = 1869 label.getBackground().getFills(); 1870 1871 1872 for (BackgroundFill bf : lbf) 1873 System.out.println("fill:" + bf.toString()); 1874 } else { 1875 System.out.println("null == label.getBackground() "); 1876 } 1877 final List<CssMetaData<? extends Styleable, ?>> ls = 1878 label.getControlCssMetaData(); 1879 1880 1881 for (CssMetaData<? extends Styleable, ?> md : ls) 1882 { 1883 System.out.println("css:" + md.toString()); 1884 if (md.getProperty().equals("-fx-region-background")){ 1885 final List<CssMetaData<? extends Styleable, ?>> subList = 1886 md.getSubProperties(); 1887 for (CssMetaData<? extends Styleable, ?> smd : subList){ 1888 System.out.println(" subcss:" + smd.toString()); 1889 if (smd.getProperty().equals("-fx-background-color")){ 1890 1891 } 1892 } 1893 } 1894 1895 } 1896 1897 1898 } 1899 catch(Exception e) 1900 { 1901 e.printStackTrace(); 1902 System.out.println("message: " + e.getMessage()); 1903 reportGetterFailure("message: " + e.getMessage()); 1904 } 1905 return label; 1906 1907 } 1908 1909 } 1910 1911 public static final String rt16815ResourcePath = RESOURCE_BASE + "FXMLLoaderAPI.fxml"; 1912 private class FXMLLoaderAPI extends TestNodeWithIOExceptionProcessing 1913 { 1914 1915 @Override 1916 protected String impl_getPathToResource() 1917 { 1918 return rt16815ResourcePath; 1919 } 1920 1921 @Override 1922 public Node impl_drawNode() throws IOException 1923 { 1924 FXMLLoader loader = new FXMLLoader(resource); 1925 ResourceBundle rb = ResourceBundle.getBundle("test.fxmltests.resources.resource1", new Locale("en", "US")); 1926 FXMLLoader loader2 = new FXMLLoader(resource, rb); 1927 FXMLLoader loader3 = new FXMLLoader(resource, rb, new JavaFXBuilderFactory()); 1928 ObservableList<Labeled> list = FXCollections.observableArrayList(); 1929 try 1930 { 1931 list.add((Labeled) loader.load()); 1932 // System.out.println(label.getStyle()); 1933 } 1934 catch(Exception e) 1935 { 1936 e.printStackTrace(); 1937 System.out.println("message: " + e.getMessage()); 1938 reportGetterFailure("message: " + e.getMessage()); 1939 } 1940 try 1941 { 1942 list.add((Labeled) loader2.load()); 1943 // System.out.println(label.getStyle()); 1944 } 1945 catch(Exception e) 1946 { 1947 e.printStackTrace(); 1948 System.out.println("message: " + e.getMessage()); 1949 reportGetterFailure("message: " + e.getMessage()); 1950 } 1951 try 1952 { 1953 list.add((Labeled) loader3.load()); 1954 // System.out.println(label.getStyle()); 1955 } 1956 catch(Exception e) 1957 { 1958 e.printStackTrace(); 1959 System.out.println("message: " + e.getMessage()); 1960 reportGetterFailure("message: " + e.getMessage()); 1961 } 1962 return VBoxBuilder.create().children(list).build(); 1963 1964 } 1965 1966 } 1967 1968 public static final String references2Path = RESOURCE_BASE + "ref_test.fxml"; 1969 private class references2Slot extends TestNodeWithIOExceptionProcessing { 1970 // RT-18178 1971 AnchorPane anchorPane = null; 1972 1973 @Override 1974 protected String impl_getPathToResource() { 1975 return references2Path; 1976 } 1977 1978 @Override 1979 public Node impl_drawNode() throws IOException { 1980 InputStream is = null; 1981 try { 1982 FXMLLoader fxmlLoader2 = new FXMLLoader(); 1983 is = resource.openStream(); 1984 anchorPane = (AnchorPane) fxmlLoader2.load(is); 1985 } catch (Exception e) { 1986 e.printStackTrace(); 1987 System.out.println("message: " + e.getMessage()); 1988 reportGetterFailure("exception thrown."); 1989 } finally { 1990 is.close(); 1991 } 1992 1993 1994 Button button = null; 1995 Label label = null; 1996 for (Node node : anchorPane.getChildren()) { 1997 if (node instanceof Button) { 1998 button = (Button)node; 1999 } 2000 if (node instanceof Label) { 2001 label = (Label)node; 2002 } 2003 } 2004 2005 if ( null != label && null != button ) { 2006 System.out.println("label: " + label.getFont() + " / " + label.getTextFill()); 2007 System.out.println("button: " + button.getFont() + " / " + button.getTextFill()); 2008 2009 if (label.getTextFill().equals(button.getTextFill()) && 2010 label.getFont().equals(button.getFont())) { 2011 return retRec; 2012 } 2013 } 2014 reportGetterFailure("failed."); 2015 return redRectangle; 2016 } 2017 } 2018 2019 2020 2021 public static final String apConstraintsPath = RESOURCE_BASE + "project-with-all-AnchorPane-constraints.fxml"; 2022 private class apConstraintsSlot extends TestNodeWithIOExceptionProcessing { 2023 // RT-18178 2024 AnchorPane anchorPane = null; 2025 2026 @Override 2027 protected String impl_getPathToResource() { 2028 return apConstraintsPath; 2029 } 2030 2031 @Override 2032 public Node impl_drawNode() throws IOException { 2033 InputStream is = null; 2034 try { 2035 FXMLLoader fxmlLoader2 = new FXMLLoader(); 2036 is = resource.openStream(); 2037 anchorPane = (AnchorPane) fxmlLoader2.load(is); 2038 } catch (Exception e) { 2039 e.printStackTrace(); 2040 System.out.println("message: " + e.getMessage()); 2041 reportGetterFailure("exception thrown."); 2042 } finally { 2043 is.close(); 2044 } 2045 2046 return retRec; 2047 } 2048 } 2049 2050 2051 2052 2053 public static final String coercePath = RESOURCE_BASE + "project-with-all-p2-components.fxml"; 2054 private class coerceSlot extends TestNodeWithIOExceptionProcessing { 2055 // RT-18178 2056 AnchorPane anchorPane = null; 2057 2058 @Override 2059 protected String impl_getPathToResource() { 2060 return coercePath; 2061 } 2062 2063 @Override 2064 public Node impl_drawNode() throws IOException { 2065 InputStream is = null; 2066 try { 2067 FXMLLoader fxmlLoader2 = new FXMLLoader(); 2068 is = resource.openStream(); 2069 anchorPane = (AnchorPane) fxmlLoader2.load(is); 2070 } catch (Exception e) { 2071 e.printStackTrace(); 2072 System.out.println("message: " + e.getMessage()); 2073 reportGetterFailure("exception thrown."); 2074 } finally { 2075 is.close(); 2076 } 2077 return retRec; 2078 } 2079 } 2080 2081 public static final String gridappletPath = RESOURCE_BASE + "rt19752.fxml"; 2082 private class gridappletSlot extends TestNodeWithIOExceptionProcessing { 2083 // RT-18178 2084 GridPane gridPane = null; 2085 2086 @Override 2087 protected String impl_getPathToResource() { 2088 return gridappletPath; 2089 } 2090 2091 @Override 2092 public Node impl_drawNode() throws IOException { 2093 InputStream is = null; 2094 try { 2095 FXMLLoader fxmlLoader2 = new FXMLLoader(); 2096 is = resource.openStream(); 2097 gridPane = (GridPane) fxmlLoader2.load(is); 2098 } catch (Exception e) { 2099 e.printStackTrace(); 2100 System.out.println("message: " + e.getMessage()); 2101 reportGetterFailure("exception thrown."); 2102 } finally { 2103 is.close(); 2104 } 2105 return retRec; 2106 } 2107 } 2108 2109 /* 2110 public static final String csspathPath = RESOURCE_BASE + "rt18956.xml"; 2111 private class csspathSlot extends TestNodeWithIOExceptionProcessing { 2112 // RT-18956 2113 BorderPane gridPane = null; 2114 2115 @Override 2116 protected String impl_getPathToResource() { 2117 return csspathPath; 2118 } 2119 2120 @Override 2121 public Node impl_drawNode() throws IOException { 2122 InputStream is = null; 2123 try { 2124 FXMLLoader fxmlLoader2 = new FXMLLoader(); 2125 fxmlLoader2.setLocation(resource); 2126 2127 is = resource.openStream(); 2128 URL ggg; 2129 AnchorPane sc = (AnchorPane) fxmlLoader2.load(is); 2130 } catch (Exception e) { 2131 e.printStackTrace(); 2132 System.out.println("message: " + e.getMessage()); 2133 reportGetterFailure("exception thrown."); 2134 } finally { 2135 is.close(); 2136 } 2137 return retRec; 2138 } 2139 } 2140 */ 2141 2142 public static final String listviewPath = RESOURCE_BASE + "listview-items.fxml"; 2143 private class listviewSlot extends TestNodeWithIOExceptionProcessing { 2144 // RT-18178 2145 AnchorPane anchorPane = null; 2146 2147 @Override 2148 protected String impl_getPathToResource() { 2149 return listviewPath; 2150 } 2151 2152 @Override 2153 public Node impl_drawNode() throws IOException { 2154 InputStream is = null; 2155 try { 2156 FXMLLoader fxmlLoader2 = new FXMLLoader(); 2157 is = resource.openStream(); 2158 anchorPane = (AnchorPane) fxmlLoader2.load(is); 2159 } catch (Exception e) { 2160 e.printStackTrace(); 2161 System.out.println("message: " + e.getMessage()); 2162 reportGetterFailure("exception thrown."); 2163 } finally { 2164 is.close(); 2165 } 2166 2167 ListView lv = null; 2168 for (Node node : anchorPane.getChildren()) { 2169 System.out.println("anchorpane child: " + node); 2170 if (node instanceof ListView) { 2171 lv = (ListView)node; 2172 } 2173 } 2174 2175 int hboxcount = 0; 2176 if (null != lv) { 2177 for (Object node : lv.getItems()) { 2178 if (node instanceof HBox) { 2179 hboxcount = hboxcount + 1; 2180 } 2181 System.out.println("listview child: " + node); 2182 } 2183 2184 } 2185 2186 if ( 3 != hboxcount ) { 2187 reportGetterFailure("wrong items/items count."); 2188 return redRectangle; 2189 } else { 2190 return retRec; 2191 } 2192 } 2193 } 2194 2195 private class listenerNullArgSlot extends TestNodeWithIOExceptionProcessing { 2196 // RT-19133 2197 2198 @Override 2199 protected String impl_getPathToResource() { 2200 return rt19133ResourcePath; 2201 } 2202 2203 @Override 2204 public Node impl_drawNode() throws IOException { 2205 //InputStream is = null; 2206 try { 2207 //is = resource.openStream(); 2208 FXMLLoader fxmlLoader = new FXMLLoader(resource); 2209 2210 fxmlLoader.impl_setStaticLoad(true); 2211 fxmlLoader.impl_setLoadListener(new LoadListener() { 2212 2213 @Override 2214 public void readImportProcessingInstruction(String target) { 2215 } 2216 2217 @Override 2218 public void readLanguageProcessingInstruction(String language) { 2219 } 2220 2221 @Override 2222 public void readComment(String comment) { 2223 } 2224 2225 @Override 2226 public void beginInstanceDeclarationElement(Class<?> type) { 2227 } 2228 2229 @Override 2230 public void beginUnknownTypeElement(String name) { 2231 } 2232 2233 @Override 2234 public void beginIncludeElement() { 2235 } 2236 2237 @Override 2238 public void beginReferenceElement() { 2239 } 2240 2241 @Override 2242 public void beginCopyElement() { 2243 } 2244 2245 @Override 2246 public void beginPropertyElement(String name, Class<?> sourceType) { 2247 } 2248 2249 @Override 2250 public void beginUnknownStaticPropertyElement(String name) { 2251 } 2252 2253 @Override 2254 public void beginScriptElement() { 2255 } 2256 2257 @Override 2258 public void beginDefineElement() { 2259 } 2260 2261 @Override 2262 public void readInternalAttribute(String name, String value) { 2263 } 2264 2265 @Override 2266 public void readPropertyAttribute(String name, Class<?> sourceType, String value) { 2267 } 2268 2269 @Override 2270 public void readUnknownStaticPropertyAttribute(String name, String value) { 2271 } 2272 2273 @Override 2274 public void readEventHandlerAttribute(String name, String value) { 2275 } 2276 2277 @Override 2278 public void endElement(Object value) { 2279 if (null == value) { 2280 System.out.println("endElement() arg is null: rt-19133"); 2281 reportGetterFailure("endElement() arg is null: rt-19133"); 2282 } else { 2283 System.out.println("endElement() arg:" + value); 2284 } 2285 } 2286 2287 @Override 2288 public void beginRootElement() { 2289 throw new UnsupportedOperationException("Not supported yet."); 2290 } 2291 }); 2292 2293 2294 fxmlLoader.load(); 2295 } catch (Exception e) { 2296 e.printStackTrace(); 2297 System.out.println("message: " + e.getMessage()); 2298 reportGetterFailure("exception thrown."); 2299 } finally { 2300 //is.close(); 2301 } 2302 return retRec; 2303 } 2304 } 2305 2306 public static final String fullyQualifiedNamesResPath = RESOURCE_BASE + "fully-qualified-name.fxml"; 2307 private class FullyQualifiedNamesSlot extends TestNodeWithIOExceptionProcessing { 2308 2309 @Override 2310 protected String impl_getPathToResource() { 2311 return fullyQualifiedNamesResPath; 2312 } 2313 2314 @Override 2315 public Node impl_drawNode() throws IOException { 2316 Label label = null; 2317 InputStream is = null; 2318 try { 2319 FXMLLoader fxmlLoader = new FXMLLoader(); 2320 is = resource.openStream(); 2321 label = (Label) fxmlLoader.load(is); 2322 } catch (Exception e) { 2323 e.printStackTrace(); 2324 System.out.println("message: " + e.getMessage()); 2325 reportGetterFailure("exception thrown."); 2326 } finally { 2327 is.close(); 2328 } 2329 return label; 2330 } 2331 } 2332 2333 public static final String importResPath = RESOURCE_BASE + "import.fxml"; 2334 private class ImportSlot extends TestNodeWithIOExceptionProcessing { 2335 2336 @Override 2337 protected String impl_getPathToResource() { 2338 return importResPath; 2339 } 2340 2341 @Override 2342 public Node impl_drawNode() throws IOException { 2343 Label label = null; 2344 InputStream is = null; 2345 try { 2346 FXMLLoader fxmlLoader = new FXMLLoader(); 2347 is = resource.openStream(); 2348 label = (Label) fxmlLoader.load(is); 2349 } catch (Exception e) { 2350 e.printStackTrace(); 2351 System.out.println("message: " + e.getMessage()); 2352 reportGetterFailure("exception thrown."); 2353 } finally { 2354 is.close(); 2355 } 2356 return label; 2357 } 2358 } 2359 2360 public static final String beanInstantiationResPath = RESOURCE_BASE + "bean-instantiation.fxml"; 2361 private class BeanInstantiationSlot extends TestNodeWithIOExceptionProcessing { 2362 2363 @Override 2364 protected String impl_getPathToResource() { 2365 return beanInstantiationResPath; 2366 } 2367 2368 @Override 2369 public Node impl_drawNode() throws IOException { 2370 Label label = new Label(); 2371 label.setId("label_from_bean"); 2372 InputStream is = null; 2373 try { 2374 FXMLLoader fxmlLoader = new FXMLLoader(); 2375 is = resource.openStream(); 2376 SimpleBean bean = (SimpleBean) fxmlLoader.load(is); 2377 label.setText(bean.getContent()); 2378 } catch (Exception e) { 2379 e.printStackTrace(); 2380 System.out.println("message: " + e.getMessage()); 2381 reportGetterFailure("exception thrown."); 2382 } finally { 2383 is.close(); 2384 } 2385 return label; 2386 } 2387 } 2388 2389 public static final String valueOfResPath = RESOURCE_BASE + "value-of.fxml"; 2390 private class ValueOfSlot extends TestNodeWithIOExceptionProcessing { 2391 2392 @Override 2393 protected String impl_getPathToResource() { 2394 return valueOfResPath; 2395 } 2396 2397 @Override 2398 public Node impl_drawNode() throws IOException { 2399 Label label = new Label(); 2400 label.setId("value_of_label"); 2401 InputStream is = null; 2402 try { 2403 FXMLLoader fxmlLoader = new FXMLLoader(); 2404 is = resource.openStream(); 2405 Double d = (Double) fxmlLoader.load(is); 2406 label.setText(d.toString()); 2407 } catch (Exception e) { 2408 e.printStackTrace(); 2409 System.out.println("message: " + e.getMessage()); 2410 reportGetterFailure("exception thrown."); 2411 } finally { 2412 is.close(); 2413 } 2414 return label; 2415 } 2416 } 2417 2418 public static final String rootResPath = RESOURCE_BASE + "root.fxml"; 2419 private class RootSlot extends TestNodeWithIOExceptionProcessing { 2420 2421 @Override 2422 protected String impl_getPathToResource() { 2423 return rootResPath; 2424 } 2425 2426 @Override 2427 public Node impl_drawNode() throws IOException { 2428 VBox vb = new VBox(); 2429 vb.setId("vb_root"); 2430 InputStream is = null; 2431 try { 2432 FXMLLoader fxmlLoader = new FXMLLoader(); 2433 fxmlLoader.setRoot(vb); 2434 is = resource.openStream(); 2435 fxmlLoader.load(is); 2436 } catch (Exception e) { 2437 e.printStackTrace(); 2438 System.out.println("message: " + e.getMessage()); 2439 reportGetterFailure("exception thrown."); 2440 } finally { 2441 is.close(); 2442 } 2443 return vb; 2444 } 2445 } 2446 2447 public static final String fxIdResPath = RESOURCE_BASE + "fx-id.fxml"; 2448 private class FxIdSlot extends TestNodeWithIOExceptionProcessing { 2449 2450 @Override 2451 protected String impl_getPathToResource() { 2452 return fxIdResPath; 2453 } 2454 2455 @Override 2456 public Node impl_drawNode() throws IOException { 2457 AnchorPane ap = null; 2458 InputStream is = null; 2459 FXMLLoader fxmlLoader = null; 2460 try { 2461 fxmlLoader = new FXMLLoader(); 2462 is = resource.openStream(); 2463 ap = (AnchorPane) fxmlLoader.load(is); 2464 } catch (Exception e) { 2465 e.printStackTrace(); 2466 System.out.println("message: " + e.getMessage()); 2467 reportGetterFailure("exception thrown."); 2468 } finally { 2469 is.close(); 2470 } 2471 Object label = fxmlLoader.getNamespace().get("cat_o_dog_label"); 2472 if(label == null || !(label instanceof Label)) 2473 { 2474 reportGetterFailure("no label with id cat_o_dog_label"); 2475 } 2476 if(label instanceof Label && !((Label) label).getText().equals("cat-o-dog")) 2477 { 2478 reportGetterFailure("invalid text in label"); 2479 } 2480 return ap; 2481 } 2482 } 2483 2484 private class controllerAttributeSlot extends TestNodeWithIOExceptionProcessing { 2485 2486 MyRootElement2 mr; 2487 2488 @Override 2489 protected String impl_getPathToResource() { 2490 return rootMethodEventHandlerResourcePath; 2491 } 2492 2493 @Override 2494 public Node impl_drawNode() { 2495 FXMLLoader loader = new FXMLLoader(); 2496 try { 2497 // https://javafx-jira.kenai.com/browse/RT-26774 2498 //mr = (MyRootElement2) FXMLLoader.load(resource); 2499 loader.setLocation(resource); 2500 mr = (MyRootElement2)loader.load(); 2501 } catch (Exception e) { 2502 System.out.println("message: " + e.getMessage()); 2503 e.printStackTrace(); 2504 reportGetterFailure("exception thrown."); 2505 } 2506 2507 if(!(loader.getController() instanceof MyRootElement2)) 2508 { 2509 reportGetterFailure("wrong controller"); 2510 } 2511 2512 return mr; 2513 } 2514 } 2515 2516 public static final String noDefControllerResPath = RESOURCE_BASE + "no-default-controller.fxml"; 2517 private class NoDefaultControllerSlot extends TestNodeWithIOExceptionProcessing { 2518 2519 @Override 2520 protected String impl_getPathToResource() { 2521 return noDefControllerResPath; 2522 } 2523 2524 @Override 2525 public Node impl_drawNode() throws IOException { 2526 Button button = null; 2527 InputStream is = null; 2528 FXMLLoader fxmlLoader = null; 2529 MyRootElement myRootElement = new MyRootElement(); 2530 try { 2531 fxmlLoader = new FXMLLoader(); 2532 fxmlLoader.setController(myRootElement); 2533 is = resource.openStream(); 2534 button = (Button) fxmlLoader.load(is); 2535 } catch (Exception e) { 2536 e.printStackTrace(); 2537 System.out.println("message: " + e.getMessage()); 2538 reportGetterFailure("exception thrown."); 2539 } finally { 2540 is.close(); 2541 } 2542 if(fxmlLoader.getController() != myRootElement) 2543 { 2544 reportGetterFailure("Wrong controller"); 2545 } 2546 return button; 2547 } 2548 } 2549 2550 private class LateRootSlot extends TestNodeWithIOExceptionProcessing { 2551 2552 @Override 2553 protected String impl_getPathToResource() { 2554 return rootResPath; 2555 } 2556 2557 @Override 2558 public Node impl_drawNode() throws IOException { 2559 VBox vb = new VBox(); 2560 vb.setId("vb_root"); 2561 Node node = null; 2562 FXMLLoader fxmlLoader = new FXMLLoader(); 2563 InputStream is = null; 2564 try { 2565 is = resource.openStream(); 2566 node = (Node) fxmlLoader.load(is); 2567 fxmlLoader.setRoot(vb); 2568 } catch (LoadException e) { 2569 e.printStackTrace(); 2570 System.out.println("message: " + e.getMessage()); 2571 return retRec; 2572 } catch (Exception exc) { 2573 exc.printStackTrace(); 2574 System.out.println("message: " + exc.getMessage()); 2575 reportGetterFailure("exception thrown."); 2576 } finally { 2577 is.close(); 2578 } 2579 // if(node.getId() == null || !node.getId().equals("default_root")) 2580 // { 2581 // reportGetterFailure("Root id: " + node.getId()); 2582 // } 2583 return redRectangle; 2584 } 2585 } 2586 2587 private class LateControllerSlot extends TestNodeWithIOExceptionProcessing { 2588 2589 @Override 2590 protected String impl_getPathToResource() { 2591 return noDefControllerResPath; 2592 } 2593 2594 @Override 2595 public Node impl_drawNode() throws IOException { 2596 Button button = null; 2597 InputStream is = null; 2598 FXMLLoader fxmlLoader = new FXMLLoader(); 2599 MyRootElement myRootElement = new MyRootElement(); 2600 try { 2601 is = resource.openStream(); 2602 fxmlLoader.load(is); 2603 fxmlLoader.setController(myRootElement); 2604 } catch (Exception e) { 2605 2606 if(e instanceof LoadException && e.getMessage().contains("No controller specified.")) 2607 { 2608 return retRec; 2609 } 2610 e.printStackTrace(); 2611 System.out.println("message: " + e.getMessage()); 2612 reportGetterFailure("exception thrown."); 2613 } finally { 2614 is.close(); 2615 } 2616 reportGetterFailure("Controller is not null."); 2617 return redRectangle; 2618 } 2619 } 2620 2621 private class VariableResolutionSlot extends TestNodeWithIOExceptionProcessing { 2622 2623 VBox vb; 2624 2625 @Override 2626 protected String impl_getPathToResource() { 2627 return fxdefineResourcePath; 2628 } 2629 2630 @Override 2631 public Node impl_drawNode() { 2632 try { 2633 vb = FXMLLoader.load(resource); 2634 } catch (Exception e) { 2635 System.out.println("message: " + e.getMessage()); 2636 reportGetterFailure("exception thrown."); 2637 } 2638 LinkedList<ToggleGroup> toggleGroups = new LinkedList<ToggleGroup>(); 2639 for(Node child: vb.getChildren()) 2640 { 2641 toggleGroups.add(((RadioButton) child).getToggleGroup()); 2642 } 2643 for(int i = 0; i < toggleGroups.size() - 2; i ++) 2644 { 2645 if(!toggleGroups.get(i).equals(toggleGroups.get(i + 1))) 2646 { 2647 reportGetterFailure("failed."); 2648 return redRectangle; 2649 } 2650 } 2651 return retRec; 2652 } 2653 } 2654 2655 public static final String externalScriptResPath = RESOURCE_BASE + "external-script.fxml"; 2656 private class ExternalScriptCodeSlot extends TestNodeWithIOExceptionProcessing 2657 { 2658 @Override 2659 protected String impl_getPathToResource() 2660 { 2661 return externalScriptResPath; 2662 } 2663 2664 @Override 2665 public Node impl_drawNode() throws IOException 2666 { 2667 FXMLLoader loader = new FXMLLoader(resource); 2668 VBox vb = null; 2669 try 2670 { 2671 vb = (VBox) loader.load(); 2672 } 2673 catch(Exception e) 2674 { 2675 e.printStackTrace(); 2676 System.out.println("message: " + e.getMessage()); 2677 reportGetterFailure("message: " + e.getMessage()); 2678 } 2679 return vb; 2680 } 2681 } 2682 2683 2684 @Override 2685 public TestNode setup() { 2686 System.out.println("java.library.path=" + System.getProperty("java.library.path")); 2687 TestNode rootTestNode = new TestNode(); 2688 2689 final int heightPageContentPane = 800; 2690 final int widthPageContentPane = 800; 2691 2692 List<Pair<String, TestNode>> hm = new ArrayList(); 2693 2694 hm.add(new Pair<String, TestNode>(Pages.staticProperty.name(), new slotStaticProperty())); 2695 hm.add(new Pair<String, TestNode>(Pages.HashMap.name(), new hashmaptest())); 2696 hm.add(new Pair<String, TestNode>(Pages.customClassAndInclude.name(), new customClassLoadSlot())); 2697 hm.add(new Pair<String, TestNode>(Pages.factory.name(), new factorySlot())); 2698 hm.add(new Pair<String, TestNode>(Pages.simple.name(), new simpleSlot())); 2699 hm.add(new Pair<String, TestNode>(Pages.propertyElements.name(), new propertyElementsSlot())); 2700 hm.add(new Pair<String, TestNode>(Pages.reference.name(), new referenceSlot())); 2701 hm.add(new Pair<String, TestNode>(Pages.copy.name(), new copySlot())); 2702 hm.add(new Pair<String, TestNode>(Pages.prSetter.name(), new propertySetterSlot())); 2703 hm.add(new Pair<String, TestNode>(Pages.roList.name(), new roListSlot())); 2704 hm.add(new Pair<String, TestNode>(Pages.roMap.name(), new roMapSlot())); 2705 hm.add(new Pair<String, TestNode>(Pages.defaultProperty.name(), new defaultPropertySlot())); 2706 hm.add(new Pair<String, TestNode>(Pages.fxdefine.name(), new fxdefineSlot())); 2707 hm.add(new Pair<String, TestNode>(Pages.namespaceBinding.name(), new namespaceBindingSlot())); 2708 hm.add(new Pair<String, TestNode>(Pages.staticProperties.name(), new staticPropertiesSlot())); 2709 hm.add(new Pair<String, TestNode>(Pages.rootMethodEventHandler.name(), new rootMethodEventHandlerSlot())); 2710 hm.add(new Pair<String, TestNode>(Pages.scriptEventHandler.name(), new scriptEventHandlerSlot())); 2711 hm.add(new Pair<String, TestNode>(Pages.script.name(), new scriptSlot())); 2712 hm.add(new Pair<String, TestNode>(Pages.menuItem.name(), new menuitemSlot())); 2713 hm.add(new Pair<String, TestNode>(Pages.resources1.name(), new resource1Slot())); 2714 hm.add(new Pair<String, TestNode>(Pages.resources2.name(), new resource2Slot())); 2715 hm.add(new Pair<String, TestNode>(Pages.namespace.name(), new namespaceSlot())); 2716 hm.add(new Pair<String, TestNode>(Pages.splitpanebug.name(), new splitpanebugSlot())); 2717 hm.add(new Pair<String, TestNode>(Pages.charset.name(), new charsetSlot())); 2718 hm.add(new Pair<String, TestNode>(Pages.loadExceptions.name(), new loadExceptionsSlot())); 2719 hm.add(new Pair<String, TestNode>(Pages.slotDefaultLabeled.name(), new slotDefaultLabeled())); 2720 hm.add(new Pair<String, TestNode>(Pages.slotDefaultListview.name(), new slotDefaultListview())); 2721 hm.add(new Pair<String, TestNode>(Pages.slotDefaultMenu.name(), new slotDefaultMenu())); 2722 hm.add(new Pair<String, TestNode>(Pages.slotDefaultMenuBar.name(), new slotDefaultMenuBar())); 2723 hm.add(new Pair<String, TestNode>(Pages.slotDefaultScrollpane.name(), new slotDefaultScrollpane())); 2724 hm.add(new Pair<String, TestNode>(Pages.slotDefaultTabpane.name(), new slotDefaultTabpane())); 2725 hm.add(new Pair<String, TestNode>(Pages.slotDefaultTableView.name(), new slotDefaultTableview())); 2726 hm.add(new Pair<String, TestNode>(Pages.slotDefaultTextinput.name(), new slotDefaultTextinput())); 2727 hm.add(new Pair<String, TestNode>(Pages.slotDefaultTitledpane.name(), new slotDefaultTitledpane())); 2728 hm.add(new Pair<String, TestNode>(Pages.slotDefaultTreeview.name(), new slotDefaultTreeview())); 2729 hm.add(new Pair<String, TestNode>(Pages.slotDefaultImageview.name(), new slotDefaultImageview())); 2730 hm.add(new Pair<String, TestNode>(Pages.slotDefaultPane.name(), new slotDefaultPane())); 2731 hm.add(new Pair<String, TestNode>(Pages.slotControllerFactory.name(), new controllerFactoryPane())); 2732 hm.add(new Pair<String, TestNode>(Pages.specificSignatureMethod.name(), new specificSignatureMethodPane())); 2733 hm.add(new Pair<String, TestNode>(Pages.loadfontSlot.name(), new loadfontSlot())); 2734 hm.add(new Pair<String, TestNode>(Pages.scenebuilderSlot.name(), new scenebuilderSlot())); 2735 hm.add(new Pair<String, TestNode>(Pages.references2.name(), new references2Slot())); 2736 hm.add(new Pair<String, TestNode>(Pages.apConstraints.name(), new apConstraintsSlot())); 2737 hm.add(new Pair<String, TestNode>(Pages.coerce.name(), new coerceSlot())); 2738 hm.add(new Pair<String, TestNode>(Pages.listviewItems.name(), new listviewSlot())); 2739 hm.add(new Pair<String, TestNode>(Pages.listenerNullArg.name(), new listenerNullArgSlot())); 2740 hm.add(new Pair<String, TestNode>(Pages.gridapplet.name(), new gridappletSlot())); 2741 //hm.add(new Pair<String, TestNode>(Pages.csspath.name(), new csspathSlot())); 2742 hm.add(new Pair<String, TestNode>(Pages.scenebuilderNoRoot.name(), new scenebuilderNoRootSlot())); 2743 hm.add(new Pair<String, TestNode>(Pages.errorFXML.name(), new errorFXMLLoader())); 2744 hm.add(new Pair<String, TestNode>(Pages.colorValueOF.name(), new ColorValueOf())); 2745 hm.add(new Pair<String, TestNode>(Pages.escapeCharacter.name(), new EscapeCharacter())); 2746 hm.add(new Pair<String, TestNode>(Pages.collectionEventsHandlers.name(), new CollectionEventsHandlers())); 2747 hm.add(new Pair<String, TestNode>(Pages.noArgControllerMethod.name(), new NoArgsControllerMethod())); 2748 hm.add(new Pair<String, TestNode>(Pages.overloadedControllerMethod.name(), new OverloadedControllerMethod())); 2749 hm.add(new Pair<String, TestNode>(Pages.customIDProperty.name(), new CustomIDProperty())); 2750 hm.add(new Pair<String, TestNode>(Pages.unknownCustomType.name(), new UnknownCustomType())); 2751 hm.add(new Pair<String, TestNode>(Pages.baseControllerProperty.name(), new BaseColntrollerProperty())); 2752 hm.add(new Pair<String, TestNode>(Pages.relativeStylesheet.name(), new RelativeStylesheet())); 2753 hm.add(new Pair<String, TestNode>(Pages.FXMLLoaderAPI.name(), new FXMLLoaderAPI())); 2754 hm.add(new Pair<String, TestNode>(Pages.fullyQualifiedNames.name(), new FullyQualifiedNamesSlot())); 2755 hm.add(new Pair<String, TestNode>(Pages.importPI.name(), new ImportSlot())); 2756 hm.add(new Pair<String, TestNode>(Pages.beanInstantiation.name(), new BeanInstantiationSlot())); 2757 hm.add(new Pair<String, TestNode>(Pages.valueOf.name(), new ValueOfSlot())); 2758 hm.add(new Pair<String, TestNode>(Pages.root.name(), new RootSlot())); 2759 hm.add(new Pair<String, TestNode>(Pages.fxId.name(), new FxIdSlot())); 2760 hm.add(new Pair<String, TestNode>(Pages.fxController.name(), new controllerAttributeSlot())); 2761 hm.add(new Pair<String, TestNode>(Pages.noDefaultController.name(), new NoDefaultControllerSlot())); 2762 hm.add(new Pair<String, TestNode>(Pages.lateRoot.name(), new LateRootSlot())); 2763 hm.add(new Pair<String, TestNode>(Pages.lateController.name(), new LateControllerSlot())); 2764 hm.add(new Pair<String, TestNode>(Pages.variableResolution.name(), new VariableResolutionSlot())); 2765 hm.add(new Pair<String, TestNode>(Pages.externalScript.name(), new ExternalScriptCodeSlot())); 2766 2767 2768 for (Pair<String, TestNode> tn : hm) { 2769 final PageWithSlots xPage = new PageWithSlots(tn.getKey(), heightPageContentPane, widthPageContentPane); 2770 xPage.setSlotSize(240, 180); 2771 xPage.add(tn.getValue(), tn.getKey()); 2772 rootTestNode.add(xPage); 2773 2774 } 2775 return rootTestNode; 2776 2777 } 2778 2779 public static void main(String[] args) { 2780 Utils.launch(staticPropertyLoadApp.class, args); 2781 } 2782 2783 }