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
uiThread = new Thread(() -> {
DebugMainWindow.setHandler(handler);
DebugMainWindow.setConnection(connection);
DebugMainWindow.initAndShow();
});
uiThread.start();

View File

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

View File

@ -2,16 +2,21 @@
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?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">
<children>
<AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="666.0" prefWidth="998.0" VBox.vgrow="ALWAYS">
<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>
<TextArea id="chat" editable="false" wrapText="true"/>
<TextArea id="chat" editable="false" maxHeight="-Infinity" maxWidth="-Infinity"
wrapText="true"/>
</content>
</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>
</AnchorPane>
</children>