Skip to content

Commit

Permalink
Merge pull request #41 from CodeDead/release/v1.0.3
Browse files Browse the repository at this point in the history
Release/v1.0.3
  • Loading branch information
CodeDead authored Jun 17, 2022
2 parents 68f6dcb + 8617fbc commit 2100d61
Show file tree
Hide file tree
Showing 36 changed files with 332 additions and 86 deletions.
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group 'com.codedead'
version '1.0.2'
version '1.0.3'

def currentOS = DefaultNativePlatform.currentOperatingSystem

Expand Down Expand Up @@ -112,13 +112,13 @@ if (currentOS.isWindows()) {
}

dependencies {
implementation "org.openjfx:javafx-base:18:${platform}"
implementation "org.openjfx:javafx-controls:18:${platform}"
implementation "org.openjfx:javafx-graphics:18:${platform}"
implementation "org.openjfx:javafx-fxml:18:${platform}"
implementation "org.openjfx:javafx-media:18:${platform}"
implementation "org.openjfx:javafx-base:18.0.1:${platform}"
implementation "org.openjfx:javafx-controls:18.0.1:${platform}"
implementation "org.openjfx:javafx-graphics:18.0.1:${platform}"
implementation "org.openjfx:javafx-fxml:18.0.1:${platform}"
implementation "org.openjfx:javafx-media:18.0.1:${platform}"
implementation 'org.apache.logging.log4j:log4j-core:2.17.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.2.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.3'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/codedead/opal/OpalApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.codedead.opal.controller.UpdateController;
import com.codedead.opal.utils.FxUtils;
import com.codedead.opal.utils.SharedVariables;
import javafx.application.Platform;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -69,6 +70,7 @@ public void start(final Stage primaryStage) {
} catch (final IOException ex) {
FxUtils.showErrorAlert("Exception occurred", ex.getMessage(), getClass().getResourceAsStream(SharedVariables.ICON_URL));
logger.error("Unable to initialize the SettingsController", ex);
Platform.exit();
return;
}

Expand All @@ -89,6 +91,7 @@ public void start(final Stage primaryStage) {
root = loader.load();
} catch (final IOException ex) {
logger.error("Unable to load FXML for MainWindow", ex);
Platform.exit();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
import com.codedead.opal.interfaces.IRunnableHelper;
import com.codedead.opal.utils.*;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;
Expand All @@ -21,14 +19,8 @@

public final class AboutWindowController {

@FXML
private Label aboutLabel;
@FXML
private ImageView aboutImageView;

private SettingsController settingsController;
private ResourceBundle translationBundle;

private final HelpUtils helpUtils;
private final Logger logger;

Expand Down Expand Up @@ -77,27 +69,15 @@ public void setSettingsController(final SettingsController settingsController) {
@FXML
private void initialize() {
logger.info("Initializing AboutWindow");

aboutImageView.setFitHeight(96);
aboutImageView.setFitWidth(96);

final InputStream inputStream = getClass().getResourceAsStream("/images/opal.png");
if (inputStream != null) {
aboutImageView.setImage(new Image(inputStream));
} else {
aboutImageView.setImage(null);
}
}

/**
* Method that is called when the close button is selected
*/
@FXML
private void closeAction() {
private void closeAction(final ActionEvent event) {
logger.info("Closing AboutWindow");

final Stage stage = (Stage) aboutLabel.getScene().getWindow();
stage.close();
((Stage) (((Button) event.getSource()).getScene().getWindow())).close();
}

/**
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/com/codedead/opal/controller/AudioController.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public AudioController(final IAudioTimer audioTimer) throws URISyntaxException {
logger = LogManager.getLogger(AudioController.class);

logger.info("Initializing new AudioController object");
logger.info("Initializing MediaPlayer objects");

mediaPlayers = new HashMap<>();
mediaPlayers.put("rain", new MediaPlayer(new Media(Objects.requireNonNull(getClass().getResource("/audio/rain.mp3")).toURI().toString())));
Expand All @@ -62,6 +61,12 @@ public AudioController(final IAudioTimer audioTimer) throws URISyntaxException {
mediaPlayers.put("zen", new MediaPlayer(new Media(Objects.requireNonNull(getClass().getResource("/audio/zen.mp3")).toURI().toString())));
mediaPlayers.put("coffee", new MediaPlayer(new Media(Objects.requireNonNull(getClass().getResource("/audio/coffee.mp3")).toURI().toString())));
mediaPlayers.put("zoo", new MediaPlayer(new Media(Objects.requireNonNull(getClass().getResource("/audio/zoo.mp3")).toURI().toString())));
mediaPlayers.put("networking", new MediaPlayer(new Media(Objects.requireNonNull(getClass().getResource("/audio/networking.mp3")).toURI().toString())));
mediaPlayers.put("tribal", new MediaPlayer(new Media(Objects.requireNonNull(getClass().getResource("/audio/tribal.mp3")).toURI().toString())));
mediaPlayers.put("drumtribal", new MediaPlayer(new Media(Objects.requireNonNull(getClass().getResource("/audio/tribal2.mp3")).toURI().toString())));
mediaPlayers.put("football", new MediaPlayer(new Media(Objects.requireNonNull(getClass().getResource("/audio/football.mp3")).toURI().toString())));
mediaPlayers.put("sleepy", new MediaPlayer(new Media(Objects.requireNonNull(getClass().getResource("/audio/sleepy.mp3")).toURI().toString())));
mediaPlayers.put("gong", new MediaPlayer(new Media(Objects.requireNonNull(getClass().getResource("/audio/gong.mp3")).toURI().toString())));

mediaVolumes = new HashMap<>();
for (final Map.Entry<String, MediaPlayer> entry : mediaPlayers.entrySet()) {
Expand Down Expand Up @@ -93,7 +98,7 @@ public void playMedia(final String key) {
throw new NullPointerException(String.format("MediaPlayer with key %s cannot be found!", key));

if (!player.getStatus().equals(MediaPlayer.Status.PLAYING)) {
logger.info("Playing media for MediaPlayer with key {}", key);
logger.info("Playing Media for MediaPlayer with key {}", key);
player.play();
}
}
Expand All @@ -109,7 +114,7 @@ public void stopMedia(final String key) {
if (key.isEmpty())
throw new IllegalArgumentException("Key cannot be empty!");

logger.info("Stopping media for MediaPlayer with key {}", key);
logger.info("Stopping Media for MediaPlayer with key {}", key);

final MediaPlayer player = mediaPlayers.get(key);

Expand Down Expand Up @@ -138,7 +143,6 @@ public void setPlayerVolume(final String key, final double newVolume) {
logger.debug("Setting volume for MediaPlayer with key {} to {}", key, newVolume);

final MediaPlayer player = mediaPlayers.get(key);

if (player == null)
throw new NullPointerException(String.format("MediaPlayer with key %s cannot be found!", key));

Expand Down Expand Up @@ -220,7 +224,7 @@ public void loadSoundPreset(final String path) throws IOException {

mediaVolumes = objectMapper.readValue(actual, typeRef);

for (Map.Entry<String, Double> entry : mediaVolumes.entrySet()) {
for (final Map.Entry<String, Double> entry : mediaVolumes.entrySet()) {
setPlayerVolume(entry.getKey(), entry.getValue());
}
}
Expand Down Expand Up @@ -274,8 +278,8 @@ public void cancelTimer() {
*
* @param delay The delay in milliseconds before the {@link Timer} object executes its function
*/
public void scheduleTimer(long delay) {
if (delay <= 1)
public void scheduleTimer(final long delay) {
if (delay < 1)
throw new IllegalArgumentException("Delay cannot be smaller than 1");

logger.info("Scheduling the Timer to stop all MediaPlayer objects after {} millisecond(s)", delay);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.codedead.opal.controller;

import com.codedead.opal.domain.InvalidHttpResponseCodeException;
import com.codedead.opal.domain.OsCheck;
import com.codedead.opal.domain.PlatformUpdate;
import com.codedead.opal.domain.SoundPane;
Expand All @@ -12,8 +13,6 @@
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.DragEvent;
Expand All @@ -34,6 +33,18 @@

public final class MainWindowController implements IAudioTimer {

@FXML
private SoundPane snpGong;
@FXML
private SoundPane snpDrumTribal;
@FXML
private SoundPane snpSleepy;
@FXML
private SoundPane snpFootball;
@FXML
private SoundPane snpTribal;
@FXML
private SoundPane snpNetworkingEvent;
@FXML
private SoundPane snpZoo;
@FXML
Expand Down Expand Up @@ -207,11 +218,14 @@ private void checkForUpdates(final boolean showNoUpdates) {
} else {
logger.info("No updates available");
if (showNoUpdates) {
final Alert alert = new Alert(Alert.AlertType.INFORMATION, translationBundle.getString("NoUpdateAvailable"), ButtonType.OK);
alert.showAndWait();
FxUtils.showInformationAlert(translationBundle.getString("NoUpdateAvailable"), null);
}
}
} catch (final Exception ex) {
} catch (final InterruptedException ex) {
logger.error("Unable to check for updates", ex);
FxUtils.showErrorAlert(translationBundle.getString("UpdateError"), ex.getMessage(), getClass().getResourceAsStream(SharedVariables.ICON_URL));
Thread.currentThread().interrupt();
} catch (final IOException | InvalidHttpResponseCodeException ex) {
logger.error("Unable to check for updates", ex);
FxUtils.showErrorAlert(translationBundle.getString("UpdateError"), ex.getMessage(), getClass().getResourceAsStream(SharedVariables.ICON_URL));
}
Expand Down Expand Up @@ -300,6 +314,14 @@ private void initialize() {
snpZen.getSlider().valueProperty().addListener((observableValue, oldValue, newValue) -> audioController.setPlayerVolume("zen", newValue.doubleValue() / 100));
snpCoffee.getSlider().valueProperty().addListener((observableValue, oldValue, newValue) -> audioController.setPlayerVolume("coffee", newValue.doubleValue() / 100));
snpZoo.getSlider().valueProperty().addListener((observableValue, oldValue, newValue) -> audioController.setPlayerVolume("zoo", newValue.doubleValue() / 100));
snpSleepy.getSlider().valueProperty().addListener((observableValue, oldValue, newValue) -> audioController.setPlayerVolume("sleepy", newValue.doubleValue() / 100));
snpGong.getSlider().valueProperty().addListener((observableValue, oldValue, newValue) -> audioController.setPlayerVolume("gong", newValue.doubleValue() / 100));

// Audiences
snpNetworkingEvent.getSlider().valueProperty().addListener((observableValue, oldValue, newValue) -> audioController.setPlayerVolume("networking", newValue.doubleValue() / 100));
snpTribal.getSlider().valueProperty().addListener((observableValue, oldValue, newValue) -> audioController.setPlayerVolume("tribal", newValue.doubleValue() / 100));
snpDrumTribal.getSlider().valueProperty().addListener((observableValue, oldValue, newValue) -> audioController.setPlayerVolume("drumtribal", newValue.doubleValue() / 100));
snpFootball.getSlider().valueProperty().addListener((observableValue, oldValue, newValue) -> audioController.setPlayerVolume("football", newValue.doubleValue() / 100));

mniTimerEnabled.setOnAction(e ->
{
Expand All @@ -319,7 +341,7 @@ private void initialize() {
*/
@FXML
private void openSoundPresetAction() {
logger.info("Attempting to open a sound preset");
logger.info("Opening a sound preset");
final FileChooser chooser = new FileChooser();

final FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("JSON (*.json)", "*.json");
Expand All @@ -329,8 +351,6 @@ private void openSoundPresetAction() {

if (file != null && file.exists()) {
openSoundPreset(file.getAbsolutePath());
} else {
logger.info("Cancelled opening a sound preset");
}
}

Expand Down Expand Up @@ -363,6 +383,12 @@ private void openSoundPreset(final String filePath) {
case "zen" -> snpZen.getSlider().setValue(entry.getValue() * 100);
case "coffee" -> snpCoffee.getSlider().setValue(entry.getValue() * 100);
case "zoo" -> snpZoo.getSlider().setValue(entry.getValue() * 100);
case "networking" -> snpNetworkingEvent.getSlider().setValue(entry.getValue() * 100);
case "tribal" -> snpTribal.getSlider().setValue(entry.getValue() * 100);
case "football" -> snpFootball.getSlider().setValue(entry.getValue() * 100);
case "sleepy" -> snpSleepy.getSlider().setValue(entry.getValue() * 100);
case "drumtribal" -> snpDrumTribal.getSlider().setValue(entry.getValue() * 100);
case "gong" -> snpGong.getSlider().setValue(entry.getValue() * 100);
default -> logger.info("Unknown key found: {}", entry.getKey());
}
}
Expand Down Expand Up @@ -427,6 +453,12 @@ private void resetAction() {
snpZen.getSlider().setValue(0);
snpCoffee.getSlider().setValue(0);
snpZoo.getSlider().setValue(0);
snpNetworkingEvent.getSlider().setValue(0);
snpTribal.getSlider().setValue(0);
snpFootball.getSlider().setValue(0);
snpSleepy.getSlider().setValue(0);
snpDrumTribal.getSlider().setValue(0);
snpGong.getSlider().setValue(0);
}

/**
Expand Down Expand Up @@ -660,7 +692,7 @@ private void onDragOver(final DragEvent dragEvent) {
* @param dragEvent The {@link DragEvent} object
*/
@FXML
public void onDragDropped(final DragEvent dragEvent) {
private void onDragDropped(final DragEvent dragEvent) {
final Dragboard db = dragEvent.getDragboard();
boolean success = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public void createDefaultProperties() throws IOException {
if (is != null) {
logger.info("Creating default properties file at {}", getPropertiesFileLocation());
Files.copy(is, propertiesPath);
logger.info("Default properties file created");
} else {
throw new IOException(String.format("Could not load default properties from application resources (%s)!", getPropertiesResourceLocation()));
}
Expand Down Expand Up @@ -132,11 +131,10 @@ public void setProperties(final Properties properties) {
* @throws IOException When the Properties object could not be stored
*/
public void saveProperties() throws IOException {
logger.info("Attempting to store the Properties object");
logger.info("Storing the Properties object");
try (final FileOutputStream fos = new FileOutputStream(getPropertiesFileLocation())) {
properties.store(fos, null);
}
logger.info("Properties object stored");
}

/**
Expand All @@ -146,13 +144,10 @@ public void saveProperties() throws IOException {
* @throws IOException When the properties file could not be loaded
*/
public Properties readPropertiesFile() throws IOException {
logger.info("Attempting to load the Properties object");
logger.info("Loading the Properties object");
try (final FileInputStream fis = new FileInputStream(getPropertiesFileLocation())) {
final Properties prop = new Properties();

prop.load(fis);

logger.info("Properties object loaded");
return prop;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ private void initialize() {
}

/**
* Set the {@link com.codedead.opal.controller.SettingsController} object
* Set the {@link SettingsController} object
*
* @param settingsController The {@link com.codedead.opal.controller.SettingsController} object
* @param settingsController The {@link SettingsController} object
*/
public void setSettingsController(final SettingsController settingsController) {
if (settingsController == null)
Expand Down Expand Up @@ -91,14 +91,19 @@ private void loadSettings() {
long timerDelay = Long.parseLong(properties.getProperty("timerDelay", "3600000"));
final int delayType = Integer.parseInt(properties.getProperty("timerDelayType", "0"));

if (timerDelay < 1) {
timerDelay = 1;
}

chbAutoUpdate.setSelected(autoUpdate);
chbTimerApplicationShutdown.setSelected(Boolean.parseBoolean(properties.getProperty("timerApplicationShutdown", "false")));

switch (locale.toLowerCase()) {
case "es-es" -> cboLanguage.getSelectionModel().select(1);
case "fr-fr" -> cboLanguage.getSelectionModel().select(2);
case "nl-nl" -> cboLanguage.getSelectionModel().select(3);
case "ru-ru" -> cboLanguage.getSelectionModel().select(4);
case "de-de" -> cboLanguage.getSelectionModel().select(1);
case "es-es" -> cboLanguage.getSelectionModel().select(2);
case "fr-fr" -> cboLanguage.getSelectionModel().select(3);
case "nl-nl" -> cboLanguage.getSelectionModel().select(4);
case "ru-ru" -> cboLanguage.getSelectionModel().select(5);
default -> cboLanguage.getSelectionModel().select(0);
}

Expand Down Expand Up @@ -166,10 +171,11 @@ private void saveSettingsAction() {
showAlertIfLanguageMismatch(properties.getProperty("locale", DEFAULT_LOCALE));

switch (cboLanguage.getSelectionModel().getSelectedIndex()) {
case 1 -> properties.setProperty("locale", "es-es");
case 2 -> properties.setProperty("locale", "fr-FR");
case 3 -> properties.setProperty("locale", "nl-NL");
case 4 -> properties.setProperty("locale", "ru-RU");
case 1 -> properties.setProperty("locale", "de-DE");
case 2 -> properties.setProperty("locale", "es-es");
case 3 -> properties.setProperty("locale", "fr-FR");
case 4 -> properties.setProperty("locale", "nl-NL");
case 5 -> properties.setProperty("locale", "ru-RU");
default -> properties.setProperty("locale", DEFAULT_LOCALE);
}

Expand Down
Loading

0 comments on commit 2100d61

Please sign in to comment.