Professional, cross-platform SystemTray , AWT , GtkStatusIcon , and AppIndicator support for Java applications. This library provides OS native menus and Swing menus. Swing menus are the default preferred type because they offer more features (images attached to menu en
| 74 | * </ul> |
| 75 | */ |
| 76 | @SuppressWarnings({"unused", "Duplicates", "WeakerAccess"}) |
| 77 | public final |
| 78 | class SystemTray { |
| 79 | public static final Logger logger = LoggerFactory.getLogger(SystemTray.class); |
| 80 | |
| 81 | public enum TrayType { |
| 82 | /** Will choose as a 'best guess' which tray type to use */ |
| 83 | AutoDetect, |
| 84 | Gtk, |
| 85 | AppIndicator, |
| 86 | WindowsNative, |
| 87 | Swing, |
| 88 | Osx, |
| 89 | Awt; |
| 90 | |
| 91 | public TrayType safeFromString(String trayName) { |
| 92 | try { |
| 93 | return valueOf(trayName); |
| 94 | } catch (Exception e) { |
| 95 | return AutoDetect; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | /** Enables auto-detection for the system tray. This should be mostly successful. */ |
| 101 | public static volatile boolean AUTO_SIZE = OS.INSTANCE.getBoolean(SystemTray.class.getCanonicalName() + ".AUTO_SIZE", true); |
| 102 | |
| 103 | /** Forces the system tray to always choose GTK2 (even when GTK3 might be available). */ |
| 104 | public static volatile boolean FORCE_GTK2 = OS.INSTANCE.getBoolean(SystemTray.class.getCanonicalName() + ".FORCE_GTK2", false); |
| 105 | |
| 106 | /** Prefer to load GTK3 before trying to load GTK2. */ |
| 107 | public static volatile boolean PREFER_GTK3 = OS.INSTANCE.getBoolean(SystemTray.class.getCanonicalName() + ".PREFER_GTK3", true); |
| 108 | |
| 109 | /** |
| 110 | * Forces the system tray detection to be AutoDetect, GtkStatusIcon, AppIndicator, WindowsNotifyIcon, Swing, or AWT. |
| 111 | * <p> |
| 112 | * This is an advanced feature, and it is recommended to leave at AutoDetect. |
| 113 | */ |
| 114 | public static volatile TrayType FORCE_TRAY_TYPE = TrayType.AppIndicator.safeFromString( |
| 115 | OS.INSTANCE.getProperty(SystemTray.class.getCanonicalName() + ".FORCE_TRAY_TYPE", TrayType.AutoDetect.name())); |
| 116 | |
| 117 | /** |
| 118 | * Allows the SystemTray logic to resolve OS inconsistencies for the SystemTray. |
| 119 | * <p> |
| 120 | * This is an advanced feature, and it is recommended to leave as true |
| 121 | */ |
| 122 | public static volatile boolean AUTO_FIX_INCONSISTENCIES = OS.INSTANCE.getBoolean(SystemTray.class.getCanonicalName() + |
| 123 | ".AUTO_FIX_INCONSISTENCIES", true); |
| 124 | |
| 125 | /** |
| 126 | * Allows the SystemTray logic to ignore if root is detected. Usually when running as root it won't work (because of how DBUS |
| 127 | * operates), but in rare situations, it might work. |
| 128 | * <p> |
| 129 | * This is an advanced feature, and it is recommended to leave as true |
| 130 | */ |
| 131 | public static volatile boolean ENABLE_ROOT_CHECK = OS.INSTANCE.getBoolean(SystemTray.class.getCanonicalName() + ".ENABLE_ROOT_CHECK", true); |
| 132 | |
| 133 | /** |
nothing calls this directly
no test coverage detected