3030import java .util .logging .Logger ;
3131import javafx .application .Application ;
3232import javafx .application .Platform ;
33+ import javafx .application .Preloader ;
3334import javafx .fxml .FXMLLoader ;
3435import javafx .scene .Parent ;
3536import javafx .scene .Scene ;
@@ -58,14 +59,14 @@ public class Main extends Application {
5859 @ Inject private GripServer server ;
5960 @ Inject private HttpPipelineSwitcher pipelineSwitcher ;
6061 private Parent root ;
62+ private boolean headless ;
6163
6264 public static void main (String [] args ) {
6365 launch (args );
6466 }
6567
6668 @ Override
67- @ SuppressWarnings ("PMD.SignatureDeclareThrowsException" )
68- public void start (Stage stage ) throws Exception {
69+ public void init () throws IOException {
6970 List <String > parameters = new ArrayList <>(getParameters ().getRaw ());
7071
7172 if (parameters .contains ("--headless" )) {
@@ -76,35 +77,28 @@ public void start(Stage stage) throws Exception {
7677 injector .injectMembers (this );
7778
7879 parameters .remove ("--headless" );
80+ headless = true ;
7981 } else {
8082 // Otherwise, run with both the core and UI modules, and show the JavaFX stage
8183 injector = Guice .createInjector (Modules .override (new GripCoreModule (), new GripFileModule (),
8284 new GripSourcesHardwareModule ()).with (new GripNetworkModule (), new GripUiModule ()));
83-
8485 injector .injectMembers (this );
86+ notifyPreloader (new Preloader .ProgressNotification (0.15 ));
8587
8688 System .setProperty ("prism.lcdtext" , "false" );
8789 Font .loadFont (this .getClass ().getResource ("roboto/Roboto-Regular.ttf" ).openStream (), -1 );
8890 Font .loadFont (this .getClass ().getResource ("roboto/Roboto-Bold.ttf" ).openStream (), -1 );
8991 Font .loadFont (this .getClass ().getResource ("roboto/Roboto-Italic.ttf" ).openStream (), -1 );
9092 Font .loadFont (this .getClass ().getResource ("roboto/Roboto-BoldItalic.ttf" ).openStream (), -1 );
91-
92- root = FXMLLoader .load (Main .class .getResource ("MainWindow.fxml" ), null , null ,
93- injector ::getInstance );
94- root .setStyle ("-fx-font-size: " + DPIUtility .FONT_SIZE + "px" );
95-
96- // If this isn't here this can cause a deadlock on windows. See issue #297
97- stage .setOnCloseRequest (event -> SafeShutdown .exit (0 , Platform ::exit ));
98- stage .setTitle ("GRIP Computer Vision Engine" );
99- stage .getIcons ().add (new Image ("/edu/wpi/grip/ui/icons/grip.png" ));
100- stage .setScene (new Scene (root ));
101- stage .show ();
93+ notifyPreloader (new Preloader .ProgressNotification (0.3 ));
10294 }
10395
10496 operations .addOperations ();
10597 cvOperations .addOperations ();
98+ notifyPreloader (new Preloader .ProgressNotification (0.45 ));
10699 server .addHandler (pipelineSwitcher );
107100 server .start ();
101+ notifyPreloader (new Preloader .ProgressNotification (0.6 ));
108102
109103 // If there was a file specified on the command line, open it immediately
110104 if (!parameters .isEmpty ()) {
@@ -117,6 +111,27 @@ public void start(Stage stage) throws Exception {
117111 }
118112
119113 pipelineRunner .startAsync ();
114+ notifyPreloader (new Preloader .ProgressNotification (0.75 ));
115+ }
116+
117+ @ Override
118+ public void start (Stage stage ) throws IOException {
119+ if (!headless ) {
120+ root = FXMLLoader .load (Main .class .getResource ("MainWindow.fxml" ), null , null ,
121+ injector ::getInstance );
122+ root .setStyle ("-fx-font-size: " + DPIUtility .FONT_SIZE + "px" );
123+ notifyPreloader (new Preloader .ProgressNotification (0.9 ));
124+
125+ // If this isn't here this can cause a deadlock on windows. See issue #297
126+ stage .setOnCloseRequest (event -> SafeShutdown .exit (0 , Platform ::exit ));
127+ stage .setTitle ("GRIP Computer Vision Engine" );
128+ stage .getIcons ().add (new Image ("/edu/wpi/grip/ui/icons/grip.png" ));
129+ stage .setScene (new Scene (root ));
130+ notifyPreloader (new Preloader .ProgressNotification (1.0 ));
131+ notifyPreloader (new Preloader .StateChangeNotification (
132+ Preloader .StateChangeNotification .Type .BEFORE_START ));
133+ stage .show ();
134+ }
120135 }
121136
122137 public void stop () {
0 commit comments