55 lines
1.5 KiB
Java
55 lines
1.5 KiB
Java
package envoy.client.ui;
|
|
|
|
import java.io.IOException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Map;
|
|
|
|
import javafx.scene.control.Label;
|
|
import javafx.scene.control.ListCell;
|
|
import javafx.scene.image.Image;
|
|
import javafx.scene.image.ImageView;
|
|
import javafx.scene.layout.HBox;
|
|
import javafx.scene.layout.VBox;
|
|
|
|
import envoy.data.Message;
|
|
import envoy.data.Message.MessageStatus;
|
|
|
|
/**
|
|
* Displays a single message inside the message list.
|
|
* <p>
|
|
* Project: <strong>envoy-client</strong><br>
|
|
* File: <strong>MessageListCell.java</strong><br>
|
|
* Created: <strong>28.03.2020</strong><br>
|
|
*
|
|
* @author Kai S. K. Engelbart
|
|
* @since Envoy Client v0.1-beta
|
|
*/
|
|
public class MessageListCell extends ListCell<Message> {
|
|
|
|
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
|
private static Map<MessageStatus, Image> statusImages;
|
|
|
|
static {
|
|
try {
|
|
statusImages = IconUtil.loadByEnum(MessageStatus.class, 32);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Displays the text, the data of creation and the status of a message.
|
|
*
|
|
* @since Envoy v0.1-beta
|
|
*/
|
|
@Override
|
|
protected void updateItem(Message message, boolean empty) {
|
|
super.updateItem(message, empty);
|
|
setGraphic(!empty && message != null ? new HBox(
|
|
new VBox(
|
|
new Label(dateFormat.format(message.getCreationDate())),
|
|
new Label(message.getText())),
|
|
new Label("", new ImageView(statusImages.get(message.getStatus())))) : null);
|
|
}
|
|
}
|