Added a small popup menu to StatusTrayIcon and loading it in Startup
This commit is contained in:
parent
fbe2d0d0b0
commit
378a83638a
@ -64,6 +64,7 @@ public class Startup {
|
|||||||
EventQueue.invokeLater(() -> {
|
EventQueue.invokeLater(() -> {
|
||||||
try {
|
try {
|
||||||
ChatWindow frame = new ChatWindow(client, localDB);
|
ChatWindow frame = new ChatWindow(client, localDB);
|
||||||
|
new StatusTrayIcon().show();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -2,6 +2,8 @@ package envoy.client.ui;
|
|||||||
|
|
||||||
import java.awt.AWTException;
|
import java.awt.AWTException;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
|
import java.awt.MenuItem;
|
||||||
|
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;
|
||||||
@ -24,16 +26,31 @@ public class StatusTrayIcon {
|
|||||||
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 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.");
|
||||||
|
|
||||||
|
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 {
|
||||||
try {
|
try {
|
||||||
SystemTray.getSystemTray().add(trayIcon);
|
SystemTray.getSystemTray().add(trayIcon);
|
||||||
} catch (AWTException e) {
|
} catch (AWTException e) {
|
||||||
throw new EnvoyException("Could not attach Envoy tray icon to system tray.", e);
|
throw new EnvoyException("Could not attach Envoy tray icon to system tray.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add event listener
|
// TODO: Add event listener
|
||||||
// trayIcon.displayMessage("Envoy Client", message, MessageType.INFO);
|
// trayIcon.displayMessage("Envoy Client", message, MessageType.INFO);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user