@@ -25,16 +25,19 @@ This file is part of Universal Gcode Sender (UGS).
2525import com .willwinder .universalgcodesender .fx .component .dro .MachineStatusPane ;
2626import com .willwinder .universalgcodesender .fx .component .jog .JogPane ;
2727import com .willwinder .universalgcodesender .fx .component .visualizer .Visualizer ;
28+ import com .willwinder .universalgcodesender .fx .component .visualizer .designer .InspectorPane ;
29+ import com .willwinder .universalgcodesender .fx .model .UgsdWorkspaceContext ;
2830import com .willwinder .universalgcodesender .services .LookupService ;
2931import com .willwinder .universalgcodesender .fx .helper .FontRegistry ;
32+ import com .willwinder .universalgcodesender .fx .helper .SplitPaneDividerPersistence ;
3033import com .willwinder .universalgcodesender .fx .helper .SvgLoader ;
3134import com .willwinder .universalgcodesender .fx .service .ActionRegistry ;
3235import com .willwinder .universalgcodesender .fx .service .JogActionRegistry ;
3336import com .willwinder .universalgcodesender .fx .service .MacroActionService ;
3437import com .willwinder .universalgcodesender .fx .service .ShortcutService ;
38+ import com .willwinder .universalgcodesender .fx .service .WorkspaceManager ;
3539import com .willwinder .universalgcodesender .fx .settings .Settings ;
3640import com .willwinder .universalgcodesender .i18n .Localization ;
37- import com .willwinder .universalgcodesender .model .BackendAPI ;
3841import com .willwinder .universalgcodesender .model .GUIBackend ;
3942import com .willwinder .universalgcodesender .pendantui .PendantUI ;
4043import com .willwinder .universalgcodesender .utils .SettingsFactory ;
@@ -56,16 +59,15 @@ This file is part of Universal Gcode Sender (UGS).
5659
5760import javax .swing .UIManager ;
5861import java .io .File ;
62+ import java .util .Objects ;
5963import java .util .logging .Level ;
6064import java .util .logging .Logger ;
6165
6266public class Main extends Application {
6367 private static final Logger LOGGER = Logger .getLogger (Main .class .getName ());
64- private SplitPane leftSplitPane ;
68+ private SplitPane motionSplitPane ;
6569 private SplitPane contentSplitPane ;
6670 private StackPane contentPanel ;
67- private SplitPane .Divider contentPaneDivider ;
68- private SplitPane .Divider leftPaneDivider ;
6971
7072 @ Override
7173 public void init () throws Exception {
@@ -109,7 +111,7 @@ public void start(Stage primaryStage) {
109111 ShortcutService .registerListener (scene );
110112 FontRegistry .registerFonts ();
111113
112- scene .getStylesheets ().add (Main .class .getResource ("/styles/root.css" ).toExternalForm ());
114+ scene .getStylesheets ().add (Objects . requireNonNull ( Main .class .getResource ("/styles/root.css" ) ).toExternalForm ());
113115 root .getChildren ().addAll (toolBarMenu , contentSplitPane );
114116
115117 primaryStage .setTitle ("Universal G-code Sender - " + Version .getVersion ());
@@ -120,24 +122,35 @@ public void start(Stage primaryStage) {
120122
121123 Parameters params = getParameters ();
122124 if (!params .getUnnamed ().isEmpty ()) {
123- BackendAPI backendAPI = LookupService .lookup (BackendAPI .class );
124125 try {
125126 File file = new File (params .getUnnamed ().get (0 ));
126- backendAPI .setGcodeFile (file );
127- backendAPI .getSettings ().setLastWorkingDirectory (file .getParent ());
127+ WorkspaceManager .getInstance ().openWorkspace (file );
128128 } catch (Exception e ) {
129129 throw new RuntimeException (e );
130130 }
131+ } else {
132+ openDefaultWorkspace ();
131133 }
132134 }
133135
134- private void registerLayoutListeners (Stage primaryStage ) {
136+ /**
137+ * Opens an empty UGSD design workspace when the application is started without a file argument,
138+ * so the designer is ready to use straight away.
139+ */
140+ private void openDefaultWorkspace () {
141+ try {
142+ UgsdWorkspaceContext workspace = new UgsdWorkspaceContext (null );
143+ WorkspaceManager .getInstance ().setWorkspace (workspace );
144+ } catch (Exception e ) {
145+ LOGGER .log (Level .SEVERE , "Could not open the default design workspace" , e );
146+ }
147+ }
148+
149+ private void registerWindowBoundsListeners (Stage primaryStage ) {
135150 primaryStage .widthProperty ().addListener ((observable , oldValue , newValue ) -> Settings .getInstance ().windowWidthProperty ().set (newValue .doubleValue ()));
136151 primaryStage .heightProperty ().addListener ((observable , oldValue , newValue ) -> Settings .getInstance ().windowHeightProperty ().set (newValue .doubleValue ()));
137152 primaryStage .xProperty ().addListener ((observable , oldValue , newValue ) -> Settings .getInstance ().windowPositionXProperty ().set (newValue .doubleValue ()));
138153 primaryStage .yProperty ().addListener ((observable , oldValue , newValue ) -> Settings .getInstance ().windowPositionYProperty ().set (newValue .doubleValue ()));
139- leftPaneDivider .positionProperty ().addListener ((obs , oldVal , newVal ) -> Settings .getInstance ().windowDividerLeftProperty ().set (newVal .doubleValue ()));
140- contentPaneDivider .positionProperty ().addListener ((obs , oldVal , newVal ) -> Settings .getInstance ().windowDividerContentProperty ().set (newVal .doubleValue ()));
141154 }
142155
143156 private void registerListeners (Stage primaryStage ) {
@@ -146,16 +159,13 @@ private void registerListeners(Stage primaryStage) {
146159 primaryStage .setY (Settings .getInstance ().windowPositionYProperty ().get ());
147160 primaryStage .setWidth (Settings .getInstance ().windowWidthProperty ().get ());
148161 primaryStage .setHeight (Settings .getInstance ().windowHeightProperty ().get ());
149- leftPaneDivider .setPosition (Settings .getInstance ().windowDividerLeftProperty ().get ());
150- contentPaneDivider .setPosition (Settings .getInstance ().windowDividerContentProperty ().get ());
162+ registerWindowBoundsListeners (primaryStage );
151163
152-
153- // Hack to make sure that the window is shown with correct size before setting the dividers
154- ThreadHelper .invokeLater (() -> {
155- leftPaneDivider .setPosition (Settings .getInstance ().windowDividerLeftProperty ().get ());
156- contentPaneDivider .setPosition (Settings .getInstance ().windowDividerContentProperty ().get ());
157- registerLayoutListeners (primaryStage );
158- }, 200 );
164+ Platform .runLater (() -> {
165+ SplitPaneDividerPersistence .install (motionSplitPane , 0 , Settings .getInstance ().windowDividerLeftProperty ());
166+ SplitPaneDividerPersistence .install (contentSplitPane , 0 , Settings .getInstance ().windowDividerContentProperty ());
167+ SplitPaneDividerPersistence .install (contentSplitPane , 1 , Settings .getInstance ().windowDividerInspectorProperty ());
168+ });
159169 });
160170
161171 primaryStage .setOnCloseRequest (event -> {
@@ -179,24 +189,18 @@ private void createContentPane() {
179189 contentSplitPane = new SplitPane ();
180190 contentSplitPane .setMinWidth (200 );
181191 contentSplitPane .setOrientation (Orientation .HORIZONTAL );
182- contentSplitPane .getItems ().addAll (leftSplitPane , contentPanel );
192+ contentSplitPane .getItems ().addAll (motionSplitPane , contentPanel );
183193 SplitPane .setResizableWithParent (contentSplitPane , false );
184-
185- contentPaneDivider = contentSplitPane .getDividers ().get (0 );
186- contentPaneDivider .setPosition (Settings .getInstance ().windowDividerContentProperty ().get ());
194+ new InspectorPane (contentSplitPane );
187195 }
188196
189197 private void createLeftPane () {
190- leftSplitPane = new SplitPane ();
191- leftSplitPane .setStyle ("-fx-border-color: transparent;" );
192-
193- leftSplitPane .setMinWidth (200 );
194- leftSplitPane .setOrientation (Orientation .VERTICAL );
195- leftSplitPane .getItems ().addAll (new MachineStatusPane (), new JogPane ());
196- SplitPane .setResizableWithParent (leftSplitPane , false );
198+ motionSplitPane = new SplitPane ();
197199
198- leftPaneDivider = leftSplitPane .getDividers ().get (0 );
199- leftPaneDivider .setPosition (Settings .getInstance ().windowDividerLeftProperty ().get ());
200+ motionSplitPane .setOrientation (Orientation .VERTICAL );
201+ motionSplitPane .getItems ().addAll (new MachineStatusPane (), new JogPane ());
202+ motionSplitPane .setMinWidth (200 );
203+ SplitPane .setResizableWithParent (motionSplitPane , false );
200204 }
201205
202206 private void registerShortCuts (Scene scene ) {
0 commit comments