6666import javafx .scene .layout .Priority ;
6767import javafx .scene .layout .RowConstraints ;
6868import javafx .scene .layout .VBox ;
69- import javafx .scene .text .Font ;
7069import javafx .scene .transform .Transform ;
7170import javafx .stage .DirectoryChooser ;
7271import javafx .stage .FileChooser ;
7574import map .*;
7675
7776public class MapTrackerUIFX extends Application {
77+ static final Properties markerNames = new Properties ();
78+
7879 private double scaleFactor = 1.0 ;
7980 private BufferedImage origBg = null , currentBg = null ;
8081 private Marker currentMarker = null ;
@@ -85,6 +86,14 @@ public class MapTrackerUIFX extends Application {
8586 private TextField tfCoordX = new TextField ();
8687 private TextField tfCoordY = new TextField ();
8788 private TextArea tfPreview = new TextArea ();
89+
90+ static {
91+ try {
92+ markerNames .load (MapTrackerUIFX .class .getResourceAsStream ("/names.properties" ));
93+ } catch (IOException e ) {
94+ e .printStackTrace ();
95+ }
96+ }
8897
8998 public static void show (String ...args ) {
9099 launch (args );
@@ -117,9 +126,10 @@ public void start(Stage stage) throws Exception {
117126 lblMarker .setStyle ("-fx-font-weight: bold;-fx-font-size: 14" );
118127
119128 ComboBox <Marker > cbMarkers = new ComboBox <>();
129+ loadInternalMarkers (cbMarkers );
120130 cbMarkers .setOnAction (e -> { currentMarker = cbMarkers .getValue (); });
121131
122- Button btnAddMarkers = new Button ("Lore more graphics..." );
132+ Button btnAddMarkers = new Button ("Load more graphics..." );
123133 btnAddMarkers .setOnAction (e -> updateMarkerList (stage , cbMarkers ));
124134
125135 FlowPane pnlMarkers = new FlowPane (cbMarkers , btnAddMarkers );
@@ -143,7 +153,10 @@ public void start(Stage stage) throws Exception {
143153 pnlForm .add (pnlCoords , 0 , 3 );
144154
145155 // Output Preview TextField (row 1 to 4, col 2)
146- tfPreview .setText ("A preview of the generated code will appear here once you start adding markers to the map..." );
156+ tfPreview .setText ("""
157+ To start, load a background map image via File > Open Background..., then select a Marker.
158+ A preview of the generated code will appear here once you start adding markers to the map.
159+ """ );
147160 tfPreview .setMaxSize (Double .MAX_VALUE , Double .MAX_VALUE );
148161 pnlForm .add (tfPreview , 1 , 0 , 4 , 4 );
149162
@@ -164,7 +177,7 @@ public void start(Stage stage) throws Exception {
164177 pnlForm .setStyle ("-fx-background-color: lightblue" );
165178
166179 // Menu
167- MenuItem jmiOpen = new MenuItem ("Open Background Map Image ..." );
180+ MenuItem jmiOpen = new MenuItem ("Open Background..." );
168181 MenuItem jmiSave = new MenuItem ("Save..." );
169182 MenuItem jmiExit = new MenuItem ("Exit" );
170183 MenuItem jmiZoomIn = new MenuItem ("Zoom In" );
@@ -222,7 +235,11 @@ private void updateMarkerList(Stage stage, ComboBox<Marker> cbMarkers) {
222235 System .out .println ("Selecting: " + f .getAbsolutePath ());
223236 for (File entry : f .listFiles ()) {
224237 if (!entry .isDirectory ()) {
225- markers .add (Marker .load (entry .getName (), entry .getAbsolutePath ()));
238+ markers .add (
239+ Marker .load (
240+ (String ) markerNames .getProperty (entry .getName ()),
241+ entry .getName (),
242+ entry ));
226243 cbMarkers .getItems ().add (markers .lastElement ());
227244 System .out .println ("Loaded: " + markers .lastElement ());
228245 }
@@ -270,15 +287,25 @@ private void save(Stage stage) {
270287 }
271288 }
272289
273- private void write (PrintWriter stream ) {
274- Properties markerNames = new Properties ();
275- try {
276- markerNames .load (getClass ().getResourceAsStream ("/names.properties" ));
277- for (Mark m : marks ) {
278- stream .format ("{%s %d %d}\n " , markerNames .get (m .marker ().name ()), (int ) m .x (), (int ) m .y ());
290+ private void loadInternalMarkers (ComboBox <Marker > cbMarkers ) {
291+ markerNames .forEach ((k , v ) -> {
292+ try {
293+ markers .add (Marker .loadInternal (
294+ (String ) v ,
295+ (String ) k ));
296+ } catch (IOException e ) {
297+ e .printStackTrace ();
279298 }
280- } catch (IOException e ) {
281- e .printStackTrace ();
299+ cbMarkers .getItems ().add (markers .lastElement ());
300+ System .out .println ("Loaded: " + markers .lastElement ());
301+ });
302+ cbMarkers .setValue (markers .firstElement ());
303+ currentMarker = markers .firstElement ();
304+ }
305+
306+ private void write (PrintWriter stream ) {
307+ for (Mark m : marks ) {
308+ stream .format ("{%s %d %d}\n " , m .marker ().name (), (int ) m .x (), (int ) m .y ());
282309 }
283310 }
284311
0 commit comments