From 7f6f538849e7294b2d58e414597a686a4384c186 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 9 Jun 2020 11:31:22 +0200 Subject: [PATCH] Display message date and status --- .../java/envoy/client/ui/MessageListCell.java | 35 ++++++++++++++++--- src/main/java/envoy/client/ui/Startup.java | 28 +++++++++------ 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/main/java/envoy/client/ui/MessageListCell.java b/src/main/java/envoy/client/ui/MessageListCell.java index 21c216d..60a2ada 100644 --- a/src/main/java/envoy/client/ui/MessageListCell.java +++ b/src/main/java/envoy/client/ui/MessageListCell.java @@ -1,11 +1,22 @@ 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.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. + *

* Project: envoy-client
* File: MessageListCell.java
* Created: 28.03.2020
@@ -15,13 +26,29 @@ import javafx.scene.control.ListCell; */ public class MessageListCell extends ListCell { + private static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); + private static Map 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 protected void updateItem(Message message, boolean empty) { super.updateItem(message, empty); - if (!empty && message != null) setGraphic(new Label(message.getText())); - else setGraphic(null); + 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); } } diff --git a/src/main/java/envoy/client/ui/Startup.java b/src/main/java/envoy/client/ui/Startup.java index ce5afb1..aff8801 100644 --- a/src/main/java/envoy/client/ui/Startup.java +++ b/src/main/java/envoy/client/ui/Startup.java @@ -20,6 +20,8 @@ import envoy.exception.EnvoyException; import envoy.util.EnvoyLog; /** + * Handles application startup and shutdown. + *

* Project: envoy-client
* File: Startup.java
* Created: 26.03.2020
@@ -37,7 +39,10 @@ public final class Startup extends Application { 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 public void start(Stage stage) throws Exception { @@ -69,13 +74,15 @@ public final class Startup extends Application { if (config.isIgnoreLocalDB()) { localDB = new TransientLocalDB(); new Alert(AlertType.WARNING, "Ignoring local database.\nMessages will not be saved!").showAndWait(); - } else try { - localDB = new PersistentLocalDB(new File(config.getHomeDirectory(), config.getLocalDB().getPath())); - } catch (final IOException e3) { - logger.log(Level.SEVERE, "Could not initialize local database", e3); - new Alert(AlertType.ERROR, "Could not initialize local database!\n" + e3).showAndWait(); - System.exit(1); - return; + } else { + try { + localDB = new PersistentLocalDB(new File(config.getHomeDirectory(), config.getLocalDB().getPath())); + } catch (final IOException e3) { + logger.log(Level.SEVERE, "Could not initialize local database", e3); + new Alert(AlertType.ERROR, "Could not initialize local database!\n" + e3).showAndWait(); + System.exit(1); + return; + } } // 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 public void stop() { try { - // Save Settings and PersistentLocalDB on shutdown logger.info("Closing connection..."); client.close();