Source Code Cross Referenced for ShellTray.java in  » Development » Tracelog » net » sourceforge » tracelog » ui » 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 » Development » Tracelog » net.sourceforge.tracelog.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.tracelog.ui;
002:
003:        import java.io.BufferedReader;
004:        import java.io.InputStreamReader;
005:        import java.net.URL;
006:
007:        import net.sourceforge.tracelog.utils.Util;
008:
009:        import org.eclipse.swt.SWT;
010:        import org.eclipse.swt.graphics.Image;
011:        import org.eclipse.swt.program.Program;
012:        import org.eclipse.swt.widgets.Event;
013:        import org.eclipse.swt.widgets.Listener;
014:        import org.eclipse.swt.widgets.Menu;
015:        import org.eclipse.swt.widgets.MenuItem;
016:        import org.eclipse.swt.widgets.Shell;
017:        import org.eclipse.swt.widgets.ToolTip;
018:        import org.eclipse.swt.widgets.Tray;
019:        import org.eclipse.swt.widgets.TrayItem;
020:
021:        public class ShellTray extends AbstractWidget {
022:            private Image activeImage;
023:            private Image idleImage;
024:            private TrayItem trayItem;
025:            private Shell trayShell;
026:
027:            public ShellTray() {
028:                super ();
029:                this .trayShell = new Shell(display);
030:                this .idleImage = new Image(display, Util
031:                        .getOwnResource(projectProperties.getShellIconPath()));
032:                this .activeImage = new Image(display, Util
033:                        .getOwnResource(projectProperties.getIconActive()));
034:            }
035:
036:            public void run() {
037:                final Tray tray = display.getSystemTray();
038:
039:                if (tray != null) {
040:
041:                    ToolTip toolTip = new ToolTip(trayShell, SWT.BALLOON
042:                            | SWT.ICON_INFORMATION);
043:
044:                    String latestVersion = getLatestSoftwareVersion();
045:
046:                    // has new version
047:                    if (!latestVersion.equals(appVersion)) {
048:                        toolTip.setText(appTitle + " Software Update");
049:                        toolTip.setAutoHide(false);
050:
051:                        toolTip
052:                                .setMessage("A new software release, "
053:                                        + latestVersion
054:                                        + ", is now available for download. "
055:                                        + "The current software release is "
056:                                        + appVersion
057:                                        + ". "
058:                                        + Util.LINE_BREAK
059:                                        + Util.LINE_BREAK
060:                                        + "Please click here to download the latest release.");
061:                        toolTip.addListener(SWT.Selection, new Listener() {
062:                            public void handleEvent(Event event) {
063:                                Program
064:                                        .launch(projectProperties
065:                                                .getUpdateURL());
066:                            }
067:                        });
068:                    }
069:                    // no updates available
070:                    else {
071:                        toolTip.setText(appTitle);
072:                        toolTip
073:                                .setMessage("This system tray icon blinks when the log viewer is updated.");
074:                    }
075:
076:                    trayItem = new TrayItem(tray, SWT.NONE);
077:                    trayItem.setToolTipText(appTitle);
078:                    trayItem.setToolTip(toolTip);
079:                    trayItem.addListener(SWT.Selection, new Listener() {
080:                        public void handleEvent(Event event) {
081:                            mediator
082:                                    .handleEvent(ActionMediator.EVENT_DISPLAY_MAIN_SHELL);
083:                        }
084:                    });
085:
086:                    final Menu menu = new Menu(trayShell, SWT.POP_UP);
087:                    MenuItem openMenuItem = new MenuItem(menu, SWT.PUSH);
088:                    openMenuItem.setText("Open " + appTitle);
089:                    openMenuItem.addListener(SWT.Selection, new Listener() {
090:                        public void handleEvent(Event event) {
091:                            mediator
092:                                    .handleEvent(ActionMediator.EVENT_DISPLAY_MAIN_SHELL);
093:                        }
094:                    });
095:                    menu.setDefaultItem(openMenuItem);
096:
097:                    new MenuItem(menu, SWT.SEPARATOR);
098:
099:                    MenuItem closeMenuItem = new MenuItem(menu, SWT.PUSH);
100:                    closeMenuItem.setText("Exit");
101:                    closeMenuItem.addListener(SWT.Selection, new Listener() {
102:                        public void handleEvent(Event event) {
103:                            tray.dispose();
104:                        }
105:                    });
106:
107:                    trayItem.addListener(SWT.MenuDetect, new Listener() {
108:                        public void handleEvent(Event event) {
109:                            menu.setVisible(true);
110:                        }
111:                    });
112:
113:                    trayItem.setImage(idleImage);
114:
115:                    // position and display the tool tip
116:                    toolTip.setLocation(trayShell.getLocation());
117:                    toolTip.setVisible(true);
118:
119:                    while (!tray.isDisposed()) {
120:                        if (!display.readAndDispatch())
121:                            display.sleep();
122:                    }
123:
124:                    idleImage.dispose();
125:                    activeImage.dispose();
126:                    display.dispose();
127:                }
128:            }
129:
130:            private String getLatestSoftwareVersion() {
131:                String latestVersion = "";
132:                BufferedReader br = null;
133:
134:                try {
135:                    URL url = new URL(projectProperties.getUpdateCheckerURL());
136:
137:                    br = new BufferedReader(new InputStreamReader(url
138:                            .openStream()));
139:
140:                    // read only the first non-blank line for the latest version
141:                    while ((latestVersion = br.readLine()) != null
142:                            && latestVersion.equals("")) {
143:                    }
144:
145:                    // somehow the line is empty, which is strange, then just default it
146:                    // to current version so that it doesn't crash
147:                    latestVersion = (latestVersion == null || latestVersion
148:                            .equals("")) ? appVersion : latestVersion.trim();
149:
150:                }
151:                // any errors, then default latest version to the current version.
152:                catch (Exception ignored) {
153:                    latestVersion = appVersion;
154:                } finally {
155:                    try {
156:                        br.close();
157:                    } catch (Exception ignored) {
158:                    }
159:                }
160:
161:                return latestVersion;
162:            }
163:
164:            // /**
165:            // * Checks if the tray icon is showing active mode.
166:            // *
167:            // * @return true if it is active, false otherwise.
168:            // */
169:            // private boolean isActive() {
170:            // return trayItem.getImage() != null &&
171:            // trayItem.getImage().equals(activeImage);
172:            // }
173:            //
174:            // /**
175:            // * Sets tray icon to be active mode.
176:            // */
177:            // private void setActiveImage() {
178:            // if (!isActive()) {
179:            // trayItem.setImage(activeImage);
180:            // }
181:            // }
182:            //
183:            // /**
184:            // * Sets tray icon to be idle mode.
185:            // */
186:            // private void setIdleImage() {
187:            // if (isActive()) {
188:            // trayItem.setImage(idleImage);
189:            // }
190:            // }
191:            //
192:            // public void updateTrayIcon(ModifyEvent e) {
193:            //
194:            // if (e == null) {
195:            // return;
196:            // }
197:            //
198:            // // has data to display
199:            // if (e.data == null) {
200:            // if (!isActive()) {
201:            // setActiveImage();
202:            // }
203:            // }
204:            // // no more data to display
205:            // else if (((String) e.data).equals(LogViewerHandler.NO_DATA)) {
206:            // if (isActive()) {
207:            // setIdleImage();
208:            // }
209:            // }
210:            // }
211:
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.