tag + basic layout for rooms
This commit is contained in:
@@ -15,6 +15,7 @@ import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -49,6 +50,7 @@ public void initialize() throws SocketException {
|
||||
client = new Client(new InetSocketAddress("localhost", 6665), this, UsernameSingleton.getInstance().getUsername());
|
||||
Platform.runLater(() -> {
|
||||
Stage stage = (Stage) vueContainer.getScene().getWindow();
|
||||
stage.setResizable(true); // Fixed a bug that made the close button disappear under my Wayland setup (don't know if it's the same for x11)
|
||||
stage.setOnCloseRequest(event -> {
|
||||
connected = false;
|
||||
client.close();
|
||||
@@ -88,24 +90,46 @@ public void initialize() throws SocketException {
|
||||
}
|
||||
@Override
|
||||
public void handleChatMessage(Instant time, String chatter, String content) {
|
||||
String untagged = untag(content);
|
||||
String messageColor = Objects.equals(content, untagged) ? "lightblue" : "lightgreen";
|
||||
Platform.runLater(() -> {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm")
|
||||
.withZone(ZoneId.systemDefault());
|
||||
String timeString = formatter.format(time);
|
||||
Text chatterText = new Text(chatter + ": ");
|
||||
chatterText.setStyle("-fx-fill: black; -fx-font-weight: bold;");
|
||||
TextFlow messageText = formatMessage(chatter, content);
|
||||
TextFlow messageText = formatMessage(chatter, untagged);
|
||||
TextFlow wholeMessage = new TextFlow(chatterText, messageText);
|
||||
Text timeText = new Text(" " + timeString);
|
||||
timeText.setStyle("-fx-fill: gray; -fx-font-size: 10px;");
|
||||
HBox messageContainer = new HBox(5, wholeMessage, timeText);
|
||||
messageContainer.setStyle("-fx-background-color: lightblue; -fx-padding: 8; -fx-background-radius: 5;");
|
||||
messageContainer.setStyle("-fx-background-color: " + messageColor + "; -fx-padding: 8; -fx-background-radius: 5;");
|
||||
messageContainer.setMaxWidth(Double.MAX_VALUE);
|
||||
HBox.setHgrow(messageText, Priority.ALWAYS);
|
||||
chatList.getChildren().add(messageContainer);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the tag from the message (handle ANSI characters encoded by the server)
|
||||
* @param message the message to untag
|
||||
* @return the untagged message
|
||||
*/
|
||||
public String untag(String message) {
|
||||
Pattern pattern = Pattern.compile("\u001B\\[44;30m(.*?)\u001B\\[49;39m");
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
|
||||
StringBuffer result = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
String taggedName = matcher.group(1);
|
||||
matcher.appendReplacement(result, taggedName);
|
||||
}
|
||||
matcher.appendTail(result);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleRoomList(List<String> roomNames) {
|
||||
Platform.runLater(() -> {
|
||||
|
||||
Reference in New Issue
Block a user