Display message date and status

This commit is contained in:
Kai S. K. Engelbart 2020-06-09 11:31:22 +02:00
parent c694247a4c
commit cb3913d95d
2 changed files with 49 additions and 14 deletions

View File

@ -1,11 +1,22 @@
package envoy.client.ui; package envoy.client.ui;
import envoy.data.Message; import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Map;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.ListCell; 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> * Project: <strong>envoy-client</strong><br>
* File: <strong>MessageListCell.java</strong><br> * File: <strong>MessageListCell.java</strong><br>
* Created: <strong>28.03.2020</strong><br> * Created: <strong>28.03.2020</strong><br>
@ -15,13 +26,29 @@ import javafx.scene.control.ListCell;
*/ */
public class MessageListCell extends ListCell<Message> { 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();
}
}
/** /**
* {@inheritDoc} * Displays the text, the data of creation and the status of a message.
*
* @since Envoy v0.1-beta
*/ */
@Override @Override
protected void updateItem(Message message, boolean empty) { protected void updateItem(Message message, boolean empty) {
super.updateItem(message, empty); super.updateItem(message, empty);
if (!empty && message != null) setGraphic(new Label(message.getText())); setGraphic(!empty && message != null ? new HBox(
else setGraphic(null); new VBox(
new Label(dateFormat.format(message.getCreationDate())),
new Label(message.getText())),
new Label("", new ImageView(statusImages.get(message.getStatus())))) : null);
} }
} }

View File

@ -20,6 +20,8 @@ import envoy.exception.EnvoyException;
import envoy.util.EnvoyLog; import envoy.util.EnvoyLog;
/** /**
* Handles application startup and shutdown.
* <p>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>Startup.java</strong><br> * File: <strong>Startup.java</strong><br>
* Created: <strong>26.03.2020</strong><br> * Created: <strong>26.03.2020</strong><br>
@ -37,7 +39,10 @@ public final class Startup extends Application {
private static final Logger logger = EnvoyLog.getLogger(Startup.class); private static final Logger logger = EnvoyLog.getLogger(Startup.class);
/** /**
* {@inheritDoc} * Loads the configuration, initializes the client and the local database and
* delegates the rest of the startup process to {@link LoginScene}.
*
* @since Envoy Client v0.1-beta
*/ */
@Override @Override
public void start(Stage stage) throws Exception { public void start(Stage stage) throws Exception {
@ -69,13 +74,15 @@ public final class Startup extends Application {
if (config.isIgnoreLocalDB()) { if (config.isIgnoreLocalDB()) {
localDB = new TransientLocalDB(); localDB = new TransientLocalDB();
new Alert(AlertType.WARNING, "Ignoring local database.\nMessages will not be saved!").showAndWait(); new Alert(AlertType.WARNING, "Ignoring local database.\nMessages will not be saved!").showAndWait();
} else try { } else {
localDB = new PersistentLocalDB(new File(config.getHomeDirectory(), config.getLocalDB().getPath())); try {
} catch (final IOException e3) { localDB = new PersistentLocalDB(new File(config.getHomeDirectory(), config.getLocalDB().getPath()));
logger.log(Level.SEVERE, "Could not initialize local database", e3); } catch (final IOException e3) {
new Alert(AlertType.ERROR, "Could not initialize local database!\n" + e3).showAndWait(); logger.log(Level.SEVERE, "Could not initialize local database", e3);
System.exit(1); new Alert(AlertType.ERROR, "Could not initialize local database!\n" + e3).showAndWait();
return; System.exit(1);
return;
}
} }
// Initialize client and unread message cache // Initialize client and unread message cache
@ -91,12 +98,13 @@ public final class Startup extends Application {
} }
/** /**
* {@inheritDoc} * Closes the client connection and saves the local database and settings.
*
* @since Envoy Client v0.1-beta
*/ */
@Override @Override
public void stop() { public void stop() {
try { try {
// Save Settings and PersistentLocalDB on shutdown
logger.info("Closing connection..."); logger.info("Closing connection...");
client.close(); client.close();