nashorn/samples/fxmlrunner.js
author xuelei
Tue, 14 Jul 2015 00:53:09 +0000
changeset 31646 6abb6f423de4
parent 29995 ead3020640fc
permissions -rw-r--r--
8130461: HandshakeStatus.NEED_UNWRAP_AGAIN applies only to DTLS Reviewed-by: wetmore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29995
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     1
#Usage: jjs -fx fxmlrunner.js -- <.fxml file>
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     2
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     3
/*
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     4
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     5
 *
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     6
 * Redistribution and use in source and binary forms, with or without
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     7
 * modification, are permitted provided that the following conditions
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     8
 * are met:
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     9
 *
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    10
 *   - Redistributions of source code must retain the above copyright
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    11
 *     notice, this list of conditions and the following disclaimer.
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    12
 *
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    13
 *   - Redistributions in binary form must reproduce the above copyright
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    14
 *     notice, this list of conditions and the following disclaimer in the
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    15
 *     documentation and/or other materials provided with the distribution.
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    16
 *
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    17
 *   - Neither the name of Oracle nor the names of its
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    18
 *     contributors may be used to endorse or promote products derived
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    19
 *     from this software without specific prior written permission.
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    20
 *
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    21
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    22
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    23
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    24
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    25
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    26
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    28
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    29
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    30
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    31
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    32
 */
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    33
 
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    34
// See also https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/doc-files/introduction_to_fxml.html
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    35
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    36
// Simple script to "run" a .FXML file specified in
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    37
// command line. FXML file is expected to have inline
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    38
// fx:script to handle GUI events. i.e., self-contained
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    39
// FXML file is assumed.
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    40
 
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    41
var file = arguments[0];
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    42
var File = Java.type("java.io.File"); 
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    43
if (!$OPTIONS._fx || !file || !new File(file).isFile()) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    44
    print("Usage: jjs -fx fxmlrunner.js -- <.fxml file> [width] [height]");
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    45
    exit(1);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    46
}
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    47
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    48
// optional stage width and height from command line
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    49
var width = arguments[1]? parseInt(arguments[1]) : 400;
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    50
var height = arguments[2]? parseInt(arguments[2]) : 300;
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    51
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    52
// JavaFX classes used
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    53
var FXMLLoader = Java.type("javafx.fxml.FXMLLoader");
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    54
var Scene = Java.type("javafx.scene.Scene");
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    55
 
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    56
function start(stage) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    57
    // load FXML
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    58
    var root = FXMLLoader.load(new File(file).toURL());
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    59
    // show it in a scene
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    60
    var scene = new Scene(root, width, height);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    61
    stage.title = file;
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    62
    stage.scene = scene;
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    63
    stage.show();
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    64
}