33import javafx .beans .value .ObservableValue ;
44import javafx .collections .FXCollections ;
55import javafx .collections .ObservableList ;
6+ import javafx .event .ActionEvent ;
67import javafx .fxml .FXML ;
7- import javafx .scene .control .CheckBox ;
8- import javafx .scene .control .ChoiceBox ;
9- import javafx .scene .control .Label ;
10- import javafx .scene .control .TextField ;
8+ import javafx .scene .control .*;
119
1210import java .io .*;
1311import java .net .URISyntaxException ;
@@ -27,7 +25,11 @@ public class Controller {
2725 @ FXML private CheckBox apnonceCheckBox ;
2826 @ FXML private CheckBox versionCheckBox ;
2927 @ FXML private Label versionLabel ;
28+ @ FXML private Button preset1Button ;
29+ @ FXML private Button preset2Button ;
30+ @ FXML private Button preset3Button ;
3031 private boolean boardConfig = false ;
32+ private boolean editingPresets = false ;
3133
3234 @ SuppressWarnings ("unchecked" )
3335 @ FXML
@@ -73,28 +75,6 @@ public void initialize() {
7375 boardConfigField .setDisable (true );
7476 }
7577 });
76- File file ;
77- try {
78- file = new File (getClass ().getResource ("options.properties" ).toURI ());
79- if (file .exists ()) {
80- Properties prop = new Properties ();
81- try (InputStream input = new FileInputStream (file )) {
82- prop .load (input );
83- ecidField .setText (prop .getProperty ("ecid" ));
84- deviceTypeChoiceBox .setValue (prop .getProperty ("deviceType" ));
85- deviceModelChoiceBox .setValue (prop .getProperty ("deviceModel" ));
86- if (!prop .getProperty ("boardConfig" ).equals ("none" )) {
87- boardConfigField .setText (prop .getProperty ("boardConfig" ));
88- }
89- } catch (IOException e ) {
90- e .printStackTrace ();
91- }
92- }
93- } catch (URISyntaxException e ) {
94- e .printStackTrace ();
95- } catch (NullPointerException e ) {
96- System .out .println ("No options file" );
97- }
9878 }
9979
10080 private void run (String device ) {
@@ -151,9 +131,46 @@ public void versionCheckBoxHandler() {
151131 }
152132 }
153133
154- public void saveOptions () {
134+ private void loadPreset (int preset ) {
135+ File file ;
136+ try {
137+ file = new File (getClass ().getResource ("preset" + Integer .toString (preset ) + ".properties" ).toURI ());
138+ if (file .exists ()) {
139+ Properties prop = new Properties ();
140+ try (InputStream input = new FileInputStream (file )) {
141+ prop .load (input );
142+ ecidField .setText (prop .getProperty ("ecid" ));
143+ deviceTypeChoiceBox .setValue (prop .getProperty ("deviceType" ));
144+ deviceModelChoiceBox .setValue (prop .getProperty ("deviceModel" ));
145+ if (!prop .getProperty ("boardConfig" ).equals ("none" )) {
146+ boardConfigField .setText (prop .getProperty ("boardConfig" ));
147+ }
148+ } catch (IOException e ) {
149+ e .printStackTrace ();
150+ }
151+ }
152+ } catch (URISyntaxException e ) {
153+ e .printStackTrace ();
154+ } catch (NullPointerException e ) {
155+ System .out .println ("No options file" );
156+ }
157+ }
158+
159+ public void presetButtonHandler (ActionEvent evt ) {
160+ Button btn = (Button ) evt .getTarget ();
161+ String text = btn .getText ();
162+ int preset = Integer .valueOf (text .substring (text .length () - 1 ));
163+ if (editingPresets ) {
164+ saveOptions (preset );
165+ saveOptionsHandler ();
166+ } else {
167+ loadPreset (preset );
168+ }
169+ }
170+
171+ private void saveOptions (int preset ) {
155172 Properties prop = new Properties ();
156- File file = new File (getClass ().getResource ("" ).toString ().substring (5 ), "options .properties" );
173+ File file = new File (getClass ().getResource ("" ).toString ().substring (5 ), "preset" + Integer . toString ( preset ) + " .properties" );
157174 try (OutputStream output = new FileOutputStream (file )) {
158175 prop .setProperty ("ecid" , ecidField .getText ());
159176 prop .setProperty ("deviceType" , (String ) deviceTypeChoiceBox .getValue ());
@@ -167,7 +184,20 @@ public void saveOptions() {
167184 } catch (IOException e ) {
168185 e .printStackTrace ();
169186 }
187+ }
170188
189+ public void saveOptionsHandler () {
190+ editingPresets = !editingPresets ;
191+ if (editingPresets ) {
192+ preset1Button .setText ("Save in Preset 1" );
193+ preset2Button .setText ("Save in Preset 2" );
194+ preset3Button .setText ("Save in Preset 3" );
195+ } else {
196+ preset1Button .setText ("Load Preset 1" );
197+ preset2Button .setText ("Load Preset 2" );
198+ preset3Button .setText ("Load Preset 3" );
199+ }
200+ System .out .println (editingPresets );
171201 }
172202
173203
0 commit comments