Skip to content

Commit a4c5575

Browse files
committed
Added multiple presets to save options to
1 parent 1c6e847 commit a4c5575

File tree

3 files changed

+68
-31
lines changed

3 files changed

+68
-31
lines changed

src/blobsaver/Controller.java

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import javafx.beans.value.ObservableValue;
44
import javafx.collections.FXCollections;
55
import javafx.collections.ObservableList;
6+
import javafx.event.ActionEvent;
67
import 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

1210
import java.io.*;
1311
import 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

src/blobsaver/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static void main(String[] args) {
1616
public void start(Stage primaryStage) throws Exception {
1717
Parent root = FXMLLoader.load(getClass().getResource("blobsaver.fxml"));
1818
primaryStage.setTitle("SHSH Blob Saver");
19-
primaryStage.setScene(new Scene(root, 300, 275));
19+
primaryStage.setScene(new Scene(root, 500, 275));
2020
primaryStage.show();
2121
}
2222
}

src/blobsaver/blobsaver.fxml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<?import javafx.scene.layout.HBox?>
55
<?import javafx.scene.layout.VBox?>
66
<VBox xmlns:fx="http://javafx.com/fxml/1" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
7-
minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8"
7+
minWidth="-Infinity"
8+
prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8"
89
fx:controller="blobsaver.Controller">
910
<Label text="ECID:"/>
1011
<HBox prefHeight="100.0" prefWidth="200.0">
@@ -26,6 +27,12 @@
2627
<TextField fx:id="apnonceField" disable="true"/>
2728
<HBox prefHeight="100.0" prefWidth="200.0">
2829
<Button mnemonicParsing="false" onAction="#go" text="Go"/>
29-
<Button mnemonicParsing="false" text="Save options" onAction="#saveOptions"/>
30+
<Button mnemonicParsing="false" onAction="#saveOptionsHandler" text="Save as preset"/>
31+
<Button mnemonicParsing="false" text="Load Preset 1" onAction="#presetButtonHandler"
32+
fx:id="preset1Button"/>
33+
<Button mnemonicParsing="false" text="Load Preset 2" onAction="#presetButtonHandler"
34+
fx:id="preset2Button"/>
35+
<Button mnemonicParsing="false" text="Load Preset 3" onAction="#presetButtonHandler"
36+
fx:id="preset3Button"/>
3037
</HBox>
3138
</VBox>

0 commit comments

Comments
 (0)