Skip to content

Commit

Permalink
Rewrites the project to use the new Settings class over the old Confi…
Browse files Browse the repository at this point in the history
…gHandler class.
  • Loading branch information
Valkryst committed Sep 4, 2017
1 parent 11d25cb commit 90811fc
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 549 deletions.
3 changes: 1 addition & 2 deletions Schillsaver.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
Expand All @@ -21,5 +19,6 @@
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" name="Maven: eu.hansolo.enzo:Enzo:0.3.6" level="project" />
</component>
</module>
74 changes: 33 additions & 41 deletions src/configuration/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,33 @@ public class Settings {
private final HashMap<String, String> settings = new HashMap<>();

public Settings() {
setSetting("FFMPEG Path", "");
setSetting("Compression Program Path", "");
settings.put("FFMPEG Path", "");
settings.put("Compression Program Path", "");

setSetting("Enc Format", "mkv");
setSetting("Dec Format", "7z");
settings.put("Enc Format", "mkv");
settings.put("Dec Format", "7z");

setSetting("Enc Vid Width", 1280);
setSetting("Enc Vid Height", 720);
setSetting("Enc Vid Framerate", 30);
setSetting("Enc Vid Macro Block Dimensions", 8);
setSetting("Enc Library", "libvpx");
settings.put("Enc Vid Width", String.valueOf(1280));
settings.put("Enc Vid Height", String.valueOf(720));
settings.put("Enc Vid Framerate", String.valueOf(30));
settings.put("Enc Vid Macro Block Dimensions", String.valueOf(8));
settings.put("Enc Library", "libvpx");

setSetting("FFMPEG Log Level", "info");
settings.put("FFMPEG Log Level", "info");

setSetting("Use Custom FFMPEG Options", false);
setSetting("Custom FFMPEG Enc Options", "");
setSetting("Custom FFMPEG Dec Options", "");
settings.put("Use Custom FFMPEG Options", String.valueOf(false));
settings.put("Custom FFMPEG Enc Options", "");
settings.put("Custom FFMPEG Dec Options", "");

setSetting("Delete Source File When Enc", false);
setSetting("Delete Source File When Dec", false);
settings.put("Delete Source File When Enc", String.valueOf(false));
settings.put("Delete Source File When Dec", String.valueOf(false));

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

setSetting("Warn If Settings Possibly Incompatible With YouTube", true);
settings.put("Warn If Settings Possibly Incompatible With YouTube", String.valueOf(true));

validateSettings();
}

/**
Expand Down Expand Up @@ -88,16 +90,6 @@ public void validateSettings() throws IllegalStateException {



if (getStringSetting("Custom FFMPEG Enc Options").isEmpty()) {
throw new IllegalStateException("'Custom FFMPEG Enc Options' cannot be empty/not set.");
}

if (getStringSetting("Custom FFMPEG Dec Options").isEmpty()) {
throw new IllegalStateException("'Custom FFMPEG Dec Options' cannot be empty/not set.");
}



if (getStringSetting("Compression Output Extension").isEmpty()) {
throw new IllegalStateException("'Compression Output Extension' cannot be empty/not set.");
}
Expand Down Expand Up @@ -143,23 +135,24 @@ public void writeToFile() throws IOException {
}

/**
* Loads the settings from a JSON file.
* Loads the settings from a the config file.
*
* @throws IOException
* If the names file exists but is a directory rather than a
* regular file, does not exist but cannot be created, or
* cannot be opened for any other reason.
* Creates the config file if it doesn't already exist.
*
* @throws ParseException
* If an error occurs while parsing the JSON.
*/
public void loadFromFile() throws IOException, ParseException {
final JSONParser jsonParser = new JSONParser();
final JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader("config.json"));

jsonObject.forEach((key, value) -> {
settings.put((String) key, (String) value);
});
try {
final JSONParser jsonParser = new JSONParser();
final JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader("config.json"));

jsonObject.forEach((key, value) -> {
settings.put((String) key, (String) value);
});
} catch (final IOException e) {
writeToFile();
}

