Display message date and status
This commit is contained in:
parent
ca029d9e13
commit
7f6f538849
@ -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.
|
||||
* <p>
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
* File: <strong>MessageListCell.java</strong><br>
|
||||
* Created: <strong>28.03.2020</strong><br>
|
||||
@ -15,13 +26,29 @@ import javafx.scene.control.ListCell;
|
||||
*/
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ import envoy.exception.EnvoyException;
|
||||
import envoy.util.EnvoyLog;
|
||||
|
||||
/**
|
||||
* Handles application startup and shutdown.
|
||||
* <p>
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
* File: <strong>Startup.java</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);
|
||||
|
||||
/**
|
||||
* {@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();
|
||||
|
||||
|
Reference in New Issue
Block a user