tray.linux.LinuxNativeTrayAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of native-tray-adapter Show documentation
Show all versions of native-tray-adapter Show documentation
Provides a simple adapter that makes the tray use gtk under linux,
providing a native look and feel.
The newest version!
package tray.linux;
import java.awt.PopupMenu;
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.Map;
import jni.utils.JniUtils;
import tray.SystemTrayAdapter;
import tray.TrayIconAdapter;
public class LinuxNativeTrayAdapter implements SystemTrayAdapter {
private static NativeLinuxTray nativeTray;
static Map trayIconInstances = new LinkedHashMap();
public LinuxNativeTrayAdapter()
{
loadNativeLibraryIfNotAlreadyLoaded();
}
private void loadNativeLibraryIfNotAlreadyLoaded() {
if (nativeTray == null) {
nativeTray = new NativeLinuxTray();
}
}
@Override
public TrayIconAdapter createAndAddTrayIcon(URL imageURL, String tooltip,
PopupMenu popup) {
LinuxTrayIconAdapter linuxTrayIconAdapter = new LinuxTrayIconAdapter(
nativeTray, imageURL, tooltip, popup);
trayIconInstances.put(linuxTrayIconAdapter.getNativeId(), linuxTrayIconAdapter);
return linuxTrayIconAdapter;
}
public static LinuxTrayIconAdapter getLinuxTrayIconAdapter(int nativeId) {
return trayIconInstances.get(nativeId);
}
@Override
public void remove(TrayIconAdapter trayIcon) {
LinuxTrayIconAdapter linuxTrayIconAdapter = (LinuxTrayIconAdapter)trayIcon;
trayIconInstances.remove(linuxTrayIconAdapter.getNativeId());
linuxTrayIconAdapter.removeMe();
}
}