Added StatusTrayIcon#displayMessageNotification method
Using this method, a message object can be displayed as a OS-specific notification, which can be useful in the future to alert the user about an incoming message while the application is not in focus.
This commit is contained in:
parent
3c7f95f869
commit
b5badae773
@ -7,8 +7,10 @@ import java.awt.PopupMenu;
|
|||||||
import java.awt.SystemTray;
|
import java.awt.SystemTray;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.TrayIcon;
|
import java.awt.TrayIcon;
|
||||||
|
import java.awt.TrayIcon.MessageType;
|
||||||
|
|
||||||
import envoy.exception.EnvoyException;
|
import envoy.exception.EnvoyException;
|
||||||
|
import envoy.schema.Message;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Project: <strong>envoy-client</strong><br>
|
* Project: <strong>envoy-client</strong><br>
|
||||||
@ -25,8 +27,8 @@ public class StatusTrayIcon {
|
|||||||
public StatusTrayIcon() throws EnvoyException {
|
public StatusTrayIcon() throws EnvoyException {
|
||||||
if (!SystemTray.isSupported()) throw new EnvoyException("The Envoy tray icon is not supported.");
|
if (!SystemTray.isSupported()) throw new EnvoyException("The Envoy tray icon is not supported.");
|
||||||
|
|
||||||
Image img = Toolkit.getDefaultToolkit().createImage(getClass().getResource("envoy_logo.png"));
|
Image img = Toolkit.getDefaultToolkit().createImage(getClass().getResource("envoy_logo.png"));
|
||||||
trayIcon = new TrayIcon(img, "Envoy Client");
|
trayIcon = new TrayIcon(img, "Envoy Client");
|
||||||
trayIcon.setImageAutoSize(true);
|
trayIcon.setImageAutoSize(true);
|
||||||
trayIcon.setToolTip("You are notified if you have unread messages.");
|
trayIcon.setToolTip("You are notified if you have unread messages.");
|
||||||
|
|
||||||
@ -41,6 +43,7 @@ public class StatusTrayIcon {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes this {@link StatusTrayIcon} appear in the system tray.
|
* Makes this {@link StatusTrayIcon} appear in the system tray.
|
||||||
|
*
|
||||||
* @throws EnvoyException
|
* @throws EnvoyException
|
||||||
*/
|
*/
|
||||||
public void show() throws EnvoyException {
|
public void show() throws EnvoyException {
|
||||||
@ -51,6 +54,13 @@ public class StatusTrayIcon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user