improve message styling
This commit is contained in:
parent
7596a2c627
commit
a9674c67d6
3 changed files with 50 additions and 20 deletions
|
@ -9,12 +9,11 @@ import javafx.fxml.Initializable;
|
|||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.VBox;
|
||||
import netscape.javascript.JSObject;
|
||||
import org.kordamp.ikonli.javafx.FontIcon;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ResourceBundle;
|
||||
|
@ -29,7 +28,8 @@ public class MessageListItemController implements Initializable {
|
|||
private JFXButton button;
|
||||
@FXML
|
||||
private Label timestamp;
|
||||
|
||||
@FXML
|
||||
private FontIcon attachmentIcon;
|
||||
/**
|
||||
* Sets the message to display
|
||||
*
|
||||
|
@ -38,25 +38,51 @@ public class MessageListItemController implements Initializable {
|
|||
public void setMessage(Message message) {
|
||||
if (!message.equals(currentMessage)) {
|
||||
currentMessage = message;
|
||||
String text = message.getText();
|
||||
if (message instanceof FileMessage) {
|
||||
FileMessage fileMessage = ((FileMessage) message);
|
||||
if (text != null && !text.isEmpty()) {
|
||||
text += "\n";
|
||||
}
|
||||
text += "<" + fileMessage.getFileName() + ">";
|
||||
button.setOnMouseClicked(event -> openFile(fileMessage.getPath()));
|
||||
}
|
||||
button.setText(text);
|
||||
timestamp.setText(DateFormat.getTimeInstance().format(message.getDate()));
|
||||
clearBackground();
|
||||
if (CurrentUser.getInstance().getId().equals(message.getSender().id)) {
|
||||
container.setAlignment(Pos.CENTER_RIGHT);
|
||||
button.getStyleClass().add("message-self");
|
||||
displayFile(fileMessage);
|
||||
} else {
|
||||
container.setAlignment(Pos.CENTER_LEFT);
|
||||
button.getStyleClass().add("message-other");
|
||||
displayClassicMessage();
|
||||
}
|
||||
styleMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private void setMessageText(String text) {
|
||||
button.setText(text);
|
||||
timestamp.setText(DateFormat.getTimeInstance().format(currentMessage.getDate()));
|
||||
}
|
||||
|
||||
private void displayFile(FileMessage fileMessage) {
|
||||
String text = currentMessage.getText();
|
||||
if (text != null && !text.isEmpty()) {
|
||||
text += "\n";
|
||||
}
|
||||
text += "<" + fileMessage.getFileName() + ">";
|
||||
setMessageText(text);
|
||||
button.setOnMouseClicked(event -> openFile(fileMessage.getPath()));
|
||||
button.setButtonType(JFXButton.ButtonType.RAISED);
|
||||
attachmentIcon.setVisible(true);
|
||||
attachmentIcon.setManaged(true);
|
||||
}
|
||||
|
||||
private void displayClassicMessage() {
|
||||
setMessageText(currentMessage.getText());
|
||||
button.setOnMouseClicked(null);
|
||||
button.setButtonType(JFXButton.ButtonType.FLAT);
|
||||
button.setDisable(true);
|
||||
attachmentIcon.setVisible(false);
|
||||
attachmentIcon.setManaged(false);
|
||||
}
|
||||
|
||||
private void styleMessage() {
|
||||
clearBackground();
|
||||
if (CurrentUser.getInstance().getId().equals(currentMessage.getSender().id)) {
|
||||
container.setAlignment(Pos.CENTER_RIGHT);
|
||||
button.getStyleClass().add("message-self");
|
||||
} else {
|
||||
container.setAlignment(Pos.CENTER_LEFT);
|
||||
button.getStyleClass().add("message-other");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import org.kordamp.ikonli.javafx.FontIcon?>
|
||||
<VBox xmlns="http://javafx.com/javafx/11.0.1"
|
||||
xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="fr.insa.clavardator.ui.chat.MessageListItemController"
|
||||
|
@ -17,7 +18,11 @@
|
|||
<JFXButton fx:id="button"
|
||||
mnemonicParsing="false"
|
||||
text="Message"
|
||||
textAlignment="CENTER"/>
|
||||
textAlignment="CENTER">
|
||||
<graphic>
|
||||
<FontIcon iconLiteral="fas-paperclip" iconSize="24" fx:id="attachmentIcon"/>
|
||||
</graphic>
|
||||
</JFXButton>
|
||||
<Label fx:id="timestamp"
|
||||
text="Timestamp"
|
||||
styleClass="timestamp"/>
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
.jfx-button {
|
||||
-fx-background-color: -primary;
|
||||
-fx-background-radius: 5;
|
||||
-jfx-button-type: "RAISED";
|
||||
-fx-cursor: "hand";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue