7
7
import com .google .inject .Injector ;
8
8
import com .sun .javafx .application .PlatformImpl ;
9
9
import edu .wpi .grip .core .GRIPCoreModule ;
10
- import edu .wpi .grip .core .Palette ;
11
10
import edu .wpi .grip .core .PipelineRunner ;
12
11
import edu .wpi .grip .core .events .UnexpectedThrowableEvent ;
13
12
import edu .wpi .grip .core .operations .Operations ;
13
+ import edu .wpi .grip .core .serialization .Project ;
14
14
import edu .wpi .grip .core .util .SafeShutdown ;
15
15
import edu .wpi .grip .generated .CVOperations ;
16
16
import edu .wpi .grip .ui .util .DPIUtility ;
23
23
import javafx .stage .Stage ;
24
24
25
25
import javax .inject .Inject ;
26
+ import java .io .File ;
27
+ import java .io .IOException ;
28
+ import java .util .ArrayList ;
29
+ import java .util .List ;
26
30
import java .util .logging .Level ;
27
31
import java .util .logging .Logger ;
28
32
29
33
public class Main extends Application {
30
34
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 ;
39
39
40
40
@ VisibleForTesting
41
41
protected final Injector injector = Guice .createInjector (new GRIPCoreModule (), new GRIPUIModule ());
@@ -58,25 +58,37 @@ public Main() {
58
58
@ Override
59
59
@ SuppressWarnings ("PMD.SignatureDeclareThrowsException" )
60
60
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
+ }
63
77
64
78
Operations .addOperations (eventBus );
65
79
CVOperations .addOperations (eventBus );
66
80
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
+ }
72
90
73
91
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
-
80
92
}
81
93
82
94
public void stop () {
0 commit comments