⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 desktopindicator.java

📁 一款即时通讯软件
💻 JAVA
字号:
package edu.ou.kmi.buddyspace.gui.systemtray;

import java.util.*;

/**
* A JNI wrapper for desktop indicators (also called tray icons and taskbar icons).
* <br><br>
*
* The actual implementation is platform specific. Currently only Win32 is supported.
* For unsupported platforms, the desktop indicator doesn't do anything, and is
* otherwise harmless. Likewise, some platforms may not support the tooltip
* feature.
* <br><br>
*
* IMPORTANT!
* <br><br>
*
* Relying on this feature will make your applet or application platform-
* dependant. If possible, treat is as an "added benefit", not a required feature.
**/

public class DesktopIndicator
{
	/**
	* Loads the JNI library, if available.
	* <br><br>
	*
	* Must be called before images are loaded and instances are created.
	**/
	public static boolean initialize()
	{
		// Load JNI library
		try
		{
			System.loadLibrary( "DesktopIndicator" );
		}
		catch( UnsatisfiedLinkError x )
		{
			return false;
		}
		
		return true;
	}
	
	/**
	* Loads an image file to memory.
	* <br><br>
	*
	* The image is loaded from the filename parameter, while the tooltip is
	* supplied in the tooltip parameter. The image file must be in a format
	* recognized by the native platform (for example, a .ico file for Win32).
	* <br><br>
	*
	* A return value of -1 indicates failure. Otherwise, it is the handle of
	* the image to be used for desktop indicators.
	**/
	public static int loadImage( String filename )
	{
		try
		{
			return nativeLoadImage( filename );
		}
		catch( UnsatisfiedLinkError x )
		{
			return -1;
		}
	}
	
	/**
	* Frees memory used by a image previously loaded with loadImage.
	* <br><br>
	*
	* The memory is freed in any case when the VM is closed.
	**/
	public static void freeImage( int image )
	{
		try
		{
			nativeFreeImage( image );
		}
		catch( UnsatisfiedLinkError x )
		{
		}
	}
	
	/**
	* Creates a desktop indicator, initially hidden.
	* <br><br>
	*
	* The image handle is the return value of a previous call to loadImage.
	**/
	public DesktopIndicator( int image, String tooltip )
	{
		this.image = image;
		this.tooltip = tooltip;
	}
	
	/**
	* Enables the desktop indicator.
	* <br><br>
	*
	* If the indicator is already active, it is "refreshed" with the filename and tooltip.
	**/
	public void show()
	{
		try
		{
			nativeEnable( image, tooltip );
		}
		catch( UnsatisfiedLinkError x )
		{
		}
	}

	/**
	* Updates the desktop indicator with an image and tooltip.
	**/
	public void update( int image, String tooltip )
	{
		this.image = image;
		this.tooltip = tooltip;
		
		try
		{
			nativeEnable( image, tooltip );
		}
		catch( UnsatisfiedLinkError x )
		{
		}
	}

	/**
	* Hides the desktop indicator.
	**/
	public void hide()
	{
		try
		{
			nativeDisable();
		}
		catch( UnsatisfiedLinkError x )
		{
		}
	}
        
        /**
	* Returns if a screen server is running.
	**/
	public boolean isScreenSaverActive()
	{
		try
		{
			return nativeIsScreenSaverActive();
		}
		catch( UnsatisfiedLinkError x )
		{
                    return false;
		}
	}

	/**
	* Notifies all listeners that the desktop indicator was clicked.
	**/	
	public void fireClicked()
	{
		Vector listenersClone = (Vector) listeners.clone();
		DesktopIndicatorListener listener;
		for( Enumeration e = listenersClone.elements(); e.hasMoreElements(); )
		{
			listener = (DesktopIndicatorListener) e.nextElement();
			listener.onDesktopIndicatorClicked( this );				
		}
	}
        
        
        /**
	* Notifies all listeners that presence was changed.
	**/	
	public void firePresenceChange(String presenceStr)
	{
                Vector listenersClone = (Vector) listeners.clone();
		DesktopIndicatorListener listener;
		for( Enumeration e = listenersClone.elements(); e.hasMoreElements(); )
		{
			listener = (DesktopIndicatorListener) e.nextElement();
			listener.onDesktopIndicatorPresenceChanged(this, presenceStr);
		}
	}
        
        
        /**
	* Notifies all listeners that exit was clicked.
	**/	
	public void fireExit()
	{
                Vector listenersClone = (Vector) listeners.clone();
		DesktopIndicatorListener listener;
		for( Enumeration e = listenersClone.elements(); e.hasMoreElements(); )
		{
			listener = (DesktopIndicatorListener) e.nextElement();
			listener.onDesktopIndicatorExit(this);
		}
	}
	
        
	/**
	* Adds a listener for clicks.
	**/	
	public void addDesktopIndicatorListener( DesktopIndicatorListener listener )
	{
		listeners.addElement( listener );
	}
	
	/**
	* Removes a listener for clicks.
	**/	
	public void removeDesktopIndicatorListener( DesktopIndicatorListener listener )
	{
		listeners.removeElement( listener );
	}
	
	/**
	* Makes sure that the desktop indicator is hidden.
	**/
	protected void finalize()
	{
		hide();
	}
	
	///////////////////////////////////////////////////////////////////////////////////////
	// Private
	//

	private int image;
	private String tooltip;
	private Vector listeners = new Vector();
	private int handler = 0;

	private synchronized static native int nativeLoadImage( String filename ) throws UnsatisfiedLinkError;
	//private synchronized static native void test() throws UnsatisfiedLinkError;
	private synchronized static native void nativeFreeImage( int image ) throws UnsatisfiedLinkError;
	private synchronized native void nativeEnable( int image, String tooltip ) throws UnsatisfiedLinkError;
	private synchronized native void nativeDisable() throws UnsatisfiedLinkError;
        
        // screen saver testing functions
        private synchronized native boolean nativeIsScreenSaverActive() throws UnsatisfiedLinkError;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -