KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > utils > HelpManager


1 /*
2
3 [The "BSD licence"]
4 Copyright (c) 2005 Jean Bovet
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10
11 1. Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16 3. The name of the author may not be used to endorse or promote products
17 derived from this software without specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 */

31
32 package org.antlr.works.utils;
33
34 import org.antlr.xjlib.appkit.app.XJApplication;
35 import org.antlr.xjlib.appkit.update.XJUpdateManager;
36 import org.antlr.xjlib.appkit.utils.BrowserLauncher;
37 import org.antlr.xjlib.appkit.utils.XJAlert;
38 import org.antlr.xjlib.foundation.XJSystem;
39 import org.antlr.xjlib.foundation.XJUtils;
40 import org.antlr.xjlib.foundation.timer.XJScheduledTimerDelegate;
41 import org.antlr.Tool;
42 import org.antlr.stringtemplate.StringTemplate;
43 import org.antlr.works.dialog.DialogReports;
44 import org.antlr.works.prefs.AWPrefs;
45
46 import java.awt.*;
47 import java.io.IOException JavaDoc;
48 import java.util.Calendar JavaDoc;
49
50 public class HelpManager implements XJScheduledTimerDelegate {
51
52     public void scheduledTimerFired(boolean startup) {
53         checkUpdatesAuto(startup);
54     }
55
56     public static void submitStats(Container parent) {
57         new DialogReports(parent, true).runModal();
58     }
59
60     public static void sendFeedback(Container parent) {
61         StringBuffer JavaDoc url = new StringBuffer JavaDoc(Localizable.getLocalizedString(Localizable.FEEDBACK_URL));
62         url.append("?ANTLRVersion=");
63         url.append(XJUtils.encodeToURL(Tool.VERSION));
64         url.append("&StringTemplateVersion=");
65         url.append(XJUtils.encodeToURL(StringTemplate.VERSION));
66         url.append("&ANTLRWorksVersion=");
67         url.append(XJUtils.encodeToURL(XJApplication.getAppVersionShort()));
68         url.append("&OS=");
69         url.append(XJUtils.encodeToURL(XJSystem.getOSName()));
70         url.append("&JavaVersion=");
71         url.append(XJUtils.encodeToURL(XJSystem.getJavaRuntimeVersion()));
72
73         try {
74             BrowserLauncher.openURL(url.toString());
75         } catch (IOException JavaDoc e) {
76             XJAlert.display(parent, "Error", "Cannot display the feedback page because:\n"+e+"\n\nTo report a feedback, go to "+url+".");
77         }
78     }
79
80     public static void checkUpdates(Container parent, boolean automatic) {
81         String JavaDoc url;
82         if(XJSystem.isMacOS())
83             url = Localizable.getLocalizedString(Localizable.UPDATE_OSX_XML_URL);
84         else
85             url = Localizable.getLocalizedString(Localizable.UPDATE_XML_URL);
86
87
88         XJUpdateManager um = new XJUpdateManager(parent, null);
89         um.checkForUpdates(Localizable.getLocalizedString(Localizable.APP_VERSION_SHORT),
90                            url,
91                            AWPrefs.getDownloadPath(),
92                            automatic);
93     }
94
95     public static void checkUpdatesAuto(boolean atStartup) {
96         int method = AWPrefs.getUpdateType();
97         boolean check = false;
98
99         if(method == AWPrefs.UPDATE_MANUALLY)
100             check = false;
101         else if(method == AWPrefs.UPDATE_AT_STARTUP && atStartup)
102             check = true;
103         else {
104             Calendar JavaDoc currentCalendar = Calendar.getInstance();
105             Calendar JavaDoc nextUpdateCalendar = AWPrefs.getUpdateNextDate();
106
107             if(nextUpdateCalendar == null || currentCalendar.equals(nextUpdateCalendar) || currentCalendar.after(nextUpdateCalendar)) {
108
109                 switch(method) {
110                     case AWPrefs.UPDATE_DAILY:
111                         check = nextUpdateCalendar != null;
112                         currentCalendar.add(Calendar.DATE, 1);
113                         AWPrefs.setUpdateNextDate(currentCalendar);
114                         break;
115                     case AWPrefs.UPDATE_WEEKLY:
116                         check = nextUpdateCalendar != null;
117                         currentCalendar.add(Calendar.DATE, 7);
118                         AWPrefs.setUpdateNextDate(currentCalendar);
119                         break;
120                 }
121             }
122         }
123
124         if(check) {
125             checkUpdates(null, true);
126         }
127     }
128
129 }
130
Popular Tags