1/*
2 * Copyright (c) 2010, 2016, 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
26// Check for fx presence.
27if (typeof javafx.application.Application != "function") {
28    print("JavaFX is not available.");
29    exit(1);
30}
31
32// Extend the javafx.application.Application class overriding init, start and stop.
33javafx.application.Application.launch((Java.extend(javafx.application.Application, {
34    // Overridden javafx.application.Application.init();
35    init: function() {
36        // Java FX packages and classes must be defined here because
37        // they may not be viable until launch time due to clinit ordering.
38    },
39
40    // Overridden javafx.application.Application.start(Stage stage);
41    start: function(stage) {
42        // Set up stage global.
43        $STAGE = stage;
44
45        // Load user FX scripts.
46        for each (var script in $SCRIPTS) {
47            load(script);
48        }
49
50        // Call the global init function if present.
51        if ($GLOBAL.init) {
52            init();
53        }
54
55        // Call the global start function if present.  Otherwise show the stage.
56        if ($GLOBAL.start) {
57            start(stage);
58        } else {
59            stage.show();
60        }
61    },
62
63    // Overridden javafx.application.Application.stop();
64    stop: function() {
65        // Call the global stop function if present.
66        if ($GLOBAL.stop) {
67            stop();
68        }
69    }
70
71    // No arguments passed to application (handled thru $ARG.)
72})).class, new (Java.type("java.lang.String[]"))(0));
73