/* * Jeti, a Java Jabber client, Copyright (C) 2001 E.S. de Boer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * For questions, comments etc, * use the website at http://jeti.jabberstudio.org * or mail/IM me at jeti@jabber.org */ package nu.fw.jeti.backend; import java.awt.*; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; import java.util.Properties; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import nu.fw.jeti.images.StatusIcons; import nu.fw.jeti.jabber.Backend; import nu.fw.jeti.plugins.PluginsInfo; import nu.fw.jeti.ui.Jeti; import nu.fw.jeti.util.I18N; import nu.fw.jeti.util.Log; import nu.fw.jeti.util.Popups; import nu.fw.jeti.util.Preferences; import org.xml.sax.SAXException; /** * @author E.S. de Boer */ public class Start { public static final String VERSION = "0.7.7"; public final static String OS2 = ""; public static String BUILD_DATE; public static String BUILD_NUM; public static URL programURL; //url where the plugins are change to plugins url can use always also if local public static URL dataURL; //url where the data is stored public static String pluginPath; //plugin path public static String path; //local path public static boolean applet=false; public static boolean webstart=false; private SAXParser parser; private static Splash splash; private PluginsInfo pluginsInfo; private Backend backend; public Start(String urlString, Container container) { try { parser = SAXParserFactory.newInstance().newSAXParser(); } catch (FactoryConfigurationError ex) { ex.printStackTrace(); } catch (SAXException ex) { ex.printStackTrace(); } catch (ParserConfigurationException ex) { ex.printStackTrace(); } if ( urlString == null) urlString = getPath(); if ( System.getProperty("file.separator").equals("/") ) pluginPath = urlString.substring(5); else pluginPath = urlString.substring(6); pluginPath = pluginPath.replace('/', File.separatorChar); /** * Se o programurl for null, applet ou network tb usa program path como data path */ dataURL = programURL; path = pluginPath; try { Properties p = new Properties(); p.load(getClass().getResource("version.properties").openStream()); BUILD_DATE = p.getProperty("buildDate"); BUILD_NUM = p.getProperty("buildNum"); } catch (Exception e){} backend = new Backend(this); new Preferences( backend, parser ); new StatusIcons(); Jeti jeti = new Jeti(backend,container); new Popups( backend.getMainWindow() ); pluginsInfo = new PluginsInfo(backend, this); jeti.init(); if( container != null) container.add(jeti); else backend.getMainWindow().setVisible(true); } public void setSplashText(String text) { nu.fw.jeti.applet.Jeti.from.setText(I18N.gettext("Loading") + " " + text + "..."); } private String getPath() { URL url = this.getClass().getResource("Start.class"); //System.out.println(url); String urlString = null; try { //remove %20 from program files etc urlString = URLDecoder.decode(url.toString(), "UTF8"); //encode if to url? probaly not } catch (Exception e) { e.printStackTrace(); } if (url.getProtocol().equals("jar")) { // Strip off JarURL-specific syntax. urlString = urlString.substring(4); urlString = urlString.substring(0, urlString.lastIndexOf("!")); urlString = urlString.substring(0, urlString.lastIndexOf("/") + 1); } else urlString = urlString.substring(0, urlString.lastIndexOf("/jeti") + 1); return urlString; } public static void remoteLoad(URL url, String path) { Start.pluginPath = path; Start.programURL = url; start(pluginPath,null); } public static void main(String[] args) { if(args.length>0)path = args[0]; start(null,null); } public static void start(String path,Container container) { Frame frame = new Frame(); splash = new Splash(frame); new Start(path,container); splash.dispose(); frame.dispose(); splash=null; } public Backend getBackend() { return backend; } public void close() { if( backend != null ) backend.getMain().close(); } public void exit() { pluginsInfo.exit(); nu.fw.jeti.applet.Jeti.exit(); backend = null; } static class Splash extends Window { Label from; public Splash(Frame frame) { super(frame); Label label = new Label("Jeti" + OS2 + " is Loading"+"..."); label.setFont(new java.awt.Font("Serif", 1, 40)); label.setBackground(new Color(150,150,255)); add(label,BorderLayout.CENTER); Panel panel = new Panel(); panel.setBackground(new Color(255,255,150)); from = new Label("(c) 2001-2008 E.S. de Boer"); from.setBackground(new Color(255,255,150)); panel.add(from); Label version = new Label("Version: " + Start.VERSION); version.setBackground(new Color(255,255,150)); panel.add(version); add(panel,BorderLayout.SOUTH); pack(); setLocationRelativeTo(null); setVisible(true); } } } /* * Overrides for emacs * Local variables: * tab-width: 4 * End: */