commit 52bcd6764df8b7ed35ccafd9b7277b7ce4699975
parent 53abf1aa95e24d2e2fa98bdafcb815d64760ebcc
Author: A Koens <[email protected]>
Date: Fri, 16 Sep 2022 09:15:50 +0200
Some Settings
Diffstat:
11 files changed, 167 insertions(+), 9 deletions(-)
diff --git a/ISYGameClient.iml b/ISYGameClient.iml
@@ -6,6 +6,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
@@ -26,5 +27,6 @@
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.9.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.9.0" level="project" />
+ <orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.24" level="project" />
</component>
</module>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
@@ -14,6 +14,8 @@
<junit.version>5.9.0</junit.version>
</properties>
+
+
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
@@ -47,6 +49,12 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>1.18.24</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
@@ -76,6 +84,13 @@
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
+ <annotationProcessorPaths>
+ <path>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>1.18.24</version>
+ </path>
+ </annotationProcessorPaths>
</configuration>
</execution>
</executions>
diff --git a/settings.properties b/settings.properties
@@ -0,0 +1,5 @@
+#Window Settings
+#Tue Sep 13 10:44:53 CEST 2022
+screenWidth=1920
+screenHeight=1080
+title=ISY Game Client
diff --git a/src/main/java/com/example/isygameclient/Application.java b/src/main/java/com/example/isygameclient/Application.java
@@ -1,5 +1,6 @@
package com.example.isygameclient;
+import com.example.isygameclient.util.Settings;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
@@ -8,14 +9,20 @@ import java.io.IOException;
public class Application extends javafx.application.Application {
@Override
- public void start(Stage stage) throws IOException {
- FXMLLoader fxmlLoader = new FXMLLoader(Application.class.getResource("views/hello-view.fxml"));
- Scene scene = new Scene(fxmlLoader.load(), 320, 240);
- stage.setTitle("Hello!");
- stage.setScene(scene);
- stage.show();
+ public void start(Stage primaryStage) throws IOException {
+ FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("views/hello-view.fxml"));
+ Scene scene = new Scene(fxmlLoader.load(), Settings.getInstance().getScreenWidth(),
+ Settings.getInstance().getScreenHeight());
+ primaryStage.setTitle(Settings.getInstance().getTitle());
+ primaryStage.setScene(scene);
+ primaryStage.setFullScreen(true);
+ primaryStage.show();
+ primaryStage.setOnCloseRequest((windowEvent) -> {
+ Settings.getInstance().saveProperties();
+ });
}
+
public static void main(String[] args) {
launch();
}
diff --git a/src/main/java/com/example/isygameclient/controllers/HelloController.java b/src/main/java/com/example/isygameclient/controllers/HelloController.java
@@ -1,14 +1,21 @@
package com.example.isygameclient.controllers;
+import com.example.isygameclient.util.Settings;
import javafx.fxml.FXML;
+import javafx.scene.control.Button;
import javafx.scene.control.Label;
+import javafx.stage.Stage;
public class HelloController {
@FXML
private Label welcomeText;
@FXML
+ private Button welcomeButton;
+
+ @FXML
protected void onHelloButtonClick() {
- welcomeText.setText("Welcome to JavaFX Application!");
+ welcomeText.setText(Settings.getInstance().getTitle());
+ ((Stage)welcomeButton.getScene().getWindow()).setFullScreen(true);
}
}
\ No newline at end of file
diff --git a/src/main/java/com/example/isygameclient/models/SimpleCalculator.java b/src/main/java/com/example/isygameclient/models/SimpleCalculator.java
@@ -0,0 +1,8 @@
+package com.example.isygameclient.models;
+
+public class SimpleCalculator {
+
+ public int add (int numberA, int numberB) {
+ return numberA + numberB;
+ }
+}
diff --git a/src/main/java/com/example/isygameclient/util/Settings.java b/src/main/java/com/example/isygameclient/util/Settings.java
@@ -0,0 +1,77 @@
+package com.example.isygameclient.util;
+
+
+import lombok.Data;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+@Data
+public class Settings {
+
+ private static Settings instance;
+
+ private String title = "ISY Game Client";
+ private int screenHeight = 1080;
+ private int screenWidth = 1920;
+
+
+ private Settings() {
+ loadSettingsFromProperties();
+ }
+
+ public static Settings getInstance() {
+ if (Settings.instance == null) {
+ Settings.instance = new Settings();
+ }
+ return Settings.instance;
+ }
+
+ private void loadSettingsFromProperties() {
+ Properties properties = loadProperties();
+ if (properties != null) {
+ try {
+ this.title = String.valueOf(properties.getProperty("title"));
+ this.screenHeight = Integer.parseInt(properties.getProperty("screenHeight"));
+ this.screenWidth = Integer.parseInt(properties.getProperty("screenWidth"));
+ } catch (NumberFormatException e) {
+ System.out.println("ERROR: Unable to load properties");
+ e.printStackTrace();
+ }
+
+ }
+ }
+
+ private Properties loadProperties() {
+ try {
+ Properties properties = new Properties();
+ InputStream is = new FileInputStream("settings.properties");
+ properties.load(is);
+ return properties;
+ } catch (IOException e) {
+ System.out.println("ERROR: Unable to load properties file");
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public void saveProperties() {
+ try {
+ FileOutputStream fos = new FileOutputStream("settings.properties");
+ Properties properties = new Properties();
+ properties.put("title", String.valueOf(Settings.getInstance().getTitle()));
+ properties.put("screenHeight", String.valueOf(Settings.getInstance().getScreenHeight()));
+ properties.put("screenWidth", String.valueOf(Settings.getInstance().getScreenWidth()));
+ properties.store(fos, "Window Settings");
+ fos.flush();
+ fos.close();
+
+ } catch (IOException e) {
+ System.out.println("ERROR: Unable to save to properties file");
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
@@ -5,8 +5,11 @@ module com.example.isygameclient {
requires org.controlsfx.controls;
requires org.kordamp.bootstrapfx.core;
- opens com.example.isygameclient to javafx.fxml;
+ requires static lombok;
+
exports com.example.isygameclient;
exports com.example.isygameclient.controllers;
+
+ opens com.example.isygameclient to javafx.fxml;
opens com.example.isygameclient.controllers to javafx.fxml;
}
\ No newline at end of file
diff --git a/src/main/resources/com/example/isygameclient/views/hello-view.fxml b/src/main/resources/com/example/isygameclient/views/hello-view.fxml
@@ -10,5 +10,5 @@
</padding>
<Label fx:id="welcomeText" />
- <Button onAction="#onHelloButtonClick" text="Hello!" />
+ <Button fx:id="welcomeButton" onAction="#onHelloButtonClick" text="Hello!" />
</VBox>
diff --git a/src/test/java/com/example/isygameclient/models/SimpleCalculatorTest.java b/src/test/java/com/example/isygameclient/models/SimpleCalculatorTest.java
@@ -0,0 +1,19 @@
+package com.example.isygameclient.models;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class SimpleCalculatorTest {
+ @Test
+ void twoPlusTwoShouldEqualFour() {
+ var calculator = new SimpleCalculator();
+ assertEquals(4, calculator.add(2,2));
+ }
+
+ @Test
+ void ThreePlusSevenShouldEqualTen() {
+ var calculator = new SimpleCalculator();
+ assertEquals(10, calculator.add(3,7));
+ }
+}
+\ No newline at end of file
diff --git a/src/test/java/com/example/isygameclient/util/SettingsTest.java b/src/test/java/com/example/isygameclient/util/SettingsTest.java
@@ -0,0 +1,13 @@
+package com.example.isygameclient.util;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class SettingsTest {
+
+ @Test
+ void ShouldGiveTitle() {
+ assertEquals(String.class, Settings.getInstance().getTitle().getClass());
+ }
+}
+\ No newline at end of file