1 | /* |
---|
2 | * Jeti, a Java Jabber client, Copyright (C) 2001 E.S. de Boer |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation; either version 2 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | * |
---|
18 | * For questions, comments etc, |
---|
19 | * use the website at http://jeti.jabberstudio.org |
---|
20 | * or mail/IM me at jeti@jabber.org |
---|
21 | */ |
---|
22 | |
---|
23 | package nu.fw.jeti.backend; |
---|
24 | |
---|
25 | import java.awt.*; |
---|
26 | import java.io.File; |
---|
27 | import java.net.MalformedURLException; |
---|
28 | import java.net.URL; |
---|
29 | import java.net.URLDecoder; |
---|
30 | import java.util.Properties; |
---|
31 | |
---|
32 | import javax.swing.JFrame; |
---|
33 | import javax.swing.JOptionPane; |
---|
34 | import javax.swing.UIManager; |
---|
35 | import javax.swing.UnsupportedLookAndFeelException; |
---|
36 | import javax.xml.parsers.FactoryConfigurationError; |
---|
37 | import javax.xml.parsers.ParserConfigurationException; |
---|
38 | import javax.xml.parsers.SAXParser; |
---|
39 | import javax.xml.parsers.SAXParserFactory; |
---|
40 | |
---|
41 | import nu.fw.jeti.images.StatusIcons; |
---|
42 | import nu.fw.jeti.jabber.Backend; |
---|
43 | import nu.fw.jeti.plugins.PluginsInfo; |
---|
44 | import nu.fw.jeti.ui.Jeti; |
---|
45 | import nu.fw.jeti.util.I18N; |
---|
46 | import nu.fw.jeti.util.Log; |
---|
47 | import nu.fw.jeti.util.Popups; |
---|
48 | import nu.fw.jeti.util.Preferences; |
---|
49 | |
---|
50 | import org.xml.sax.SAXException; |
---|
51 | /** |
---|
52 | * @author E.S. de Boer |
---|
53 | */ |
---|
54 | |
---|
55 | public class Start |
---|
56 | { |
---|
57 | public static final String VERSION = "0.7.7"; |
---|
58 | public final static String OS2 = ""; |
---|
59 | public static String BUILD_DATE; |
---|
60 | public static String BUILD_NUM; |
---|
61 | public static URL programURL; //url where the plugins are change to plugins url can use always also if local |
---|
62 | public static URL dataURL; //url where the data is stored |
---|
63 | public static String pluginPath; //plugin path |
---|
64 | public static String path; //local path |
---|
65 | public static boolean applet=false; |
---|
66 | public static boolean webstart=false; |
---|
67 | private SAXParser parser; |
---|
68 | private static Splash splash; |
---|
69 | private PluginsInfo pluginsInfo; |
---|
70 | private Backend backend; |
---|
71 | |
---|
72 | public Start(String urlString, Container container) |
---|
73 | { |
---|
74 | try |
---|
75 | { |
---|
76 | parser = SAXParserFactory.newInstance().newSAXParser(); |
---|
77 | } |
---|
78 | catch (FactoryConfigurationError ex) |
---|
79 | { |
---|
80 | ex.printStackTrace(); |
---|
81 | } |
---|
82 | catch (SAXException ex) |
---|
83 | { |
---|
84 | ex.printStackTrace(); |
---|
85 | } |
---|
86 | catch (ParserConfigurationException ex) |
---|
87 | { |
---|
88 | ex.printStackTrace(); |
---|
89 | } |
---|
90 | |
---|
91 | if ( urlString == null) |
---|
92 | urlString = getPath(); |
---|
93 | |
---|
94 | if ( System.getProperty("file.separator").equals("/") ) |
---|
95 | pluginPath = urlString.substring(5); |
---|
96 | else |
---|
97 | pluginPath = urlString.substring(6); |
---|
98 | |
---|
99 | pluginPath = pluginPath.replace('/', File.separatorChar); |
---|
100 | |
---|
101 | /** |
---|
102 | * Se o programurl for null, applet ou network tb usa program path como data path |
---|
103 | */ |
---|
104 | |
---|
105 | dataURL = programURL; |
---|
106 | path = pluginPath; |
---|
107 | |
---|
108 | try |
---|
109 | { |
---|
110 | Properties p = new Properties(); |
---|
111 | p.load(getClass().getResource("version.properties").openStream()); |
---|
112 | BUILD_DATE = p.getProperty("buildDate"); |
---|
113 | BUILD_NUM = p.getProperty("buildNum"); |
---|
114 | } |
---|
115 | catch (Exception e){} |
---|
116 | |
---|
117 | backend = new Backend(this); |
---|
118 | new Preferences( backend, parser ); |
---|
119 | new StatusIcons(); |
---|
120 | Jeti jeti = new Jeti(backend,container); |
---|
121 | new Popups( backend.getMainWindow() ); |
---|
122 | pluginsInfo = new PluginsInfo(backend, this); |
---|
123 | jeti.init(); |
---|
124 | if( container != null) |
---|
125 | container.add(jeti); |
---|
126 | else |
---|
127 | backend.getMainWindow().setVisible(true); |
---|
128 | } |
---|
129 | |
---|
130 | public void setSplashText(String text) |
---|
131 | { |
---|
132 | nu.fw.jeti.applet.Jeti.from.setText(I18N.gettext("Loading") + " " + text + "..."); |
---|
133 | } |
---|
134 | |
---|
135 | private String getPath() |
---|
136 | { |
---|
137 | URL url = this.getClass().getResource("Start.class"); |
---|
138 | //System.out.println(url); |
---|
139 | String urlString = null; |
---|
140 | |
---|
141 | try |
---|
142 | { |
---|
143 | //remove %20 from program files etc |
---|
144 | urlString = URLDecoder.decode(url.toString(), "UTF8"); //encode if to url? probaly not |
---|
145 | } |
---|
146 | catch (Exception e) |
---|
147 | { |
---|
148 | e.printStackTrace(); |
---|
149 | } |
---|
150 | |
---|
151 | if (url.getProtocol().equals("jar")) |
---|
152 | { |
---|
153 | // Strip off JarURL-specific syntax. |
---|
154 | urlString = urlString.substring(4); |
---|
155 | urlString = urlString.substring(0, urlString.lastIndexOf("!")); |
---|
156 | urlString = urlString.substring(0, urlString.lastIndexOf("/") + 1); |
---|
157 | } |
---|
158 | else urlString = urlString.substring(0, urlString.lastIndexOf("/jeti") + 1); |
---|
159 | return urlString; |
---|
160 | } |
---|
161 | |
---|
162 | public static void remoteLoad(URL url, String path) |
---|
163 | { |
---|
164 | Start.pluginPath = path; |
---|
165 | Start.programURL = url; |
---|
166 | start(pluginPath,null); |
---|
167 | } |
---|
168 | |
---|
169 | public static void main(String[] args) |
---|
170 | { |
---|
171 | if(args.length>0)path = args[0]; |
---|
172 | start(null,null); |
---|
173 | } |
---|
174 | |
---|
175 | public static void start(String path,Container container) |
---|
176 | { |
---|
177 | Frame frame = new Frame(); |
---|
178 | splash = new Splash(frame); |
---|
179 | new Start(path,container); |
---|
180 | splash.dispose(); |
---|
181 | frame.dispose(); |
---|
182 | splash=null; |
---|
183 | } |
---|
184 | |
---|
185 | public Backend getBackend() |
---|
186 | { |
---|
187 | return backend; |
---|
188 | } |
---|
189 | |
---|
190 | public void close() |
---|
191 | { |
---|
192 | if( backend != null ) backend.getMain().close(); |
---|
193 | } |
---|
194 | |
---|
195 | public void exit() |
---|
196 | { |
---|
197 | pluginsInfo.exit(); |
---|
198 | nu.fw.jeti.applet.Jeti.exit(); |
---|
199 | backend = null; |
---|
200 | } |
---|
201 | |
---|
202 | static class Splash extends Window |
---|
203 | { |
---|
204 | Label from; |
---|
205 | public Splash(Frame frame) |
---|
206 | { |
---|
207 | super(frame); |
---|
208 | Label label = new Label("Jeti" + OS2 + " is Loading"+"..."); |
---|
209 | label.setFont(new java.awt.Font("Serif", 1, 40)); |
---|
210 | label.setBackground(new Color(150,150,255)); |
---|
211 | add(label,BorderLayout.CENTER); |
---|
212 | Panel panel = new Panel(); |
---|
213 | panel.setBackground(new Color(255,255,150)); |
---|
214 | from = new Label("(c) 2001-2008 E.S. de Boer"); |
---|
215 | from.setBackground(new Color(255,255,150)); |
---|
216 | panel.add(from); |
---|
217 | Label version = new Label("Version: " + Start.VERSION); |
---|
218 | version.setBackground(new Color(255,255,150)); |
---|
219 | panel.add(version); |
---|
220 | add(panel,BorderLayout.SOUTH); |
---|
221 | pack(); |
---|
222 | setLocationRelativeTo(null); |
---|
223 | setVisible(true); |
---|
224 | } |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | /* |
---|
229 | * Overrides for emacs |
---|
230 | * Local variables: |
---|
231 | * tab-width: 4 |
---|
232 | * End: |
---|
233 | */ |
---|