Skip to content

Commit 90811fc

Browse files
committed
Rewrites the project to use the new Settings class over the old ConfigHandler class.
1 parent 11d25cb commit 90811fc

17 files changed

+175
-549
lines changed

Schillsaver.iml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
<output url="file://$MODULE_DIR$/target/classes" />
55
<output-test url="file://$MODULE_DIR$/target/test-classes" />
66
<content url="file://$MODULE_DIR$">
7-
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
87
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
9-
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
108
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
119
<excludeFolder url="file://$MODULE_DIR$/target" />
1210
</content>
@@ -21,5 +19,6 @@
2119
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
2220
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
2321
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
22+
<orderEntry type="library" name="Maven: eu.hansolo.enzo:Enzo:0.3.6" level="project" />
2423
</component>
2524
</module>

src/configuration/Settings.java

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,33 @@ public class Settings {
1616
private final HashMap<String, String> settings = new HashMap<>();
1717

1818
public Settings() {
19-
setSetting("FFMPEG Path", "");
20-
setSetting("Compression Program Path", "");
19+
settings.put("FFMPEG Path", "");
20+
settings.put("Compression Program Path", "");
2121

22-
setSetting("Enc Format", "mkv");
23-
setSetting("Dec Format", "7z");
22+
settings.put("Enc Format", "mkv");
23+
settings.put("Dec Format", "7z");
2424

25-
setSetting("Enc Vid Width", 1280);
26-
setSetting("Enc Vid Height", 720);
27-
setSetting("Enc Vid Framerate", 30);
28-
setSetting("Enc Vid Macro Block Dimensions", 8);
29-
setSetting("Enc Library", "libvpx");
25+
settings.put("Enc Vid Width", String.valueOf(1280));
26+
settings.put("Enc Vid Height", String.valueOf(720));
27+
settings.put("Enc Vid Framerate", String.valueOf(30));
28+
settings.put("Enc Vid Macro Block Dimensions", String.valueOf(8));
29+
settings.put("Enc Library", "libvpx");
3030

31-
setSetting("FFMPEG Log Level", "info");
31+
settings.put("FFMPEG Log Level", "info");
3232

33-
setSetting("Use Custom FFMPEG Options", false);
34-
setSetting("Custom FFMPEG Enc Options", "");
35-
setSetting("Custom FFMPEG Dec Options", "");
33+
settings.put("Use Custom FFMPEG Options", String.valueOf(false));
34+
settings.put("Custom FFMPEG Enc Options", "");
35+
settings.put("Custom FFMPEG Dec Options", "");
3636

37-
setSetting("Delete Source File When Enc", false);
38-
setSetting("Delete Source File When Dec", false);
37+
settings.put("Delete Source File When Enc", String.valueOf(false));
38+
settings.put("Delete Source File When Dec", String.valueOf(false));
3939

40-
setSetting("Compression Commands", "a -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on");
41-
setSetting("Compression Output Extension", "7z");
40+
settings.put("Compression Commands", "a -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on");
41+
settings.put("Compression Output Extension", "7z");
4242

43-
setSetting("Warn If Settings Possibly Incompatible With YouTube", true);
43+
settings.put("Warn If Settings Possibly Incompatible With YouTube", String.valueOf(true));
44+
45+
validateSettings();
4446
}
4547

4648
/**
@@ -88,16 +90,6 @@ public void validateSettings() throws IllegalStateException {
8890

8991

9092

91-
if (getStringSetting("Custom FFMPEG Enc Options").isEmpty()) {
92-
throw new IllegalStateException("'Custom FFMPEG Enc Options' cannot be empty/not set.");
93-
}
94-
95-
if (getStringSetting("Custom FFMPEG Dec Options").isEmpty()) {
96-
throw new IllegalStateException("'Custom FFMPEG Dec Options' cannot be empty/not set.");
97-
}
98-
99-
100-
10193
if (getStringSetting("Compression Output Extension").isEmpty()) {
10294
throw new IllegalStateException("'Compression Output Extension' cannot be empty/not set.");
10395
}
@@ -143,23 +135,24 @@ public void writeToFile() throws IOException {
143135
}
144136

145137
/**
146-
* Loads the settings from a JSON file.
138+
* Loads the settings from a the config file.
147139
*
148-
* @throws IOException
149-
* If the names file exists but is a directory rather than a
150-
* regular file, does not exist but cannot be created, or
151-
* cannot be opened for any other reason.
140+
* Creates the config file if it doesn't already exist.
152141
*
153142
* @throws ParseException
154143
* If an error occurs while parsing the JSON.
155144
*/
156145
public void loadFromFile() throws IOException, ParseException {
157-
final JSONParser jsonParser = new JSONParser();
158-
final JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader("config.json"));
159-
160-
jsonObject.forEach((key, value) -> {
161-
settings.put((String) key, (String) value);
162-
});
146+
try {
147+
final JSONParser jsonParser = new JSONParser();
148+
final JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader("config.json"));
149+
150+
jsonObject.forEach((key, value) -> {
151+
settings.put((String) key, (String) value);
152+
});
153+
} catch (final IOException e) {
154+
writeToFile();
155+
}
163156

