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

Revision 1064, 6.5 KB checked in by alexandrecorreia, 15 years ago (diff)

Ticket #474 - Arquivos modificados para a tradução do Applet.

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 = "";
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                {
96                        pluginPath = urlString.substring(5);
97                }
98                else
99                        pluginPath = urlString.substring(6);
100               
101                pluginPath = pluginPath.replace('/', File.separatorChar);
102               
103                /**
104                 * Se o programurl for null, applet ou network tb usa program path como data path
105                 */
106               
107                dataURL = programURL;
108                path = pluginPath;
109
110                try
111                {
112                        Properties p = new Properties();
113                        p.load(getClass().getResource("version.properties").openStream());
114                        BUILD_DATE = p.getProperty("buildDate");
115                        BUILD_NUM = p.getProperty("buildNum");
116                }
117                catch (Exception e)
118                {
119                        System.out.println("Can't find the version.properties file");
120                }
121               
122               
123                backend = new Backend(this);
124                new Preferences(backend, parser);
125                JFrame.setDefaultLookAndFeelDecorated(Preferences.getBoolean("jeti","javadecorations",false));
126               
127                //parse plugins? make better or make comments
128                new StatusIcons(parser);
129                Jeti jeti = new Jeti(backend,container);
130                new Log(backend);
131                new Popups(backend.getMainWindow());
132                pluginsInfo = new PluginsInfo(backend,parser,this);
133                jeti.init();
134                if(container!=null) container.add(jeti);
135                else backend.getMainWindow().setVisible(true);
136        }
137       
138        public void setSplashText(String text)
139        {
140                nu.fw.jeti.applet.Jeti.from.setText(I18N.gettext("Loading") + " " + text + "...");
141        }
142
143        private String getPath()
144        {
145                // Now, search for and get the URL for this class.
146                URL url = this.getClass().getResource("Start.class");
147                //System.out.println(url);
148                String urlString = null;
149
150                try
151                { //remove %20 from program files etc
152                        urlString = URLDecoder.decode(url.toString(), "UTF8"); //encode if to url? probaly not
153                }
154                catch (Exception e)
155                {
156                        e.printStackTrace();
157                } //1.2 error
158
159                //System.out.println(url.getPath()  ); //werkt niet in 1.2
160                //System.out.println(url);
161                if (url.getProtocol().equals("jar"))
162                {
163                        // Strip off JarURL-specific syntax.
164                        urlString = urlString.substring(4);
165                        urlString = urlString.substring(0, urlString.lastIndexOf("!"));
166                        urlString = urlString.substring(0, urlString.lastIndexOf("/") + 1);
167                }
168                else urlString = urlString.substring(0, urlString.lastIndexOf("/jeti") + 1);
169                return urlString;
170        }
171
172        public static void remoteLoad(URL url, String path)
173        {
174                Start.pluginPath = path;
175                Start.programURL = url;
176                start(pluginPath,null);
177        }
178       
179        public static void main(String[] args)
180        {
181                if(args.length>0)path = args[0];
182                start(null,null);
183        }
184       
185        public static void start(String path,Container container)
186        {
187                Frame frame = new Frame();
188                splash = new Splash(frame);
189                new Start(path,container);
190                splash.dispose();
191                frame.dispose();
192                splash=null;
193        }
194       
195        public Backend getBackend()
196        {
197                return backend;
198        }
199       
200        public void close()
201        {
202                if( backend != null ) backend.getMain().close();
203        }
204       
205        public void exit()
206        {
207                pluginsInfo.exit();
208                if(applet)nu.fw.jeti.applet.Jeti.exit();
209                backend=null;
210        }
211
212    static class Splash extends Window
213    {
214        Label from;
215        public Splash(Frame frame)
216        {
217            super(frame);
218            Label label = new Label("Jeti" + OS2 + " is Loading"+"...");
219            label.setFont(new java.awt.Font("Serif", 1, 40));
220            label.setBackground(new Color(150,150,255));
221            add(label,BorderLayout.CENTER);
222            Panel panel = new Panel();
223            panel.setBackground(new Color(255,255,150));
224            from = new Label("(c) 2001-2008 E.S. de Boer");
225            from.setBackground(new Color(255,255,150));
226            panel.add(from);
227            Label version = new Label("Version: " + Start.VERSION);
228            version.setBackground(new Color(255,255,150));
229            panel.add(version);
230            add(panel,BorderLayout.SOUTH);
231            pack();
232            setLocationRelativeTo(null);
233            setVisible(true);
234        }
235    }
236}
237/*
238 * Overrides for emacs
239 * Local variables:
240 * tab-width: 4
241 * End:
242 */
243
Note: See TracBrowser for help on using the repository browser.