001: /*
002: * regain - A file search engine providing plenty of formats
003: * Copyright (C) 2004 Til Schneider
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * Contact: Til Schneider, info@murfman.de
020: *
021: * CVS information:
022: * $RCSfile$
023: * $Source$
024: * $Date: 2005-03-16 09:55:48 +0100 (Mi, 16 Mrz 2005) $
025: * $Author: til132 $
026: * $Revision: 87 $
027: */
028: package net.sf.regain.ui.desktop;
029:
030: import java.awt.event.ActionEvent;
031: import java.awt.event.ActionListener;
032:
033: import javax.swing.ImageIcon;
034: import javax.swing.JMenuItem;
035: import javax.swing.JPopupMenu;
036: import javax.swing.UIManager;
037:
038: import net.sf.regain.util.io.Localizer;
039:
040: import org.jdesktop.jdic.tray.SystemTray;
041: import org.jdesktop.jdic.tray.TrayIcon;
042:
043: /**
044: * Manages the tray icon.
045: *
046: * @author Til Schneider, www.murfman.de
047: */
048: public class TrayIconManager {
049:
050: /** The localizer for this class. */
051: private static Localizer mLocalizer = new Localizer(
052: TrayIconManager.class);
053:
054: /** The singleton. */
055: private static TrayIconManager mSingleton;
056:
057: /** The try icon */
058: private TrayIcon mTrayIcon;
059:
060: /**
061: * Gets the singleton.
062: *
063: * @return The singleton.
064: */
065: public static TrayIconManager getInstance() {
066: if (mSingleton == null) {
067: mSingleton = new TrayIconManager();
068: }
069: return mSingleton;
070: }
071:
072: /**
073: * Initializes the tray icon.
074: */
075: public void init() {
076: try {
077: UIManager.setLookAndFeel(UIManager
078: .getSystemLookAndFeelClassName());
079: } catch (Exception evt) {
080: evt.printStackTrace();
081: }
082:
083: JPopupMenu menu = new JPopupMenu();
084: JMenuItem item;
085:
086: item = new JMenuItem(mLocalizer.msg("search", "Search"));
087: item.addActionListener(new ActionListener() {
088: public void actionPerformed(ActionEvent evt) {
089: DesktopToolkit.openPageInBrowser("searchinput.jsp");
090: }
091: });
092: menu.add(item);
093:
094: item = new JMenuItem(mLocalizer.msg("status", "Status"));
095: item.addActionListener(new ActionListener() {
096: public void actionPerformed(ActionEvent evt) {
097: DesktopToolkit.openPageInBrowser("status.jsp");
098: }
099: });
100: menu.add(item);
101:
102: item = new JMenuItem(mLocalizer.msg("config", "Preferences"));
103: item.addActionListener(new ActionListener() {
104: public void actionPerformed(ActionEvent evt) {
105: DesktopToolkit.openPageInBrowser("config.jsp");
106: }
107: });
108: menu.add(item);
109:
110: menu.addSeparator();
111:
112: item = new JMenuItem(mLocalizer.msg("exit", "Exit"));
113: item.addActionListener(new ActionListener() {
114: public void actionPerformed(ActionEvent evt) {
115: Main.quit();
116: }
117: });
118: menu.add(item);
119:
120: ImageIcon icon = new ImageIcon(getClass().getResource(
121: "regain_icon_16.gif"));
122:
123: // NOTE: The SystemTray must be created get before the TrayIcon is created.
124: // Otherwise a UnsatisfiedLinkError will raise on linux systems
125: SystemTray tray = SystemTray.getDefaultSystemTray();
126:
127: mTrayIcon = new TrayIcon(icon, "regain", menu);
128: mTrayIcon.setIconAutoSize(true);
129: mTrayIcon.addActionListener(new ActionListener() {
130: public void actionPerformed(ActionEvent evt) {
131: DesktopToolkit.openPageInBrowser("searchinput.jsp");
132: }
133: });
134:
135: tray.addTrayIcon(mTrayIcon);
136: }
137:
138: /**
139: * Sets whether there is currently an index update running.
140: *
141: * @param updateRunning Whether there is currently an index update running.
142: */
143: public void setIndexUpdateRunning(boolean updateRunning) {
144: if (updateRunning) {
145: ImageIcon icon = new ImageIcon(getClass().getResource(
146: "regain_icon_scan_16.gif"));
147: mTrayIcon.setIcon(icon);
148: mTrayIcon.setToolTip("regain - "
149: + mLocalizer.msg("indexUpdate", "Updating index"));
150: } else {
151: ImageIcon icon = new ImageIcon(getClass().getResource(
152: "regain_icon_16.gif"));
153: mTrayIcon.setIcon(icon);
154: mTrayIcon.setToolTip("regain");
155: }
156: }
157:
158: }
|