1 7 8 package com.memoire.vainstall; 9 10 import java.awt.Color ; 11 import java.text.MessageFormat ; 12 import java.util.Hashtable ; 13 import java.util.Locale ; 14 import java.util.MissingResourceException ; 15 import java.util.ResourceBundle ; 16 import java.util.StringTokenizer ; 17 import java.util.Vector ; 18 19 import javax.swing.UIManager ; 20 21 25 26 public class VAGlobals 27 { 28 public final static boolean DEBUG="yes".equals(System.getProperty("DEBUG")); 29 30 public final static String NAME ="VAInstall"; 31 public final static String VERSION ="0.23a"; 32 public final static String AUTHOR ="Axel von Arnim"; 33 public final static String COPYRIGHT="2000-2002"; 34 public final static String LICENSE ="GPL2"; 35 public final static String HTTP="http://www.ifrance.com/vonarnim/vainstall"; 36 public final static String EMAIL="vonarnim@club-internet.fr"; 37 public final static Class BASE_CLASS=new VAGlobals().getClass(); 38 39 public final static int UNKNOWN =0; 40 public final static int INSTALL =1; 41 public final static int UNINSTALL=2; 42 public final static int UPDATE =3; 43 public static int OPERATION=UNKNOWN; 44 45 public static String UI_MODE; 46 public static boolean UI_BLUESCREEN; 47 public static Color UI_BLUESCREEN_COLOR; 48 public static String IMAGE; 49 public static boolean USE_FULL_JAVA_PATH; 50 public static boolean SHORTCUTS_IN_INSTALLDIR; 51 public static String DEST_PATH; 52 public static String APP_NAME; 53 public static String APP_VERSION; 54 55 public static String JNI_DLL_FILE; 56 57 public static String LINK_SECTION_NAME; 58 public static String LINK_SECTION_ICON; 59 public static String LINK_ENTRY_NAME; 60 public static String LINK_ENTRY_ICON; 61 public static boolean CREATE_UNINSTALL_SHORTCUT; 62 63 66 public static String [][] languages = 67 { 68 {"danish" ,"Danish" ,"da","DK"}, 69 {"german" ,"Deutsch" ,"de","DE"}, 70 {"english" ,"English" ,"en","UK"}, 71 {"french" ,"Français","fr","FR"}, 72 {"italian" ,"Italian" ,"it","IT"}, 73 {"japanese","Japanese","ja","JP"} 74 }; 75 private static String [] allSupportedLanguages; 76 77 private static String [] supportedLanguages; 78 79 82 private static Locale locale; 83 84 87 private static String currentLanguage; 88 89 92 private static Hashtable resourceList = null; 93 94 97 public static void printDebug(String msg) 98 { if(DEBUG) System.err.println(msg); } 99 100 public static String i18n(String key) 101 { 102 String s=null; 103 try { 104 s=getResource("com.memoire.vainstall.Language",key); 105 } catch( MissingResourceException e ) { } 106 if( s==null ) 107 try { 108 s=getResource("com.memoire.vainstall.gui.Language",key); 109 } catch( MissingResourceException e ) { } 110 if( s==null ) 111 try { 112 s=getResource("com.memoire.vainstall.xui.Language",key); 113 } catch( MissingResourceException e ) { } 114 if( s==null ) 115 try { 116 s=getResource("com.memoire.vainstall.tui.Language",key); 117 } catch( MissingResourceException e ) { } 118 if( s==null ) s=key; 120 return s; 121 } 122 123 public static String i18n(String key, Object [] params) 124 { 125 String s=i18n(key); 126 if (s != null && params != null) { 127 s = MessageFormat.format(s, params); 128 } 129 return s; 130 } 131 132 152 153 159 public static String getResource(String baseName,String key) 160 throws MissingResourceException  161 { 162 163 if( (locale == null) || DEBUG ) 164 { 165 locale = new Locale ("en","UK"); 166 } 167 168 if(resourceList == null) 169 { 170 resourceList = new java.util.Hashtable (); 171 } 172 173 if(resourceList.contains(baseName) == false) 175 { 176 ResourceBundle resource = ResourceBundle.getBundle(baseName,locale); 178 179 resourceList.put(baseName,resource); 181 return resource.getString(key); 182 } 183 else 184 { 185 return ((ResourceBundle )resourceList.get(baseName)).getString(key); 186 } 187 188 } 190 196 public static int getResourceInt(String baseName,String key) 197 throws java.util.MissingResourceException  198 { 199 200 if(locale == null) 201 { 202 locale = new Locale ("en","UK"); 203 } 204 205 if(resourceList == null) 206 { 207 resourceList = new java.util.Hashtable (); 208 } 209 210 if(resourceList.contains(baseName) == false) 212 { 213 ResourceBundle resource = ResourceBundle.getBundle(baseName,locale); 215 216 resourceList.put(baseName,resource); 218 219 Integer value=(Integer )resource.getObject(key); 220 return (int)value.intValue(); 221 } 222 else 223 { 224 Integer value=(Integer )((ResourceBundle )resourceList.get(baseName)).getObject(key); 225 return (int)value.intValue(); 226 } 227 228 } 230 237 public static void setLanguage(String language) 238 { 239 if(resourceList != null) 241 { 242 resourceList.clear(); 243 } 244 245 if(language.toLowerCase().indexOf("choose") != -1) 246 { 247 if(language.equalsIgnoreCase("choose") == true) 250 { 251 setLanguage("default"); 252 return; 253 } 254 255 Vector languageList = new Vector (); 256 String [] supportedLangs = getAllSupportedLanguages(); 257 258 Locale l=Locale.getDefault(); 259 for(int i=0;i<languages.length;i++) 260 { 261 if(l.getLanguage().equals(languages[i][2]) == true) 262 { 263 currentLanguage = languages[i][0]; 264 } 265 } 266 267 StringTokenizer nizer = new StringTokenizer (language,","); 268 while(nizer.hasMoreTokens() == true) 269 { 270 String element = (String )nizer.nextToken(); 271 element = element.trim().toLowerCase(); 272 273 for(int i=0;i<languages.length;i++) 274 { 275 if(element.equals(languages[i][0]) == true) 276 { 277 278 if(element.equals(currentLanguage) == true) 279 { 280 languageList.insertElementAt(languages[i][0],0); 281 } 282 else 283 { 284 languageList.addElement(languages[i][0]); 285 } 286 } 287 } 288 } 289 290 supportedLanguages = new String [languageList.size()]; 291 for(int i = 0;i < languageList.size(); i++) 292 { 293 for(int j=0;j<languages.length;j++) 294 { 295 if(languageList.elementAt(i).equals(languages[j][0]) == true) 296 { 297 supportedLanguages[i] = (String )languages[j][1]; 298 } 299 } 300 } 301 setLanguage("default"); 302 return; 303 } 304 305 312 if(language.equals("default") == true) 313 { 314 Locale l=Locale.getDefault(); 315 String shortLanguage = l.getLanguage(); 316 317 for(int i = 0; i < languages.length; i++) 318 { 319 if(shortLanguage.equals(languages[i][2]) == true) 320 { 321 currentLanguage = languages[i][0]; 322 locale = new Locale (languages[i][2],languages[i][3]); 323 } 324 } 325 326 } 327 else 328 { 329 for(int i = 0; i < languages.length; i++) 331 { 332 if(language.equals(languages[i][0]) == true) 333 { 334 currentLanguage = languages[i][0]; 335 locale = new Locale (languages[i][2],languages[i][3]); 336 } 337 } 338 } 339 340 UIManager.put("OptionPane.yesButtonText",getResource("com.memoire.vainstall.Language","Common_OptionPane.yesButtonText")); 342 UIManager.put("OptionPane.noButtonText",getResource("com.memoire.vainstall.Language","Common_OptionPane.noButtonText")); 343 UIManager.put("OptionPane.okButtonText",getResource("com.memoire.vainstall.Language","Common_OptionPane.okButtonText")); 344 UIManager.put("OptionPane.cancelButtonText",getResource("com.memoire.vainstall.Language","Common_OptionPane.cancelButtonText")); 345 346 } 347 348 public static String [] getSupportedLanguages() 349 { 350 if(supportedLanguages == null) 351 { 352 supportedLanguages = new String [languages.length]; 353 for(int i = 0;i < languages.length; i++) 354 { 355 supportedLanguages[i] = languages[i][1]; 356 } 357 } 358 return supportedLanguages; 359 } 360 361 public static String [] getAllSupportedLanguages() 362 { 363 if(allSupportedLanguages == null) 364 { 365 allSupportedLanguages = new String [languages.length]; 366 for(int i = 0;i < languages.length; i++) 367 { 368 allSupportedLanguages[i] = languages[i][1]; 369 } 370 } 371 return allSupportedLanguages; 372 } 373 374 public static String getCurrentLanguage() 375 { 376 return currentLanguage; 377 } 378 379 387 public static int suggestLanguage() 388 { 389 Locale syslocale = Locale.getDefault(); 390 String syslang = syslocale.getLanguage(); 391 String syscountry = syslocale.getCountry(); 392 int langonly = -1; 393 for (int idx = 0; idx < languages.length; idx ++) { 394 if (syslang.equals(languages[idx][2])) { 395 if (syscountry.equals(languages[idx][3])) { 396 return idx; 397 } else { 398 if (langonly == -1) langonly = idx; 399 } 400 } 401 } 402 if (langonly == -1) langonly = 0; 403 return langonly; 404 } 405 406 } 407
| Popular Tags
|