base.js revision 953:221a84ef44c0
1/* 2 * Copyright (c) 2010, 2013, 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 26var JFX_BASE_CLASSES = []; 27var JFX_GRAPHICS_CLASSES = []; 28var JFX_CONTROLS_CLASSES = []; 29var JFX_FXML_CLASSES = []; 30var JFX_WEB_CLASSES = []; 31var JFX_MEDIA_CLASSES = []; 32var JFX_SWING_CLASSES = []; 33var JFX_SWT_CLASSES = []; 34 35function LOAD_FX_CLASSES(clsList) { 36 for each (var cls in clsList) { 37 // Ex. Stage = Java.type("javafx.stage.Stage"); 38 this[cls[cls.length - 1]] = Java.type(cls.join(".")); 39 } 40} 41 42(function() { 43 var System = Java.type("java.lang.System"); 44 var ZipFile = Java.type("java.util.zip.ZipFile"); 45 46 var SUFFIX_LENGTH = ".class".length; 47 48 try { 49 var jfxrtJar = new ZipFile(System.getProperty("java.home") + "/lib/ext/jfxrt.jar"); 50 } catch (ex) { 51 throw new Error("JavaFX runtime not found"); 52 } 53 54 var entries = jfxrtJar.entries(); 55 56 while (entries.hasMoreElements()) { 57 var entry = entries.nextElement(); 58 59 if (entry.isDirectory()) { 60 continue; 61 } 62 63 var name = entry.name; 64 65 if (!name.endsWith(".class")) { 66 continue; 67 } 68 69 name = name.substring(0, name.length - SUFFIX_LENGTH); 70 cls = name.split("/"); 71 72 if (cls[0] != "javafx") { 73 continue; 74 } 75 76 var last = cls[cls.length - 1]; 77 var nested = last.lastIndexOf("$"); 78 79 // If class name ends with $nnn 80 if (nested != -1 && !(last.substring(nested) - 0)) { 81 continue; 82 } 83 84 switch (cls[1]) { 85 case "stage": 86 if (cls[2] == "Stage") { 87 JFX_BASE_CLASSES.push(cls); 88 } else { 89 JFX_GRAPHICS_CLASSES.push(cls); 90 } 91 break; 92 93 case "scene": 94 switch (cls[2]) { 95 case "Scene": 96 case "Group": 97 JFX_BASE_CLASSES.push(cls); 98 break; 99 100 case "chart": 101 case "control": 102 JFX_CONTROLS_CLASSES.push(cls); 103 break; 104 105 case "web": 106 JFX_WEB_CLASSES.push(cls); 107 break; 108 109 case "media": 110 JFX_MEDIA_CLASSES.push(cls); 111 break; 112 113 default: 114 JFX_GRAPHICS_CLASSES.push(cls); 115 break; 116 } 117 break; 118 119 case "beans": 120 case "collections": 121 case "events": 122 case "util": 123 JFX_BASE_CLASSES.push(cls); 124 break; 125 126 case "animation": 127 case "application": 128 case "concurrent": 129 case "css": 130 case "geometry": 131 JFX_GRAPHICS_CLASSES.push(cls); 132 break; 133 134 case "fxml": 135 JFX_FXML_CLASSES.push(cls); 136 break; 137 138 case "embed": 139 if (cls[2] == "swing") { 140 JFX_SWING_CLASSES.push(cls); 141 } else { 142 JFX_SWT_CLASSES.push(cls); 143 } 144 break; 145 } 146 } 147})(); 148 149LOAD_FX_CLASSES(JFX_BASE_CLASSES); 150