Added a small popup menu to StatusTrayIcon and loading it in Startup
This commit is contained in:
		| @@ -64,6 +64,7 @@ public class Startup { | ||||
| 		EventQueue.invokeLater(() -> { | ||||
| 			try { | ||||
| 				ChatWindow frame = new ChatWindow(client, localDB); | ||||
| 				new StatusTrayIcon().show(); | ||||
| 				frame.setVisible(true); | ||||
| 			} catch (Exception e) { | ||||
| 				e.printStackTrace(); | ||||
|   | ||||
| @@ -2,6 +2,8 @@ package envoy.client.ui; | ||||
|  | ||||
| import java.awt.AWTException; | ||||
| import java.awt.Image; | ||||
| import java.awt.MenuItem; | ||||
| import java.awt.PopupMenu; | ||||
| import java.awt.SystemTray; | ||||
| import java.awt.Toolkit; | ||||
| import java.awt.TrayIcon; | ||||
| @@ -24,16 +26,31 @@ public class StatusTrayIcon { | ||||
| 		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	= 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 { | ||||
| 		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); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user