Skip to content

Commit

Permalink
Improve code quality (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
code-irisnk committed Mar 15, 2024
1 parent ede64de commit d890ba0
Show file tree
Hide file tree
Showing 11 changed files with 440 additions and 140 deletions.
204 changes: 204 additions & 0 deletions .idea/intellij-javadocs-4.0.1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,18 @@
<artifactId>smack-java8</artifactId>
<version>4.4.7</version>
</dependency>
<dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.23.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.23.1</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.1.0</version>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
requires smack.tcp;
requires smack.core;
requires org.jetbrains.annotations;
requires org.apache.logging.log4j;

opens team.elrant.bubbles.gui to javafx.fxml;
exports team.elrant.bubbles.gui;
Expand Down
53 changes: 33 additions & 20 deletions src/main/java/team/elrant/bubbles/gui/ChatViewApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import team.elrant.bubbles.xmpp.ConnectedUser;

/**
* The ChatViewApplication class is responsible for launching the chat application GUI.
* It initializes the primary stage with the ChatView.fxml layout and sets up the ChatViewController.
*/
public class ChatViewApplication extends Application {
private static final Logger logger = LogManager.getLogger(ChatViewApplication.class);

private final ConnectedUser connectedUser;
private final String contactJid;

/**
* Constructs a ChatViewApplication with the specified connected user and contact JID.
*
* @param connectedUser The connected user object.
* @param contactJid The JID of the contact to chat with.
* @param contactJid The JID of the contact to chat with.
*/
public ChatViewApplication(ConnectedUser connectedUser, String contactJid) {
this.connectedUser = connectedUser;
Expand All @@ -28,36 +34,43 @@ public ChatViewApplication(ConnectedUser connectedUser, String contactJid) {
/**
* The start method initializes the primary stage of the chat application.
* It loads the ChatView.fxml layout, sets up the ChatViewController, and displays the stage.
*
* @param primaryStage The primary stage of the application.
* @throws Exception If an error occurs during the initialization.
*/
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("ChatView.fxml"));
public void start(@NotNull Stage primaryStage) throws Exception {
try {
@NotNull FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("ChatView.fxml"));

// Set custom controller factory
fxmlLoader.setControllerFactory(param -> {
try {
// Instantiate the controller with the required properties
return new ChatViewController(connectedUser, contactJid);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
});
// Set custom controller factory
fxmlLoader.setControllerFactory(param -> {
try {
// Instantiate the controller with the required properties
return new ChatViewController(connectedUser, contactJid);
} catch (Exception e) {
logger.error("Error creating ChatViewController: " + e.getMessage());
throw new RuntimeException(e);
}
});

AnchorPane root = fxmlLoader.load();
Scene scene = new Scene(root, 400, 800);
AnchorPane root = fxmlLoader.load();
@NotNull Scene scene = new Scene(root, 400, 800);

primaryStage.setTitle("Chat");
primaryStage.setScene(scene);
primaryStage.centerOnScreen();
primaryStage.setResizable(false);
primaryStage.show();
primaryStage.setTitle("Chat");
primaryStage.setScene(scene);
primaryStage.centerOnScreen();
primaryStage.setResizable(false);
primaryStage.show();
} catch (Exception e) {
logger.error("Error starting ChatViewApplication: " + e.getMessage());
throw e;
}
}

/**
* The main method launches the JavaFX application.
*
* @param args The command-line arguments.
*/
public static void main(String[] args) {
Expand Down
Loading

0 comments on commit d890ba0

Please sign in to comment.