1 import org.jivesoftware.smack.*; 2 import org.jivesoftware.smackx.ServiceDiscoveryManager; 3 4 import whisper.*; 5 6 import java.awt.*; 7 import java.awt.event.KeyEvent ; 8 import java.io.File ; 9 import java.io.FileInputStream ; 10 import java.io.FileOutputStream ; 11 import java.io.PrintStream ; 12 import java.util.ListResourceBundle ; 13 import java.util.ResourceBundle ; 14 import java.util.Properties ; 15 import java.security.SecureRandom ; 16 import javax.swing.*; 17 import javax.swing.plaf.*; 18 import javax.swing.plaf.metal.MetalLookAndFeel ; 19 20 21 public final class WhisperIM{ 22 23 private static final String ERROR_FILE_NAME="error.txt"; 25 public static final String VERSION="0.2"; 26 27 public static final String VERSION_INFO="Free For Non-Commercial Use"; 28 30 public static final String USER_PREF_FILE_NAME="prefs.properties"; 31 33 public static final String KCK_FILE_NAME="kck.dat"; 34 35 public static final String CONFIG_FILE_NAME="config.dat"; 36 37 public static final String KEYPAIR_FILENAME="keypair.dat"; 38 39 public static File CONFIG_FILE; 40 41 public static Properties Config; 42 43 public static Properties UserPref; 44 45 public static ResourceBundle lang; 46 47 public static boolean isMac=false; 48 49 public static boolean userPrefLoaded=false; 50 51 public static String currentLaf="metal"; 52 53 public static boolean sharedMachine=false; 54 55 public static File accountDir; 56 57 public static File userDir; 58 59 public static KeyPair KEYPAIR; 60 61 public static AccountSettings accountSettings; 62 63 public static SecureRandom SR; 64 65 public static HelpWindow Help_Window; 66 67 public static LogInFrame Login_Window; 68 69 public static ConfigDialog Config_Window; 70 71 public static NewAccountWindow New_Account_Window; 72 73 public static JMainFrame MainWindow; 74 75 public static JAboutDialog About; 76 78 public static int HELP_KEY=KeyEvent.VK_F1; 79 80 public static JSplash splash; 81 82 public static void main(String [] args){ 83 try{ System.setErr(new PrintStream (new FileOutputStream (ERROR_FILE_NAME,true),true)); 86 javax.swing.SwingUtilities.invokeLater(new Runnable (){ 88 public void run(){ 89 try{ 90 splash=new JSplash(); 91 splash.show(); 92 splash.inc(); 93 } 94 catch(Throwable t){ 95 GUI.errorStop(null,t); 96 } 97 } 98 }); 99 100 lang=ListResourceBundle.getBundle("Lang"); 101 CONFIG_FILE=new File (CONFIG_FILE_NAME); 102 SR=new SecureRandom (); 103 accountSettings=new AccountSettings(); 104 Config=new Properties (new DefaultConfig()); 105 UserPref=new Properties (new DefaultUserPref()); 106 107 try{ 109 Config.load(new FileInputStream (CONFIG_FILE)); 110 } 111 catch(Exception e){ 112 GUI.errorStop(lang.getString("cannot load config file"),e); 113 } 114 115 javax.swing.SwingUtilities.invokeLater(new SplashInc()); 116 117 SmackConfiguration.setKeepAliveInterval(Integer.parseInt(Config.getProperty("keepalive"))); 119 SmackConfiguration.setPacketReplyTimeout(Integer.parseInt(Config.getProperty("timeout"))); 120 VCardIQProvider.Install(); SearchIQProvider.install(); VersionIQ.install(); DelayExtensionProvider.install(); Chat.setFilteredOnThreadID(false); 125 Roster.setDefaultSubscriptionMode(Roster.SUBSCRIPTION_MANUAL); 126 XMPPConnection.DEBUG_ENABLED=false; 127 javax.swing.SwingUtilities.invokeLater(new SplashInc()); 128 129 if(System.getProperty("os.name").toLowerCase().indexOf("mac")!=-1){ 131 isMac=true; 132 HELP_KEY=KeyEvent.VK_HELP; 134 } 135 136 setAccountDir(); 137 138 javax.swing.SwingUtilities.invokeLater(new SplashInc()); 139 140 ToolTipManager.sharedInstance().setEnabled(true); if(!(UserPref.getProperty("laf").compareTo("native")==0 || ((!userPrefLoaded) && isMac))){ 144 UIManager.setLookAndFeel(new com.incors.plaf.kunststoff.KunststoffLookAndFeel()); 146 } 147 else{ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 149 currentLaf="native"; 150 } 151 152 javax.swing.SwingUtilities.invokeLater(new Runnable (){ 153 public void run(){ 154 try{ 155 splash.inc(); 156 JFrame.setDefaultLookAndFeelDecorated(true); 158 JDialog.setDefaultLookAndFeelDecorated(true); 159 splash.inc(); 160 About=new JAboutDialog(); 161 splash.inc(); 162 MainWindow=new JMainFrame(); 163 splash.inc(); 164 Login_Window=new LogInFrame(); 165 splash.inc(); 166 Login_Window.show(); 167 splash.dispose(); 168 splash=null; 169 } 170 catch(Throwable t){ 171 GUI.errorStop(null,t); 172 } 173 } 174 }); 175 } catch(Throwable t){ t.printStackTrace(); 178 GUI.errorStop(null,t); 179 } 180 } 181 182 public static void setAccountDir() throws java.io.IOException { 183 188 accountDir=new File ("accounts"); sharedMachine=false; 190 if(Config.getProperty("accountLocation").compareTo("application")!=0){ 191 if(Config.getProperty("accountLocation").compareTo("userhome")==0){ accountDir=new File (System.getProperties().getProperty("user.home")); 194 } 195 else{ String dir=Config.getProperty("accountLocation"); 197 accountDir=new File (dir.replaceAll("USER",System.getProperties().getProperty("user.name"))); 198 } 199 if(!accountDir.exists()){ 201 GUI.showWarning(null,null,"addne",accountDir.getCanonicalPath()); 202 } 203 userDir=new File (accountDir,"whisper"); 205 if(userDir.exists() && userDir.isDirectory()){ 207 GUI.loadPrefs(); 208 } 209 } 210 else{ sharedMachine=true; 212 if(!accountDir.exists()){ 214 GUI.showWarning(null,null,"addne",accountDir.getCanonicalPath()); 215 } 216 } 217 } 218 219 }
| Popular Tags
|