Revision 42362 trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/Launcher.java
Launcher.java | ||
---|---|---|
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2007-2013 gvSIG Association. |
5 | 5 |
* |
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License
|
|
8 |
* as published by the Free Software Foundation; either version 3
|
|
9 |
* of the License, or (at your option) any later version.
|
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
9 |
* version. |
|
10 | 10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
* details. |
|
15 | 15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 | 19 |
* |
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
23 | 22 |
*/ |
24 | 23 |
package org.gvsig.andami; |
25 | 24 |
|
... | ... | |
89 | 88 |
import javax.swing.SwingUtilities; |
90 | 89 |
import javax.swing.UIManager; |
91 | 90 |
|
92 |
import com.jgoodies.looks.windows.WindowsLookAndFeel; |
|
93 | 91 |
|
94 | 92 |
import org.apache.commons.cli.CommandLine; |
95 | 93 |
import org.apache.commons.cli.CommandLineParser; |
... | ... | |
204 | 202 |
*/ |
205 | 203 |
public class Launcher { |
206 | 204 |
|
207 |
public static abstract class MapWithAlias<Item> extends HashMap<String, Item> { |
|
208 |
private HashMap<String, String> aliases = new HashMap<String, String>(); |
|
205 |
public static abstract class MapWithAlias<Item> extends HashMap<String, Item> { |
|
209 | 206 |
|
210 |
public abstract String[] getAliases(Item item);
|
|
207 |
private HashMap<String, String> aliases = new HashMap<String, String>();
|
|
211 | 208 |
|
212 |
public boolean isAlias(String key) { |
|
213 |
return aliases.get(key)!=null ; |
|
214 |
} |
|
209 |
public abstract String[] getAliases(Item item); |
|
215 | 210 |
|
216 |
public String getMainKey(String key) { |
|
217 |
Item item = super.get(key); |
|
218 |
if( item != null ) { |
|
219 |
return key; |
|
220 |
} |
|
221 |
String alias = aliases.get(key); |
|
222 |
if( alias != null ) { |
|
223 |
return alias; |
|
224 |
} |
|
225 |
return null; |
|
226 |
} |
|
211 |
public boolean isAlias(String key) { |
|
212 |
return aliases.get(key) != null; |
|
213 |
} |
|
227 | 214 |
|
228 |
public Item get(Object key) {
|
|
229 |
Item item = super.get(key);
|
|
230 |
if( item != null ) {
|
|
231 |
return item;
|
|
232 |
}
|
|
233 |
String alias = aliases.get(key);
|
|
234 |
if( alias != null ) {
|
|
235 |
return super.get(alias);
|
|
236 |
}
|
|
237 |
return null;
|
|
238 |
}
|
|
215 |
public String getMainKey(String key) {
|
|
216 |
Item item = super.get(key);
|
|
217 |
if (item != null) {
|
|
218 |
return key;
|
|
219 |
}
|
|
220 |
String alias = aliases.get(key);
|
|
221 |
if (alias != null) {
|
|
222 |
return alias;
|
|
223 |
}
|
|
224 |
return null;
|
|
225 |
}
|
|
239 | 226 |
|
240 |
public boolean containsKey(Object key) { |
|
241 |
boolean contains = super.containsKey(key); |
|
242 |
if( contains ) { |
|
243 |
return true; |
|
244 |
} |
|
245 |
String alias = aliases.get(key); |
|
246 |
return super.containsKey(alias); |
|
247 |
} |
|
227 |
public Item get(Object key) { |
|
228 |
Item item = super.get(key); |
|
229 |
if (item != null) { |
|
230 |
return item; |
|
231 |
} |
|
232 |
String alias = aliases.get(key); |
|
233 |
if (alias != null) { |
|
234 |
return super.get(alias); |
|
235 |
} |
|
236 |
return null; |
|
237 |
} |
|
248 | 238 |
|
249 |
public Item put(String key, Item value) { |
|
250 |
super.put(key, value); |
|
251 |
String[] aliases = getAliases(value); |
|
252 |
if( aliases==null ) { |
|
253 |
return value; |
|
254 |
} |
|
255 |
for( int n=0; n<aliases.length; n++ ) { |
|
256 |
this.aliases.put(aliases[n].trim(), key); |
|
257 |
} |
|
258 |
return value; |
|
259 |
} |
|
239 |
public boolean containsKey(Object key) { |
|
240 |
boolean contains = super.containsKey(key); |
|
241 |
if (contains) { |
|
242 |
return true; |
|
243 |
} |
|
244 |
String alias = aliases.get(key); |
|
245 |
return super.containsKey(alias); |
|
246 |
} |
|
260 | 247 |
|
261 |
public void putAll(Map<? extends String, ? extends Item> m) { |
|
262 |
Iterator<?> it = m.entrySet().iterator(); |
|
263 |
while( it.hasNext() ) { |
|
264 |
Map.Entry<String, Item> x = (Map.Entry<String, Item>) it.next(); |
|
265 |
this.put(x.getKey(), x.getValue()); |
|
266 |
} |
|
267 |
} |
|
248 |
public Item put(String key, Item value) { |
|
249 |
super.put(key, value); |
|
250 |
String[] aliases = getAliases(value); |
|
251 |
if (aliases == null) { |
|
252 |
return value; |
|
253 |
} |
|
254 |
for (int n = 0; n < aliases.length; n++) { |
|
255 |
this.aliases.put(aliases[n].trim(), key); |
|
256 |
} |
|
257 |
return value; |
|
258 |
} |
|
268 | 259 |
|
269 |
public Item remove(Object key) { |
|
270 |
Item item = super.get(key); |
|
271 |
if( item == null ) { |
|
272 |
String alias = aliases.get(key); |
|
273 |
if( alias == null ) { |
|
274 |
return null; |
|
275 |
} |
|
276 |
item = super.get(alias); |
|
277 |
super.remove(alias); |
|
278 |
} else { |
|
279 |
super.remove(key); |
|
280 |
} |
|
281 |
String[] aliases = getAliases(item); |
|
282 |
if( aliases==null ) { |
|
283 |
return item; |
|
284 |
} |
|
285 |
// Rebuild the alias list |
|
286 |
this.aliases = new HashMap<String, String>(); |
|
287 |
Iterator<java.util.Map.Entry<String, Item>> it = this.entrySet().iterator(); |
|
288 |
while(it.hasNext()) { |
|
289 |
java.util.Map.Entry<String, Item> entry = it.next(); |
|
290 |
aliases = getAliases(entry.getValue()); |
|
291 |
if( aliases==null ) { |
|
292 |
continue; |
|
293 |
} |
|
294 |
for( int n=0; n<aliases.length; n++ ) { |
|
295 |
this.aliases.put(aliases[n].trim(), entry.getKey()); |
|
296 |
} |
|
297 |
} |
|
260 |
public void putAll(Map<? extends String, ? extends Item> m) { |
|
261 |
Iterator<?> it = m.entrySet().iterator(); |
|
262 |
while (it.hasNext()) { |
|
263 |
Map.Entry<String, Item> x = (Map.Entry<String, Item>) it.next(); |
|
264 |
this.put(x.getKey(), x.getValue()); |
|
265 |
} |
|
266 |
} |
|
298 | 267 |
|
299 |
return item; |
|
300 |
} |
|
268 |
public Item remove(Object key) { |
|
269 |
Item item = super.get(key); |
|
270 |
if (item == null) { |
|
271 |
String alias = aliases.get(key); |
|
272 |
if (alias == null) { |
|
273 |
return null; |
|
274 |
} |
|
275 |
item = super.get(alias); |
|
276 |
super.remove(alias); |
|
277 |
} else { |
|
278 |
super.remove(key); |
|
279 |
} |
|
280 |
String[] aliases = getAliases(item); |
|
281 |
if (aliases == null) { |
|
282 |
return item; |
|
283 |
} |
|
284 |
// Rebuild the alias list |
|
285 |
this.aliases = new HashMap<String, String>(); |
|
286 |
Iterator<java.util.Map.Entry<String, Item>> it = this.entrySet().iterator(); |
|
287 |
while (it.hasNext()) { |
|
288 |
java.util.Map.Entry<String, Item> entry = it.next(); |
|
289 |
aliases = getAliases(entry.getValue()); |
|
290 |
if (aliases == null) { |
|
291 |
continue; |
|
292 |
} |
|
293 |
for (int n = 0; n < aliases.length; n++) { |
|
294 |
this.aliases.put(aliases[n].trim(), entry.getKey()); |
|
295 |
} |
|
296 |
} |
|
301 | 297 |
|
302 |
} |
|
298 |
return item; |
|
299 |
} |
|
303 | 300 |
|
304 |
public static class PluginsConfig extends MapWithAlias<org.gvsig.andami.plugins.config.generate.PluginConfig> {
|
|
301 |
}
|
|
305 | 302 |
|
306 |
public String[] getAliases( |
|
307 |
org.gvsig.andami.plugins.config.generate.PluginConfig item) { |
|
308 |
return getAlternativeNames(item); |
|
309 |
} |
|
303 |
public static class PluginsConfig extends MapWithAlias<org.gvsig.andami.plugins.config.generate.PluginConfig> { |
|
310 | 304 |
|
311 |
static String[] getAlternativeNames(org.gvsig.andami.plugins.config.generate.PluginConfig item) { |
|
312 |
AlternativeNames[] x = item.getAlternativeNames(); |
|
313 |
if( x == null ) { |
|
314 |
return null; |
|
315 |
} |
|
316 |
String[] r = new String[x.length]; |
|
317 |
for( int i=0; i<x.length; i++) { |
|
318 |
r[i] = x[i].getName(); |
|
319 |
} |
|
320 |
return r; |
|
321 |
} |
|
305 |
public String[] getAliases( |
|
306 |
org.gvsig.andami.plugins.config.generate.PluginConfig item) { |
|
307 |
return getAlternativeNames(item); |
|
308 |
} |
|
322 | 309 |
|
323 |
} |
|
310 |
static String[] getAlternativeNames(org.gvsig.andami.plugins.config.generate.PluginConfig item) { |
|
311 |
AlternativeNames[] x = item.getAlternativeNames(); |
|
312 |
if (x == null) { |
|
313 |
return null; |
|
314 |
} |
|
315 |
String[] r = new String[x.length]; |
|
316 |
for (int i = 0; i < x.length; i++) { |
|
317 |
r[i] = x[i].getName(); |
|
318 |
} |
|
319 |
return r; |
|
320 |
} |
|
324 | 321 |
|
325 |
public static class PluginsServices extends MapWithAlias<org.gvsig.andami.PluginServices> {
|
|
322 |
}
|
|
326 | 323 |
|
327 |
public String[] getAliases(org.gvsig.andami.PluginServices item) { |
|
328 |
return item.getAlternativeNames(); |
|
329 |
} |
|
330 |
} |
|
324 |
public static class PluginsServices extends MapWithAlias<org.gvsig.andami.PluginServices> { |
|
331 | 325 |
|
332 |
protected static Logger logger = LoggerFactory.getLogger(Launcher.class |
|
333 |
.getName()); |
|
334 |
protected static Preferences prefs = Preferences.userRoot().node( |
|
335 |
"gvsig.connection"); |
|
336 |
protected static AndamiConfig andamiConfig; |
|
337 |
protected static MultiSplashWindow splashWindow; |
|
338 |
protected static String appName; |
|
339 |
protected static Locale locale; |
|
340 |
protected static PluginsConfig pluginsConfig = new PluginsConfig(); |
|
341 |
protected static PluginsServices pluginsServices = new PluginsServices(); |
|
342 |
protected static MDIFrame frame; |
|
343 |
protected static HashMap<Class<? extends IExtension>, ExtensionDecorator> classesExtensions = new HashMap<Class<? extends IExtension>, ExtensionDecorator>(); |
|
344 |
protected static String andamiConfigPath; |
|
345 |
protected static final String nonWinDefaultLookAndFeel = "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"; |
|
326 |
public String[] getAliases(org.gvsig.andami.PluginServices item) { |
|
327 |
return item.getAlternativeNames(); |
|
328 |
} |
|
329 |
} |
|
346 | 330 |
|
347 |
protected static ArrayList<String> pluginsOrdered = new ArrayList<String>(); |
|
348 |
protected static ArrayList<IExtension> extensions = new ArrayList<IExtension>(); |
|
349 |
protected static String appHomeDir = null; |
|
350 |
// it seems castor uses this encoding |
|
351 |
protected static final String CASTORENCODING = "UTF8"; |
|
331 |
protected static Logger logger = LoggerFactory.getLogger(Launcher.class |
|
332 |
.getName()); |
|
333 |
protected static Preferences prefs = Preferences.userRoot().node( |
|
334 |
"gvsig.connection"); |
|
335 |
protected static AndamiConfig andamiConfig; |
|
336 |
protected static MultiSplashWindow splashWindow; |
|
337 |
protected static String appName; |
|
338 |
protected static Locale locale; |
|
339 |
protected static PluginsConfig pluginsConfig = new PluginsConfig(); |
|
340 |
protected static PluginsServices pluginsServices = new PluginsServices(); |
|
341 |
protected static MDIFrame frame; |
|
342 |
protected static HashMap<Class<? extends IExtension>, ExtensionDecorator> classesExtensions = new HashMap<Class<? extends IExtension>, ExtensionDecorator>(); |
|
343 |
protected static String andamiConfigPath; |
|
344 |
protected static final String nonWinDefaultLookAndFeel = "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"; |
|
352 | 345 |
|
353 |
protected static ListBaseException launcherrors = null; |
|
346 |
protected static ArrayList<String> pluginsOrdered = new ArrayList<String>(); |
|
347 |
protected static ArrayList<IExtension> extensions = new ArrayList<IExtension>(); |
|
348 |
protected static String appHomeDir = null; |
|
349 |
// it seems castor uses this encoding |
|
350 |
protected static final String CASTORENCODING = "UTF8"; |
|
354 | 351 |
|
355 |
protected static Theme theme = null;
|
|
352 |
protected static ListBaseException launcherrors = null;
|
|
356 | 353 |
|
357 |
private List<String> deprecatedPluginNames = null;
|
|
354 |
protected static Theme theme = null;
|
|
358 | 355 |
|
359 |
private static final class ProxyAuth extends Authenticator {
|
|
356 |
private List<String> deprecatedPluginNames = null;
|
|
360 | 357 |
|
361 |
private PasswordAuthentication auth;
|
|
358 |
private static final class ProxyAuth extends Authenticator {
|
|
362 | 359 |
|
363 |
private ProxyAuth(String user, String pass) { |
|
364 |
auth = new PasswordAuthentication(user, pass.toCharArray()); |
|
365 |
} |
|
360 |
private PasswordAuthentication auth; |
|
366 | 361 |
|
367 |
protected PasswordAuthentication getPasswordAuthentication() { |
|
368 |
return auth; |
|
369 |
} |
|
370 |
} |
|
362 |
private ProxyAuth(String user, String pass) { |
|
363 |
auth = new PasswordAuthentication(user, pass.toCharArray()); |
|
364 |
} |
|
371 | 365 |
|
372 |
private static Launcher launcherInstance; |
|
366 |
protected PasswordAuthentication getPasswordAuthentication() { |
|
367 |
return auth; |
|
368 |
} |
|
369 |
} |
|
373 | 370 |
|
374 |
public static Launcher getInstance() { |
|
375 |
if( launcherInstance == null ) { |
|
376 |
launcherInstance = new Launcher(); |
|
377 |
} |
|
378 |
return launcherInstance; |
|
379 |
} |
|
371 |
private static Launcher launcherInstance; |
|
380 | 372 |
|
381 |
public static void main(String[] args) throws Exception { |
|
382 |
Launcher launcher = getInstance(); |
|
383 |
boolean install = false; |
|
384 |
for (int i = 0; i < args.length; i++) { |
|
385 |
if (args[i].equalsIgnoreCase("--install")) { |
|
386 |
install = true; |
|
387 |
} |
|
388 |
} |
|
373 |
public static Launcher getInstance() { |
|
374 |
if (launcherInstance == null) { |
|
375 |
launcherInstance = new Launcher(); |
|
376 |
} |
|
377 |
return launcherInstance; |
|
378 |
} |
|
389 | 379 |
|
390 |
try { |
|
391 |
if (install) { |
|
392 |
launcher.doInstall(args); |
|
393 |
} else { |
|
394 |
launcher.doMain(args); |
|
395 |
} |
|
396 |
} catch (Exception e) { |
|
397 |
logger.error("excepci�n al arrancar", e); |
|
398 |
System.exit(-1); |
|
399 |
} |
|
400 |
} |
|
380 |
public static void main(String[] args) throws Exception { |
|
381 |
Launcher launcher = getInstance(); |
|
382 |
boolean install = false; |
|
383 |
for (int i = 0; i < args.length; i++) { |
|
384 |
if (args[i].equalsIgnoreCase("--install")) { |
|
385 |
install = true; |
|
386 |
} |
|
387 |
} |
|
401 | 388 |
|
402 |
protected void downloadExtensions(String extDir) { |
|
403 |
// do nothing |
|
404 |
} |
|
389 |
try { |
|
390 |
if (install) { |
|
391 |
launcher.doInstall(args); |
|
392 |
} else { |
|
393 |
launcher.doMain(args); |
|
394 |
} |
|
395 |
} catch (Exception e) { |
|
396 |
logger.error("excepci�n al arrancar", e); |
|
397 |
System.exit(-1); |
|
398 |
} |
|
399 |
} |
|
405 | 400 |
|
406 |
public static class LaunchException extends ListBaseException { |
|
401 |
protected void downloadExtensions(String extDir) { |
|
402 |
// do nothing |
|
403 |
} |
|
407 | 404 |
|
408 |
private static final long serialVersionUID = 4541192746962684705L;
|
|
405 |
public static class LaunchException extends ListBaseException {
|
|
409 | 406 |
|
410 |
public LaunchException() { |
|
411 |
super("Errors in initialization of application.", |
|
412 |
"_errors_in_initialization_of_application", |
|
413 |
serialVersionUID); |
|
414 |
} |
|
407 |
private static final long serialVersionUID = 4541192746962684705L; |
|
415 | 408 |
|
416 |
} |
|
409 |
public LaunchException() { |
|
410 |
super("Errors in initialization of application.", |
|
411 |
"_errors_in_initialization_of_application", |
|
412 |
serialVersionUID); |
|
413 |
} |
|
417 | 414 |
|
418 |
protected void addError(Throwable ex) { |
|
419 |
if (launcherrors == null) { |
|
420 |
launcherrors = new LaunchException(); |
|
421 |
} |
|
422 |
launcherrors.add(ex); |
|
423 |
} |
|
415 |
} |
|
424 | 416 |
|
425 |
protected void addError(String msg, Throwable cause) { |
|
426 |
logger.error(msg, cause); |
|
427 |
this.addError(new RuntimeException(msg, cause)); |
|
428 |
} |
|
417 |
protected void addError(Throwable ex) { |
|
418 |
if (launcherrors == null) { |
|
419 |
launcherrors = new LaunchException(); |
|
420 |
} |
|
421 |
launcherrors.add(ex); |
|
422 |
} |
|
429 | 423 |
|
430 |
protected void addError(String msg) { |
|
431 |
this.addError(msg, null); |
|
432 |
} |
|
424 |
protected void addError(String msg, Throwable cause) { |
|
425 |
logger.error(msg, cause); |
|
426 |
this.addError(new RuntimeException(msg, cause)); |
|
427 |
} |
|
433 | 428 |
|
434 |
private String translate(String msg) {
|
|
435 |
return PluginServices.getText(Launcher.class,msg);
|
|
436 |
}
|
|
429 |
protected void addError(String msg) {
|
|
430 |
this.addError(msg, null);
|
|
431 |
}
|
|
437 | 432 |
|
438 |
private List<String> getDeprecatedPluginNames() { |
|
439 |
if( deprecatedPluginNames == null ) { |
|
440 |
String[] ss = new String[] { |
|
441 |
"org.gvsig.app", |
|
442 |
"org.gvsig.coreplugin", |
|
443 |
"org.gvsig.editing", |
|
444 |
"org.gvsig.installer.app.extension", |
|
445 |
"org.gvsig.exportto.app.extension" |
|
446 |
}; |
|
447 |
deprecatedPluginNames = Arrays.asList(ss); |
|
448 |
} |
|
449 |
return deprecatedPluginNames; |
|
450 |
} |
|
433 |
private String translate(String msg) { |
|
434 |
return PluginServices.getText(Launcher.class, msg); |
|
435 |
} |
|
451 | 436 |
|
452 |
public void doMain(String[] args) throws Exception { |
|
437 |
private List<String> getDeprecatedPluginNames() { |
|
438 |
if (deprecatedPluginNames == null) { |
|
439 |
String[] ss = new String[]{ |
|
440 |
"org.gvsig.app", |
|
441 |
"org.gvsig.coreplugin", |
|
442 |
"org.gvsig.editing", |
|
443 |
"org.gvsig.installer.app.extension", |
|
444 |
"org.gvsig.exportto.app.extension" |
|
445 |
}; |
|
446 |
deprecatedPluginNames = Arrays.asList(ss); |
|
447 |
} |
|
448 |
return deprecatedPluginNames; |
|
449 |
} |
|
453 | 450 |
|
454 |
if (args.length < 1) { |
|
455 |
System.err.println("Usage: Launcher appName plugins-directory [language=locale]"); |
|
456 |
System.err.println("No arguments specified."); |
|
457 |
System.err.println("Use default arguments 'gvSIG gvSIG/extensiones'"); |
|
458 |
args = new String[] { "gvSIG", "gvSIG/extensiones" }; |
|
459 |
} |
|
451 |
public void doMain(String[] args) throws Exception { |
|
460 | 452 |
|
461 |
initializeApp(args, null); |
|
453 |
if (args.length < 1) { |
|
454 |
System.err.println("Usage: Launcher appName plugins-directory [language=locale]"); |
|
455 |
System.err.println("No arguments specified."); |
|
456 |
System.err.println("Use default arguments 'gvSIG gvSIG/extensiones'"); |
|
457 |
args = new String[]{"gvSIG", "gvSIG/extensiones"}; |
|
458 |
} |
|
462 | 459 |
|
460 |
initializeApp(args, null); |
|
461 |
|
|
463 | 462 |
// Solucionamos el problema de permisos que se produc?do con Java |
464 |
// Web Start con este codigo.
|
|
465 |
// System.setSecurityManager(null);
|
|
466 |
Policy.setPolicy(new Policy() {
|
|
463 |
// Web Start con este codigo.
|
|
464 |
// System.setSecurityManager(null);
|
|
465 |
Policy.setPolicy(new Policy() {
|
|
467 | 466 |
|
468 |
public PermissionCollection getPermissions(CodeSource codesource) {
|
|
469 |
Permissions perms = new Permissions();
|
|
470 |
perms.add(new AllPermission());
|
|
471 |
return (perms);
|
|
472 |
}
|
|
467 |
public PermissionCollection getPermissions(CodeSource codesource) {
|
|
468 |
Permissions perms = new Permissions();
|
|
469 |
perms.add(new AllPermission());
|
|
470 |
return (perms);
|
|
471 |
}
|
|
473 | 472 |
|
474 |
public void refresh() {
|
|
475 |
}
|
|
476 |
});
|
|
473 |
public void refresh() {
|
|
474 |
}
|
|
475 |
});
|
|
477 | 476 |
|
478 | 477 |
new DefaultLibrariesInitializer().fullInitialize(true); |
479 | 478 |
InstallerLocator.getInstallerManager().setDownloadBaseURL( |
480 |
new URL("http://downloads.gvsig.org/download/gvsig-desktop/")); |
|
479 |
new URL("http://downloads.gvsig.org/download/gvsig-desktop/"));
|
|
481 | 480 |
|
482 |
try {
|
|
483 |
initIconThemes();
|
|
484 |
} catch (Exception ex) {
|
|
485 |
this.addError("Can't initialize icon theme", ex);
|
|
486 |
}
|
|
487 |
// Registramos los iconos base
|
|
488 |
try {
|
|
489 |
registerIcons();
|
|
490 |
} catch (Exception ex) {
|
|
491 |
this.addError("Can't register icons", ex);
|
|
492 |
}
|
|
481 |
try {
|
|
482 |
initIconThemes();
|
|
483 |
} catch (Exception ex) {
|
|
484 |
this.addError("Can't initialize icon theme", ex);
|
|
485 |
}
|
|
486 |
// Registramos los iconos base
|
|
487 |
try {
|
|
488 |
registerIcons();
|
|
489 |
} catch (Exception ex) {
|
|
490 |
this.addError("Can't register icons", ex);
|
|
491 |
}
|
|
493 | 492 |
|
494 |
// Obtener la personalizaci�n de la aplicacion.
|
|
495 |
try {
|
|
496 |
logger.info("Initialize andami theme");
|
|
497 |
theme = getTheme(andamiConfig.getPluginsDirectory());
|
|
498 |
} catch (Exception ex) {
|
|
499 |
this.addError("Can't get personalized theme for the application",
|
|
500 |
ex);
|
|
501 |
}
|
|
502 |
UIManager.put("Desktop.background", theme.getBackgroundColor());
|
|
493 |
// Obtener la personalizaci�n de la aplicacion.
|
|
494 |
try {
|
|
495 |
logger.info("Initialize andami theme");
|
|
496 |
theme = getTheme(andamiConfig.getPluginsDirectory());
|
|
497 |
} catch (Exception ex) {
|
|
498 |
this.addError("Can't get personalized theme for the application",
|
|
499 |
ex);
|
|
500 |
}
|
|
501 |
UIManager.put("Desktop.background", theme.getBackgroundColor()); |
|
503 | 502 |
|
503 |
// Mostrar la ventana de inicio |
|
504 |
Frame f = new Frame(); |
|
505 |
splashWindow = new MultiSplashWindow(f, theme, 27); |
|
504 | 506 |
|
505 |
// Mostrar la ventana de inicio |
|
506 |
Frame f = new Frame(); |
|
507 |
splashWindow = new MultiSplashWindow(f, theme, 27); |
|
507 |
// Ponemos los datos del proxy |
|
508 |
splashWindow.process(translate("SplashWindow.configuring_proxy")); |
|
509 |
logger.info("Configute http proxy"); |
|
510 |
configureProxy(); |
|
508 | 511 |
|
509 |
// Ponemos los datos del proxy |
|
510 |
splashWindow.process(translate("SplashWindow.configuring_proxy")); |
|
511 |
logger.info("Configute http proxy"); |
|
512 |
configureProxy(); |
|
513 |
|
|
514 |
// Buscar actualizaciones de los plugins |
|
515 |
splashWindow.process(translate("SplashWindow.looking_for_updates")); |
|
516 |
try { |
|
512 |
// Buscar actualizaciones de los plugins |
|
513 |
splashWindow.process(translate("SplashWindow.looking_for_updates")); |
|
514 |
try { |
|
517 | 515 |
// this.downloadExtensions(andamiConfig.getPluginsDirectory()); |
518 |
} catch (Exception ex) {
|
|
519 |
this.addError("Can't downloads plugins", ex);
|
|
520 |
}
|
|
516 |
} catch (Exception ex) {
|
|
517 |
this.addError("Can't downloads plugins", ex);
|
|
518 |
}
|
|
521 | 519 |
|
522 |
splashWindow.process(translate("SplashWindow.initialize_install_manager"));
|
|
523 |
initializeInstallerManager();
|
|
520 |
splashWindow.process(translate("SplashWindow.initialize_install_manager"));
|
|
521 |
initializeInstallerManager(); |
|
524 | 522 |
|
523 |
InstallerManager installerManager = InstallerLocator.getInstallerManager(); |
|
524 |
PackageInfo[] installedPackages = null; |
|
525 |
try { |
|
526 |
installedPackages = installerManager.getInstalledPackages(); |
|
527 |
} catch (MakePluginPackageServiceException e) { |
|
528 |
// Do nothing, ignore errors |
|
529 |
} |
|
530 |
logger.info("Dump system information"); |
|
531 |
logger_info(getInformation(installedPackages)); |
|
532 |
saveEnvironInformation(installedPackages); |
|
525 | 533 |
|
526 |
InstallerManager installerManager = InstallerLocator.getInstallerManager(); |
|
527 |
PackageInfo[] installedPackages = null; |
|
528 |
try { |
|
529 |
installedPackages = installerManager.getInstalledPackages(); |
|
530 |
} catch (MakePluginPackageServiceException e) { |
|
531 |
// Do nothing, ignore errors |
|
532 |
} |
|
533 |
logger.info("Dump system information"); |
|
534 |
logger_info(getInformation(installedPackages)); |
|
535 |
saveEnvironInformation(installedPackages); |
|
534 |
// Se leen los config.xml de los plugins |
|
535 |
splashWindow.process(translate("SplashWindow.load_plugins_configuration")); |
|
536 |
try { |
|
537 |
logger.info("Load plugins information"); |
|
538 |
this.loadPluginConfigs(); |
|
539 |
if (pluginsConfig.isEmpty()) { |
|
540 |
logger.warn("No valid plugin was found."); |
|
541 |
System.exit(-1); |
|
542 |
} |
|
543 |
} catch (Throwable ex) { |
|
544 |
this.addError("Can't load plugins", ex); |
|
545 |
} |
|
536 | 546 |
|
547 |
splashWindow.process(translate("SplashWindow.check_incompatible_plugins")); |
|
548 |
fixIncompatiblePlugins(installedPackages); |
|
537 | 549 |
|
538 |
// Se leen los config.xml de los plugins |
|
539 |
splashWindow.process(translate("SplashWindow.load_plugins_configuration")); |
|
540 |
try { |
|
541 |
logger.info("Load plugins information"); |
|
542 |
this.loadPluginConfigs(); |
|
543 |
if ( pluginsConfig.isEmpty() ) { |
|
544 |
logger.warn("No valid plugin was found."); |
|
545 |
System.exit(-1); |
|
546 |
} |
|
547 |
} catch (Throwable ex) { |
|
548 |
this.addError("Can't load plugins", ex); |
|
549 |
} |
|
550 |
// Se configura el classloader del plugin |
|
551 |
splashWindow.process(translate("SplashWindow.setup_plugins_configuration")); |
|
552 |
try { |
|
553 |
logger.info("Configure plugins class loader"); |
|
554 |
this.loadPluginServices(); |
|
555 |
} catch (Throwable ex) { |
|
556 |
logger.warn("Can't initialize plugin's classloaders ", ex); |
|
557 |
} |
|
558 |
try { |
|
559 |
registerActions(); |
|
560 |
} catch (Throwable ex) { |
|
561 |
logger.warn("Can't register actions of plugins", ex); |
|
562 |
} |
|
550 | 563 |
|
551 |
splashWindow.process(translate("SplashWindow.check_incompatible_plugins")); |
|
552 |
fixIncompatiblePlugins(installedPackages); |
|
564 |
initializeIdentityManagement(new File(andamiConfig.getPluginsDirectory()).getAbsoluteFile()); |
|
553 | 565 |
|
566 |
// Initialize libraries |
|
567 |
splashWindow.process(translate("SplashWindow.initialize_plugins_libraries")); |
|
568 |
initializeLibraries(); |
|
554 | 569 |
|
555 |
// Se configura el classloader del plugin |
|
556 |
splashWindow.process(translate("SplashWindow.setup_plugins_configuration")); |
|
557 |
try { |
|
558 |
logger.info("Configure plugins class loader"); |
|
559 |
this.loadPluginServices(); |
|
560 |
} catch (Throwable ex) { |
|
561 |
logger.warn("Can't initialize plugin's classloaders ", ex); |
|
562 |
} |
|
563 |
try { |
|
564 |
registerActions(); |
|
565 |
} catch (Throwable ex) { |
|
566 |
logger.warn("Can't register actions of plugins", ex); |
|
567 |
} |
|
570 |
// Se carga un Skin si alguno ide los plugins trae informacion para ello |
|
571 |
splashWindow.process(translate("SplashWindow.looking_for_a_skin")); |
|
572 |
logger.info("Initialize skin"); |
|
573 |
skinPlugin(null); |
|
568 | 574 |
|
569 |
initializeIdentityManagement(new File(andamiConfig.getPluginsDirectory()).getAbsoluteFile()); |
|
575 |
// Se configura la cola de eventos |
|
576 |
splashWindow.process(translate("setting_up_event_queue")); |
|
577 |
EventQueue waitQueue = new AndamiEventQueue(); |
|
578 |
Toolkit.getDefaultToolkit().getSystemEventQueue().push(waitQueue); |
|
570 | 579 |
|
571 |
// Initialize libraries
|
|
572 |
splashWindow.process(translate("SplashWindow.initialize_plugins_libraries"));
|
|
573 |
initializeLibraries();
|
|
580 |
// Se configura la internacionalizacion del plugin
|
|
581 |
splashWindow.process(translate("SplashWindow.starting_plugin_internationalization_system"));
|
|
582 |
pluginsMessages();
|
|
574 | 583 |
|
575 |
// Se carga un Skin si alguno ide los plugins trae informacion para ello |
|
576 |
splashWindow.process(translate("SplashWindow.looking_for_a_skin")); |
|
577 |
logger.info("Initialize skin"); |
|
578 |
skinPlugin(null); |
|
584 |
// Se modifica el andami-config con los plugins nuevos |
|
585 |
splashWindow.process(translate("SplashWindow.update_framework_configuration")); |
|
586 |
updateAndamiConfig(); |
|
579 | 587 |
|
580 |
// Se configura la cola de eventos
|
|
581 |
splashWindow.process(translate("setting_up_event_queue"));
|
|
582 |
EventQueue waitQueue = new AndamiEventQueue();
|
|
583 |
Toolkit.getDefaultToolkit().getSystemEventQueue().push(waitQueue);
|
|
588 |
frame = MDIFrame.getInstance();
|
|
589 |
// Se configura el nombre e icono de la aplicacion
|
|
590 |
splashWindow.process(translate("SplashWindow.setting_up_applications_name_and_icons"));
|
|
591 |
frameIcon(theme);
|
|
584 | 592 |
|
585 |
// Se configura la internacionalizacion del plugin |
|
586 |
splashWindow.process(translate("SplashWindow.starting_plugin_internationalization_system")); |
|
587 |
pluginsMessages(); |
|
593 |
// Se prepara el MainFrame para albergar las extensiones |
|
594 |
splashWindow.process(translate("SplashWindow.preparing_workbench")); |
|
595 |
JPopupMenu.setDefaultLightWeightPopupEnabled(false); |
|
596 |
SwingUtilities.invokeAndWait(new Runnable() { |
|
597 |
public void run() { |
|
598 |
frame.init(); |
|
599 |
} |
|
600 |
}); |
|
601 |
ToolsSwingLocator.registerWindowManager(ToolsWindowManager.class); |
|
588 | 602 |
|
589 |
// Se modifica el andami-config con los plugins nuevos
|
|
590 |
splashWindow.process(translate("SplashWindow.update_framework_configuration"));
|
|
591 |
updateAndamiConfig();
|
|
603 |
// Leer el fichero de persistencia de los plugins
|
|
604 |
splashWindow.process(translate("SplashWindow.loading_plugin_settings"));
|
|
605 |
loadPluginsPersistence();
|
|
592 | 606 |
|
593 |
frame = MDIFrame.getInstance(); |
|
594 |
// Se configura el nombre e icono de la aplicacion |
|
595 |
splashWindow.process(translate("SplashWindow.setting_up_applications_name_and_icons")); |
|
596 |
frameIcon(theme); |
|
597 |
|
|
598 |
// Se prepara el MainFrame para albergar las extensiones |
|
599 |
splashWindow.process(translate("SplashWindow.preparing_workbench")); |
|
600 |
JPopupMenu.setDefaultLightWeightPopupEnabled(false); |
|
601 |
SwingUtilities.invokeAndWait(new Runnable() { |
|
602 |
public void run() { |
|
603 |
frame.init(); |
|
604 |
} |
|
605 |
}); |
|
606 |
ToolsSwingLocator.registerWindowManager(ToolsWindowManager.class); |
|
607 |
|
|
608 |
// Leer el fichero de persistencia de los plugins |
|
609 |
splashWindow.process(translate("SplashWindow.loading_plugin_settings")); |
|
610 |
loadPluginsPersistence(); |
|
611 |
|
|
612 | 607 |
// Se instalan los controles del skin |
613 |
// Se inicializan todas las extensiones de todos los plugins
|
|
614 |
splashWindow.process(translate("SplashWindow.initializing_extensions"));
|
|
615 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
616 |
public void run() {
|
|
617 |
initializeExtensions();
|
|
618 |
}
|
|
619 |
});
|
|
608 |
// Se inicializan todas las extensiones de todos los plugins
|
|
609 |
splashWindow.process(translate("SplashWindow.initializing_extensions"));
|
|
610 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
611 |
public void run() {
|
|
612 |
initializeExtensions();
|
|
613 |
}
|
|
614 |
});
|
|
620 | 615 |
|
621 |
// Se inicializan la extension exclusiva
|
|
622 |
splashWindow.process(translate("SplashWindow.setting_up_master_extension"));
|
|
623 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
624 |
public void run() {
|
|
625 |
initializeExclusiveUIExtension();
|
|
626 |
}
|
|
627 |
});
|
|
628 |
frame.setClassesExtensions(classesExtensions);
|
|
616 |
// Se inicializan la extension exclusiva
|
|
617 |
splashWindow.process(translate("SplashWindow.setting_up_master_extension"));
|
|
618 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
619 |
public void run() {
|
|
620 |
initializeExclusiveUIExtension();
|
|
621 |
}
|
|
622 |
});
|
|
623 |
frame.setClassesExtensions(classesExtensions);
|
|
629 | 624 |
|
630 |
// Se instalan los controles de las extensiones de los plugins
|
|
631 |
message(translate("SplashWindow.installing_extensions_controls"));
|
|
632 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
633 |
public void run() {
|
|
634 |
installPluginsControls();
|
|
635 |
}
|
|
636 |
});
|
|
625 |
// Se instalan los controles de las extensiones de los plugins
|
|
626 |
message(translate("SplashWindow.installing_extensions_controls"));
|
|
627 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
628 |
public void run() {
|
|
629 |
installPluginsControls();
|
|
630 |
}
|
|
631 |
});
|
|
637 | 632 |
|
638 |
// Se instalan los menus de las extensiones de los plugins
|
|
639 |
message(translate("SplashWindow.installing_extensions_menus"));
|
|
640 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
641 |
public void run() {
|
|
642 |
installPluginsMenus();
|
|
643 |
}
|
|
644 |
});
|
|
633 |
// Se instalan los menus de las extensiones de los plugins
|
|
634 |
message(translate("SplashWindow.installing_extensions_menus"));
|
|
635 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
636 |
public void run() {
|
|
637 |
installPluginsMenus();
|
|
638 |
}
|
|
639 |
});
|
|
645 | 640 |
|
646 |
message(translate("SplashWindow.initializing_server_data_persistence"));
|
|
647 |
ServerDataPersistence.registerPersistence();
|
|
641 |
message(translate("SplashWindow.initializing_server_data_persistence"));
|
|
642 |
ServerDataPersistence.registerPersistence();
|
|
648 | 643 |
|
649 |
// Se instalan las etiquetas de las extensiones de los plugins
|
|
650 |
message(translate("SplashWindow.installing_extensions_labels"));
|
|
651 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
652 |
public void run() {
|
|
653 |
installPluginsLabels();
|
|
654 |
}
|
|
655 |
});
|
|
644 |
// Se instalan las etiquetas de las extensiones de los plugins
|
|
645 |
message(translate("SplashWindow.installing_extensions_labels"));
|
|
646 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
647 |
public void run() {
|
|
648 |
installPluginsLabels();
|
|
649 |
}
|
|
650 |
});
|
|
656 | 651 |
|
657 |
// Se muestra el frame principal
|
|
658 |
message(translate("creating_main_window"));
|
|
659 |
frame.setVisible(true);
|
|
660 |
frame.setCursor(Cursor.WAIT_CURSOR);
|
|
652 |
// Se muestra el frame principal
|
|
653 |
message(translate("creating_main_window"));
|
|
654 |
frame.setVisible(true);
|
|
655 |
frame.setCursor(Cursor.WAIT_CURSOR);
|
|
661 | 656 |
|
662 | 657 |
// Definimos un KeyEventDispatcher global para que las extensiones |
663 |
// puedan registrar sus "teclas rapidas".
|
|
664 |
message(translate("SplashWindow.initializing_accelerator_keys"));
|
|
665 |
GlobalKeyEventDispatcher keyDispatcher = GlobalKeyEventDispatcher.getInstance();
|
|
666 |
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keyDispatcher);
|
|
658 |
// puedan registrar sus "teclas rapidas".
|
|
659 |
message(translate("SplashWindow.initializing_accelerator_keys"));
|
|
660 |
GlobalKeyEventDispatcher keyDispatcher = GlobalKeyEventDispatcher.getInstance();
|
|
661 |
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keyDispatcher);
|
|
667 | 662 |
|
668 |
message(translate("SplashWindow.enable_controls"));
|
|
669 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
670 |
public void run() {
|
|
671 |
try {
|
|
672 |
frame.enableControls();
|
|
673 |
} catch(Throwable th) {
|
|
674 |
logger.warn("Problems enabling controls",th);
|
|
675 |
}
|
|
676 |
}
|
|
677 |
});
|
|
663 |
message(translate("SplashWindow.enable_controls"));
|
|
664 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
665 |
public void run() {
|
|
666 |
try { |
|
667 |
frame.enableControls();
|
|
668 |
} catch (Throwable th) {
|
|
669 |
logger.warn("Problems enabling controls", th);
|
|
670 |
} |
|
671 |
}
|
|
672 |
});
|
|
678 | 673 |
|
679 |
// Se ejecuta el postInitialize
|
|
680 |
message(translate("SplashWindow.post_initializing_extensions"));
|
|
681 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
682 |
public void run() {
|
|
683 |
postInitializeExtensions();
|
|
684 |
}
|
|
685 |
});
|
|
674 |
// Se ejecuta el postInitialize
|
|
675 |
message(translate("SplashWindow.post_initializing_extensions"));
|
|
676 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
677 |
public void run() {
|
|
678 |
postInitializeExtensions();
|
|
679 |
}
|
|
680 |
});
|
|
686 | 681 |
|
687 |
message(translate("SplashWindow.enable_controls"));
|
|
688 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
689 |
public void run() {
|
|
690 |
try {
|
|
691 |
frame.enableControls();
|
|
692 |
message(translate("StatusBar.Aplicacion_iniciada"));
|
|
693 |
} catch(Throwable th) {
|
|
694 |
logger.warn("Problems enabling controls",th);
|
|
695 |
}
|
|
696 |
}
|
|
697 |
});
|
|
682 |
message(translate("SplashWindow.enable_controls"));
|
|
683 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
684 |
public void run() {
|
|
685 |
try { |
|
686 |
frame.enableControls();
|
|
687 |
message(translate("StatusBar.Aplicacion_iniciada"));
|
|
688 |
} catch (Throwable th) {
|
|
689 |
logger.warn("Problems enabling controls", th);
|
|
690 |
} |
|
691 |
}
|
|
692 |
});
|
|
698 | 693 |
|
699 |
splashWindow.close();
|
|
694 |
splashWindow.close();
|
|
700 | 695 |
|
701 |
frame.setCursor(Cursor.DEFAULT_CURSOR);
|
|
696 |
frame.setCursor(Cursor.DEFAULT_CURSOR);
|
|
702 | 697 |
|
703 |
if (launcherrors != null) {
|
|
704 |
NotificationManager.addError(launcherrors);
|
|
705 |
}
|
|
706 |
org.apache.log4j.Logger.getRootLogger().addAppender(
|
|
707 |
new NotificationAppender());
|
|
698 |
if (launcherrors != null) {
|
|
699 |
NotificationManager.addError(launcherrors);
|
|
700 |
}
|
|
701 |
org.apache.log4j.Logger.getRootLogger().addAppender(
|
|
702 |
new NotificationAppender());
|
|
708 | 703 |
|
709 |
/*
|
|
710 |
* Executes additional tasks required by plugins
|
|
711 |
*/
|
|
712 |
PluginsLocator.getManager().executeStartupTasks();
|
|
704 |
/*
|
|
705 |
* Executes additional tasks required by plugins
|
|
706 |
*/
|
|
707 |
PluginsLocator.getManager().executeStartupTasks();
|
|
713 | 708 |
|
714 |
}
|
|
709 |
}
|
|
715 | 710 |
|
716 |
private void initializeInstallerManager() {
|
|
717 |
PluginsManager pluginmgr = PluginsLocator.getManager();
|
|
718 |
InstallerManager installerManager = InstallerLocator.getInstallerManager();
|
|
711 |
private void initializeInstallerManager() { |
|
712 |
PluginsManager pluginmgr = PluginsLocator.getManager(); |
|
713 |
InstallerManager installerManager = InstallerLocator.getInstallerManager(); |
|
719 | 714 |
|
720 | 715 |
// |
721 |
// Configure repository of plugins |
|
716 |
// Configure repository of plugins |
|
717 |
// |
|
718 |
List<File> folders = pluginmgr.getPluginsFolders(); |
|
719 |
for (File folder : folders) { |
|
720 |
installerManager.addLocalAddonRepository(folder, "plugin"); |
|
721 |
} |
|
722 |
installerManager.setDefaultLocalAddonRepository(folders.get(0), "plugin"); |
|
723 |
|
|
722 | 724 |
// |
723 |
List<File> folders = pluginmgr.getPluginsFolders(); |
|
724 |
for ( File folder : folders ) { |
|
725 |
installerManager.addLocalAddonRepository(folder, "plugin"); |
|
725 |
// Configure repository of iconsets |
|
726 |
// |
|
727 |
IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager(); |
|
728 |
FolderSet fset = iconManager.getRepository(); |
|
729 |
Iterator<FolderSet.FolderEntry> it = fset.iterator(); |
|
730 |
boolean first = true; |
|
731 |
while (it.hasNext()) { |
|
732 |
FolderEntry entry = it.next(); |
|
733 |
installerManager.addLocalAddonRepository(entry.getFolder(), "iconset"); |
|
734 |
if (first) { |
|
735 |
first = false; |
|
736 |
installerManager.setDefaultLocalAddonRepository(entry.getFolder(), "iconset"); |
|
726 | 737 |
} |
727 |
installerManager.setDefaultLocalAddonRepository(folders.get(0), "plugin");
|
|
738 |
}
|
|
728 | 739 |
|
729 |
// |
|
730 |
// Configure repository of iconsets |
|
731 |
// |
|
732 |
IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager(); |
|
733 |
FolderSet fset = iconManager.getRepository(); |
|
734 |
Iterator<FolderSet.FolderEntry> it = fset.iterator(); |
|
735 |
boolean first = true; |
|
736 |
while( it.hasNext() ) { |
|
737 |
FolderEntry entry = it.next(); |
|
738 |
installerManager.addLocalAddonRepository(entry.getFolder(),"iconset"); |
|
739 |
if( first ) { |
|
740 |
first = false; |
|
741 |
installerManager.setDefaultLocalAddonRepository(entry.getFolder(),"iconset"); |
|
740 |
} |
|
741 |
|
|
742 |
private void message(final String msg) { |
|
743 |
if (!SwingUtilities.isEventDispatchThread()) { |
|
744 |
try { |
|
745 |
SwingUtilities.invokeAndWait(new Runnable() { |
|
746 |
public void run() { |
|
747 |
message(msg); |
|
742 | 748 |
} |
749 |
}); |
|
750 |
} catch (Exception e) { |
|
751 |
logger.info(msg); |
|
752 |
logger.warn("Error showing message.", e); |
|
743 | 753 |
} |
744 |
|
|
754 |
return; |
|
745 | 755 |
} |
756 |
if (splashWindow.isVisible()) { |
|
757 |
splashWindow.process(msg); |
|
758 |
} |
|
759 |
if (frame.isVisible()) { |
|
760 |
frame.message(msg, JOptionPane.INFORMATION_MESSAGE); |
|
761 |
} |
|
762 |
} |
|
746 | 763 |
|
747 |
private void message(final String msg) { |
|
748 |
if (!SwingUtilities.isEventDispatchThread()) { |
|
749 |
try { |
|
750 |
SwingUtilities.invokeAndWait(new Runnable() { |
|
751 |
public void run() { |
|
752 |
message(msg); |
|
753 |
} |
|
754 |
}); |
|
755 |
} catch (Exception e) { |
|
756 |
logger.info(msg); |
|
757 |
logger.warn("Error showing message.", e); |
|
758 |
} |
|
759 |
return; |
|
760 |
} |
|
761 |
if (splashWindow.isVisible()) { |
|
762 |
splashWindow.process(msg); |
|
763 |
} |
|
764 |
if (frame.isVisible()) { |
|
765 |
frame.message(msg, JOptionPane.INFORMATION_MESSAGE); |
|
766 |
} |
|
767 |
} |
|
764 |
private void initializeLibraries() { |
|
765 |
List<ClassLoader> classLoaders = new ArrayList<ClassLoader>( |
|
766 |
pluginsOrdered.size() + 1); |
|
767 |
classLoaders.add(getClass().getClassLoader()); |
|
768 |
Iterator<String> iter = pluginsOrdered.iterator(); |
|
768 | 769 |
|
769 |
private void initializeLibraries() { |
|
770 |
List<ClassLoader> classLoaders = new ArrayList<ClassLoader>( |
|
771 |
pluginsOrdered.size() + 1); |
|
772 |
classLoaders.add(getClass().getClassLoader()); |
|
773 |
Iterator<String> iter = pluginsOrdered.iterator(); |
|
770 |
logger.info("Initializing plugins libraries: "); |
|
771 |
while (iter.hasNext()) { |
|
772 |
String pName = (String) iter.next(); |
|
773 |
PluginServices ps = (PluginServices) pluginsServices.get(pName); |
|
774 |
logger.info("Initializing plugin libraries (" + pName + ")"); |
|
775 |
classLoaders.add(ps.getClassLoader()); |
|
776 |
} |
|
774 | 777 |
|
775 |
logger.info("Initializing plugins libraries: "); |
|
776 |
while (iter.hasNext()) { |
|
777 |
String pName = (String) iter.next(); |
|
778 |
PluginServices ps = (PluginServices) pluginsServices.get(pName); |
|
779 |
logger.info("Initializing plugin libraries (" + pName + ")"); |
|
780 |
classLoaders.add(ps.getClassLoader()); |
|
781 |
} |
|
782 |
|
|
783 | 778 |
// Create the libraries initializer and |
784 |
// initialize the plugin libraries
|
|
785 |
new DefaultLibrariesInitializer(classLoaders
|
|
786 |
.toArray(new ClassLoader[classLoaders.size()]))
|
|
787 |
.fullInitialize(true);
|
|
779 |
// initialize the plugin libraries
|
|
780 |
new DefaultLibrariesInitializer(classLoaders
|
|
781 |
.toArray(new ClassLoader[classLoaders.size()]))
|
|
782 |
.fullInitialize(true);
|
|
788 | 783 |
|
789 |
// Remove them all, we don't need them anymore
|
|
790 |
classLoaders.clear();
|
|
791 |
classLoaders = null;
|
|
792 |
}
|
|
784 |
// Remove them all, we don't need them anymore
|
|
785 |
classLoaders.clear();
|
|
786 |
classLoaders = null;
|
|
787 |
}
|
|
793 | 788 |
|
794 |
/**
|
|
795 |
* @param args
|
|
796 |
* @throws IOException
|
|
797 |
* @throws ConfigurationException
|
|
798 |
*/
|
|
799 |
private void initializeApp(String[] args, String applicationClasifier) throws IOException, ConfigurationException {
|
|
800 |
if( args.length<1 ) {
|
|
801 |
appName = "gvSIG"; // Nombre de aplicacion por defecto es "gvSIG"
|
|
802 |
} else {
|
|
803 |
appName = args[0];
|
|
804 |
}
|
|
805 |
getOrCreateConfigFolder();
|
|
806 |
configureLogging(appName, applicationClasifier);
|
|
807 |
if (!validJVM()) {
|
|
808 |
logger.error("Not a valid JRE. Exit application.");
|
|
809 |
System.exit(-1);
|
|
810 |
}
|
|
811 |
// Clean temporal files
|
|
812 |
Utilities.cleanUpTempFiles();
|
|
789 |
/**
|
|
790 |
* @param args
|
|
791 |
* @throws IOException
|
|
792 |
* @throws ConfigurationException
|
|
793 |
*/
|
|
794 |
private void initializeApp(String[] args, String applicationClasifier) throws IOException, ConfigurationException {
|
|
795 |
if (args.length < 1) {
|
|
796 |
appName = "gvSIG"; // Nombre de aplicacion por defecto es "gvSIG"
|
|
797 |
} else {
|
|
798 |
appName = args[0];
|
|
799 |
}
|
|
800 |
getOrCreateConfigFolder();
|
|
801 |
configureLogging(appName, applicationClasifier);
|
|
802 |
if (!validJVM()) {
|
|
803 |
logger.error("Not a valid JRE. Exit application."); |
|
804 |
System.exit(-1); |
|
805 |
}
|
|
806 |
// Clean temporal files
|
|
807 |
Utilities.cleanUpTempFiles();
|
|
813 | 808 |
|
814 |
if( args.length<2 ) {
|
|
815 |
loadAndamiConfig("gvSIG/extensiones"); // Valor por defecto
|
|
816 |
} else {
|
|
817 |
loadAndamiConfig(args[1]);
|
|
818 |
}
|
|
809 |
if (args.length < 2) {
|
|
810 |
loadAndamiConfig("gvSIG/extensiones"); // Valor por defecto
|
|
811 |
} else {
|
|
812 |
loadAndamiConfig(args[1]);
|
|
813 |
}
|
|
819 | 814 |
|
820 | 815 |
// Hacemos visibles los argumentos como una propiedad est�tica |
821 |
// de plugin services para quien lo quiera usar (por ejemplo, para
|
|
822 |
// cargar un proyecto por l�nea de comandos)
|
|
823 |
PluginServices.setArguments(args);
|
|
816 |
// de plugin services para quien lo quiera usar (por ejemplo, para
|
|
817 |
// cargar un proyecto por l�nea de comandos)
|
|
818 |
PluginServices.setArguments(args);
|
|
824 | 819 |
|
825 |
configureLocales(args);
|
|
820 |
configureLocales(args);
|
|
826 | 821 |
|
827 |
logger.info("Configure LookAndFeel");
|
|
828 |
configureLookAndFeel();
|
|
829 |
}
|
|
822 |
logger.info("Configure LookAndFeel");
|
|
823 |
configureLookAndFeel();
|
|
824 |
}
|
|
830 | 825 |
|
831 |
/**
|
|
826 |
/**
|
|
832 | 827 |
* |
833 | 828 |
*/ |
834 |
private void configureLookAndFeel() {
|
|
835 |
// Se pone el lookAndFeel
|
|
836 |
try {
|
|
837 |
String lookAndFeel = getAndamiConfig().getLookAndFeel();
|
|
838 |
if (lookAndFeel == null) {
|
|
839 |
lookAndFeel = getDefaultLookAndFeel();
|
|
840 |
}
|
|
841 |
UIManager.setLookAndFeel(lookAndFeel);
|
|
842 |
} catch (Exception e) {
|
|
843 |
logger.warn(Messages.getString("Launcher.look_and_feel"), e);
|
|
844 |
}
|
|
845 |
FontUtils.initFonts();
|
|
846 |
}
|
|
829 |
private void configureLookAndFeel() {
|
|
830 |
// Se pone el lookAndFeel
|
|
831 |
try {
|
|
832 |
String lookAndFeel = getAndamiConfig().getLookAndFeel();
|
|
833 |
if (lookAndFeel == null) {
|
|
834 |
lookAndFeel = getDefaultLookAndFeel();
|
|
835 |
}
|
|
836 |
UIManager.setLookAndFeel(lookAndFeel);
|
|
837 |
} catch (Exception e) {
|
|
838 |
logger.warn(Messages.getString("Launcher.look_and_feel"), e);
|
|
839 |
}
|
|
840 |
FontUtils.initFonts();
|
|
841 |
}
|
|
847 | 842 |
|
848 |
/**
|
|
849 |
* @param args
|
|
850 |
* @throws ConfigurationException
|
|
851 |
*/
|
|
852 |
private void loadAndamiConfig(String pluginFolder)
|
|
853 |
throws ConfigurationException {
|
|
854 |
andamiConfigPath = appHomeDir + File.separator + "andami-config.xml";
|
|
855 |
andamiConfigFromXML(andamiConfigPath);
|
|
856 |
andamiConfig.setPluginsDirectory(pluginFolder);
|
|
857 |
}
|
|
843 |
/**
|
|
844 |
* @param args
|
|
845 |
* @throws ConfigurationException
|
|
846 |
*/
|
|
847 |
private void loadAndamiConfig(String pluginFolder)
|
|
848 |
throws ConfigurationException {
|
|
849 |
andamiConfigPath = appHomeDir + File.separator + "andami-config.xml";
|
|
850 |
andamiConfigFromXML(andamiConfigPath);
|
|
851 |
andamiConfig.setPluginsDirectory(pluginFolder);
|
|
852 |
}
|
|
858 | 853 |
|
859 |
/**
|
|
854 |
/**
|
|
860 | 855 |
* |
861 | 856 |
*/ |
862 |
private void getOrCreateConfigFolder() {
|
|
863 |
// Create application configuration folder
|
|
864 |
appHomeDir = System.getProperty(appName + ".home");
|
|
865 |
if (appHomeDir == null) {
|
|
866 |
appHomeDir = System.getProperty("user.home");
|
|
867 |
}
|
|
857 |
private void getOrCreateConfigFolder() {
|
|
858 |
// Create application configuration folder
|
|
859 |
appHomeDir = System.getProperty(appName + ".home");
|
|
860 |
if (appHomeDir == null) {
|
|
861 |
appHomeDir = System.getProperty("user.home");
|
|
862 |
}
|
|
868 | 863 |
|
869 |
appHomeDir += File.separator + appName;
|
|
870 |
File parent = new File(appHomeDir);
|
|
871 |
parent.mkdirs();
|
|
872 |
}
|
|
864 |
appHomeDir += File.separator + appName;
|
|
865 |
File parent = new File(appHomeDir);
|
|
866 |
parent.mkdirs();
|
|
867 |
}
|
|
873 | 868 |
|
874 |
/**
|
|
875 |
* @param args
|
|
876 |
* @throws IOException
|
|
877 |
*/
|
|
878 |
private void configureLogging(String appName, String applicationClasifier) throws IOException {
|
|
879 |
// Configurar el log4j
|
|
869 |
/**
|
|
870 |
* @param args
|
|
871 |
* @throws IOException
|
|
872 |
*/
|
|
873 |
private void configureLogging(String appName, String applicationClasifier) throws IOException {
|
|
874 |
// Configurar el log4j
|
|
880 | 875 |
|
881 |
String pathname;
|
|
882 |
if( StringUtils.isBlank(applicationClasifier) ) {
|
|
883 |
pathname = appHomeDir + File.separator + appName + ".log";
|
|
884 |
} else {
|
|
885 |
pathname = appHomeDir + File.separator + appName + "-" + applicationClasifier + ".log";
|
|
886 |
}
|
|
887 |
URL config = Launcher.class.getClassLoader().getResource("log4j.properties");
|
|
888 |
if( config == null ) {
|
|
889 |
config = Launcher.class.getClassLoader().getResource("default-log4j/log4j.properties");
|
|
890 |
}
|
|
891 |
PropertyConfigurator.configure(config);
|
|
892 |
PatternLayout l = new PatternLayout("%p %t %C - %m%n");
|
|
893 |
RollingFileAppender fa = new RollingFileAppender(l, pathname, false);
|
|
894 |
fa.setMaxFileSize("512KB");
|
|
895 |
fa.setMaxBackupIndex(3);
|
|
896 |
org.apache.log4j.Logger.getRootLogger().addAppender(fa);
|
|
897 |
logger.info("Loadded log4j.properties from " + config.toString());
|
|
898 |
if( StringUtils.isBlank(applicationClasifier) ) {
|
|
899 |
logger.info("Application "+ appName );
|
|
900 |
} else {
|
|
901 |
logger.info("Application "+ appName + "-" + applicationClasifier );
|
|
902 |
}
|
|
903 |
}
|
|
876 |
String pathname; |
|
877 |
if (StringUtils.isBlank(applicationClasifier)) {
|
|
878 |
pathname = appHomeDir + File.separator + appName + ".log"; |
|
879 |
} else { |
|
880 |
pathname = appHomeDir + File.separator + appName + "-" + applicationClasifier + ".log"; |
|
881 |
} |
|
882 |
URL config = Launcher.class.getClassLoader().getResource("log4j.properties");
|
|
883 |
if (config == null) {
|
|
884 |
config = Launcher.class.getClassLoader().getResource("default-log4j/log4j.properties");
|
|
885 |
}
|
|
886 |
PropertyConfigurator.configure(config);
|
|
887 |
PatternLayout l = new PatternLayout("%p %t %C - %m%n");
|
|
888 |
RollingFileAppender fa = new RollingFileAppender(l, pathname, false);
|
|
889 |
fa.setMaxFileSize("512KB");
|
|
890 |
fa.setMaxBackupIndex(3);
|
|
891 |
org.apache.log4j.Logger.getRootLogger().addAppender(fa);
|
|
892 |
logger.info("Loadded log4j.properties from " + config.toString());
|
|
893 |
if (StringUtils.isBlank(applicationClasifier)) {
|
|
894 |
logger.info("Application " + appName);
|
|
895 |
} else { |
|
896 |
logger.info("Application " + appName + "-" + applicationClasifier);
|
|
897 |
} |
|
898 |
}
|
|
904 | 899 |
|
905 |
private class NotificationAppender extends AppenderSkeleton {
|
|
900 |
private class NotificationAppender extends AppenderSkeleton {
|
|
906 | 901 |
|
907 |
@Override
|
|
908 |
protected void append(LoggingEvent event) {
|
|
909 |
if (event.getLevel() == org.apache.log4j.Level.ERROR
|
|
910 |
|| event.getLevel() == org.apache.log4j.Level.FATAL) {
|
|
902 |
@Override
|
|
903 |
protected void append(LoggingEvent event) {
|
|
904 |
if (event.getLevel() == org.apache.log4j.Level.ERROR
|
|
905 |
|| event.getLevel() == org.apache.log4j.Level.FATAL) {
|
|
911 | 906 |
|
912 |
Throwable th = null;
|
|
913 |
ThrowableInformation thi = event.getThrowableInformation();
|
|
914 |
if (thi != null) {
|
|
915 |
th = thi.getThrowable();
|
|
916 |
}
|
|
917 |
NotificationManager.dispatchError(event.getRenderedMessage(), th);
|
|
918 |
return;
|
|
919 |
}
|
|
907 |
Throwable th = null;
|
|
908 |
ThrowableInformation thi = event.getThrowableInformation();
|
|
909 |
if (thi != null) {
|
|
910 |
th = thi.getThrowable();
|
|
911 |
}
|
|
912 |
NotificationManager.dispatchError(event.getRenderedMessage(), th);
|
|
913 |
return;
|
|
914 |
}
|
|
920 | 915 |
// if (event.getLevel() == org.apache.log4j.Level.WARN) { |
921 |
// NotificationManager.dispatchWarning(event.getRenderedMessage(),
|
|
922 |
// null);
|
|
923 |
// return;
|
|
924 |
// }
|
|
925 |
}
|
|
916 |
// NotificationManager.dispatchWarning(event.getRenderedMessage(),
|
|
917 |
// null);
|
|
918 |
// return;
|
|
919 |
// }
|
|
920 |
}
|
|
926 | 921 |
|
922 |
@Override |
|
923 |
public void close() { |
|
924 |
// TODO Auto-generated method stub |
|
927 | 925 |
|
928 |
@Override |
|
929 |
public void close() { |
|
930 |
// TODO Auto-generated method stub |
|
926 |
} |
|
931 | 927 |
|
932 |
} |
|
928 |
@Override |
|
929 |
public boolean requiresLayout() { |
|
930 |
// TODO Auto-generated method stub |
|
931 |
return false; |
|
932 |
} |
|
933 | 933 |
|
934 |
@Override |
|
935 |
public boolean requiresLayout() { |
|
936 |
// TODO Auto-generated method stub |
|
937 |
return false; |
|
938 |
} |
|
934 |
} |
|
939 | 935 |
|
940 |
} |
|
936 |
/** |
|
937 |
* Return the directory applicaction is installed. |
|
938 |
*/ |
|
939 |
public static String getApplicationDirectory() { |
|
940 |
return getApplicationFolder().getAbsolutePath(); |
|
941 |
} |
|
941 | 942 |
|
942 |
/** |
|
943 |
* Return the directory applicaction is installed. |
|
944 |
*/ |
|
945 |
public static String getApplicationDirectory() { |
|
946 |
return getApplicationFolder().getAbsolutePath(); |
|
947 |
} |
|
948 |
|
|
949 | 943 |
public static File getApplicationFolder() { |
950 | 944 |
// TODO: check if there is a better way to handle this |
951 | 945 |
return new File(System.getProperty("user.dir")); |
952 | 946 |
} |
953 | 947 |
|
954 |
private void registerIcons() {
|
|
955 |
IconTheme theme = PluginServices.getIconTheme();
|
|
956 |
ClassLoader loader = Launcher.class.getClassLoader();
|
|
948 |
private void registerIcons() {
|
|
949 |
IconTheme theme = PluginServices.getIconTheme();
|
|
950 |
ClassLoader loader = Launcher.class.getClassLoader();
|
|
957 | 951 |
|
958 |
String[][] icons = { |
|
959 |
// MultiSplashWindow |
|
960 |
{ "main", "splash-default" }, |
|
961 |
// NewStatusBar |
|
962 |
{ "main", "statusbar-info" }, |
|
963 |
{ "main", "statusbar-warning" }, |
|
964 |
{ "main", "statusbar-error" } |
|
965 |
}; |
|
966 |
for( int i=0; i<icons.length; i++) { |
|
967 |
try { |
|
968 |
IconThemeHelper.registerIcon(icons[i][0], icons[i][1], Launcher.class); |
|
969 |
} catch(Exception e) { |
|
970 |
logger.info("Can't register icon '"+icons[i][0]+"' ("+icons[i][1]+")."); |
|
971 |
} |
|
972 |
} |
|
973 |
theme.setDefaultIcon(loader.getResource("images/main/default-icon.png" )); |
|
974 |
} |
|
975 |
|
|
976 |
private Properties loadProperties(File f) { |
|
977 |
FileInputStream fin = null; |
|
978 |
Properties p = null; |
|
952 |
String[][] icons = { |
|
953 |
// MultiSplashWindow |
|
954 |
{"main", "splash-default"}, |
|
955 |
// NewStatusBar |
|
956 |
{"main", "statusbar-info"}, |
|
957 |
{"main", "statusbar-warning"}, |
|
958 |
{"main", "statusbar-error"} |
|
959 |
}; |
|
960 |
for (int i = 0; i < icons.length; i++) { |
|
979 | 961 |
try { |
980 |
fin = new FileInputStream(f); |
|
981 |
p = new Properties(); |
|
982 |
p.load(fin); |
|
983 |
} catch (IOException ex) { |
|
984 |
// Do nothing |
|
962 |
IconThemeHelper.registerIcon(icons[i][0], icons[i][1], Launcher.class); |
|
963 |
} catch (Exception e) { |
|
964 |
logger.info("Can't register icon '" + icons[i][0] + "' (" + icons[i][1] + ")."); |
|
985 | 965 |
} |
986 |
return p; |
|
987 | 966 |
} |
967 |
theme.setDefaultIcon(loader.getResource("images/main/default-icon.png")); |
|
968 |
} |
|
988 | 969 |
|
989 |
/** |
|
990 |
* Obtiene la personalizaci�n de los iconos, splash, fondo y el nombre de la |
|
991 |
* aplicaci�n. |
|
992 |
* |
|
993 |
* @return Theme |
|
994 |
*/ |
|
970 |
private Properties loadProperties(File f) { |
|
971 |
FileInputStream fin = null; |
|
972 |
Properties p = null; |
|
973 |
try { |
|
974 |
fin = new FileInputStream(f); |
|
975 |
p = new Properties(); |
|
976 |
p.load(fin); |
|
977 |
} catch (IOException ex) { |
|
978 |
// Do nothing |
|
979 |
} |
|
980 |
return p; |
|
981 |
} |
|
982 |
|
|
983 |
/** |
|
984 |
* Obtiene la personalizaci�n de los iconos, splash, fondo y el nombre de |
|
985 |
* la aplicaci�n. |
|
986 |
* |
|
987 |
* @return Theme |
|
988 |
*/ |
|
995 | 989 |
private Theme getTheme(String pluginsDirectory) { |
996 | 990 |
File infoFile = new File(Launcher.getApplicationFolder(), "package.info"); |
997 | 991 |
File themeFile = null; |
... | ... | |
999 | 993 |
|
1000 | 994 |
// Try to get theme from args |
1001 | 995 |
String name = PluginServices.getArgumentByName("andamiTheme"); |
1002 |
if ( name != null ) {
|
|
996 |
if (name != null) {
|
|
1003 | 997 |
themeFile = new File(name); |
1004 | 998 |
logger.info("search andami-theme in {}", themeFile.getAbsolutePath()); |
1005 |
if ( themeFile.exists() ) { |
|
999 |
if (themeFile.exists()) { |
Also available in: Unified diff