001: package org.methodize.nntprss;
002:
003: /* -----------------------------------------------------------
004: * nntp//rss - a bridge between the RSS world and NNTP clients
005: * Copyright (c) 2002, 2003 Jason Brome. All Rights Reserved.
006: *
007: * email: nntprss@methodize.org
008: * mail: Methodize Solutions
009: * PO Box 3865
010: * Grand Central Station
011: * New York NY 10163
012: *
013: * This file is part of nntp//rss
014: *
015: * This class uses the SysTray for Java libraries,
016: * distributed under the GNU LGPL.
017: * Further information: http://www.eikon.tum.de/~tamas/
018: *
019: * nntp//rss is free software; you can redistribute it
020: * and/or modify it under the terms of the GNU General
021: * Public License as published by the Free Software Foundation;
022: * either version 2 of the License, or (at your option) any
023: * later version.
024: *
025: * This program is distributed in the hope that it will be
026: * useful, but WITHOUT ANY WARRANTY; without even the implied
027: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
028: * PURPOSE. See the GNU General Public License for more
029: * details.
030: *
031: * You should have received a copy of the GNU General Public
032: * License along with this program; if not, write to the
033: * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
034: * Boston, MA 02111-1307 USA
035: * ----------------------------------------------------- */
036:
037: import java.awt.event.MouseEvent;
038: import java.awt.event.MouseListener;
039: import java.io.IOException;
040: import java.util.Vector;
041:
042: import javax.swing.JFrame;
043: import javax.swing.JLabel;
044: import javax.swing.JOptionPane;
045:
046: import org.methodize.nntprss.util.AppConstants;
047: import snoozesoft.systray4j.SysTrayMenu;
048: import snoozesoft.systray4j.SysTrayMenuEvent;
049: import snoozesoft.systray4j.SysTrayMenuIcon;
050: import snoozesoft.systray4j.SysTrayMenuItem;
051: import snoozesoft.systray4j.SysTrayMenuListener;
052:
053: /**
054: * @author Jason Brome <jason@methodize.org>
055: * @version $Id: WindowsSysTray.java,v 1.1 2003/03/24 03:15:45 jasonbrome Exp $
056: */
057:
058: public class WindowsSysTray extends JFrame implements
059: SysTrayMenuListener {
060:
061: private SysTrayMenu menu;
062: private SysTrayMenuIcon nntpIcon;
063:
064: private String adminURL = "http://127.0.0.1:7810/";
065:
066: private static final String MENU_ABOUT_TEXT = "About nntp//rss...";
067: private static final String MENU_ABOUT_CMD = "about";
068: private static final String MENU_EXIT_TEXT = "Exit";
069: private static final String MENU_EXIT_CMD = "exit";
070: private static final String MENU_PROPERTIES_TEXT = "Properties";
071: private static final String MENU_PROPERTIES_CMD = "properties";
072: private static final String ICON_FILE = "nntprss.ico";
073:
074: public WindowsSysTray() {
075:
076: super ("nntp//rss");
077:
078: nntpIcon = new SysTrayMenuIcon(ICON_FILE);
079: nntpIcon.addSysTrayMenuListener(this );
080:
081: SysTrayMenuItem itemCfg = new SysTrayMenuItem(
082: MENU_PROPERTIES_TEXT, MENU_PROPERTIES_CMD);
083: itemCfg.setEnabled(false);
084: itemCfg.addSysTrayMenuListener(this );
085:
086: SysTrayMenuItem itemExit = new SysTrayMenuItem(MENU_EXIT_TEXT,
087: MENU_EXIT_CMD);
088: itemExit.addSysTrayMenuListener(this );
089:
090: SysTrayMenuItem itemAbout = new SysTrayMenuItem(
091: MENU_ABOUT_TEXT, MENU_ABOUT_CMD);
092: itemAbout.addSysTrayMenuListener(this );
093:
094: Vector items = new Vector();
095: items.add(itemExit);
096: items.add(SysTrayMenu.SEPARATOR);
097: items.add(itemAbout);
098: items.add(SysTrayMenu.SEPARATOR);
099: items.add(itemCfg);
100:
101: menu = new SysTrayMenu(nntpIcon, "nntp//rss v"
102: + AppConstants.VERSION + " starting...", items);
103: }
104:
105: public void showStarted() {
106: menu.setToolTip("nntp//rss v" + AppConstants.VERSION);
107: menu.getItem(MENU_PROPERTIES_TEXT).setEnabled(true);
108: }
109:
110: public void shutdown() {
111: menu.setToolTip("nntp//rss v" + AppConstants.VERSION
112: + " shutting down...");
113: menu.getItem(MENU_PROPERTIES_TEXT).setEnabled(false);
114: menu.getItem(MENU_ABOUT_TEXT).setEnabled(false);
115: menu.getItem(MENU_EXIT_TEXT).setEnabled(false);
116: }
117:
118: /**
119: * @see snoozesoft.systray4j.SysTrayMenuListener#iconLeftClicked(SysTrayMenuEvent)
120: */
121: public void iconLeftClicked(SysTrayMenuEvent arg0) {
122: }
123:
124: /**
125: * @see snoozesoft.systray4j.SysTrayMenuListener#iconLeftDoubleClicked(SysTrayMenuEvent)
126: */
127: public void iconLeftDoubleClicked(SysTrayMenuEvent arg0) {
128: startBrowser(adminURL);
129: }
130:
131: private void startBrowser(String url) {
132: try {
133: Process process = Runtime.getRuntime().exec(
134: new String[] { "cmd.exe", "/c", "start", "\"\"",
135: "\"" + url + "\"" });
136: process.waitFor();
137: process.exitValue();
138:
139: } catch (IOException ie) {
140: } catch (InterruptedException ie) {
141: }
142: }
143:
144: /**
145: * @see snoozesoft.systray4j.SysTrayMenuListener#menuItemSelected(SysTrayMenuEvent)
146: */
147: public void menuItemSelected(SysTrayMenuEvent e) {
148: if (e.getActionCommand().equals(MENU_ABOUT_CMD)) {
149: final JLabel url = new JLabel(
150: "<html><u><font color=blue>http://www.methodize.org/nntprss</font></u></html>");
151: url.addMouseListener(new MouseListener() {
152: /**
153: * @see java.awt.event.MouseListener#mouseClicked(MouseEvent)
154: */
155: public void mouseClicked(MouseEvent arg0) {
156: startBrowser("http://www.methodize.org/nntprss");
157: }
158:
159: public void mouseEntered(MouseEvent arg0) {
160: url
161: .setText("<html><u><font color=red>http://www.methodize.org/nntprss</font></u></html>");
162: }
163:
164: public void mouseExited(MouseEvent arg0) {
165: url
166: .setText("<html><u><font color=blue>http://www.methodize.org/nntprss</font></u></html>");
167: }
168:
169: public void mousePressed(MouseEvent arg0) {
170: }
171:
172: public void mouseReleased(MouseEvent arg0) {
173: }
174:
175: });
176:
177: Object[] message = new Object[] {
178: "nntp//rss v" + AppConstants.VERSION, url, "\n",
179: "Copyright (c) 2002, 2003 Jason Brome",
180: "Licensed under the GNU Public License\n" };
181: JOptionPane.showMessageDialog(this , message,
182: MENU_ABOUT_TEXT, JOptionPane.INFORMATION_MESSAGE);
183: } else if (e.getActionCommand().equals(MENU_EXIT_CMD)) {
184: Object[] options = { "QUIT", "CANCEL" };
185: int option = JOptionPane.showOptionDialog(this ,
186: "Are you sure you want to quit?",
187: "nntp//rss - Warning", JOptionPane.DEFAULT_OPTION,
188: JOptionPane.WARNING_MESSAGE, null, options,
189: options[1]);
190: if (option == 0) {
191: System.exit(0);
192: }
193: } else if (e.getActionCommand().equals(MENU_PROPERTIES_CMD)) {
194: startBrowser(adminURL);
195: } else {
196: // Invalid command, should not happen
197: JOptionPane.showMessageDialog(this , e.getActionCommand());
198: }
199: }
200:
201: /**
202: * Returns the adminURL.
203: * @return String
204: */
205: public String getAdminURL() {
206: return adminURL;
207: }
208:
209: /**
210: * Sets the adminURL.
211: * @param adminURL The adminURL to set
212: */
213: public void setAdminURL(String adminURL) {
214: this.adminURL = adminURL;
215: }
216:
217: }
|