java.lang.Object
net.i2p.desktopgui.TrayManager
Direct Known Subclasses:
ExternalTrayManager, InternalTrayManager

abstract class TrayManagerextends Object
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 Details

    • _appContext

      protected final I2PAppContext _appContext
      The router context the tray manager runs in.
    • _useSwing

      protected final boolean _useSwing
      True to build Swing menu items, false for plain AWT.
    • tray

      protected SystemTray tray
      The tray area, or null if unsupported
    • trayIcon

      protected TrayIcon trayIcon
      Our tray icon, or null if unsupported
    • _showNotifications

      protected volatile boolean _showNotifications
      Whether tray notifications are currently shown, defaults to true.
    • _notificationItem1

      protected MenuItem _notificationItem1
      _notificationItem1.
    • _notificationItem2

      protected MenuItem _notificationItem2
      _notificationItem2.
    • _jnotificationItem1

      protected JMenuItem _jnotificationItem1
      _jnotificationItem1.
    • _jnotificationItem2

      protected JMenuItem _jnotificationItem2
      _jnotificationItem2.
    • PNG_DIR

      private static final String PNG_DIR
      Where the tray icons are loaded from.
      See Also:
    • MAC_ICON

      private static final String MAC_ICON
      Icon used on macOS.
      See Also:
    • WIN_ICON

      private static final String WIN_ICON
      Icon used on Windows.
      See Also:
    • LIN_ICON

      private static final String LIN_ICON
      Icon used on Linux.
      See Also:
    • PROP_NOTIFICATIONS

      protected static final String PROP_NOTIFICATIONS
      Config key holding the tray notification preference.
      See Also:
  • Constructor Details

    • TrayManager

      protected TrayManager(I2PAppContext ctx, boolean useSwing)
      Create a new tray manager.
      Parameters:
      ctx - the I2P application context
      useSwing - true to use Swing components, false for AWT
  • Method Details

    • startManager

      public void startManager() throws AWTException
      Add the tray icon to the system tray and start everything up.
      Throws:
      AWTException - if the system tray is not supported
    • getAWTTrayIcon

      private TrayIcon getAWTTrayIcon(String tooltip) throws AWTException
      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

      private TrayIcon getSwingTrayIcon(String tooltip) throws AWTException
      Create a Swing tray icon with JPopupMenu.
      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

      protected abstract PopupMenu getMainMenu()
      Build a popup menu, adding callbacks to the different items.
      Returns:
      the AWT menu to install on the tray icon
    • getSwingMainMenu

      protected abstract JPopupMenu 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

      private Image getTrayImage() throws AWTException
      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

      public int displayMessage(int priority, String title, String message, String path)
      Send a notification to the user.
      Parameters:
      priority - severity of the message, tested against the Log level constants to pick the tray balloon type
      title - for the popup, translated
      message - translated, shown as the body of the tray balloon
      path - 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

      protected String _t(String s)
      Translate a string.
      Parameters:
      s - the string to translate
      Returns:
      the translated string
    • _t

      protected String _t(String s, Object o)
      Translate a string with one parameter.
      Parameters:
      s - the string to translate
      o - the parameter to insert
      Returns:
      the translated string