Skip to content

Commit

Permalink
Intellij updates (#71)
Browse files Browse the repository at this point in the history
* Applying editor auto format

* Implement ide encouraged changes

* Using language tag to store locale

* fun with switch
  • Loading branch information
JayPi4c authored Jun 18, 2024
1 parent 3972ea3 commit a5fe762
Show file tree
Hide file tree
Showing 63 changed files with 3,181 additions and 3,291 deletions.
22 changes: 11 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<javafx.version>21</javafx.version> <!-- Version 16 is used to resolve conflicts with monacoFX -->
<junit.version>5.8.2</junit.version>
<javafx.version>22.0.1</javafx.version> <!-- Version 16 is used to resolve conflicts with monacoFX -->
<junit.version>5.10.2</junit.version>
<derby.version>10.17.1.0</derby.version>
<lombok.version>1.18.30</lombok.version>
<hibernate.version>6.4.2.Final</hibernate.version>
<lombok.version>1.18.32</lombok.version>
<hibernate.version>6.5.2.Final</hibernate.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
Expand Down Expand Up @@ -57,7 +57,7 @@
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.2.0</version>
<version>11.2.1</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -94,14 +94,14 @@
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>3.0.2</version>
<artifactId>jaxb-core</artifactId>
<version>4.0.5</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.22.1</version>
<version>2.23.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand All @@ -112,13 +112,13 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.3.1</version>
<version>5.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.3.1</version>
<version>5.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
182 changes: 89 additions & 93 deletions src/main/java/com/JayPi4c/RobbiSimulator/App.java
Original file line number Diff line number Diff line change
@@ -1,117 +1,113 @@
package com.JayPi4c.RobbiSimulator;

import static com.JayPi4c.RobbiSimulator.utils.I18nUtils.i18n;

import java.util.ResourceBundle;

import com.JayPi4c.RobbiSimulator.controller.program.ProgramController;
import com.JayPi4c.RobbiSimulator.controller.tutor.TutorController;
import com.JayPi4c.RobbiSimulator.utils.AlertHelper;
import com.JayPi4c.RobbiSimulator.utils.HibernateUtils;
import com.JayPi4c.RobbiSimulator.utils.I18nUtils;
import com.JayPi4c.RobbiSimulator.utils.PropertiesLoader;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.control.Alert.AlertType;
import javafx.stage.Stage;
import lombok.extern.slf4j.Slf4j;

import javax.swing.*;
import java.util.ResourceBundle;

import static com.JayPi4c.RobbiSimulator.utils.I18nUtils.i18n;

/**
*
* Hauptklasse des Robbi Simulators.<br>
* Javaversion: 17 <br>
*
* @author Jonas Pohl
* Application entry point.<br>
* Java version: 21
*
* @author Jonas Pohl
*/
@Slf4j
public class App extends Application {

private static final String INIT_ERROR_MESSAGE = "Init.error.message";
private static final String INIT_ERROR_TITLE = "Init.error.title";
private static final String INIT_ERROR_HEADER = "Init.error.header";

/**
* Application entry point
*
* @param args the arguments from the command line
*/
public static void main(String[] args) {
try {
launch(args);
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, """
Failed to load application.
Further information can be obtained running the
application in the command line.
Please consider submitting your error.
""");
}
}

@Override
public void init() {
logger.info("Initialize application");

logger.debug("Initializing properties...");
if (PropertiesLoader.initialize()) {
logger.debug("Loaded properties successfully");
} else
logger.debug("Failed to load properties.");

I18nUtils.setBundle(ResourceBundle.getBundle("lang.messages", PropertiesLoader.getLocale()));

logger.debug("Loading Program Controller");
if (!ProgramController.initialize()) {
logger.error("Failed to load Program Controller");
AlertHelper.showAlertAndWait(AlertType.ERROR, i18n(INIT_ERROR_MESSAGE), null, null, i18n(INIT_ERROR_TITLE),
i18n(INIT_ERROR_HEADER));
Platform.exit();
}
logger.debug("loading Program Controller successfully");

if (PropertiesLoader.isTutor()) {
logger.debug("Starting Tutor RMI server");
if (TutorController.initialize())
logger.debug("RMI server started");
else
logger.debug("Failed to initialize RMI server.");
}
}

@Override
public void start(Stage primaryStage) {
logger.info("Starting application");
logger.debug("Creating scene");
ProgramController.createAndShow(ProgramController.DEFAULT_ROBBI_FILE_NAME);
logger.debug("Scene creation done");
}

@Override
public void stop() {

logger.debug("Shutting down database connection");
HibernateUtils.shutdown();

if (PropertiesLoader.isTutor()) {
logger.debug("Stopping Tutor-Server.");
if (TutorController.shutdown())
logger.debug("Tutor RMI server stopped successfully.");
else
logger.debug("Failed to shutdown Tutor RMI server");
}

logger.debug("saving properties...");
if (PropertiesLoader.finish())
logger.debug("Properties saved");
else
logger.debug("Failed to save properties");

logger.info("Quitting application");
}
private static final String INIT_ERROR_MESSAGE = "Init.error.message";
private static final String INIT_ERROR_TITLE = "Init.error.title";
private static final String INIT_ERROR_HEADER = "Init.error.header";

/**
* Application entry point
*
* @param args the arguments from the command line
*/
public static void main(String[] args) {
try {
launch(args);
} catch (Exception e) {
logger.error("Failed to load application", e);
JOptionPane.showMessageDialog(null, """
Failed to load application.
Further information can be obtained running the
application in the command line.
Please consider submitting your error.
""");
}
}

@Override
public void init() {
logger.info("Initialize application");

logger.debug("Initializing properties...");
if (PropertiesLoader.initialize()) {
logger.debug("Loaded properties successfully");
} else
logger.debug("Failed to load properties.");

I18nUtils.setBundle(ResourceBundle.getBundle("lang.messages", PropertiesLoader.getLocale()));

logger.debug("Loading Program Controller");
if (!ProgramController.initialize()) {
logger.error("Failed to load Program Controller");
AlertHelper.showAlertAndWait(AlertType.ERROR, i18n(INIT_ERROR_MESSAGE), null, null, i18n(INIT_ERROR_TITLE),
i18n(INIT_ERROR_HEADER));
Platform.exit();
}
logger.debug("loading Program Controller successfully");

if (PropertiesLoader.isTutor()) {
logger.debug("Starting Tutor RMI server");
if (TutorController.initialize())
logger.debug("RMI server started");
else
logger.debug("Failed to initialize RMI server.");
}
}

@Override
public void start(Stage primaryStage) {
logger.info("Starting application");
logger.debug("Creating scene");
ProgramController.createAndShow(ProgramController.DEFAULT_ROBBI_FILE_NAME);
logger.debug("Scene creation done");
}

@Override
public void stop() {

logger.debug("Shutting down database connection");
HibernateUtils.shutdown();

if (PropertiesLoader.isTutor()) {
logger.debug("Stopping Tutor-Server.");
if (TutorController.shutdown())
logger.debug("Tutor RMI server stopped successfully.");
else
logger.debug("Failed to shutdown Tutor RMI server");
}

logger.debug("saving properties...");
if (PropertiesLoader.finish())
logger.debug("Properties saved");
else
logger.debug("Failed to save properties");

logger.info("Quitting application");
}

}
107 changes: 53 additions & 54 deletions src/main/java/com/JayPi4c/RobbiSimulator/controller/ButtonState.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,68 @@
/**
* This class stores the state of the currently selected territory button state.
* The state should be modified by the editor tool buttons.
*
* <p>
* If the TerritoryEventHandler does register a click, the eventHandler gets the
* current state from this class
*
* @author Jonas Pohl
*
* @author Jonas Pohl
*/
@Getter
@Setter
public class ButtonState {

/**
* Constant for the ButtonState NONE.
*/
public static final int NONE = -1;
/**
* Constant for the ButtonState ROBBI.
*/
public static final int ROBBI = 0;
/**
* Constant for the ButtonState NONE.
*/
public static final int NONE = -1;
/**
* Constant for the ButtonState ROBBI.
*/
public static final int ROBBI = 0;

/**
* Constant for the ButtonState HOLLOW.
*/
public static final int HOLLOW = 1;
/**
* Constant for the ButtonState PILE_OF_SCRAP.
*/
public static final int PILE_OF_SCRAP = 2;
/**
* Constant for the ButtonState STOCKPILE.
*/
public static final int STOCKPILE = 3;
/**
* Constant for the ButtonState ACCU.
*/
public static final int ACCU = 4;
/**
* Constant for the ButtonState SCREW.
*/
public static final int SCREW = 5;
/**
* Constant for the ButtonState NUT.
*/
public static final int NUT = 6;
/**
* Constant for the ButtonState CLEAR.
*/
public static final int CLEAR = 7;
/**
* Constant for the ButtonState HOLLOW.
*/
public static final int HOLLOW = 1;
/**
* Constant for the ButtonState PILE_OF_SCRAP.
*/
public static final int PILE_OF_SCRAP = 2;
/**
* Constant for the ButtonState STOCKPILE.
*/
public static final int STOCKPILE = 3;
/**
* Constant for the ButtonState ACCU.
*/
public static final int ACCU = 4;
/**
* Constant for the ButtonState SCREW.
*/
public static final int SCREW = 5;
/**
* Constant for the ButtonState NUT.
*/
public static final int NUT = 6;
/**
* Constant for the ButtonState CLEAR.
*/
public static final int CLEAR = 7;

@Getter
@Setter
private int selected;
private int selected;

/**
* Creates a new ButtonState and sets the selected state to NONE
*/
public ButtonState() {
selected = NONE;
}
/**
* Creates a new ButtonState and sets the selected state to NONE
*/
public ButtonState() {
selected = NONE;
}

/**
* reset the currently selected state to NONE
*/
public void deselect() {
selected = NONE;
}
/**
* reset the currently selected state to NONE
*/
public void deselect() {
selected = NONE;
}

}
Loading

0 comments on commit a5fe762

Please sign in to comment.