Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Down Expand Up @@ -98,7 +97,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 @@ -114,7 +113,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 @@ -225,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 @@ -280,7 +279,7 @@ public void cancelTimer() {
* @param delay The delay in milliseconds before the {@link Timer} object executes its function
*/
public void scheduleTimer(final long delay) {
if (delay <= 1)
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 Down Expand Up @@ -217,11 +216,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 @@ -336,7 +338,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 @@ -346,8 +348,6 @@ private void openSoundPresetAction() {

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

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,6 +91,10 @@ 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")));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Optional<PlatformUpdate> checkForUpdates(final String currentPlatform, fi
* @param v2 The second {@link String} object that contains a version
* @return 1 if v1 is larger than v2, -1 if v2 is larger than v1 and 0 if both are equal
*/
private int versionCompare(String v1, String v2) {
private int versionCompare(final String v1, final String v2) {
int vnum1 = 0;
int vnum2 = 0;

Expand Down
32 changes: 29 additions & 3 deletions src/main/java/com/codedead/opal/domain/NumberTextField.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.codedead.opal.domain;

import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;

public final class NumberTextField extends TextField {

@FXML
private int min;

/**
* Initialize a new NumberTextField
*/
Expand All @@ -22,8 +26,10 @@ public NumberTextField() {
if (!this.getText().isEmpty()) {
currentValue = Integer.parseInt(this.getText());
}
currentValue--;
this.setText(Integer.toString(currentValue));
if (currentValue - 1 >= getMin()) {
currentValue--;
this.setText(Integer.toString(currentValue));
}
}
});
}
Expand Down Expand Up @@ -61,6 +67,26 @@ public void replaceSelection(final String text) {
* @return True if the text is a number, otherwise false
*/
private boolean validate(final String text) {
return text.matches("[0-9]*");
return text.matches("\\d*");
}

/**
* Get the minimum allowed value
*
* @return The mimium allowed value
*/
@FXML
public int getMin() {
return min;
}

/**
* Set the minimum allowed value
*
* @param min The minimum allowed value
*/
@FXML
public void setMin(final int min) {
this.min = min;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/codedead/opal/domain/OSType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.codedead.opal.domain;

public enum OSType {
Windows, MacOS, Linux, Other,
WINDOWS, MACOS, LINUX, OTHER,
}
8 changes: 4 additions & 4 deletions src/main/java/com/codedead/opal/domain/OsCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public static OSType getOperatingSystemType() {
if (detectedOS == null) {
final String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if ((OS.contains("mac")) || (OS.contains("darwin"))) {
detectedOS = OSType.MacOS;
detectedOS = OSType.MACOS;
} else if (OS.contains("win")) {
detectedOS = OSType.Windows;
detectedOS = OSType.WINDOWS;
} else if (OS.contains("nux")) {
detectedOS = OSType.Linux;
detectedOS = OSType.LINUX;
} else {
detectedOS = OSType.Other;
detectedOS = OSType.OTHER;
}
}
return detectedOS;
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/codedead/opal/domain/SoundPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public final class SoundPane extends GridPane {
private Label lblName;
@FXML
private Slider sldVolume;
@FXML
private String key;

/**
* Initialize a new SoundPane
Expand Down Expand Up @@ -108,4 +110,24 @@ public void setVolume(final double volume) {
public Slider getSlider() {
return sldVolume;
}

/**
* Get the key
*
* @return The key
*/
@FXML
public String getKey() {
return key;
}

/**
* Set the key
*
* @param key The key
*/
@FXML
public void setKey(final String key) {
this.key = key;
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/codedead/opal/utils/HelpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public void openFile(final RunnableFileOpener runnableFileOpener) throws FileNot
public void openFileFromResources(final RunnableFileOpener runnableFileOpener, final String resource) throws IOException {
if (runnableFileOpener == null)
throw new NullPointerException("RunnableFileOpener cannot be null!");
if (resource == null)
throw new NullPointerException("Resource cannot be null!");
if (resource.isEmpty())
throw new IllegalArgumentException("Resource cannot be empty!");

logger.info("Attempting to open file from resources {}", resource);

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/windows/SettingsWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
</GridPane.margin>
</Label>

<NumberTextField GridPane.columnIndex="1" GridPane.rowIndex="0" fx:id="numDelay">
<NumberTextField GridPane.columnIndex="1" GridPane.rowIndex="0" fx:id="numDelay" min="1">
<GridPane.margin>
<Insets bottom="3" left="3" right="3" top="3"/>
</GridPane.margin>
Expand Down