All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tray.linux.LinuxNativeTrayAdapter Maven / Gradle / Ivy

Go to download

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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy