Moved the LoginDialogController class inside the LoginDialog class
This commit is contained in:
parent
0b05d54953
commit
2b09a2dbde
@ -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) {
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.CheckBox?>
|
||||
<?import javafx.scene.control.DialogPane?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.PasswordField?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
@ -12,52 +13,37 @@
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<VBox maxHeight="-Infinity" maxWidth="-Infinity"
|
||||
minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
|
||||
prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1"
|
||||
xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="envoy.client.ui.LoginDialogController">
|
||||
<children>
|
||||
<Label text="User Login">
|
||||
<font>
|
||||
<Font size="26.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<GridPane>
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES"
|
||||
minWidth="10.0" percentWidth="40.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES"
|
||||
minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0"
|
||||
vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0"
|
||||
vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0"
|
||||
vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label text="User Name:" />
|
||||
<Label text="Password" GridPane.rowIndex="1" />
|
||||
<Label text="Repeat Password:" visible="false"
|
||||
GridPane.rowIndex="2" fx:id="repeatPasswordLabel" />
|
||||
<TextField GridPane.columnIndex="1" />
|
||||
<PasswordField GridPane.columnIndex="1"
|
||||
GridPane.rowIndex="1" fx:id="repeatPasswordField"/>
|
||||
<PasswordField visible="false"
|
||||
GridPane.columnIndex="1" GridPane.rowIndex="2" fx:id="repeatPasswordField"/>
|
||||
</children>
|
||||
</GridPane>
|
||||
<CheckBox mnemonicParsing="false" text="Register" fx:id="registerCheckBox" onAction="#registerCheckboxChanged"/>
|
||||
<HBox prefHeight="100.0" prefWidth="200.0">
|
||||
<children>
|
||||
<Button cancelButton="true" mnemonicParsing="false"
|
||||
text="Cancel" onAction="#cancelButtonClicked"/>
|
||||
<Button defaultButton="true" mnemonicParsing="false"
|
||||
text="Submit" disable="true" onAction="#submitButtonClicked"/>
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
</VBox>
|
||||
|
||||
<DialogPane xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="envoy.client.ui.LoginDialog$Controller">
|
||||
<content>
|
||||
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0">
|
||||
<children>
|
||||
<Label text="User Login">
|
||||
<font>
|
||||
<Font size="26.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<GridPane>
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="40.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label text="User Name:" />
|
||||
<Label text="Password" GridPane.rowIndex="1" />
|
||||
<Label fx:id="repeatPasswordLabel" text="Repeat Password:" visible="false" GridPane.rowIndex="2" />
|
||||
<TextField fx:id="userTextField" GridPane.columnIndex="1" />
|
||||
<PasswordField fx:id="repeatPasswordField" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||
<PasswordField fx:id="repeatPasswordField" visible="false" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||
</children>
|
||||
</GridPane>
|
||||
<CheckBox fx:id="registerCheckBox" mnemonicParsing="false" onAction="#registerCheckboxChanged" text="Register" />
|
||||
</children>
|
||||
</VBox>
|
||||
</content>
|
||||
</DialogPane>
|
||||
|
70
src/main/java/envoy/client/ui/LoginDialog.java
Normal file
70
src/main/java/envoy/client/ui/LoginDialog.java
Normal file
@ -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: <strong>envoy-client</strong><br>
|
||||
* File: <strong>LoginDialog.java</strong><br>
|
||||
* Created: <strong>03.04.2020</strong><br>
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since Envoy Client v0.1-beta
|
||||
*/
|
||||
public final class LoginDialog extends Dialog<Void> {
|
||||
|
||||
/**
|
||||
* 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.<DialogPane>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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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: <strong>envoy-client</strong><br>
|
||||
* File: <strong>LoginDialogController.java</strong><br>
|
||||
* Created: <strong>03.04.2020</strong><br>
|
||||
*
|
||||
* @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(); }
|
||||
}
|
@ -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"));
|
||||
|
Reference in New Issue
Block a user