164157
validateSettings();
165158
}
@@ -296,8 +289,7 @@ public String getStringSetting(final @NonNull String setting) {
296289
* @param value
297290
* The value.
298291
*/
299-
public void setSetting(final @NonNull String setting, final @NonNull java.io.Serializable value) {
292+
public void setSetting(final @NonNull String setting, final @NonNull Object value) {
300293
settings.put(setting, String.valueOf(value));
301-
validateSettings();
302294
}
303295
}

src/controller/JobSetupDialogController.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package controller;
22

3+
import configuration.Settings;
34
import eu.hansolo.enzo.notification.Notification;
4-
import handler.ConfigHandler;
55
import handler.StatisticsHandler;
66
import javafx.collections.FXCollections;
77
import javafx.collections.ObservableList;
@@ -22,8 +22,8 @@
2222
import org.apache.logging.log4j.Logger;
2323
import view.JobSetupDialogView;
2424

25-
import javax.swing.*;
26-
import java.awt.*;
25+
import javax.swing.JFileChooser;
26+
import java.awt.HeadlessException;
2727
import java.io.File;
2828
import java.nio.file.Files;
2929
import java.nio.file.Paths;
@@ -42,14 +42,14 @@ public class JobSetupDialogController extends Stage implements EventHandler {
4242
/**
4343
* Construct a new job setup dialog controller.
4444
* @param primaryStage todo JavaDoc
45-
* @param configHandler The object that handles settings for encoding, decoding, compression, and a number of other features.
45+
* @param settings The object that handles settings for encoding, decoding, compression, and a number of other features.
4646
* @param statisticsHandler todo JavaDoc
4747
* @param jobToEdit The job to load into the setup dialog. This is null if the user is creating a new job, not editing an existing one.
4848
*/
49-
public JobSetupDialogController(final Stage primaryStage, final ConfigHandler configHandler, final StatisticsHandler statisticsHandler, final Job jobToEdit) {
49+
public JobSetupDialogController(final Stage primaryStage, final Settings settings, final StatisticsHandler statisticsHandler, final Job jobToEdit) {
5050
this.statisticsHandler = statisticsHandler;
5151

52-
view = new JobSetupDialogView(primaryStage, this, configHandler, jobToEdit);
52+
view = new JobSetupDialogView(primaryStage, this, settings, jobToEdit);
5353
model = new JobSetupDialogModel();
5454

5555
// Setup Stage:

src/controller/MainScreenController.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package controller;
22

3-
import handler.ConfigHandler;
3+
import configuration.Settings;
44
import handler.FFMPEGHandler;
55
import handler.JobHandler;
66
import handler.StatisticsHandler;
@@ -31,20 +31,20 @@ public class MainScreenController implements EventHandler {
3131
@Getter private final MainScreenModel model;
3232

3333
/** The object that handles settings for encoding, decoding, compression, and a number of other features. */
34-
private final ConfigHandler configHandler;
34+
private final Settings settings;
3535

3636
// todo JavaDoc
3737
private final StatisticsHandler statisticsHandler;
3838

3939
/**
4040
* Construct a new main screen controller.
4141
* @param primaryStage todo JavaDoc
42-
* @param configHandler The object that handles settings for encoding, decoding, compression, and a number of other features.
42+
* @param settings The object that handles settings for encoding, decoding, compression, and a number of other features.
4343
* @param statisticsHandler todo JavaDoc
4444
*/
45-
public MainScreenController(final Stage primaryStage, final ConfigHandler configHandler, final StatisticsHandler statisticsHandler) {
45+
public MainScreenController(final Stage primaryStage, final Settings settings, final StatisticsHandler statisticsHandler) {
4646
this.primaryStage = primaryStage;
47-
this.configHandler = configHandler;
47+
this.settings = settings;
4848
this.statisticsHandler = statisticsHandler;
4949

5050
view = new MainScreenView(this);
@@ -57,7 +57,7 @@ public void handle(Event event) {
5757

5858
// The button to open the handler selection dialog.
5959
if(source.equals(view.getButton_createJob())) {
60-
final JobSetupDialogController jobSetupDialogController = new JobSetupDialogController(primaryStage, configHandler, statisticsHandler, null);
60+
final JobSetupDialogController jobSetupDialogController = new JobSetupDialogController(primaryStage, settings, statisticsHandler, null);
6161
jobSetupDialogController.show();
6262

6363

@@ -86,7 +86,7 @@ public void handle(Event event) {
8686
// update the Job List and model when the dialog is closed.
8787
final Job job = model.getList_jobs().get(firstSelectedIndex);
8888

89-
final JobSetupDialogController jobSetupDialogController = new JobSetupDialogController(primaryStage, configHandler, statisticsHandler, job);
89+
final JobSetupDialogController jobSetupDialogController = new JobSetupDialogController(primaryStage, settings, statisticsHandler, job);
9090
jobSetupDialogController.getModel().getList_files().addAll(job.getFiles());
9191
jobSetupDialogController.show();
9292

@@ -107,7 +107,7 @@ public void handle(Event event) {
107107

108108
// The button to encode the currently selected handler(s).
109109
if(source.equals(view.getButton_encode())) {
110-
if (!new File(configHandler.getFfmpegPath()).exists()) {
110+
if (!new File(settings.getStringSetting("FFMPEG Path")).exists()) {
111111
showFfmpegPathErrorAndWait();
112112
return;
113113
}
@@ -122,7 +122,7 @@ public void handle(Event event) {
122122
.parallelStream()
123123
.filter(Job::isEncodeJob)
124124
.forEach(job -> {
125-
final FFMPEGHandler ffmpegHandler = new FFMPEGHandler(job, this, configHandler, statisticsHandler);
125+
final FFMPEGHandler ffmpegHandler = new FFMPEGHandler(job, this, settings, statisticsHandler);
126126
ffmpegHandler.setOnSucceeded(ffmpegHandler);
127127
preparedJobs.add(ffmpegHandler);
128128
});
@@ -137,7 +137,7 @@ public void handle(Event event) {
137137

138138
// The button to decode the currently selected handler(s).
139139
if(source.equals(view.getButton_decode())) {
140-
if (!new File(configHandler.getFfmpegPath()).exists()) {
140+
if (!new File(settings.getStringSetting("FFMPEG Path")).exists()) {
141141
showFfmpegPathErrorAndWait();
142142
return;
143143
}
@@ -152,7 +152,7 @@ public void handle(Event event) {
152152
.parallelStream()
153153
.filter(job -> ! job.isEncodeJob())
154154
.forEach(job -> {
155-
final FFMPEGHandler ffmpegHandler = new FFMPEGHandler(job, this, configHandler, statisticsHandler);
155+
final FFMPEGHandler ffmpegHandler = new FFMPEGHandler(job, this, settings, statisticsHandler);
156156
ffmpegHandler.setOnSucceeded(ffmpegHandler);
157157
preparedJobs.add(ffmpegHandler);
158158
});
@@ -210,7 +210,7 @@ public void handle(Event event) {
210210

211211
// The button to open the settings dialog.
212212
if(source.equals(view.getButton_editSettings())) {
213-
new SettingsDialogController(primaryStage, configHandler).show();
213+
new SettingsDialogController(primaryStage, settings).show();
214214
}
215215
}
216216

src/controller/SettingsDialogController.java

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package controller;
22

3-
import handler.ConfigHandler;
3+
import configuration.Settings;
44
import javafx.event.Event;
55
import javafx.event.EventHandler;
66
import javafx.scene.Scene;
@@ -20,16 +20,16 @@ public class SettingsDialogController extends Stage implements EventHandler {
2020
/**
2121
* The object that handles settings for encoding, decoding, compression, and a number of other features.
2222
*/
23-
private final ConfigHandler configHandler;
23+
private final Settings settings;
2424

2525
/**
2626
* Construct a new settings dialog controller.
27-
* @param configHandler The object that handles settings for encoding, decoding, compression, and a number of other features.
27+
* @param settings The object that handles settings for encoding, decoding, compression, and a number of other features.
2828
*/
29-
public SettingsDialogController(final Stage settingsStage, final ConfigHandler configHandler) {
30-
this.configHandler = configHandler;
29+
public SettingsDialogController(final Stage settingsStage, final Settings settings) {
30+
this.settings = settings;
3131

32-
view = new SettingsDialogView(settingsStage, this, configHandler);
32+
view = new SettingsDialogView(settingsStage, this, this.settings);
3333

3434
// Setup Stage:
3535
final Scene scene = new Scene(view);
@@ -48,36 +48,44 @@ public void handle(Event event) {
4848
final Object source = event.getSource();
4949

5050
// The button to close the window and save settings.
51-
if(source.equals(view.getButton_accept())) {
51+
if (source.equals(view.getButton_accept())) {
5252
// Check to see if all data is correct.
5353
// If it is, then save the settings.
54-
if(! view.getController_ffmpegSettings().areSettingsCorrect()) {
54+
if (! view.getController_ffmpegSettings().areSettingsCorrect()) {
5555
// Show any warnings about YouTube compatability:
56-
if(configHandler.isWarnUserIfSettingsMayNotWorkForYouTube()) {
56+
if (settings.getBooleanSetting("Warn If Settings Possibly Incompatible With YouTube")) {
5757
view.getController_ffmpegSettings().displayWarningsAboutYouTubeCompatability();
5858
}
5959

6060
final ArchivalSettingsPane pane_archival = view.getController_archivalSettings().getPane();
6161
final FfmpegSettingsPane pane_ffmpeg = view.getController_ffmpegSettings().getPane();
6262
final MiscSettingsPane pane_misc = view.getPane_miscSettings();
6363

64-
configHandler.setFfmpegPath(pane_ffmpeg.getField_ffmpegPath().getText());
65-
configHandler.setCompressionProgramPath(pane_archival.getField_compressionProgramPath().getText());
66-
configHandler.setCompressionOutputExtension(pane_archival.getField_archiveOutputExtension().getText());
67-
configHandler.setEncodeFormat(pane_ffmpeg.getField_encodeFormat().getText());
68-
configHandler.setDecodeFormat(pane_ffmpeg.getField_decodeFormat().getText());
69-
configHandler.setEncodedVideoWidth(Integer.valueOf(pane_ffmpeg.getField_encodedVideoWidth().getText()));
70-
configHandler.setEncodedVideoHeight(Integer.valueOf(pane_ffmpeg.getField_encodedVideoHeight().getText()));
71-
configHandler.setEncodedFramerate(Integer.valueOf(pane_ffmpeg.getField_encodedFramerate().getText()));
72-
configHandler.setMacroBlockDimensions(Integer.valueOf(pane_ffmpeg.getField_macroBlockDimensions().getText()));
73-
configHandler.setUseFullyCustomFfmpegOptions(pane_ffmpeg.getRadioButton_useFullyCustomEncodingOptions_yes().isSelected());
74-
configHandler.setFullyCustomFfmpegEncodingOptions(pane_ffmpeg.getField_fullyCustomFfmpegEncodingOptions().getText());
75-
configHandler.setFullyCustomFfmpegDecodingOptions(pane_ffmpeg.getField_fullyCustomFfmpegDecodingptions().getText());
76-
configHandler.setEncodingLibrary(pane_ffmpeg.getField_encodingLibrary().getText());
77-
configHandler.setFfmpegLogLevel(pane_ffmpeg.getComboBox_ffmpegLogLevel().getSelectionModel().getSelectedItem());
78-
configHandler.setCompressionCommands(pane_archival.getField_compressionCommands().getText());
79-
configHandler.setWarnUserIfSettingsMayNotWorkForYouTube(pane_misc.getWarnUserIfSettingsMayNotWorkForYouTube());
80-
configHandler.createConfigFile();
64+
settings.setSetting("FFMPEG Path", pane_ffmpeg.getField_ffmpegPath().getText());
65+
settings.setSetting("Compression Program Path", pane_archival.getField_compressionProgramPath().getText());
66+
67+
settings.setSetting("Enc Format", pane_ffmpeg.getField_encodeFormat().getText());
68+
settings.setSetting("Dec Format", pane_ffmpeg.getField_decodeFormat().getText());
69+
70+
settings.setSetting("Enc Vid Width", pane_ffmpeg.getField_encodedVideoWidth().getText());
71+
settings.setSetting("Enc Vid Height", pane_ffmpeg.getField_encodedVideoHeight().getText());
72+
settings.setSetting("Enc Vid Framerate", pane_ffmpeg.getField_encodedFramerate().getText());
73+
settings.setSetting("Enc Vid Macro Block Dimensions", pane_ffmpeg.getField_macroBlockDimensions().getText());
74+
settings.setSetting("Enc Library", pane_ffmpeg.getField_encodingLibrary().getText());
75+
76+
settings.setSetting("FFMPEG Log Level", pane_ffmpeg.getComboBox_ffmpegLogLevel().getSelectionModel().getSelectedItem());
77+
78+
settings.setSetting("Use Custom FFMPEG Options", pane_ffmpeg.getRadioButton_useFullyCustomEncodingOptions_yes().isSelected());
79+
settings.setSetting("Custom FFMPEG Enc Options", pane_ffmpeg.getField_fullyCustomFfmpegEncodingOptions().getText());
80+
settings.setSetting("Custom FFMPEG Dec Options", pane_ffmpeg.getField_fullyCustomFfmpegDecodingptions().getText());
81+
82+
settings.setSetting("Delete Source File When Enc", false);
83+
settings.setSetting("Delete Source File When Dec", false);
84+
85+
settings.setSetting("Compression Commands", pane_archival.getField_compressionCommands().getText());
86+
settings.setSetting("Compression Output Extension", pane_archival.getField_archiveOutputExtension().getText());
87+
88+
settings.setSetting("Warn If Settings Possibly Incompatible With YouTube", pane_misc.getWarnUserIfSettingsMayNotWorkForYouTube());
8189

8290
this.close();
8391
}

src/controller/settings/ArchivalSettingsController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package controller.settings;
22

3-
import handler.ConfigHandler;
3+
import configuration.Settings;
44
import javafx.event.Event;
55
import javafx.event.EventHandler;
66
import javafx.stage.FileChooser;
@@ -17,9 +17,9 @@ public class ArchivalSettingsController implements EventHandler {
1717
// todo JavaDoc
1818
private final Stage settingsStage;
1919

20-
public ArchivalSettingsController(final Stage settingsStage, final ConfigHandler configHandler) {
20+
public ArchivalSettingsController(final Stage settingsStage, final Settings settings) {
2121
this.settingsStage = settingsStage;
22-
pane = new ArchivalSettingsPane(settingsStage, this, configHandler);
22+
pane = new ArchivalSettingsPane(settingsStage, this, settings);
2323
}
2424

2525
@Override

0 commit comments

Comments
 (0)