diff --git a/src/main/java/team/elrant/bubbles/gui/ChatPageApplication.java b/src/main/java/team/elrant/bubbles/gui/ChatPageApplication.java deleted file mode 100644 index fa43742..0000000 --- a/src/main/java/team/elrant/bubbles/gui/ChatPageApplication.java +++ /dev/null @@ -1,26 +0,0 @@ -package team.elrant.bubbles.gui; - -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Scene; -import javafx.stage.Stage; -import java.io.IOException; - -public class ChatPageApplication extends Application { - - public static void main(String[] args) { - launch(); - } - - @Override - public void start(@org.jetbrains.annotations.NotNull Stage primaryStage) throws IOException { - FXMLLoader fxmlLoader = new FXMLLoader(ChatPageApplication.class.getResource("ChatView.fxml")); - Scene scene = new Scene(fxmlLoader.load(),400,800); - primaryStage.setTitle("Chat"); - primaryStage.setScene(scene); - primaryStage.centerOnScreen(); - primaryStage.setResizable(false); - primaryStage.show(); - - } -} diff --git a/src/main/java/team/elrant/bubbles/gui/ChatViewApplication.java b/src/main/java/team/elrant/bubbles/gui/ChatViewApplication.java new file mode 100644 index 0000000..2bea8b9 --- /dev/null +++ b/src/main/java/team/elrant/bubbles/gui/ChatViewApplication.java @@ -0,0 +1,48 @@ +package team.elrant.bubbles.gui; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; +import team.elrant.bubbles.xmpp.ConnectedUser; + +public class ChatViewApplication extends Application { + private ConnectedUser connectedUser = null; + private String contactJid = null; + + public ChatViewApplication(ConnectedUser connectedUser, String contactJid) { + this.connectedUser = connectedUser; + this.contactJid = contactJid; + } + + @Override + public void start(Stage primaryStage) throws Exception { + 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); + } + }); + + AnchorPane root = fxmlLoader.load(); + Scene scene = new Scene(root, 400, 800); + + primaryStage.setTitle("Chat"); + primaryStage.setScene(scene); + primaryStage.centerOnScreen(); + primaryStage.setResizable(false); + primaryStage.show(); + } + + public static void main(String[] args) { + launch(args); + } +} + diff --git a/src/main/java/team/elrant/bubbles/gui/ChatPageController.java b/src/main/java/team/elrant/bubbles/gui/ChatViewController.java similarity index 79% rename from src/main/java/team/elrant/bubbles/gui/ChatPageController.java rename to src/main/java/team/elrant/bubbles/gui/ChatViewController.java index ce8c270..050858d 100644 --- a/src/main/java/team/elrant/bubbles/gui/ChatPageController.java +++ b/src/main/java/team/elrant/bubbles/gui/ChatViewController.java @@ -1,14 +1,12 @@ package team.elrant.bubbles.gui; import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextArea; import team.elrant.bubbles.xmpp.ConnectedUser; -import java.io.IOException; -public class ChatPageController{ +public class ChatViewController { @FXML private TextArea chatTextArea; @FXML @@ -18,13 +16,16 @@ public class ChatPageController{ @FXML private Label failedLoginLabel; private ConnectedUser connectedUser; - private String contactJid; - private String password; + private String contactJid; - public ChatPageController(ConnectedUser connectedUser,String contactJid,String password){ + public ChatViewController() { + // Default constructor + } + + + public ChatViewController(ConnectedUser connectedUser, String contactJid){ this.connectedUser = connectedUser; this.contactJid = contactJid; - this.password = password; } @FXML diff --git a/src/main/java/team/elrant/bubbles/gui/LoginController.java b/src/main/java/team/elrant/bubbles/gui/LoginController.java index 6c0a1f1..e60d5ae 100644 --- a/src/main/java/team/elrant/bubbles/gui/LoginController.java +++ b/src/main/java/team/elrant/bubbles/gui/LoginController.java @@ -6,6 +6,7 @@ import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; import team.elrant.bubbles.xmpp.ConnectedUser; import team.elrant.bubbles.xmpp.User; @@ -30,6 +31,7 @@ public class LoginController { protected void onSubmitButtonClick() { try { connectedUser = new ConnectedUser(username_field.getText(), password_field.getText(), "elrant.team"); + connectedUser.initializeConnection(); } catch (Exception e) { // e.printStackTrace(); // Only for debugging purposes failedLoginLabel.setVisible(true); @@ -37,11 +39,16 @@ protected void onSubmitButtonClick() { if (connectedUser != null && connectedUser.isLoggedIn()) { // Close the login window and proceed to the main application - failedLoginLabel.setVisible(false); - successfulLoginLabel.setVisible(true); - submitButton.getScene().getWindow().hide(); - connectedUser.disconnect(); - connectedUser.saveUserToFile("user.dat"); + Stage stage = (Stage) submitButton.getScene().getWindow(); + stage.close(); // Close the login window + + // Open the chat window + try { + ChatViewApplication chatViewApplication = new ChatViewApplication(connectedUser, "dummy@elrant.team"); + chatViewApplication.start(new Stage()); + } catch (Exception e) { + e.printStackTrace(); // Replace with more robust error handling in the future + } } } diff --git a/src/main/resources/team/elrant/bubbles/gui/ChatView.fxml b/src/main/resources/team/elrant/bubbles/gui/ChatView.fxml index 7defad7..614fd23 100644 --- a/src/main/resources/team/elrant/bubbles/gui/ChatView.fxml +++ b/src/main/resources/team/elrant/bubbles/gui/ChatView.fxml @@ -6,17 +6,10 @@ - //Text Area for chat