Fixed multiple bugs concerning enterToSend and the postButton
This commit is contained in:
parent
9bf28acfcb
commit
3960f955d8
@ -197,6 +197,34 @@ public final class ChatScene {
|
||||
sceneContext.<ContactSearchScene>getController().initializeData(sceneContext, localDB);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the text length of the {@code messageTextArea}, adjusts the
|
||||
* {@code remainingChars} - Label and checks whether to send the message
|
||||
* automatically.
|
||||
*
|
||||
* @param e the keys that have been entered
|
||||
* @since Envoy Client v0.1-beta
|
||||
*/
|
||||
@FXML
|
||||
private void checkKeyCombination(KeyEvent e) {
|
||||
// checks whether the text is too long
|
||||
messageTextUpdated();
|
||||
// Automatic sending of messages via (ctrl +) enter
|
||||
checkPostConditions(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param e the keys that have been pressed
|
||||
* @since Envoy Client v0.1-beta
|
||||
*/
|
||||
@FXML
|
||||
private void checkPostConditions(KeyEvent e) {
|
||||
if (!postButton.isDisabled() && settings.isEnterToSend() && e.getCode() == KeyCode.ENTER
|
||||
|| !settings.isEnterToSend() && e.getCode() == KeyCode.ENTER && e.isControlDown())
|
||||
postMessage();
|
||||
postButton.setDisable(messageTextArea.getText().isBlank() || currentChat == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions to perform when the text was updated in the messageTextArea.
|
||||
*
|
||||
@ -210,29 +238,21 @@ public final class ChatScene {
|
||||
messageTextArea.positionCaret(MAX_MESSAGE_LENGTH);
|
||||
messageTextArea.setScrollTop(Double.MAX_VALUE);
|
||||
}
|
||||
designRemainingCharsLabel();
|
||||
}
|
||||
|
||||
// Redesigning the remainingChars - Label
|
||||
/**
|
||||
* Sets the text and text-color of the {@code remainingChars} - Label.
|
||||
*
|
||||
* @since Envoy Client v0.1-beta
|
||||
*/
|
||||
private void designRemainingCharsLabel() {
|
||||
final int currentLength = messageTextArea.getText().length();
|
||||
final int remainingLength = MAX_MESSAGE_LENGTH - currentLength;
|
||||
remainingChars.setText(String.format("remaining chars: %d/%d", remainingLength, MAX_MESSAGE_LENGTH));
|
||||
remainingChars.setTextFill(Color.rgb(currentLength, remainingLength, 0, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions to perform when a key has been entered.
|
||||
*
|
||||
* @param e the Keys that have been entered
|
||||
* @since Envoy Client v0.1-beta
|
||||
*/
|
||||
@FXML
|
||||
private void checkKeyCombination(KeyEvent e) {
|
||||
// Automatic sending of messages via (ctrl +) enter
|
||||
if (!postButton.isDisabled() && settings.isEnterToSend() && e.getCode() == KeyCode.ENTER
|
||||
|| !settings.isEnterToSend() && e.getCode() == KeyCode.ENTER && e.isControlDown())
|
||||
postMessage();
|
||||
postButton.setDisable(messageTextArea.getText().isBlank() || currentChat == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a new message to the server based on the text entered in the
|
||||
* messageTextArea.
|
||||
@ -241,10 +261,12 @@ public final class ChatScene {
|
||||
*/
|
||||
@FXML
|
||||
private void postMessage() {
|
||||
final var text = messageTextArea.getText().strip();
|
||||
if (text.isBlank()) throw new IllegalArgumentException("A message without visible text can not be sent.");
|
||||
try {
|
||||
// Create and send message
|
||||
final var message = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB.getIDGenerator())
|
||||
.setText(messageTextArea.getText().strip())
|
||||
.setText(text)
|
||||
.build();
|
||||
|
||||
// Send message
|
||||
@ -264,5 +286,6 @@ public final class ChatScene {
|
||||
// Clear text field and disable post button
|
||||
messageTextArea.setText("");
|
||||
postButton.setDisable(true);
|
||||
designRemainingCharsLabel();
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
<Button fx:id="settingsButton" mnemonicParsing="true" onAction="#settingsButtonClicked" text="_Settings" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
|
||||
<ListView fx:id="messageList" prefHeight="257.0" prefWidth="155.0" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="1" GridPane.rowSpan="2" />
|
||||
<Button fx:id="postButton" defaultButton="true" disable="true" mnemonicParsing="true" onAction="#postMessage" prefHeight="10.0" prefWidth="65.0" text="_Post" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER" />
|
||||
<TextArea fx:id="messageTextArea" disable="true" onInputMethodTextChanged="#messageTextUpdated" onKeyPressed="#checkKeyCombination" onKeyTyped="#messageTextUpdated" prefHeight="200.0" prefWidth="200.0" wrapText="true" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
||||
<TextArea fx:id="messageTextArea" disable="true" onInputMethodTextChanged="#messageTextUpdated" onKeyPressed="#checkPostConditions" onKeyTyped="#checkKeyCombination" prefHeight="200.0" prefWidth="200.0" wrapText="true" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
||||
<Button mnemonicParsing="true" onAction="#addContactButtonClicked" text="_Add Contacts" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER">
|
||||
<padding>
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||
|
Reference in New Issue
Block a user