40 lines
1.1 KiB
Java
40 lines
1.1 KiB
Java
|
package envoy.client.ui;
|
||
|
|
||
|
import java.awt.AWTException;
|
||
|
import java.awt.Image;
|
||
|
import java.awt.SystemTray;
|
||
|
import java.awt.Toolkit;
|
||
|
import java.awt.TrayIcon;
|
||
|
|
||
|
import envoy.exception.EnvoyException;
|
||
|
|
||
|
/**
|
||
|
* Project: <strong>envoy-client</strong><br>
|
||
|
* File: <strong>StatusTrayIcon.java</strong><br>
|
||
|
* Created: <strong>3 Dec 2019</strong><br>
|
||
|
*
|
||
|
* @author Kai S. K. Engelbart
|
||
|
* @since Envoy v0.2-alpha
|
||
|
*/
|
||
|
public class StatusTrayIcon {
|
||
|
|
||
|
private TrayIcon trayIcon;
|
||
|
|
||
|
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 trayIcon = new TrayIcon(img, "Envoy Client");
|
||
|
trayIcon.setImageAutoSize(true);
|
||
|
trayIcon.setToolTip("You are notified if you have unread messages.");
|
||
|
try {
|
||
|
SystemTray.getSystemTray().add(trayIcon);
|
||
|
} catch (AWTException e) {
|
||
|
throw new EnvoyException("Could not attach Envoy tray icon to system tray.", e);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// TODO: Add event listener
|
||
|
// trayIcon.displayMessage("Envoy Client", message, MessageType.INFO);
|
||
|
}
|