java.lang.Object
net.i2p.desktopgui.TrayManager
- Direct Known Subclasses:
ExternalTrayManager, InternalTrayManager
Abstract base class for managing system tray icons and menus for I2P. Handles tray icon lifecycle, notifications, and provides platform-specific menu creation for both AWT and Swing implementations.
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final I2PAppContextThe router context the tray manager runs in.protected JMenuItem_jnotificationItem1.protected JMenuItem_jnotificationItem2.protected MenuItem_notificationItem1.protected MenuItem_notificationItem2.protected booleanWhether tray notifications are currently shown, defaults to true.protected final booleanTrue to build Swing menu items, false for plain AWT.private static final StringIcon used on Linux.private static final StringIcon used on macOS.private static final StringWhere the tray icons are loaded from.protected static final StringConfig key holding the tray notification preference.protected SystemTrayThe tray area, or null if unsupportedprotected TrayIconOur tray icon, or null if unsupportedprivate static final StringIcon used on Windows.Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTrayManager(I2PAppContext ctx, boolean useSwing) Create a new tray manager.Method Summary
Modifier and TypeMethodDescriptionprotected StringTranslate a string.protected StringTranslate a string with one parameter.protected voidconfigureNotifications(boolean enable) Does not save.intdisplayMessage(int priority, String title, String message, String path) Send a notification to the user.private TrayIcongetAWTTrayIcon(String tooltip) Create an AWT tray icon with popup menu.protected abstract PopupMenuBuild a popup menu, adding callbacks to the different items.protected abstract JPopupMenuBuild a popup menu, adding callbacks to the different items.private TrayIcongetSwingTrayIcon(String tooltip) Create a Swing tray icon withJPopupMenu.private ImageGet tray icon image from the desktopgui resources in the jar file.protected voidInitializes _jnotificationItem 1 and 2.protected voidInitializes _notificationItem 1 and 2.voidUpdate the tray menu when the language changes.voidAdd the tray icon to the system tray and start everything up.voidRemove the tray icon from the system tray.protected abstract voidUpdate the menu.
Field Details
_appContext
The router context the tray manager runs in._useSwing
protected final boolean _useSwingTrue to build Swing menu items, false for plain AWT.tray
The tray area, or null if unsupportedtrayIcon
Our tray icon, or null if unsupported_showNotifications
protected volatile boolean _showNotificationsWhether tray notifications are currently shown, defaults to true._notificationItem1
_notificationItem1._notificationItem2
_notificationItem2._jnotificationItem1
_jnotificationItem1._jnotificationItem2
_jnotificationItem2.PNG_DIR
Where the tray icons are loaded from.- See Also:
MAC_ICON
WIN_ICON
LIN_ICON
PROP_NOTIFICATIONS
Config key holding the tray notification preference.- See Also:
Constructor Details
TrayManager
Create a new tray manager.- Parameters:
ctx- the I2P application contextuseSwing- true to use Swing components, false for AWT
Method Details
startManager
Add the tray icon to the system tray and start everything up.- Throws:
AWTException- if the system tray is not supported
getAWTTrayIcon
Create an AWT tray icon with popup menu.- Parameters:
tooltip- the tooltip text- Returns:
- the tray icon
- Throws:
AWTException- if the tray icon cannot be created
getSwingTrayIcon
Create a Swing tray icon withJPopupMenu.- Parameters:
tooltip- the tooltip text- Returns:
- the tray icon
- Throws:
AWTException- if the tray icon cannot be created
stopManager
public void stopManager()Remove the tray icon from the system tray.languageChanged
public void languageChanged()Update the tray menu when the language changes.getMainMenu
Build a popup menu, adding callbacks to the different items.- Returns:
- the AWT menu to install on the tray icon
getSwingMainMenu
Build a popup menu, adding callbacks to the different items.- Returns:
- the Swing menu to install, for the headless-capable path
updateMenu
protected abstract void updateMenu()Update the menu.getTrayImage
Get tray icon image from the desktopgui resources in the jar file.- Returns:
- image used for the tray icon
- Throws:
AWTException- if image not found
displayMessage
Send a notification to the user.- Parameters:
priority- severity of the message, tested against the Log level constants to pick the tray balloon typetitle- for the popup, translatedmessage- translated, shown as the body of the tray balloonpath- unsupported; the AWT API takes no path, so it is ignored- Returns:
- 0, or -1 on failure
configureNotifications
protected void configureNotifications(boolean enable) Does not save. See InternalTrayManager.- Parameters:
enable- true to display notifications, false to suppress them
initializeNotificationItems
protected void initializeNotificationItems()Initializes _notificationItem 1 and 2.initializeJNotificationItems
protected void initializeJNotificationItems()Initializes _jnotificationItem 1 and 2._t
_t