Source Code Cross Referenced for SysTrayControl.java in  » Web-Server » Acme-WebServer » rogatkin » web » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Server » Acme WebServer » rogatkin.web 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* tjws - SysTrayControl.java
002:         * Copyright (C) 1999-2007 Dmitriy Rogatkin.  All rights reserved.
003:         * Redistribution and use in source and binary forms, with or without
004:         * modification, are permitted provided that the following conditions
005:         * are met:
006:         * 1. Redistributions of source code must retain the above copyright
007:         *    notice, this list of conditions and the following disclaimer.
008:         * 2. Redistributions in binary form must reproduce the above copyright
009:         *    notice, this list of conditions and the following disclaimer in the
010:         *    documentation and/or other materials provided with the distribution.
011:         *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
012:         *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
013:         *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
014:         *  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
015:         *  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
016:         *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
017:         *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
018:         *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
019:         *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
020:         *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
021:         *  SUCH DAMAGE.
022:         *  
023:         *  Visit http://tjws.sourceforge.net to get the latest infromation
024:         *  about Rogatkin's products.                                                        
025:         *  $Id: SysTrayControl.java,v 1.5 2007/04/12 05:24:51 rogatkin Exp $                
026:         *  Created on Jul 2, 2006
027:         *  @author Dmitriy
028:         */
029:        package rogatkin.web;
030:
031:        import java.awt.AWTException;
032:        import java.awt.Desktop;
033:        import java.awt.MenuItem;
034:        import java.awt.PopupMenu;
035:        import java.awt.SplashScreen;
036:        import java.awt.SystemTray;
037:        import java.awt.Toolkit;
038:        import java.awt.TrayIcon;
039:        import java.awt.event.ActionEvent;
040:        import java.awt.event.ActionListener;
041:        import java.io.IOException;
042:        import java.lang.reflect.InvocationTargetException;
043:        import java.lang.reflect.Method;
044:        import java.net.URI;
045:        import java.net.URISyntaxException;
046:        import java.util.Arrays;
047:        import java.util.Timer;
048:        import java.util.TimerTask;
049:
050:        import rogatkin.web.WebApp.ServiceController;
051:        import Acme.Serve.Serve;
052:
053:        public class SysTrayControl implements  ServiceController,
054:                ActionListener {
055:
056:            private Method s;
057:
058:            private TrayIcon ti;
059:
060:            private String contextPath;
061:
062:            private String port = "" + Serve.DEF_PORT;
063:
064:            public void attachServe(Method stop, String contextPath) {
065:                s = stop;
066:                this .contextPath = contextPath;
067:                if (SystemTray.isSupported() == false)
068:                    return;
069:                SystemTray st = SystemTray.getSystemTray();
070:                // TODO get text from localized resource
071:                PopupMenu popup = new PopupMenu();
072:                MenuItem mi;
073:                if (Desktop.isDesktopSupported()) {
074:                    popup.add(mi = new MenuItem("Go " + contextPath));
075:                    mi.addActionListener(this );
076:                }
077:                popup.add(mi = new MenuItem("stop"));
078:                mi.addActionListener(this );
079:                popup.add(mi = new MenuItem("exit"));
080:                mi.addActionListener(this );
081:                //java.net.URL u;
082:                ti = new TrayIcon(Toolkit.getDefaultToolkit().getImage(
083:                        getClass().getClassLoader().getResource(
084:                                "rogatkin/resource/tjws.gif")),
085:                        "TJWS control panel", popup);
086:                //javax.swing.JOptionPane.showMessageDialog(null, String.format("Created sys tray icon with image%s%n",u));
087:                ti.setImageAutoSize(true);
088:
089:                try {
090:                    st.add(ti);
091:                } catch (AWTException e) {
092:
093:                }
094:                new Timer("Splash closer", true).schedule(new TimerTask() {
095:                    @Override
096:                    public void run() {
097:                        SplashScreen ss = SplashScreen.getSplashScreen();
098:                        if (ss != null)
099:                            ss.close();
100:                    }
101:                }, 3 * 1000);
102:            }
103:
104:            public String[] massageSettings(String[] args) {
105:                boolean nohup = false;
106:                boolean nextPort = false;
107:                for (String arg : args)
108:                    if ("-nohup".equals(arg)) {
109:                        nohup = true;
110:                    } else if ("-p".equals(arg))
111:                        nextPort = true;
112:                    else if (nextPort) {
113:                        port = arg;
114:                        nextPort = false;
115:                    }
116:
117:                if (SystemTray.isSupported()) {
118:                    if (nohup == false) {
119:                        args = Arrays.copyOf(args, args.length + 1);
120:                        args[args.length - 1] = "-nohup";
121:                    }
122:                } else {
123:                    // remove '-nohup'
124:
125:                }
126:                return args;
127:            }
128:
129:            public void actionPerformed(ActionEvent event) {
130:                try {
131:                    if ("stop".equals(event.getActionCommand())) {
132:                        ti.displayMessage("TJWS", "Server stopped",
133:                                TrayIcon.MessageType.INFO);
134:                        s.invoke(null); // TODO suspend it
135:                    } else if ("exit".equals(event.getActionCommand())) {
136:                        s.invoke(null);
137:                        System.exit(0);
138:                    } else if (event.getActionCommand().startsWith("Go")) {
139:                        //javax.swing.JOptionPane.showMessageDialog(null, String.format("http://localhost:%s/%s", port, contextPath));
140:                        ti.displayMessage("TJWS", "Going to " + contextPath,
141:                                TrayIcon.MessageType.INFO);
142:                        Desktop desktop = Desktop.getDesktop();
143:                        desktop.browse(new URI(String.format(
144:                                "http://localhost:%s/%s", port, contextPath)));
145:                    } //else
146:                    //javax.swing.JOptionPane.showMessageDialog(null, "Command "+event.getActionCommand());
147:                } catch (URISyntaxException e) {
148:                    //e.printStackTrace();
149:                } catch (IOException e) {
150:                    //e.printStackTrace();
151:                } catch (IllegalArgumentException e) {
152:                    e.printStackTrace();
153:                } catch (IllegalAccessException e) {
154:                    e.printStackTrace();
155:                } catch (InvocationTargetException e) {
156:                    e.printStackTrace();
157:                }
158:            }
159:
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.