1 19 20 package org.netbeans.editor; 21 22 import java.util.Arrays ; 23 import java.util.ArrayList ; 24 import java.util.HashMap ; 25 import java.util.MissingResourceException ; 26 27 39 40 public class LocaleSupport { 41 42 private static final boolean debug 43 = Boolean.getBoolean("netbeans.debug.editor.localesupport"); 44 45 48 49 52 private static Localizer[] localizers = new Localizer[0]; 53 54 59 public static void addLocalizer(Localizer localizer) { 60 ArrayList ll = new ArrayList (Arrays.asList(localizers)); 61 ll.add(localizer); 62 Localizer[] la = new Localizer[ll.size()]; 63 ll.toArray(la); 64 localizers = la; 65 66 } 68 69 72 public static void removeLocalizer(Localizer localizer) { 73 ArrayList ll = new ArrayList (Arrays.asList(localizers)); 74 ll.remove(localizer); 75 Localizer[] la = new Localizer[ll.size()]; 76 ll.toArray(la); 77 localizers = la; 78 79 } 81 82 87 public static synchronized String getString(String key) { 88 String ret = null; 90 int i; 93 for (i = localizers.length - 1; i >= 0; i--) { 94 95 try { 97 ret = localizers[i].getString(key); 98 } catch (MissingResourceException e) { ret = null; 100 } 101 102 if (ret != null) { 103 break; 104 } 105 } 106 107 113 if (debug) { 115 String inLocalizerString = (i >= 0) 116 ? " found in localizer=" + localizers[i] : ""; System.err.println("LocaleSupport.getString(): key=\"" + key + "\", value=\"" + ret + "\"" + inLocalizerString); 120 Thread.dumpStack(); 121 } 122 return ret; 123 } 124 125 131 public static String getString(String key, String defaultValue) { 132 String ret = getString(key); 133 return (ret != null) ? ret : defaultValue; 134 } 135 136 143 public static char getChar( String key, char defaultValue ) { 144 String value = getString( key ); 145 if( value == null || value.length() < 1 ) return defaultValue; 146 return value.charAt( 0 ); 147 } 148 149 152 public interface Localizer { 153 154 157 public String getString(String key); 158 159 } 160 161 } 162 | Popular Tags |