Skip to content

Commit 4447c12

Browse files
committed
* Added general design for MainWindow
* Added general design for AboutWindow * Added logging * Added LICENSE * Added audio files * Added images * Added translation properties
1 parent 700fba6 commit 4447c12

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2507
-19
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,5 @@ fabric.properties
6969

7070
# Android studio 3.1+ serialized cache file
7171
.idea/caches/build_file_checksums.ser
72+
.idea/*
73+
.gradle/*

LICENSE

+674
Large diffs are not rendered by default.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Opal
2+
3+
A free and open-source JavaFX application that plays relaxing music in the background.

build.gradle

+40-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,61 @@
1+
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
2+
13
plugins {
24
id 'java'
35
id 'idea'
46
id 'eclipse'
57
id 'application'
6-
id 'org.openjfx.javafxplugin' version '0.0.9'
8+
id 'org.beryx.jlink' version '2.23.1'
79
}
810

911
group 'com.codedead'
1012
version '1.0-SNAPSHOT'
1113

12-
targetCompatibility = '15'
13-
sourceCompatibility = '15'
14+
java {
15+
modularity.inferModulePath = true
16+
targetCompatibility = JavaVersion.VERSION_15
17+
sourceCompatibility = JavaVersion.VERSION_15
18+
}
19+
20+
application {
21+
mainModule = 'Opal'
22+
mainClass = 'com.codedead.opal.OpalApplication'
23+
}
24+
25+
jlink {
26+
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
27+
forceMerge('log4j-api')
28+
launcher {
29+
name = 'Opal'
30+
}
31+
}
1432

15-
javafx {
16-
version = '15.0.1'
17-
modules = [ 'javafx.controls' ]
33+
clean.doFirst {
34+
delete 'default.properties'
35+
delete 'license.pdf'
1836
}
1937

2038
repositories {
2139
mavenCentral()
2240
}
2341

42+
def currentOS = DefaultNativePlatform.currentOperatingSystem;
43+
def platform
44+
if (currentOS.isWindows()) {
45+
platform = 'win'
46+
} else if (currentOS.isLinux()) {
47+
platform = 'linux'
48+
} else if (currentOS.isMacOsX()) {
49+
platform = 'mac'
50+
}
51+
2452
dependencies {
53+
implementation "org.openjfx:javafx-base:15.0.1:${platform}"
54+
implementation "org.openjfx:javafx-controls:15.0.1:${platform}"
55+
implementation "org.openjfx:javafx-graphics:15.0.1:${platform}"
56+
implementation "org.openjfx:javafx-fxml:15.0.1:${platform}"
57+
implementation "org.openjfx:javafx-media:15.0.1:${platform}"
58+
implementation "org.apache.logging.log4j:log4j-core:2.14.0"
2559
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
2660
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
2761
}

src/main/java/com/codedead/opal/Application.java

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.codedead.opal;
2+
3+
import org.apache.logging.log4j.LogManager;
4+
import org.apache.logging.log4j.Logger;
5+
6+
import com.codedead.opal.controller.MainWindowController;
7+
import com.codedead.opal.controller.SettingsController;
8+
import javafx.application.Application;
9+
import javafx.fxml.FXMLLoader;
10+
import javafx.scene.Parent;
11+
import javafx.scene.Scene;
12+
import javafx.scene.image.Image;
13+
import javafx.stage.Stage;
14+
15+
import java.io.IOException;
16+
import java.util.Locale;
17+
import java.util.Properties;
18+
import java.util.ResourceBundle;
19+
20+
public class OpalApplication extends Application {
21+
22+
private static final Logger logger = LogManager.getLogger(OpalApplication.class);
23+
private static final String PROPERTIES_LOCATION = "default.properties";
24+
25+
/**
26+
* Initialize the application
27+
*
28+
* @param args The application arguments
29+
*/
30+
public static void main(final String[] args) {
31+
launch(args);
32+
}
33+
34+
@Override
35+
public void start(final Stage primaryStage) throws Exception {
36+
logger.info("Creating the SettingsController");
37+
final SettingsController settingsController = new SettingsController(PROPERTIES_LOCATION, PROPERTIES_LOCATION);
38+
final Properties properties = settingsController.getProperties();
39+
40+
final String languageTag = properties.getProperty("locale", "en-US");
41+
logger.info(String.format("Attempting to load the ResourceBundle for locale %s", languageTag));
42+
43+
final Locale locale = Locale.forLanguageTag(languageTag);
44+
final ResourceBundle translationBundle = ResourceBundle.getBundle("translations.OpalApplication", locale);
45+
46+
final FXMLLoader loader = new FXMLLoader(getClass().getResource("/windows/MainWindow.fxml"), translationBundle);
47+
Parent root;
48+
try {
49+
root = loader.load();
50+
} catch (final IOException ex) {
51+
logger.error("Unable to load FXML for MainWindow", ex);
52+
return;
53+
}
54+
55+
logger.info("Creating the MainWindowController");
56+
final MainWindowController mainWindowController = loader.getController();
57+
mainWindowController.setSettingsController(settingsController);
58+
59+
final Scene scene = new Scene(root);
60+
61+
primaryStage.setTitle(translationBundle.getString("MainWindowTitle"));
62+
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/images/opal.png")));
63+
primaryStage.setScene(scene);
64+
65+
logger.info("Showing the MainWindow");
66+
primaryStage.show();
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package com.codedead.opal.controller;
2+
3+
import com.codedead.opal.utils.FxUtils;
4+
import com.codedead.opal.utils.HelpUtils;
5+
import javafx.fxml.FXML;
6+
import javafx.scene.control.Label;
7+
import javafx.scene.image.Image;
8+
import javafx.scene.image.ImageView;
9+
import javafx.stage.Stage;
10+
import org.apache.logging.log4j.LogManager;
11+
import org.apache.logging.log4j.Logger;
12+
13+
import java.io.IOException;
14+
import java.util.Locale;
15+
import java.util.Properties;
16+
import java.util.ResourceBundle;
17+
18+
public final class AboutWindowController {
19+
20+
private static final Logger logger = LogManager.getLogger(AboutWindowController.class);
21+
22+
@FXML
23+
private Label aboutLabel;
24+
@FXML
25+
private ImageView aboutImageView;
26+
27+
private final HelpUtils helpUtils;
28+
private SettingsController settingsController;
29+
private ResourceBundle translationBundle;
30+
31+
/**
32+
* Initialize a new AboutWindowController
33+
*/
34+
public AboutWindowController() {
35+
logger.info("Initializing new AboutWindowController object");
36+
37+
helpUtils = new HelpUtils();
38+
}
39+
40+
/**
41+
* Get the SettingsController
42+
*
43+
* @return The SettingsController
44+
*/
45+
public final SettingsController getSettingsController() {
46+
return settingsController;
47+
}
48+
49+
/**
50+
* Set the SettingsController
51+
*
52+
* @param settingsController The SettingsController
53+
*/
54+
public final void setSettingsController(final SettingsController settingsController) {
55+
if (settingsController == null)
56+
throw new NullPointerException("SettingsController cannot be null!");
57+
58+
this.settingsController = settingsController;
59+
60+
final Properties properties = settingsController.getProperties();
61+
final String languageTag = properties.getProperty("locale", "en-US");
62+
63+
logger.info(String.format("Attempting to load the ResourceBundle for locale %s", languageTag));
64+
final Locale locale = Locale.forLanguageTag(languageTag);
65+
translationBundle = ResourceBundle.getBundle("translations.OpalApplication", locale);
66+
}
67+
68+
/**
69+
* Method that is invoked to initialize the FXML window
70+
*/
71+
@FXML
72+
private void initialize() {
73+
logger.info("Initializing AboutWindow");
74+
75+
aboutImageView.setFitHeight(96);
76+
aboutImageView.setFitWidth(96);
77+
aboutImageView.setImage(new Image(getClass().getResourceAsStream("/images/opal.png")));
78+
}
79+
80+
/**
81+
* Method that is called when the close button is selected
82+
*/
83+
@FXML
84+
private void closeAction() {
85+
logger.info("Closing AboutWindow");
86+
87+
final Stage stage = (Stage) aboutLabel.getScene().getWindow();
88+
stage.close();
89+
}
90+
91+
/**
92+
* Method that is called when the license button is selected
93+
*/
94+
@FXML
95+
private void licenseAction() {
96+
logger.info("Attempting to open the license file");
97+
98+
try {
99+
helpUtils.openFileFromResources("license.pdf", "/documents/license.pdf");
100+
} catch (final IOException ex) {
101+
logger.error("Error opening the license file", ex);
102+
FxUtils.showErrorAlert(translationBundle.getString("LicenseFileError"), ex.getMessage(), getClass().getResourceAsStream("/images/opal.png"));
103+
}
104+
}
105+
106+
/**
107+
* Method that is called when the CodeDead button is selected
108+
*/
109+
@FXML
110+
private void codeDeadAction() {
111+
logger.info("Opening the CodeDead website");
112+
113+
helpUtils.openWebsite("https://codedead.com");
114+
}
115+
}

0 commit comments

Comments
 (0)