From da309098b7419c8461f060477b4114d56a118492 Mon Sep 17 00:00:00 2001 From: DieGurke Date: Mon, 24 Aug 2020 21:54:25 +0200 Subject: [PATCH] Added offline mode warning and note --- .../envoy/client/ui/controller/ChatScene.java | 44 ++++++++++++++----- client/src/main/resources/css/dark.css | 2 +- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index 0167b3d..d7ff678 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -22,15 +22,15 @@ import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; +import javafx.geometry.Pos; import javafx.scene.control.*; import javafx.scene.control.Alert.AlertType; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; -import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.GridPane; -import javafx.scene.layout.VBox; +import javafx.scene.layout.*; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.FileChooser; @@ -183,12 +183,20 @@ public final class ChatScene implements Restorable { clip.setArcWidth(43); clientProfilePic.setClip(clip); - try { - 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) { - e2.printStackTrace(); - } + Platform.runLater(() -> { + if(client.isOnline()) { + try { + 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) { + e2.printStackTrace(); + } + } else { + contactSearchTab.setContent(createOfflineNote()); + groupCreationTab.setContent(createOfflineNote()); + } + }); + //Listen to backEvents eventBus.register(BackEvent.class, e -> tabPane.getSelectionModel().select(0)); @@ -263,6 +271,22 @@ public final class ChatScene implements Restorable { } }); } + + private AnchorPane createOfflineNote() { + AnchorPane anc = new AnchorPane(); + VBox vBox = new VBox(); + vBox.setAlignment(Pos.TOP_CENTER); + vBox.setPrefWidth(316); + Label label = new Label("You have to be online!"); + label.setPadding(new Insets(50, 0, 5, 0)); + Button button = new Button("OK"); + button.setOnAction(e -> eventBus.dispatch(new BackEvent())); + vBox.getChildren().add(label); + vBox.getChildren().add(button); + anc.getChildren().add(vBox); + anc.setId("note-background"); + return anc; + } /** * Initializes all {@code SystemCommands} used in {@code ChatScene}. @@ -398,8 +422,6 @@ public final class ChatScene implements Restorable { */ @FXML private void addContactButtonClicked() { -// sceneContext.load(SceneContext.SceneInfo.CONTACT_SEARCH_SCENE); -// sceneContext.getController().initializeData(sceneContext, localDB); tabPane.getSelectionModel().select(1); } diff --git a/client/src/main/resources/css/dark.css b/client/src/main/resources/css/dark.css index de35c5a..6c0c7b0 100644 --- a/client/src/main/resources/css/dark.css +++ b/client/src/main/resources/css/dark.css @@ -46,7 +46,7 @@ -fx-background-color: rgb(25, 25, 25); } -#chatList, #topBar, #search-panel { +#chatList, #topBar, #search-panel, #note-background { -fx-background-color: #303030; }