Revision 6951
trunk/frameworks/_fwAndami/src/com/iver/andami/Launcher.java | ||
---|---|---|
48 | 48 |
import java.awt.Toolkit; |
49 | 49 |
import java.io.BufferedInputStream; |
50 | 50 |
import java.io.BufferedOutputStream; |
51 |
import java.io.BufferedReader; |
|
51 | 52 |
import java.io.File; |
52 | 53 |
import java.io.FileFilter; |
53 | 54 |
import java.io.FileInputStream; |
... | ... | |
58 | 59 |
import java.io.FilenameFilter; |
59 | 60 |
import java.io.IOException; |
60 | 61 |
import java.io.InputStream; |
62 |
import java.io.InputStreamReader; |
|
61 | 63 |
import java.lang.reflect.InvocationTargetException; |
62 | 64 |
import java.net.MalformedURLException; |
63 | 65 |
import java.net.URL; |
... | ... | |
209 | 211 |
// de plugin services para quien lo quiera usar (por ejemplo, para |
210 | 212 |
// cargar un proyecto por l?nea de comandos) |
211 | 213 |
PluginServices.setArguments(args); |
212 |
|
|
213 |
// Configurar el locale |
|
214 |
String localeStr = null; |
|
215 |
for (int i=2; i < args.length; i++) |
|
216 |
{ |
|
217 |
int index = args[i].indexOf("language="); |
|
218 |
if (index != -1) |
|
219 |
localeStr = args[i].substring(index+9); |
|
220 |
} |
|
221 |
if (localeStr == null) |
|
222 |
{ |
|
223 |
localeStr = andamiConfig.getLocaleLanguage(); |
|
224 |
/* locale = getLocale(localeStr, |
|
225 |
andamiConfig.getLocaleCountry(), |
|
226 |
andamiConfig.getLocaleVariant()); */ |
|
227 |
} |
|
228 |
if (localeStr.compareTo("va")==0) |
|
229 |
{ |
|
230 |
locale = new Locale("ca"); |
|
231 |
} |
|
232 |
else |
|
233 |
{ |
|
234 |
// locale = Locale.getDefault(); |
|
235 |
locale = getLocale(localeStr, |
|
236 |
andamiConfig.getLocaleCountry(), |
|
237 |
andamiConfig.getLocaleVariant()); |
|
238 |
} |
|
239 |
Locale.setDefault(locale); |
|
240 |
JComponent.setDefaultLocale(locale); |
|
241 |
org.gvsig.i18n.Messages.addLocale(locale); |
|
242 |
// add english and spanish as fallback languages |
|
243 |
org.gvsig.i18n.Messages.addLocale(new Locale("en")); |
|
244 |
org.gvsig.i18n.Messages.addLocale(new Locale("es")); |
|
245 |
org.gvsig.i18n.Messages.addResourceFamily("com.iver.andami.text", "com.iver.andami.text"); |
|
246 |
|
|
214 |
|
|
215 |
configureLocales(args); |
|
216 |
|
|
247 | 217 |
//Se pone el lookAndFeel |
248 | 218 |
try { |
249 | 219 |
String lookAndFeel = getAndamiConfig().getLookAndFeel(); |
... | ... | |
327 | 297 |
GlobalKeyEventDispatcher keyDispatcher = GlobalKeyEventDispatcher.getInstance(); |
328 | 298 |
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keyDispatcher); |
329 | 299 |
|
330 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
300 |
SwingUtilities.invokeAndWait(new Runnable() { |
|
331 | 301 |
public void run() { |
332 | 302 |
frame.enableControls(); |
333 | 303 |
} |
... | ... | |
1930 | 1900 |
else |
1931 | 1901 |
return nonWinDefaultLookAndFeel; |
1932 | 1902 |
} |
1903 |
|
|
1904 |
/** |
|
1905 |
* Gets the ISO 839 two-characters-long language code matching the |
|
1906 |
* provided language code (which may be an ISO 839-2/T |
|
1907 |
* three-characters-long code or an ISO 839-1 two-characters-long |
|
1908 |
* code). |
|
1909 |
* |
|
1910 |
* If the provided parameter is already two characters long, it |
|
1911 |
* returns the parameter without any modification. |
|
1912 |
* |
|
1913 |
* @param langCode A language code representing either |
|
1914 |
* an ISO 839-2/T language code or an ISO 839-1 code. |
|
1915 |
* @return A two-characters-long code specifying |
|
1916 |
* an ISO 839 language code. |
|
1917 |
*/ |
|
1918 |
private static String normalizeLanguageCode(String langCode) { |
|
1919 |
final String fileName = "iso_639.tab"; |
|
1920 |
if (langCode.length()==2) |
|
1921 |
return langCode; |
|
1922 |
else if (langCode.length()==3) { |
|
1923 |
if (langCode.equals("va") || langCode.equals("val")) { // special case for Valencian |
|
1924 |
return "ca"; |
|
1925 |
} |
|
1926 |
URL isoCodes = Launcher.class.getClassLoader().getResource(fileName); |
|
1927 |
if (isoCodes!=null) { |
|
1928 |
try { |
|
1929 |
BufferedReader reader = |
|
1930 |
new BufferedReader(new InputStreamReader(isoCodes.openStream(), "ISO-8859-1")); |
|
1931 |
String line; |
|
1932 |
|
|
1933 |
while ((line = reader.readLine()) != null) { |
|
1934 |
String[] language = line.split("\t"); |
|
1935 |
if (language[0].equals(langCode)) // first column is the three characters code |
|
1936 |
return language[2]; // third column i the two characters code |
|
1937 |
} |
|
1938 |
} |
|
1939 |
catch (IOException ex) { |
|
1940 |
logger.error(Messages.getString("Error_reading_isocodes_file"), ex); |
|
1941 |
return "es"; |
|
1942 |
} |
|
1943 |
} |
|
1944 |
else { |
|
1945 |
logger.error(Messages.getString("Error_reading_isocodes_file")); |
|
1946 |
return "es"; |
|
1947 |
} |
|
1948 |
} |
|
1949 |
return "es"; |
|
1950 |
} |
|
1951 |
|
|
1952 |
/** |
|
1953 |
* Configures the locales (languages and local resources) to be used |
|
1954 |
* by the application. |
|
1955 |
* |
|
1956 |
* First it tries to get the locale from the command line parameters, |
|
1957 |
* then the andami-config file is checked. |
|
1958 |
* |
|
1959 |
* The locale name is normalized to get a two characters language code |
|
1960 |
* as defined by ISO-639-1 (although ISO-639-2/T three characters codes |
|
1961 |
* are also accepted from the command line or the configuration file). |
|
1962 |
* |
|
1963 |
* Finally, the gvsig-i18n library and the default locales for Java and |
|
1964 |
* Swing are configured. |
|
1965 |
* |
|
1966 |
*/ |
|
1967 |
private static void configureLocales(String[] args) { |
|
1968 |
// Configurar el locale |
|
1969 |
String localeStr = null; |
|
1970 |
for (int i=2; i < args.length; i++) |
|
1971 |
{ |
|
1972 |
int index = args[i].indexOf("language="); |
|
1973 |
if (index != -1) |
|
1974 |
localeStr = args[i].substring(index+9); |
|
1975 |
} |
|
1976 |
if (localeStr == null) |
|
1977 |
{ |
|
1978 |
localeStr = andamiConfig.getLocaleLanguage(); |
|
1979 |
} |
|
1980 |
localeStr = normalizeLanguageCode(localeStr); |
|
1981 |
locale = getLocale(localeStr, |
|
1982 |
andamiConfig.getLocaleCountry(), |
|
1983 |
andamiConfig.getLocaleVariant()); |
|
1984 |
Locale.setDefault(locale); |
|
1985 |
JComponent.setDefaultLocale(locale); |
|
1986 |
org.gvsig.i18n.Messages.addLocale(locale); |
|
1987 |
// add english and spanish as fallback languages |
|
1988 |
org.gvsig.i18n.Messages.addLocale(new Locale("en")); |
|
1989 |
org.gvsig.i18n.Messages.addLocale(new Locale("es")); |
|
1990 |
org.gvsig.i18n.Messages.addResourceFamily("com.iver.andami.text", "com.iver.andami.text"); |
|
1991 |
|
|
1992 |
} |
|
1933 | 1993 |
} |
Also available in: Unified diff