diff --git a/src/main/java/envoy/client/ui/StatusTrayIcon.java b/src/main/java/envoy/client/ui/StatusTrayIcon.java
index 7ef6877..869e678 100644
--- a/src/main/java/envoy/client/ui/StatusTrayIcon.java
+++ b/src/main/java/envoy/client/ui/StatusTrayIcon.java
@@ -7,8 +7,10 @@ import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
+import java.awt.TrayIcon.MessageType;
import envoy.exception.EnvoyException;
+import envoy.schema.Message;
/**
* Project: envoy-client
@@ -25,22 +27,23 @@ public class StatusTrayIcon {
public StatusTrayIcon() throws EnvoyException {
if (!SystemTray.isSupported()) throw new EnvoyException("The Envoy tray icon is not supported.");
- Image img = Toolkit.getDefaultToolkit().createImage(getClass().getResource("envoy_logo.png"));
- trayIcon = new TrayIcon(img, "Envoy Client");
+ Image img = Toolkit.getDefaultToolkit().createImage(getClass().getResource("envoy_logo.png"));
+ trayIcon = new TrayIcon(img, "Envoy Client");
trayIcon.setImageAutoSize(true);
trayIcon.setToolTip("You are notified if you have unread messages.");
-
+
PopupMenu popup = new PopupMenu();
-
+
MenuItem exitMenuItem = new MenuItem("Exit");
exitMenuItem.addActionListener((evt) -> System.exit(0));
popup.add(exitMenuItem);
-
+
trayIcon.setPopupMenu(popup);
}
/**
* Makes this {@link StatusTrayIcon} appear in the system tray.
+ *
* @throws EnvoyException
*/
public void show() throws EnvoyException {
@@ -50,7 +53,14 @@ public class StatusTrayIcon {
throw new EnvoyException("Could not attach Envoy tray icon to system tray.", e);
}
}
-
- // TODO: Add event listener
- // trayIcon.displayMessage("Envoy Client", message, MessageType.INFO);
+
+ /**
+ * Notifies the user of a message by displaying a popup.
+ *
+ * @param message the {@link Message} object to display in the popup
+ */
+ public void displayMessageNotification(Message message) {
+ // TODO: Add event listener
+ trayIcon.displayMessage("New message received", message.getContent().get(0).getText(), MessageType.INFO);
+ }
}