Implemented ContactSearchScene completely
additionally added default keyboard shortcuts for all buttons
This commit is contained in:
parent
33abd461a5
commit
a0e11d99ca
@ -25,6 +25,7 @@ import envoy.data.MessageBuilder;
|
|||||||
import envoy.event.EventBus;
|
import envoy.event.EventBus;
|
||||||
import envoy.event.MessageStatusChangeEvent;
|
import envoy.event.MessageStatusChangeEvent;
|
||||||
import envoy.event.UserStatusChangeEvent;
|
import envoy.event.UserStatusChangeEvent;
|
||||||
|
import envoy.event.contact.ContactOperationEvent;
|
||||||
import envoy.util.EnvoyLog;
|
import envoy.util.EnvoyLog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,9 +91,25 @@ public final class ChatSceneController {
|
|||||||
// Update UI if in current chat
|
// Update UI if in current chat
|
||||||
if (currentChat != null && message.getSenderID() == currentChat.getRecipient().getID()) Platform.runLater(() -> messageList.refresh());
|
if (currentChat != null && message.getSenderID() == currentChat.getRecipient().getID()) Platform.runLater(() -> messageList.refresh());
|
||||||
});
|
});
|
||||||
|
|
||||||
// Listen to user status changes
|
// Listen to user status changes
|
||||||
eventBus.register(UserStatusChangeEvent.class, e -> Platform.runLater(() -> userList.refresh()));
|
eventBus.register(UserStatusChangeEvent.class, e -> Platform.runLater(userList::refresh));
|
||||||
|
|
||||||
|
// Listen to contacts changes
|
||||||
|
eventBus.register(ContactOperationEvent.class, e -> {
|
||||||
|
final var contact = e.get();
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
switch (e.getOperationType()) {
|
||||||
|
case ADD:
|
||||||
|
localDB.getUsers().put(contact.getName(), contact);
|
||||||
|
localDB.getChats().add(new Chat(contact));
|
||||||
|
userList.getItems().add(contact);// TODO might cause contact duplication
|
||||||
|
break;
|
||||||
|
case REMOVE:
|
||||||
|
// TODO add deletion capability
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializeData(SceneContext sceneContext, LocalDB localDB, Client client, WriteProxy writeProxy) {
|
void initializeData(SceneContext sceneContext, LocalDB localDB, Client client, WriteProxy writeProxy) {
|
||||||
@ -118,10 +135,11 @@ public final class ChatSceneController {
|
|||||||
.stream()
|
.stream()
|
||||||
.filter(c -> c.getRecipient().getID() == user.getID())
|
.filter(c -> c.getRecipient().getID() == user.getID())
|
||||||
.findAny()
|
.findAny()
|
||||||
.orElseGet(() -> { var chat = new Chat(user); localDB.getChats().add(chat); return chat; });
|
.orElseGet(() -> { final var chat = new Chat(user); localDB.getChats().add(chat); return chat; });
|
||||||
|
|
||||||
messageList.setItems(FXCollections.observableList(currentChat.getMessages()));
|
messageList.setItems(FXCollections.observableList(currentChat.getMessages()));
|
||||||
}
|
}
|
||||||
|
messageTextArea.setDisable(currentChat == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@ -132,7 +150,17 @@ public final class ChatSceneController {
|
|||||||
try {
|
try {
|
||||||
sceneContext.load(SceneContext.SceneInfo.SETTINGS_SCENE);
|
sceneContext.load(SceneContext.SceneInfo.SETTINGS_SCENE);
|
||||||
sceneContext.<SettingsSceneController>getController().initializeData(sceneContext);
|
sceneContext.<SettingsSceneController>getController().initializeData(sceneContext);
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void addContactButtonClicked() {
|
||||||
|
try {
|
||||||
|
sceneContext.load(SceneContext.SceneInfo.CONTACT_SEARCH_SCENE);
|
||||||
|
sceneContext.<ContactSearchSceneController>getController().initializeData(sceneContext);
|
||||||
|
} catch (final IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,7 +210,7 @@ public final class ChatSceneController {
|
|||||||
// Request a new ID generator if all IDs were used
|
// Request a new ID generator if all IDs were used
|
||||||
if (!localDB.getIDGenerator().hasNext() && client.isOnline()) client.requestIdGenerator();
|
if (!localDB.getIDGenerator().hasNext() && client.isOnline()) client.requestIdGenerator();
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
logger.log(Level.SEVERE, "Error sending message", e);
|
logger.log(Level.SEVERE, "Error sending message", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
117
src/main/java/envoy/client/ui/ContactSearchSceneController.java
Normal file
117
src/main/java/envoy/client/ui/ContactSearchSceneController.java
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
package envoy.client.ui;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
|
||||||
|
import envoy.client.event.SendEvent;
|
||||||
|
import envoy.data.Contact;
|
||||||
|
import envoy.event.ElementOperation;
|
||||||
|
import envoy.event.EventBus;
|
||||||
|
import envoy.event.contact.ContactOperationEvent;
|
||||||
|
import envoy.event.contact.ContactSearchRequest;
|
||||||
|
import envoy.event.contact.ContactSearchResult;
|
||||||
|
import envoy.util.EnvoyLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: <strong>envoy-client</strong><br>
|
||||||
|
* File: <strong>ContactSearchSceneController.java</strong><br>
|
||||||
|
* Created: <strong>07.06.2020</strong><br>
|
||||||
|
*
|
||||||
|
* @author Leon Hofmeister
|
||||||
|
* @since Envoy Client v0.1-beta
|
||||||
|
*/
|
||||||
|
public class ContactSearchSceneController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button backButton;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button clearButton;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button searchButton;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField searchBar;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ListView<Contact> contactList;
|
||||||
|
|
||||||
|
private SceneContext sceneContext;
|
||||||
|
|
||||||
|
private static EventBus eventBus = EventBus.getInstance();
|
||||||
|
private static final Logger logger = EnvoyLog.getLogger(ChatSceneController.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param sceneContext enables the user to return to the chat scene
|
||||||
|
* @since Envoy Client v0.1-beta
|
||||||
|
*/
|
||||||
|
public void initializeData(SceneContext sceneContext) { this.sceneContext = sceneContext; }
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void initialize() {
|
||||||
|
contactList.setCellFactory(e -> new UserListCell());
|
||||||
|
eventBus.register(ContactSearchResult.class, response -> Optional.of(response.get()).ifPresent(list -> contactList.getItems().addAll(list)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables the clear and search button if no text is present in the search bar.
|
||||||
|
*
|
||||||
|
* @since Envoy Client v0.1-beta
|
||||||
|
*/
|
||||||
|
@FXML
|
||||||
|
private void checkClearButton() {
|
||||||
|
final var containsContent = searchBar.getText().strip().isEmpty();
|
||||||
|
clearButton.setDisable(containsContent);
|
||||||
|
searchButton.setDisable(containsContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a {@link ContactSearchRequest} to the server.
|
||||||
|
*
|
||||||
|
* @since Envoy Client v0.1-beta
|
||||||
|
*/
|
||||||
|
@FXML
|
||||||
|
private void suggestContacts() { eventBus.dispatch(new SendEvent(new ContactSearchRequest(searchBar.getText()))); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the text in the search bar and the items shown in the list.
|
||||||
|
* Additionally disables both clear and search button.
|
||||||
|
*
|
||||||
|
* @since Envoy Client v0.1-beta
|
||||||
|
*/
|
||||||
|
@FXML
|
||||||
|
private void clear() {
|
||||||
|
searchBar.setText(null);
|
||||||
|
contactList.getItems().clear();
|
||||||
|
clearButton.setDisable(true);
|
||||||
|
searchButton.setDisable(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends an {@link ContactOperationEvent} for every selected contact to the
|
||||||
|
* server.
|
||||||
|
*
|
||||||
|
* @since Envoy Client v0.1-beta
|
||||||
|
*/
|
||||||
|
@FXML
|
||||||
|
private void contactListClicked() {
|
||||||
|
Optional.ofNullable(contactList.getSelectionModel().getSelectedItems()).ifPresent(contacts -> contacts.forEach(contact -> {
|
||||||
|
final var event = new ContactOperationEvent(contact, ElementOperation.ADD);
|
||||||
|
// Sends the event to the server
|
||||||
|
eventBus.dispatch(new SendEvent(event));
|
||||||
|
// Updates the UI
|
||||||
|
eventBus.dispatch(event);
|
||||||
|
logger.log(Level.INFO, "Added contact " + contact);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void backButtonClicked() { sceneContext.pop(); }
|
||||||
|
}
|
@ -24,14 +24,17 @@
|
|||||||
<children>
|
<children>
|
||||||
<ListView fx:id="userList" onMouseClicked="#userListClicked" prefHeight="211.0" prefWidth="300.0" GridPane.rowIndex="1" GridPane.rowSpan="2147483647" />
|
<ListView fx:id="userList" onMouseClicked="#userListClicked" prefHeight="211.0" prefWidth="300.0" GridPane.rowIndex="1" GridPane.rowSpan="2147483647" />
|
||||||
<Label fx:id="contactLabel" prefHeight="16.0" prefWidth="250.0" text="Select a contact to chat with" GridPane.columnSpan="2" />
|
<Label fx:id="contactLabel" prefHeight="16.0" prefWidth="250.0" text="Select a contact to chat with" GridPane.columnSpan="2" />
|
||||||
<Button fx:id="settingsButton" mnemonicParsing="false" onAction="#settingsButtonClicked" text="Settings" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.valignment="CENTER"/>
|
<Button fx:id="settingsButton" mnemonicParsing="true" onAction="#settingsButtonClicked" text="_Settings" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
|
||||||
<ListView fx:id="messageList" prefHeight="257.0" prefWidth="155.0" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="1" GridPane.rowSpan="2" />
|
<ListView fx:id="messageList" prefHeight="257.0" prefWidth="155.0" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="1" GridPane.rowSpan="2" />
|
||||||
<Button fx:id="postButton" defaultButton="true" disable="true" mnemonicParsing="false" onAction="#postButtonClicked" prefHeight="10.0" prefWidth="65.0" text="Post" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER" />
|
<Button fx:id="postButton" defaultButton="true" disable="true" mnemonicParsing="true" onAction="#postButtonClicked" prefHeight="10.0" prefWidth="65.0" text="_Post" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER" />
|
||||||
<TextArea fx:id="messageTextArea" onKeyReleased="#messageTextUpdated" onInputMethodTextChanged="#messageTextUpdated" prefHeight="200.0" prefWidth="200.0" wrapText="true" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
<TextArea fx:id="messageTextArea" disable="true" onInputMethodTextChanged="#messageTextUpdated" onKeyReleased="#messageTextUpdated" prefHeight="200.0" prefWidth="200.0" wrapText="true" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
||||||
<Button mnemonicParsing="false" text="Add Contacts" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER">
|
<Button mnemonicParsing="true" onAction="#addContactButtonClicked" text="_Add Contacts" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER">
|
||||||
<padding>
|
<padding>
|
||||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
</padding>
|
</padding>
|
||||||
|
<GridPane.margin>
|
||||||
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
|
</GridPane.margin>
|
||||||
</Button>
|
</Button>
|
||||||
</children>
|
</children>
|
||||||
</GridPane>
|
</GridPane>
|
||||||
|
@ -1,8 +1,67 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.ListView?>
|
||||||
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.control.Tooltip?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
<?import javafx.scene.layout.Pane?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
|
||||||
<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.ContactSearchSceneController"
|
|
||||||
<!-- TODO Add Nodes -->
|
|
||||||
</VBox>
|
|
||||||
|
|
||||||
|
<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.ContactSearchSceneController">
|
||||||
|
<children>
|
||||||
|
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
|
||||||
|
<children>
|
||||||
|
<TextField fx:id="searchBar" onInputMethodTextChanged="#checkClearButton" onKeyTyped="#checkClearButton" prefColumnCount="22" promptText="Enter username to search for">
|
||||||
|
<HBox.margin>
|
||||||
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
|
</HBox.margin>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
|
</padding>
|
||||||
|
<tooltip>
|
||||||
|
<Tooltip text="Enter a name. If an account by that name exists, it will be displayed below." wrapText="true" />
|
||||||
|
</tooltip>
|
||||||
|
</TextField>
|
||||||
|
<Button fx:id="clearButton" disable="true" mnemonicParsing="true" onAction="#clear" text="Clea_r">
|
||||||
|
<tooltip>
|
||||||
|
<Tooltip autoHide="true" text="Clears the text to the left and the elements below" wrapText="true" />
|
||||||
|
</tooltip>
|
||||||
|
</Button>
|
||||||
|
<Pane disable="true" maxWidth="20.0" prefWidth="20.0" visible="false">
|
||||||
|
<HBox.margin>
|
||||||
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
|
</HBox.margin>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
|
</padding>
|
||||||
|
</Pane>
|
||||||
|
<Button fx:id="searchButton" disable="true" defaultButton="true" mnemonicParsing="true" onAction="#suggestContacts" prefHeight="26.0" prefWidth="71.0" text="_Search" textOverrun="LEADING_WORD_ELLIPSIS">
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
|
</padding>
|
||||||
|
<HBox.margin>
|
||||||
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
|
</HBox.margin>
|
||||||
|
<tooltip>
|
||||||
|
<Tooltip autoHide="true" text="Search for accounts with the name entered to the left" wrapText="true" />
|
||||||
|
</tooltip>
|
||||||
|
</Button>
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
<ListView fx:id="contactList" onMouseClicked="#contactListClicked" prefHeight="314.0" prefWidth="600.0" />
|
||||||
|
<Button fx:id="backButton" cancelButton="true" mnemonicParsing="true" onAction="#backButtonClicked" text="_Back">
|
||||||
|
<VBox.margin>
|
||||||
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
|
</VBox.margin>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
|
</padding>
|
||||||
|
<tooltip>
|
||||||
|
<Tooltip autoHide="true" text="Takes you back to the screen where you can chat with others" wrapText="true" />
|
||||||
|
</tooltip>
|
||||||
|
</Button>
|
||||||
|
</children>
|
||||||
|
</VBox>
|
||||||
|
@ -36,12 +36,12 @@
|
|||||||
<Label fx:id="repeatPasswordLabel" text="Repeat Password:" visible="false" GridPane.rowIndex="2" />
|
<Label fx:id="repeatPasswordLabel" text="Repeat Password:" visible="false" GridPane.rowIndex="2" />
|
||||||
<TextField fx:id="userTextField" GridPane.columnIndex="1" />
|
<TextField fx:id="userTextField" GridPane.columnIndex="1" />
|
||||||
<PasswordField fx:id="passwordField" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
<PasswordField fx:id="passwordField" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||||
<PasswordField fx:id="repeatPasswordField" visible="false" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
<PasswordField fx:id="repeatPasswordField" promptText="Repeat the chosen password" visible="false" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||||
</children>
|
</children>
|
||||||
</GridPane>
|
</GridPane>
|
||||||
<CheckBox fx:id="registerCheckBox" mnemonicParsing="false" onAction="#registerCheckboxChanged" prefHeight="17.0" prefWidth="181.0" text="Register" />
|
<CheckBox fx:id="registerCheckBox" mnemonicParsing="true" onAction="#registerCheckboxChanged" prefHeight="17.0" prefWidth="181.0" text="_Register" />
|
||||||
<Label fx:id="connectionLabel" />
|
<Label fx:id="connectionLabel" />
|
||||||
<CheckBox fx:id="offlineCheckBox" layoutX="20.0" layoutY="144.0" mnemonicParsing="false" prefHeight="17.0" prefWidth="181.0" text="Offline mode" />
|
<CheckBox fx:id="offlineCheckBox" layoutX="20.0" layoutY="144.0" mnemonicParsing="true" prefHeight="17.0" prefWidth="181.0" text="_Offline mode" />
|
||||||
</children>
|
</children>
|
||||||
</VBox>
|
</VBox>
|
||||||
</content>
|
</content>
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<TitledPane fx:id="titledPane" collapsible="false" prefHeight="200.0" prefWidth="200.0" />
|
<TitledPane fx:id="titledPane" collapsible="false" prefHeight="200.0" prefWidth="200.0" />
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
<Button defaultButton="true" mnemonicParsing="false" onMouseClicked="#backButtonClicked" text="Back">
|
<Button defaultButton="true" mnemonicParsing="true" onMouseClicked="#backButtonClicked" text="_Back">
|
||||||
<opaqueInsets>
|
<opaqueInsets>
|
||||||
<Insets />
|
<Insets />
|
||||||
</opaqueInsets>
|
</opaqueInsets>
|
||||||
|
Reference in New Issue
Block a user