77import com .google .inject .Injector ;
88import com .sun .javafx .application .PlatformImpl ;
99import edu .wpi .grip .core .GRIPCoreModule ;
10- import edu .wpi .grip .core .Palette ;
1110import edu .wpi .grip .core .PipelineRunner ;
1211import edu .wpi .grip .core .events .UnexpectedThrowableEvent ;
1312import edu .wpi .grip .core .operations .Operations ;
13+ import edu .wpi .grip .core .serialization .Project ;
1414import edu .wpi .grip .core .util .SafeShutdown ;
1515import edu .wpi .grip .generated .CVOperations ;
1616import edu .wpi .grip .ui .util .DPIUtility ;
2323import javafx .stage .Stage ;
2424
2525import javax .inject .Inject ;
26+ import java .io .File ;
27+ import java .io .IOException ;
28+ import java .util .ArrayList ;
29+ import java .util .List ;
2630import java .util .logging .Level ;
2731import java .util .logging .Logger ;
2832
2933public class Main extends Application {
3034
31- @ Inject
32- private EventBus eventBus ;
33- @ Inject
34- private Palette palette ;
35- @ Inject
36- private PipelineRunner pipelineRunner ;
37- @ Inject
38- private Logger logger ;
35+ @ Inject private EventBus eventBus ;
36+ @ Inject private PipelineRunner pipelineRunner ;
37+ @ Inject private Project project ;
38+ @ Inject private Logger logger ;
3939
4040 @ VisibleForTesting
4141 protected final Injector injector = Guice .createInjector (new GRIPCoreModule (), new GRIPUIModule ());
@@ -58,25 +58,37 @@ public Main() {
5858 @ Override
5959 @ SuppressWarnings ("PMD.SignatureDeclareThrowsException" )
6060 public void start (Stage stage ) throws Exception {
61- root = FXMLLoader .load (Main .class .getResource ("MainWindow.fxml" ), null , null , injector ::getInstance );
62- root .setStyle ("-fx-font-size: " + DPIUtility .FONT_SIZE + "px" );
61+ // If --headless was specified on the command line, run in headless mode
62+ List <String > parameters = new ArrayList <>(getParameters ().getRaw ());
63+
64+ if (parameters .contains ("--headless" )) {
65+ parameters .remove ("--headless" );
66+ } else {
67+ root = FXMLLoader .load (Main .class .getResource ("MainWindow.fxml" ), null , null , injector ::getInstance );
68+ root .setStyle ("-fx-font-size: " + DPIUtility .FONT_SIZE + "px" );
69+
70+ // If this isn't here this can cause a deadlock on windows. See issue #297
71+ stage .setOnCloseRequest (event -> SafeShutdown .exit (0 , Platform ::exit ));
72+ stage .setTitle ("GRIP Computer Vision Engine" );
73+ stage .getIcons ().add (new Image ("/edu/wpi/grip/ui/icons/grip.png" ));
74+ stage .setScene (new Scene (root ));
75+ stage .show ();
76+ }
6377
6478 Operations .addOperations (eventBus );
6579 CVOperations .addOperations (eventBus );
6680
67- stage .setOnCloseRequest ((event ) -> {
68- // If this isn't here this can cause a deadlock on windows
69- // See issue #297
70- SafeShutdown .exit (0 , Platform ::exit );
71- });
81+ // If there was a file specified on the command line, open it immediately
82+ if (!parameters .isEmpty ()) {
83+ try {
84+ project .open (new File (parameters .get (0 )));
85+ } catch (IOException e ) {
86+ logger .log (Level .SEVERE , "Error loading file: " + parameters .get (0 ));
87+ throw e ;
88+ }
89+ }
7290
7391 pipelineRunner .startAsync ();
74-
75- stage .setTitle ("GRIP Computer Vision Engine" );
76- stage .getIcons ().add (new Image ("/edu/wpi/grip/ui/icons/grip.png" ));
77- stage .setScene (new Scene (root ));
78- stage .show ();
79-
8092 }
8193
8294 public void stop () {
0 commit comments