implemented groupCreationTab

This commit is contained in:
Maximilian P. Käfer 2020-08-23 20:15:52 +02:00
parent f77795edb1
commit bd75da1ab9
8 changed files with 85 additions and 112 deletions

View File

@ -55,13 +55,6 @@ public final class SceneContext {
*/ */
SETTINGS_SCENE("/fxml/SettingsScene.fxml"), SETTINGS_SCENE("/fxml/SettingsScene.fxml"),
/**
* The scene in which the group creation screen is displayed.
*
* @since Envoy Client v0.1-beta
*/
GROUP_CREATION_SCENE("/fxml/GroupCreationScene.fxml"),
/** /**
* The scene in which the login screen is displayed. * The scene in which the login screen is displayed.
* *

View File

@ -133,6 +133,9 @@ public final class ChatScene implements Restorable {
@FXML @FXML
private Tab contactSearchTab; private Tab contactSearchTab;
@FXML
private Tab groupCreationTab;
private LocalDB localDB; private LocalDB localDB;
private Client client; private Client client;
@ -184,6 +187,7 @@ public final class ChatScene implements Restorable {
try { try {
contactSearchTab.setContent(FXMLLoader.load(new File("src/main/resources/fxml/ContactSearchTab.fxml").toURI().toURL())); contactSearchTab.setContent(FXMLLoader.load(new File("src/main/resources/fxml/ContactSearchTab.fxml").toURI().toURL()));
groupCreationTab.setContent(FXMLLoader.load(new File("src/main/resources/fxml/GroupCreationTab.fxml").toURI().toURL()));
} catch (Exception e2) { } catch (Exception e2) {
e2.printStackTrace(); e2.printStackTrace();
} }
@ -400,6 +404,12 @@ public final class ChatScene implements Restorable {
// sceneContext.<ContactSearchScene>getController().initializeData(sceneContext, localDB); // sceneContext.<ContactSearchScene>getController().initializeData(sceneContext, localDB);
tabPane.getSelectionModel().select(1); tabPane.getSelectionModel().select(1);
} }
@FXML
private void groupCreationButtonClicked() {
//TODO: initialize Data
tabPane.getSelectionModel().select(2);
}
@FXML @FXML
private void voiceButtonClicked() { private void voiceButtonClicked() {

View File

@ -32,7 +32,7 @@ import envoy.util.EnvoyLog;
* <i>The actual search algorithm is implemented on the server. * <i>The actual search algorithm is implemented on the server.
* <p> * <p>
* To create a group, a button is available that loads the * To create a group, a button is available that loads the
* {@link GroupCreationScene}. * {@link GroupCreationTab}.
* <p> * <p>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>ContactSearchScene.java</strong><br> * File: <strong>ContactSearchScene.java</strong><br>
@ -50,10 +50,6 @@ public class ContactSearchTab {
@FXML @FXML
private ListView<User> userList; private ListView<User> userList;
private SceneContext sceneContext;
private LocalDB localDB;
private Alert alert = new Alert(AlertType.CONFIRMATION); private Alert alert = new Alert(AlertType.CONFIRMATION);
private User currentlySelectedUser; private User currentlySelectedUser;
@ -69,16 +65,6 @@ public class ContactSearchTab {
private static final EventBus eventBus = EventBus.getInstance(); private static final EventBus eventBus = EventBus.getInstance();
private static final Logger logger = EnvoyLog.getLogger(ChatScene.class); private static final Logger logger = EnvoyLog.getLogger(ChatScene.class);
/**
* @param sceneContext enables the user to return to the chat scene
* @param localDB the local database to which new contacts are added
* @since Envoy Client v0.1-beta
*/
public void initializeData(SceneContext sceneContext, LocalDB localDB) {
this.sceneContext = sceneContext;
this.localDB = localDB;
}
@FXML @FXML
private void initialize() { private void initialize() {
userList.setCellFactory(new ListCellFactory<>(ContactControl::new)); userList.setCellFactory(new ListCellFactory<>(ContactControl::new));

View File

@ -11,8 +11,8 @@ import javafx.scene.control.Alert.AlertType;
import envoy.client.data.Chat; import envoy.client.data.Chat;
import envoy.client.data.LocalDB; import envoy.client.data.LocalDB;
import envoy.client.event.BackEvent;
import envoy.client.event.SendEvent; import envoy.client.event.SendEvent;
import envoy.client.ui.ClearableTextField;
import envoy.client.ui.SceneContext; import envoy.client.ui.SceneContext;
import envoy.client.ui.listcell.ContactControl; import envoy.client.ui.listcell.ContactControl;
import envoy.client.ui.listcell.ListCellFactory; import envoy.client.ui.listcell.ListCellFactory;
@ -39,19 +39,17 @@ import envoy.util.Bounds;
* @author Maximilian K&auml;fer * @author Maximilian K&auml;fer
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public class GroupCreationScene { public class GroupCreationTab {
@FXML @FXML
private Button createButton; private Button createButton;
@FXML @FXML
private ClearableTextField groupNameField; private TextArea groupNameField;
@FXML @FXML
private ListView<User> userList; private ListView<User> userList;
private SceneContext sceneContext;
private LocalDB localDB; private LocalDB localDB;
private static final EventBus eventBus = EventBus.getInstance(); private static final EventBus eventBus = EventBus.getInstance();
@ -60,17 +58,14 @@ public class GroupCreationScene {
private void initialize() { private void initialize() {
userList.setCellFactory(new ListCellFactory<>(ContactControl::new)); userList.setCellFactory(new ListCellFactory<>(ContactControl::new));
userList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); userList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
groupNameField.setClearButtonListener(e -> { groupNameField.getTextField().clear(); createButton.setDisable(true); });
} }
/** /**
* @param sceneContext enables the user to return to the chat scene
* @param localDB the local database from which potential group members can * @param localDB the local database from which potential group members can
* be selected * be selected
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public void initializeData(SceneContext sceneContext, LocalDB localDB) { public void initializeData(LocalDB localDB) {
this.sceneContext = sceneContext;
this.localDB = localDB; this.localDB = localDB;
Platform.runLater(() -> userList.getItems() Platform.runLater(() -> userList.getItems()
.addAll(localDB.getChats() .addAll(localDB.getChats()
@ -89,7 +84,7 @@ public class GroupCreationScene {
*/ */
@FXML @FXML
private void userListClicked() { private void userListClicked() {
createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getTextField().getText().isBlank()); createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank());
} }
/** /**
@ -99,7 +94,7 @@ public class GroupCreationScene {
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
@FXML @FXML
private void textUpdated() { createButton.setDisable(groupNameField.getTextField().getText().isBlank()); } private void textUpdated() { createButton.setDisable(groupNameField.getText().isBlank()); }
/** /**
* Sends a {@link GroupCreation} to the server and closes this scene. * Sends a {@link GroupCreation} to the server and closes this scene.
@ -110,10 +105,10 @@ public class GroupCreationScene {
*/ */
@FXML @FXML
private void createButtonClicked() { private void createButtonClicked() {
final var name = groupNameField.getTextField().getText(); final var name = groupNameField.getText();
if (!Bounds.isValidContactName(name)) { if (!Bounds.isValidContactName(name)) {
new Alert(AlertType.ERROR, "The entered group name is not valid (" + Bounds.CONTACT_NAME_PATTERN + ")").showAndWait(); new Alert(AlertType.ERROR, "The entered group name is not valid (" + Bounds.CONTACT_NAME_PATTERN + ")").showAndWait();
groupNameField.getTextField().clear(); groupNameField.clear();
} else if (groupNameAlreadyPresent(name)) { } else if (groupNameAlreadyPresent(name)) {
final var alert = new Alert(AlertType.WARNING, "You already have a group with that name.", ButtonType.OK, ButtonType.CANCEL); final var alert = new Alert(AlertType.WARNING, "You already have a group with that name.", ButtonType.OK, ButtonType.CANCEL);
alert.setTitle("Create Group?"); alert.setTitle("Create Group?");
@ -135,7 +130,6 @@ public class GroupCreationScene {
private void createGroup(String name) { private void createGroup(String name) {
eventBus.dispatch(new SendEvent( eventBus.dispatch(new SendEvent(
new GroupCreation(name, userList.getSelectionModel().getSelectedItems().stream().map(User::getID).collect(Collectors.toSet())))); new GroupCreation(name, userList.getSelectionModel().getSelectedItems().stream().map(User::getID).collect(Collectors.toSet()))));
sceneContext.pop();
} }
/** /**
@ -156,5 +150,5 @@ public class GroupCreationScene {
} }
@FXML @FXML
private void backButtonClicked() { sceneContext.pop(); } private void backButtonClicked() { eventBus.dispatch(new BackEvent()); }
} }

View File

@ -68,7 +68,7 @@
<Insets /> <Insets />
</HBox.margin> </HBox.margin>
</Button> </Button>
<Button mnemonicParsing="false" prefWidth="100.0" text="New Group"> <Button mnemonicParsing="false" onAction="#groupCreationButtonClicked" prefWidth="100.0" text="New Group">
<HBox.margin> <HBox.margin>
<Insets /> <Insets />
</HBox.margin> </HBox.margin>
@ -108,6 +108,7 @@
<content> <content>
</content> </content>
</Tab> </Tab>
<Tab fx:id="groupCreationTab" text=""/>
</tabs> </tabs>
<GridPane.margin> <GridPane.margin>
<Insets right="1.0" /> <Insets right="1.0" />

View File

@ -1,73 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import envoy.client.ui.ClearableTextField?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.layout.HBox?>
<?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.controller.ContactSearchTab">
<children>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children>
<ClearableTextField fx:id="searchBar"
prefWidth="310.0">
<textField onInputMethodTextChanged="#sendRequest"
onKeyTyped="#sendRequest" prefColumnCount="22"
promptText="Enter username to search for">
</textField>
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="15.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>
</ClearableTextField>
<Button mnemonicParsing="false"
onAction="#newGroupButtonClicked" prefHeight="26.0"
prefWidth="139.0" text="New Group">
<HBox.margin>
<Insets bottom="5.0" left="30.0" right="5.0" top="5.0" />
</HBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Button>
</children>
</HBox>
<ListView fx:id="userList" onMouseClicked="#userListClicked"
prefHeight="314.0" prefWidth="600.0">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</ListView>
<Button cancelButton="true" mnemonicParsing="true"
onAction="#backButtonClicked" text="_Back">
<VBox.margin>
<Insets bottom="10.0" left="10.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>

View File

@ -15,7 +15,7 @@
minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="envoy.client.ui.controller.GroupCreationScene"> fx:controller="envoy.client.ui.controller.GroupCreationTab
<children> <children>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0"> <HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children> <children>

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="envoy.client.ui.controller.GroupCreationTab">
<VBox id="search-panel" alignment="TOP_CENTER" prefHeight="3000.0" prefWidth="316.0">
<children>
<Label alignment="CENTER" text="Create New Group" textAlignment="CENTER" textFill="WHITE">
<font>
<Font size="18.0" />
</font>
<VBox.margin>
<Insets top="8.0" />
</VBox.margin>
</Label>
<Label id="contact-search-enter-container" maxHeight="30.0" minHeight="30.0" prefHeight="30.0" prefWidth="325.0">
<graphic>
<TextArea id="contactSearchInput" fx:id="groupNameField" focusTraversable="false" maxHeight="30.0" minHeight="30.0" onInputMethodTextChanged="#textUpdated" onKeyTyped="#textUpdated" prefHeight="30.0" prefWidth="200.0" promptText="Enter Group Name">
<font>
<Font size="14.0" />
</font>
<padding>
<Insets left="12.0" right="12.0" />
</padding>
</TextArea>
</graphic>
<VBox.margin>
<Insets left="10.0" right="10.0" top="5.0" />
</VBox.margin>
</Label>
<HBox id="underline" alignment="TOP_CENTER" prefWidth="200.0" spacing="5.0">
<children>
<Button fx:id="createButton" onAction="#createButtonClicked" maxHeight="30.0" maxWidth="-Infinity" minHeight="30.0" mnemonicParsing="false" prefHeight="30.0" text="Create" />
<Button maxHeight="30.0" maxWidth="-Infinity" minHeight="30.0" mnemonicParsing="false" onAction="#backButtonClicked" prefHeight="30.0" text="Cancel" />
</children>
<VBox.margin>
<Insets left="10.0" right="10.0" />
</VBox.margin>
<padding>
<Insets bottom="17.0" top="5.0" />
</padding>
</HBox>
<ListView id="chatList" fx:id="userList" focusTraversable="false" onMouseClicked="#userListClicked" prefWidth="316.0" VBox.vgrow="ALWAYS">
<contextMenu>
<ContextMenu anchorLocation="CONTENT_TOP_LEFT" />
</contextMenu>
<padding>
<Insets bottom="5.0" left="5.0" right="2.0" top="5.0" />
</padding>
</ListView>
</children>
</VBox>
</AnchorPane>