validateSettings();
}
Expand Down Expand Up @@ -296,8 +289,7 @@ public String getStringSetting(final @NonNull String setting) {
* @param value
* The value.
*/
public void setSetting(final @NonNull String setting, final @NonNull java.io.Serializable value) {
public void setSetting(final @NonNull String setting, final @NonNull Object value) {
settings.put(setting, String.valueOf(value));
validateSettings();
}
}
12 changes: 6 additions & 6 deletions src/controller/JobSetupDialogController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package controller;

import configuration.Settings;
import eu.hansolo.enzo.notification.Notification;
import handler.ConfigHandler;
import handler.StatisticsHandler;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
Expand All @@ -22,8 +22,8 @@
import org.apache.logging.log4j.Logger;
import view.JobSetupDialogView;

import javax.swing.*;
import java.awt.*;
import javax.swing.JFileChooser;
import java.awt.HeadlessException;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand All @@ -42,14 +42,14 @@ public class JobSetupDialogController extends Stage implements EventHandler {
/**
* Construct a new job setup dialog controller.
* @param primaryStage todo JavaDoc
* @param configHandler The object that handles settings for encoding, decoding, compression, and a number of other features.
* @param settings The object that handles settings for encoding, decoding, compression, and a number of other features.
* @param statisticsHandler todo JavaDoc
* @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.
*/
public JobSetupDialogController(final Stage primaryStage, final ConfigHandler configHandler, final StatisticsHandler statisticsHandler, final Job jobToEdit) {
public JobSetupDialogController(final Stage primaryStage, final Settings settings, final StatisticsHandler statisticsHandler, final Job jobToEdit) {
this.statisticsHandler = statisticsHandler;

view = new JobSetupDialogView(primaryStage, this, configHandler, jobToEdit);
view = new JobSetupDialogView(primaryStage, this, settings, jobToEdit);
model = new JobSetupDialogModel();

// Setup Stage:
Expand Down
24 changes: 12 additions & 12 deletions src/controller/MainScreenController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package controller;

import handler.ConfigHandler;
import configuration.Settings;
import handler.FFMPEGHandler;
import handler.JobHandler;
import handler.StatisticsHandler;
Expand Down Expand Up @@ -31,20 +31,20 @@ public class MainScreenController implements EventHandler {
@Getter private final MainScreenModel model;

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

// todo JavaDoc
private final StatisticsHandler statisticsHandler;

/**
* Construct a new main screen controller.
* @param primaryStage todo JavaDoc
* @param configHandler The object that handles settings for encoding, decoding, compression, and a number of other features.
* @param settings The object that handles settings for encoding, decoding, compression, and a number of other features.
* @param statisticsHandler todo JavaDoc
*/
public MainScreenController(final Stage primaryStage, final ConfigHandler configHandler, final StatisticsHandler statisticsHandler) {
public MainScreenController(final Stage primaryStage, final Settings settings, final StatisticsHandler statisticsHandler) {
this.primaryStage = primaryStage;
this.configHandler = configHandler;
this.settings = settings;
this.statisticsHandler = statisticsHandler;

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

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


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

final JobSetupDialogController jobSetupDialogController = new JobSetupDialogController(primaryStage, configHandler, statisticsHandler, job);
final JobSetupDialogController jobSetupDialogController = new JobSetupDialogController(primaryStage, settings, statisticsHandler, job);
jobSetupDialogController.getModel().getList_files().addAll(job.getFiles());
jobSetupDialogController.show();

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

// The button to encode the currently selected handler(s).
if(source.equals(view.getButton_encode())) {
if (!new File(configHandler.getFfmpegPath()).exists()) {
if (!new File(settings.getStringSetting("FFMPEG Path")).exists()) {
showFfmpegPathErrorAndWait();
return;
}
Expand All @@ -122,7 +122,7 @@ public void handle(Event event) {
.parallelStream()
.filter(Job::isEncodeJob)
.forEach(job -> {
final FFMPEGHandler ffmpegHandler = new FFMPEGHandler(job, this, configHandler, statisticsHandler);
final FFMPEGHandler ffmpegHandler = new FFMPEGHandler(job, this, settings, statisticsHandler);
ffmpegHandler.setOnSucceeded(ffmpegHandler);
preparedJobs.add(ffmpegHandler);
});
Expand All @@ -137,7 +137,7 @@ public void handle(Event event) {

// The button to decode the currently selected handler(s).
if(source.equals(view.getButton_decode())) {
if (!new File(configHandler.getFfmpegPath()).exists()) {
if (!new File(settings.getStringSetting("FFMPEG Path")).exists()) {
showFfmpegPathErrorAndWait();
return;
}
Expand All @@ -152,7 +152,7 @@ public void handle(Event event) {
.parallelStream()
.filter(job -> ! job.isEncodeJob())
.forEach(job -> {
final FFMPEGHandler ffmpegHandler = new FFMPEGHandler(job, this, configHandler, statisticsHandler);
final FFMPEGHandler ffmpegHandler = new FFMPEGHandler(job, this, settings, statisticsHandler);
ffmpegHandler.setOnSucceeded(ffmpegHandler);
preparedJobs.add(ffmpegHandler);
});
Expand Down Expand Up @@ -210,7 +210,7 @@ public void handle(Event event) {

// The button to open the settings dialog.
if(source.equals(view.getButton_editSettings())) {
new SettingsDialogController(primaryStage, configHandler).show();
new SettingsDialogController(primaryStage, settings).show();
}
}

Expand Down
60 changes: 34 additions & 26 deletions src/controller/SettingsDialogController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package controller;

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

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

view = new SettingsDialogView(settingsStage, this, configHandler);
view = new SettingsDialogView(settingsStage, this, this.settings);

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

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

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

configHandler.setFfmpegPath(pane_ffmpeg.getField_ffmpegPath().getText());
configHandler.setCompressionProgramPath(pane_archival.getField_compressionProgramPath().getText());
configHandler.setCompressionOutputExtension(pane_archival.getField_archiveOutputExtension().getText());
configHandler.setEncodeFormat(pane_ffmpeg.getField_encodeFormat().getText());
configHandler.setDecodeFormat(pane_ffmpeg.getField_decodeFormat().getText());
configHandler.setEncodedVideoWidth(Integer.valueOf(pane_ffmpeg.getField_encodedVideoWidth().getText()));
configHandler.setEncodedVideoHeight(Integer.valueOf(pane_ffmpeg.getField_encodedVideoHeight().getText()));
configHandler.setEncodedFramerate(Integer.valueOf(pane_ffmpeg.getField_encodedFramerate().getText()));
configHandler.setMacroBlockDimensions(Integer.valueOf(pane_ffmpeg.getField_macroBlockDimensions().getText()));
configHandler.setUseFullyCustomFfmpegOptions(pane_ffmpeg.getRadioButton_useFullyCustomEncodingOptions_yes().isSelected());
configHandler.setFullyCustomFfmpegEncodingOptions(pane_ffmpeg.getField_fullyCustomFfmpegEncodingOptions().getText());
configHandler.setFullyCustomFfmpegDecodingOptions(pane_ffmpeg.getField_fullyCustomFfmpegDecodingptions().getText());
configHandler.setEncodingLibrary(pane_ffmpeg.getField_encodingLibrary().getText());
configHandler.setFfmpegLogLevel(pane_ffmpeg.getComboBox_ffmpegLogLevel().getSelectionModel().getSelectedItem());
configHandler.setCompressionCommands(pane_archival.getField_compressionCommands().getText());
configHandler.setWarnUserIfSettingsMayNotWorkForYouTube(pane_misc.getWarnUserIfSettingsMayNotWorkForYouTube());
configHandler.createConfigFile();
settings.setSetting("FFMPEG Path", pane_ffmpeg.getField_ffmpegPath().getText());
settings.setSetting("Compression Program Path", pane_archival.getField_compressionProgramPath().getText());

settings.setSetting("Enc Format", pane_ffmpeg.getField_encodeFormat().getText());
settings.setSetting("Dec Format", pane_ffmpeg.getField_decodeFormat().getText());

settings.setSetting("Enc Vid Width", pane_ffmpeg.getField_encodedVideoWidth().getText());
settings.setSetting("Enc Vid Height", pane_ffmpeg.getField_encodedVideoHeight().getText());
settings.setSetting("Enc Vid Framerate", pane_ffmpeg.getField_encodedFramerate().getText());
settings.setSetting("Enc Vid Macro Block Dimensions", pane_ffmpeg.getField_macroBlockDimensions().getText());
settings.setSetting("Enc Library", pane_ffmpeg.getField_encodingLibrary().getText());

settings.setSetting("FFMPEG Log Level", pane_ffmpeg.getComboBox_ffmpegLogLevel().getSelectionModel().getSelectedItem());

settings.setSetting("Use Custom FFMPEG Options", pane_ffmpeg.getRadioButton_useFullyCustomEncodingOptions_yes().isSelected());
settings.setSetting("Custom FFMPEG Enc Options", pane_ffmpeg.getField_fullyCustomFfmpegEncodingOptions().getText());
settings.setSetting("Custom FFMPEG Dec Options", pane_ffmpeg.getField_fullyCustomFfmpegDecodingptions().getText());

settings.setSetting("Delete Source File When Enc", false);
settings.setSetting("Delete Source File When Dec", false);

settings.setSetting("Compression Commands", pane_archival.getField_compressionCommands().getText());
settings.setSetting("Compression Output Extension", pane_archival.getField_archiveOutputExtension().getText());

settings.setSetting("Warn If Settings Possibly Incompatible With YouTube", pane_misc.getWarnUserIfSettingsMayNotWorkForYouTube());

this.close();
}
Expand Down
6 changes: 3 additions & 3 deletions src/controller/settings/ArchivalSettingsController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package controller.settings;

import handler.ConfigHandler;
import configuration.Settings;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.stage.FileChooser;
Expand All @@ -17,9 +17,9 @@ public class ArchivalSettingsController implements EventHandler {
// todo JavaDoc
private final Stage settingsStage;

public ArchivalSettingsController(final Stage settingsStage, final ConfigHandler configHandler) {
public ArchivalSettingsController(final Stage settingsStage, final Settings settings) {
this.settingsStage = settingsStage;
pane = new ArchivalSettingsPane(settingsStage, this, configHandler);
pane = new ArchivalSettingsPane(settingsStage, this, settings);
}

@Override
Expand Down
Loading

0 comments on commit 90811fc

Please sign in to comment.