source: trunk/jabberit_messenger/java_source/src/nu/fw/jeti/backend/Start.java @ 1001

Revision 1001, 8.1 KB checked in by alexandrecorreia, 15 years ago (diff)

Ticket #552 - Inclusão do projeto Java referente ao applet do módulo.

Line 
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
23package nu.fw.jeti.backend;
24
25import java.awt.*;
26import java.io.File;
27import java.net.MalformedURLException;
28import java.net.URL;
29import java.net.URLDecoder;
30import java.util.Properties;
31
32import javax.swing.JFrame;
33import javax.swing.JOptionPane;
34import javax.swing.UIManager;
35import javax.swing.UnsupportedLookAndFeelException;
36import javax.xml.parsers.FactoryConfigurationError;
37import javax.xml.parsers.ParserConfigurationException;
38import javax.xml.parsers.SAXParser;
39import javax.xml.parsers.SAXParserFactory;
40
41import nu.fw.jeti.images.StatusIcons;
42import nu.fw.jeti.jabber.Backend;
43import nu.fw.jeti.plugins.PluginsInfo;
44import nu.fw.jeti.ui.Jeti;
45import nu.fw.jeti.util.I18N;
46import nu.fw.jeti.util.Log;
47import nu.fw.jeti.util.Popups;
48import nu.fw.jeti.util.Preferences;
49
50import org.xml.sax.SAXException;
51/**
52 * @author E.S. de Boer
53 */
54
55public class Start
56{
57        public static final String VERSION = "0.7.7";
58        //public final static String OS2 = "/2";
59        public final static String OS2 = "";
60        public static String BUILD_DATE;
61        public static String BUILD_NUM;
62        public static URL programURL; //url where the plugins are change to plugins url can use always also if local
63        public static URL dataURL; //url where the data is stored
64        public static String pluginPath; //plugin path
65        public static String path; //local path
66        public static boolean applet=false;
67        public static boolean webstart=false;
68        private SAXParser parser;
69        private static Splash splash;
70        private PluginsInfo pluginsInfo;
71        private Backend backend;
72       
73        public Start(String urlString,Container container)
74        {
75                try
76                {
77                        parser = SAXParserFactory.newInstance().newSAXParser();
78                }
79                catch (FactoryConfigurationError ex)
80                {
81                        ex.printStackTrace();
82                }
83                catch (SAXException ex)
84                {
85                        ex.printStackTrace();
86                }
87                catch (ParserConfigurationException ex)
88                {
89                        ex.printStackTrace();
90                }
91                if(!applet && System.getProperty("jnlpx.home")!=null)webstart = true;
92               
93                if (urlString == null) urlString = getPath();
94               
95                if (System.getProperty("file.separator").equals("/"))
96                {
97                        pluginPath = urlString.substring(5);
98                }
99                else pluginPath = urlString.substring(6);
100                pluginPath = pluginPath.replace('/', File.separatorChar);
101               
102               
103               
104                if(programURL==null)
105                {
106                        try
107                        {
108                                programURL = new URL(urlString);
109                               
110                                if(webstart || (path!=null&&path.equals("home")))
111                                {
112                                        path = System.getProperty("user.home")+ File.separatorChar
113                                                                                                + ".jeti" +File.separatorChar;
114                                        File dir =new File(path);
115                                        if(!dir.exists())
116                                        {
117                                                if(!dir.mkdir())
118                                                {
119                                                        JOptionPane.showMessageDialog(null, "Directory " + dir + " could not be created, Jeti will close");
120                                                        System.exit(1);
121                                                }
122                                        }
123                                        dataURL = new URL("file:/"+path);
124                                }
125                                else if(path!=null)
126                                {
127                                        File dir =new File(path);
128                                        if(!dir.exists())
129                                        {
130                                                if(!dir.mkdir())
131                                                {
132                                                        JOptionPane.showMessageDialog(null, "Directory " + dir + " could not be created, Jeti will close");
133                                                        System.exit(1);
134                                                }
135                                        }
136                                        dataURL = new URL("file:/"+path);
137                                }
138                                else
139                                {
140                                        dataURL = programURL;
141                                        path = pluginPath;
142                                }
143                                System.out.println(programURL);
144                                System.out.println(dataURL);
145                        }
146                        catch (MalformedURLException ex)
147                        {
148                                ex.printStackTrace();
149                        }
150                }
151                else
152                {
153                        //if programurl null applet or network so use program path as data path
154                        dataURL = programURL;
155                        path = pluginPath;
156                }
157                                               
158                try
159                {
160                        Properties p = new Properties();
161                        p.load(getClass().getResource("version.properties").openStream());
162                        BUILD_DATE = p.getProperty("buildDate");
163                        BUILD_NUM = p.getProperty("buildNum");
164                } catch (Exception e)
165                {
166                        System.out.println("Can't find the version.properties file");
167                }
168               
169               
170                backend = new Backend(this);
171                new Preferences(backend, parser);
172                I18N.init();
173                //Preferences.initMessages();
174                JFrame.setDefaultLookAndFeelDecorated(Preferences.getBoolean("jeti","javadecorations",false));
175               
176                if(Preferences.getBoolean("jeti", "nativeLnF", false))
177                {
178                        try
179                        {
180                                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
181                        } catch (ClassNotFoundException e)
182                        {
183                                e.printStackTrace();
184                        } catch (InstantiationException e)
185                        {
186                                e.printStackTrace();
187                        } catch (IllegalAccessException e)
188                        {
189                                e.printStackTrace();
190                        } catch (UnsupportedLookAndFeelException e)
191                        {
192                                e.printStackTrace();
193                        }
194                }
195                //parse plugins? make better or make comments
196                new StatusIcons(parser);
197                Jeti jeti = new Jeti(backend,container);
198                new Log(backend);
199                new Popups(backend.getMainWindow());
200                pluginsInfo = new PluginsInfo(backend,parser,this);
201                jeti.init();
202                if(container!=null) container.add(jeti);
203                else backend.getMainWindow().setVisible(true);
204        }
205       
206        public void setSplashText(String text)
207        {
208                nu.fw.jeti.applet.Jeti.from.setText(I18N.gettext("Loading") + " " + text + "...");
209        }
210
211        private String getPath()
212        {
213                // Now, search for and get the URL for this class.
214                URL url = this.getClass().getResource("Start.class");
215                //System.out.println(url);
216                String urlString = null;
217
218                try
219                { //remove %20 from program files etc
220                        urlString = URLDecoder.decode(url.toString(), "UTF8"); //encode if to url? probaly not
221                }
222                catch (Exception e)
223                {
224                        e.printStackTrace();
225                } //1.2 error
226
227                //System.out.println(url.getPath()  ); //werkt niet in 1.2
228                //System.out.println(url);
229                if (url.getProtocol().equals("jar"))
230                {
231                        // Strip off JarURL-specific syntax.
232                        urlString = urlString.substring(4);
233                        urlString = urlString.substring(0, urlString.lastIndexOf("!"));
234                        urlString = urlString.substring(0, urlString.lastIndexOf("/") + 1);
235                }
236                else urlString = urlString.substring(0, urlString.lastIndexOf("/jeti") + 1);
237                return urlString;
238        }
239
240        public static void remoteLoad(URL url, String path)
241        {
242                Start.pluginPath = path;
243                Start.programURL = url;
244                start(pluginPath,null);
245        }
246       
247        public static void main(String[] args)
248        {
249                if(args.length>0)path = args[0];
250                start(null,null);
251        }
252       
253        public static void start(String path,Container container)
254        {
255                Frame frame = new Frame();
256                splash = new Splash(frame);
257                new Start(path,container);
258                splash.dispose();
259                frame.dispose();
260                splash=null;
261        }
262       
263        public Backend getBackend()
264        {
265                return backend;
266        }
267       
268        public void close()
269        {
270                if( backend != null ) backend.getMain().close();
271        }
272       
273        public void exit()
274        {
275                pluginsInfo.exit();
276                if(applet)nu.fw.jeti.applet.Jeti.exit();
277                backend=null;
278        }
279
280    static class Splash extends Window
281    {
282        Label from;
283        public Splash(Frame frame)
284        {
285            super(frame);
286            Label label = new Label("Jeti" + OS2 + " is Loading"+"...");
287            label.setFont(new java.awt.Font("Serif", 1, 40));
288            label.setBackground(new Color(150,150,255));
289            add(label,BorderLayout.CENTER);
290            Panel panel = new Panel();
291            panel.setBackground(new Color(255,255,150));
292            from = new Label("(c) 2001-2008 E.S. de Boer");
293            from.setBackground(new Color(255,255,150));
294            panel.add(from);
295            Label version = new Label("Version: " + Start.VERSION);
296            version.setBackground(new Color(255,255,150));
297            panel.add(version);
298            add(panel,BorderLayout.SOUTH);
299            pack();
300            setLocationRelativeTo(null);
301            setVisible(true);
302        }
303    }
304}
305/*
306 * Overrides for emacs
307 * Local variables:
308 * tab-width: 4
309 * End:
310 */
311
Note: See TracBrowser for help on using the repository browser.