diff --git a/src/main/java/envoy/client/net/Client.java b/src/main/java/envoy/client/net/Client.java
index 9ae69fb..50019f4 100644
--- a/src/main/java/envoy/client/net/Client.java
+++ b/src/main/java/envoy/client/net/Client.java
@@ -46,9 +46,10 @@ public class Client implements Closeable {
private volatile Set extends Contact> contacts;
private volatile boolean rejected;
- // Configuration and logging
- private static final ClientConfig config = ClientConfig.getInstance();
- private static final Logger logger = EnvoyLog.getLogger(Client.class);
+ // Configuration, logging and event management
+ private static final ClientConfig config = ClientConfig.getInstance();
+ private static final Logger logger = EnvoyLog.getLogger(Client.class);
+ private static final EventBus eventBus = EventBus.getInstance();
/**
* Enters the online mode by acquiring a user ID from the server. As a
@@ -80,7 +81,7 @@ public class Client implements Closeable {
// Register user creation processor, contact list processor and message cache
receiver.registerProcessor(User.class, sender -> { this.sender = sender; contacts = sender.getContacts(); });
receiver.registerProcessor(Message.class, receivedMessageCache);
- receiver.registerProcessor(HandshakeRejectionEvent.class, evt -> { rejected = true; EventBus.getInstance().dispatch(evt); });
+ receiver.registerProcessor(HandshakeRejectionEvent.class, evt -> { rejected = true; eventBus.dispatch(evt); });
rejected = false;
@@ -146,20 +147,19 @@ public class Client implements Closeable {
receiver.registerProcessor(IDGenerator.class, localDB::setIDGenerator);
// Process name changes
- receiver.registerProcessor(NameChangeEvent.class, evt -> { localDB.replaceContactName(evt); EventBus.getInstance().dispatch(evt); });
+ receiver.registerProcessor(NameChangeEvent.class, evt -> { localDB.replaceContactName(evt); eventBus.dispatch(evt); });
// Process contact searches
- receiver.registerProcessor(ContactSearchResult.class, EventBus.getInstance()::dispatch);
+ receiver.registerProcessor(ContactSearchResult.class, eventBus::dispatch);
receiver.registerProcessor(Contact.class,
- contacts -> EventBus.getInstance()
- .dispatch(new ContactOperationEvent(contacts.getContacts().iterator().next(), ElementOperation.ADD)));
+ contacts -> eventBus.dispatch(new ContactOperationEvent(contacts.getContacts().iterator().next(), ElementOperation.ADD)));
// Process group size changes
- receiver.registerProcessor(GroupResizeEvent.class, evt -> { localDB.updateGroup(evt); EventBus.getInstance().dispatch(evt); });
+ receiver.registerProcessor(GroupResizeEvent.class, evt -> { localDB.updateGroup(evt); eventBus.dispatch(evt); });
// Send event
- EventBus.getInstance().register(SendEvent.class, evt -> {
+ eventBus.register(SendEvent.class, evt -> {
try {
sendEvent(evt.get());
} catch (IOException e) {
diff --git a/src/main/java/envoy/client/ui/LoginDialog.fxml b/src/main/java/envoy/client/ui/LoginDialog.fxml
index 45b2d60..30020e9 100644
--- a/src/main/java/envoy/client/ui/LoginDialog.fxml
+++ b/src/main/java/envoy/client/ui/LoginDialog.fxml
@@ -2,6 +2,7 @@
+
@@ -12,52 +13,37 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/envoy/client/ui/LoginDialog.java b/src/main/java/envoy/client/ui/LoginDialog.java
new file mode 100644
index 0000000..cb9453e
--- /dev/null
+++ b/src/main/java/envoy/client/ui/LoginDialog.java
@@ -0,0 +1,70 @@
+package envoy.client.ui;
+
+import java.io.IOException;
+
+import javafx.application.Platform;
+import javafx.fxml.FXML;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.control.*;
+
+/**
+ * Project: envoy-client
+ * File: LoginDialog.java
+ * Created: 03.04.2020
+ *
+ * @author Kai S. K. Engelbart
+ * @since Envoy Client v0.1-beta
+ */
+public final class LoginDialog extends Dialog {
+
+ /**
+ * Loads the login dialog using the FXML file {@code LoginDialog.fxml}.
+ *
+ * @throws IOException if an exception occurs during loading
+ * @since Envoy Client v0.1-beta
+ */
+ public LoginDialog() throws IOException {
+ final var dialogPane = FXMLLoader.load(getClass().getResource("LoginDialog.fxml"));
+
+ // Configure buttons
+ dialogPane.getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK);
+
+ setDialogPane(dialogPane);
+ }
+
+ public static class Controller {
+
+ @FXML
+ private TextField userTextField;
+
+ @FXML
+ private PasswordField passwordField;
+
+ @FXML
+ private PasswordField repeatPasswordField;
+
+ @FXML
+ private Label repeatPasswordLabel;
+
+ @FXML
+ private CheckBox registerCheckBox;
+
+ @FXML
+ private void initialize() {
+
+ // Set initial cursor
+ Platform.runLater(userTextField::requestFocus);
+ }
+
+ @FXML
+ private void registerCheckboxChanged() {
+
+ // Make repeat password field and label visible / invisible
+ repeatPasswordField.setVisible(registerCheckBox.isSelected());
+ repeatPasswordLabel.setVisible(registerCheckBox.isSelected());
+
+ // Clear repeat password field if registration cancelled
+ if (!registerCheckBox.isSelected()) repeatPasswordField.clear();
+ }
+ }
+}
diff --git a/src/main/java/envoy/client/ui/LoginDialogController.java b/src/main/java/envoy/client/ui/LoginDialogController.java
deleted file mode 100644
index 4513809..0000000
--- a/src/main/java/envoy/client/ui/LoginDialogController.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package envoy.client.ui;
-
-import javafx.event.ActionEvent;
-import javafx.fxml.FXML;
-import javafx.scene.Node;
-import javafx.scene.control.CheckBox;
-import javafx.scene.control.Label;
-import javafx.scene.control.PasswordField;
-import javafx.stage.Stage;
-
-/**
- * Project: envoy-client
- * File: LoginDialogController.java
- * Created: 03.04.2020
- *
- * @author Kai S. K. Engelbart
- * @since Envoy Client v0.1-beta
- */
-public final class LoginDialogController {
-
- @FXML
- private PasswordField passwordField;
-
- @FXML
- private PasswordField repeatPasswordField;
-
- @FXML
- private Label repeatPasswordLabel;
-
- @FXML
- private CheckBox registerCheckBox;
-
- @FXML
- private void registerCheckboxChanged() {
-
- // Make repeat password field and label visible / invisible
- repeatPasswordField.setVisible(registerCheckBox.isSelected());
- repeatPasswordLabel.setVisible(registerCheckBox.isSelected());
-
- // Clear repeat password field if registration cancelled
- if (!registerCheckBox.isSelected()) repeatPasswordField.clear();
- }
-
- @FXML
- private void submitButtonClicked() {
-
- }
-
- @FXML
- private void cancelButtonClicked(ActionEvent e) { closeStage(e); }
-
- private void closeStage(ActionEvent e) { ((Stage) ((Node) e.getSource()).getScene().getWindow()).close(); }
-}
diff --git a/src/main/java/envoy/client/ui/Startup.java b/src/main/java/envoy/client/ui/Startup.java
index e007058..94f1b38 100644
--- a/src/main/java/envoy/client/ui/Startup.java
+++ b/src/main/java/envoy/client/ui/Startup.java
@@ -12,7 +12,6 @@ import javax.swing.JOptionPane;
import envoy.client.data.*;
import envoy.client.net.Client;
import envoy.client.net.WriteProxy;
-import envoy.client.ui.container.LoginDialog;
import envoy.data.Message;
import envoy.data.User;
import envoy.data.User.UserStatus;
@@ -91,9 +90,18 @@ public final class Startup extends Application {
// Initialize client and unread message cache
client = new Client();
cache = new Cache<>();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void start(Stage stage) throws Exception {
// Try to connect to the server
- new LoginDialog(client, localDB, cache);
+ // new LoginDialog(client, localDB, cache);
+ new LoginDialog().showAndWait();
+ System.exit(0);
// Set client user in local database
localDB.setUser(client.getSender());
@@ -128,13 +136,6 @@ public final class Startup extends Application {
.filter(u -> u instanceof User && u != localDB.getUser())
.map(User.class::cast)
.forEach(u -> u.setStatus(UserStatus.OFFLINE));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void start(Stage stage) throws Exception {
// Prepare stage and load ChatScene
var loader = new FXMLLoader(getClass().getResource("ChatScene.fxml"));