PageRenderTime 285ms CodeModel.GetById 277ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/gui/tray/JTrayIconManager.java

#
Java | 111 lines | 72 code | 9 blank | 30 comment | 12 complexity | 2cfb7d259e7c1e8549295418b46bd09e MD5 | raw file
  1/*
  2 * jEdit - Programmer's Text Editor
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright Š 2011 jEdit contributors
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * as published by the Free Software Foundation; either version 2
 11 * of the License, or any later version.
 12 * This program is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 * GNU General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU General Public License
 18 * along with this program; if not, write to the Free Software
 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 20 */
 21
 22package org.gjt.sp.jedit.gui.tray;
 23
 24//{{{ Imports
 25import org.gjt.sp.jedit.EBComponent;
 26import org.gjt.sp.jedit.EditBus;
 27import org.gjt.sp.jedit.ServiceManager;
 28import org.gjt.sp.jedit.jEdit;
 29import org.gjt.sp.util.Log;
 30
 31import java.awt.*;
 32//}}}
 33
 34/**
 35 * @author Matthieu Casanova
 36 * @since jEdit 4.5pre1
 37 * 
 38 */
 39public class JTrayIconManager
 40{
 41	private static JEditTrayIcon trayIcon;
 42	private static boolean restore;
 43	private static String userDir;
 44	private static String[] args;
 45
 46	//{{{ setTrayIconArgs() method
 47	public static void setTrayIconArgs(boolean restore, String userDir, String[] args)
 48	{
 49		JTrayIconManager.restore = restore;
 50		JTrayIconManager.userDir = userDir;
 51		JTrayIconManager.args = args;
 52	} //}}}
 53
 54	//{{{ addTrayIcon() method
 55	public static void addTrayIcon()
 56	{
 57		if (trayIcon == null && SystemTray.isSupported())
 58		{
 59
 60			SystemTray systemTray = SystemTray.getSystemTray();
 61			String trayIconName = jEdit.getProperty("systrayicon.service", "swing");
 62			trayIcon = ServiceManager.getService(JEditTrayIcon.class, trayIconName);
 63			if (trayIcon == null)
 64			{
 65				if ("swing".equals(trayIconName))
 66				{
 67					Log.log(Log.ERROR, JTrayIconManager.class, "No service " +
 68						JEditTrayIcon.class.getName() + " with name swing");
 69					return;
 70				}
 71				Log.log(Log.WARNING, JTrayIconManager.class, "No service " +
 72					JEditTrayIcon.class.getName() + " with name "+ trayIconName);
 73				trayIcon = ServiceManager.getService(JEditTrayIcon.class, "swing");
 74			}
 75			if (trayIcon == null)
 76			{
 77				Log.log(Log.ERROR, JTrayIconManager.class, "No service " +
 78					JEditTrayIcon.class.getName() + " with name swing");
 79				return;
 80			}
 81			trayIcon.setTrayIconArgs(restore, userDir, args);
 82			try
 83			{
 84				systemTray.add(trayIcon);
 85			}
 86			catch (AWTException e)
 87			{
 88				Log.log(Log.ERROR, JEditSwingTrayIcon.class, "Unable to add Tray icon", e);
 89				trayIcon = null;
 90				return;
 91			}
 92			if (trayIcon instanceof EBComponent) {
 93				EditBus.addToBus(trayIcon);
 94			}
 95		}
 96	} //}}}
 97
 98	//{{{ removeTrayIcon() method
 99	public static void removeTrayIcon()
100	{
101		if (trayIcon != null)
102		{
103			SystemTray.getSystemTray().remove(trayIcon);
104			if (trayIcon instanceof EBComponent) {
105				EditBus.removeFromBus(trayIcon);
106			}
107			trayIcon = null;
108		}
109	} //}}}
110
111}