debugUi: send chat messages

This commit is contained in:
bixilon 2020-06-15 13:37:26 +02:00
parent 3f414fb6df
commit 950915eb9f
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 24 additions and 9 deletions

View File

@ -37,6 +37,7 @@ public class DebugWindow {
// start gui // start gui
uiThread = new Thread(() -> { uiThread = new Thread(() -> {
DebugMainWindow.setHandler(handler); DebugMainWindow.setHandler(handler);
DebugMainWindow.setConnection(connection);
DebugMainWindow.initAndShow(); DebugMainWindow.initAndShow();
}); });
uiThread.start(); uiThread.start();

View File

@ -14,12 +14,14 @@
package de.bixilon.minosoft.debug.gui; package de.bixilon.minosoft.debug.gui;
import de.bixilon.minosoft.debug.handling.DebugUIHandler; import de.bixilon.minosoft.debug.handling.DebugUIHandler;
import de.bixilon.minosoft.protocol.network.Connection;
import javafx.application.Application; import javafx.application.Application;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
@ -29,6 +31,7 @@ public class DebugMainWindow extends Application {
static DebugUIHandler handler; static DebugUIHandler handler;
static Stage stage; static Stage stage;
static boolean initialized = false; static boolean initialized = false;
private static Connection connection;
public static void initAndShow() { public static void initAndShow() {
launch(); launch();
@ -46,6 +49,10 @@ public class DebugMainWindow extends Application {
return initialized; return initialized;
} }
public static void setConnection(Connection connection) {
DebugMainWindow.connection = connection;
}
@Override @Override
public void start(Stage stage) throws IOException { public void start(Stage stage) throws IOException {
@ -56,15 +63,17 @@ public class DebugMainWindow extends Application {
stage.show(); stage.show();
// autoscroll for chat // autoscroll for chat
((TextArea) scene.lookup("#chat")).textProperty().addListener(new ChangeListener<Object>() { ((TextArea) scene.lookup("#chat")).textProperty().addListener((ChangeListener<Object>) (observableValue, o, t1) -> ((TextArea) scene.lookup("#chat")).setScrollTop(Double.MAX_VALUE));
@Override // listen for enter in text field
public void changed(ObservableValue<?> observableValue, Object o, Object t1) { TextField chatToSend = ((TextField) scene.lookup("#chatToSend"));
((TextArea) scene.lookup("#chat")).setScrollTop(Double.MAX_VALUE); //this will scroll to the bottom chatToSend.setOnKeyPressed(event -> {
if (event.getCode().equals(KeyCode.ENTER)) {
// send chat message
connection.sendChatMessage(chatToSend.getText());
chatToSend.setText("");
} }
}); });
DebugMainWindow.stage = stage; DebugMainWindow.stage = stage;
initialized = true; initialized = true;
handler.initializedCallback(); handler.initializedCallback();

View File

@ -2,16 +2,21 @@
<?import javafx.scene.control.ScrollPane?> <?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TextArea?> <?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<VBox xmlns:fx="http://javafx.com/fxml/1" prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8.0.171"> <VBox xmlns:fx="http://javafx.com/fxml/1" prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8.0.171">
<children> <children>
<AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="666.0" prefWidth="998.0" VBox.vgrow="ALWAYS"> <AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="666.0" prefWidth="998.0" VBox.vgrow="ALWAYS">
<children> <children>
<ScrollPane layoutX="440.0" layoutY="186.0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0"> <ScrollPane layoutX="112.0" layoutY="85.0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0">
<content> <content>
<TextArea id="chat" editable="false" wrapText="true"/> <TextArea id="chat" editable="false" maxHeight="-Infinity" maxWidth="-Infinity"
wrapText="true"/>
</content> </content>
</ScrollPane> </ScrollPane>
<TextField id="chatToSend" layoutX="112.0" layoutY="358.0" prefHeight="28.0" prefWidth="520.0"
promptText="&lt;Enter Chat Message&gt;" AnchorPane.bottomAnchor="0.0"
AnchorPane.rightAnchor="0.0"/>
</children> </children>
</AnchorPane> </AnchorPane>
</children> </children>