1 /* 2 * Copyright (c) 2009, 2012, 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 */ 24 package test.fxapp; 25 26 import java.util.List; 27 import java.util.Map; 28 import javafx.application.Application; 29 import javafx.event.ActionEvent; 30 import javafx.event.EventHandler; 31 import javafx.scene.Group; 32 import javafx.scene.Scene; 33 import javafx.scene.control.Button; 34 import javafx.stage.Stage; 35 36 /** 37 * 38 * @author Sergey 39 */ 40 public class LifecycleApp extends Application { 41 42 static final String PARAM1 = "param1"; 43 static final String PARAM2 = " param2"; 44 static final String PARAM3 = " param3 "; 45 static final String PARAMZ = "param4 param5"; 46 static final String NAME1 = "named1"; 47 static final String VALUE1 = "value1"; 48 static final String NAME2 = "named2"; 49 static final String FAKENAMED = "fakenamed3=value3"; 50 51 static final String[] DEFAULT_PARAMS = new String[] {PARAM1, PARAM2, "--" + NAME1 + "=" + VALUE1, "--" + NAME2 + "=", FAKENAMED, PARAMZ, PARAM3}; 52 53 public static void main(String[] args) { 54 reset(); 55 launch(DEFAULT_PARAMS); 56 } 57 58 @Override 59 public void start(final Stage stage) throws Exception { 60 61 System.out.println("START"); 62 status.start = now(); 63 64 status.named = getParameters().getNamed(); 65 System.out.println("Named Parameters:"); 66 for (String pkey : status.named.keySet()) { 67 System.out.println(pkey + "=" + status.named.get(pkey)); 68 } 69 System.out.println("Unnamed Parameters:"); 70 for (String string : status.unnamed = getParameters().getUnnamed()) { 71 System.out.println(string); 72 } 73 System.out.println("Raw Parameters:"); 74 for (String string : status.raw = getParameters().getRaw()) { 75 System.out.println(string); 76 } 77 Button temp = new Button(); 78 temp.setText("close"); 79 temp.setOnAction(new EventHandler<ActionEvent>() { 80 public void handle(ActionEvent t) { 81 stage.close(); 82 } 83 }); 84 stage.setScene(new Scene(new Group(temp))); 85 stage.show(); 86 87 } 88 89 @Override 90 public void init() throws Exception { 91 super.init(); 92 System.out.println("INIT"); 93 status.init = now(); 94 } 95 96 @Override 97 public void stop() throws Exception { 98 super.stop(); 99 System.out.println("STOP"); 100 status.stop = now(); 101 } 102 103 104 // reporting utility, we use an interpid assume that there is one test in the VM at one time 105 static class Status { 106 long zero = System.nanoTime(); 107 108 long init = -1; 109 long start = -1; 110 long stop = -1; 111 112 Map<String, String> named = null; 113 List<String> unnamed = null; 114 List<String> raw = null; 115 } 116 117 private static long now() { 118 return System.nanoTime() - status.zero; 119 } 120 121 static Status status = null; 122 123 static void reset() { 124 status = new Status(); 125 } 126 }