r2824 - trunk/pollen-ui/src/main/java/org/chorem/pollen/war
Author: echatellier Date: 2009-12-15 17:53:19 +0100 (Tue, 15 Dec 2009) New Revision: 2824 Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/war/PollenWarLauncher.java Log: Add systray and popup menu to stop server. Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/war/PollenWarLauncher.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/war/PollenWarLauncher.java 2009-12-15 14:15:45 UTC (rev 2823) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/war/PollenWarLauncher.java 2009-12-15 16:53:19 UTC (rev 2824) @@ -18,12 +18,22 @@ package org.chorem.pollen.war; +import java.awt.AWTException; +import java.awt.Image; +import java.awt.MenuItem; +import java.awt.PopupMenu; +import java.awt.SystemTray; +import java.awt.TrayIcon; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import java.net.JarURLConnection; import java.net.URL; import java.util.Map; +import javax.swing.ImageIcon; + import winstone.Launcher; /** @@ -40,8 +50,10 @@ * Last update : $Date$ * By : $Author$ */ -public class PollenWarLauncher { +public class PollenWarLauncher implements ActionListener { + protected Launcher winstone; + /** * Main method (used by war in manifest). * @@ -49,7 +61,18 @@ * @throws IOException */ public static void main(String[] args) throws IOException { + PollenWarLauncher launcher = new PollenWarLauncher(); + launcher.startServer(args); + launcher.installSystemTray(); + } + /** + * Launch servlet container. + * + * @param args args + * @throws IOException + */ + protected void startServer(String[] args) throws IOException { System.out.println("Starting pollen embedded mode..."); String fqnLauncherFile = PollenWarLauncher.class.getName().replaceAll("\\.", "/") + ".class"; @@ -75,6 +98,47 @@ System.out.println(" - using args : " + hashArgs); Launcher.initLogger(hashArgs); - Launcher winstone = new Launcher(hashArgs); // spawns threads, so your application doesn't block + winstone = new Launcher(hashArgs); // spawns threads, so your application doesn't block } + + /** + * Install system tray to stop server. + */ + protected void installSystemTray() { + if (SystemTray.isSupported()) { + // build menu + PopupMenu menu = new PopupMenu(); + MenuItem stopItem = new MenuItem("Stop pollen"); + stopItem.addActionListener(this); + stopItem.setActionCommand("stop"); + menu.add(stopItem); + + // build tray icon + URL imageURL = PollenWarLauncher.class.getResource("/favicon.ico"); + Image image = new ImageIcon(imageURL).getImage(); + TrayIcon icon = new TrayIcon(image, "Pollen", menu); + icon.setImageAutoSize(true); + + // System tray + SystemTray systemTray = SystemTray.getSystemTray(); + try { + systemTray.add(icon); + } catch (AWTException ex) { + throw new RuntimeException("Can't install tray icon", ex); + } + } + } + + /* + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + @Override + public void actionPerformed(ActionEvent e) { + if ("stop".equalsIgnoreCase(e.getActionCommand())) { + if (winstone != null) { + winstone.shutdown(); + System.exit(0); + } + } + } }
Le Tue, 15 Dec 2009 17:53:19 +0100 (CET), echatellier@users.chorem.org a écrit :
Author: echatellier Date: 2009-12-15 17:53:19 +0100 (Tue, 15 Dec 2009) New Revision: 2824
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/war/PollenWarLauncher.java Log: Add systray and popup menu to stop server.
lol, c'est bien la première fois que je vois du swing pour un serveur web :) donc on a du X sur nos serveurs ? moi pas comprendre... Tony Chemit -------------------- tél: +33 (0) 2 40 50 29 28 email: chemit@codelutin.com http://www.codelutin.com
participants (2)
-
echatellier@users.chorem.org -
Tony Chemit