Revision 41314

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.i18n/src/main/java/org/gvsig/i18n/Messages.java
35 35
import java.util.HashSet;
36 36
import java.util.IllegalFormatException;
37 37
import java.util.Iterator;
38
import java.util.List;
38 39
import java.util.Locale;
39 40
import java.util.Properties;
40 41
import java.util.Set;
......
69 70
 *
70 71
 */
71 72
public class Messages {
73
    
74
    private static class FamilyDescriptor {
75
        String family = null;
76
        ClassLoader loader = null;
77
        String callerName = null;
78
        
79
        public FamilyDescriptor(String family, ClassLoader loader, String callerName ) {
80
            this.family  = family;
81
            this.loader = loader;
82
            this.callerName = callerName;
83
        }
84
    }
85
    
72 86
    private static Logger logger = LoggerFactory.getLogger("Messages");
73 87
    private static String _CLASSNAME = "org.gvsig.i18n.Messages";
88
    private static Locale currentLocale;
74 89

  
75 90
    /* Each entry will contain a hashmap with translations. Each hasmap
76 91
     * contains the translations for one language, indexed by the
......
84 99
	private static Set resourceFamilies = new HashSet();
85 100
	private static Set classLoaders = new HashSet();
86 101

  
102
        private static List familyDescriptors = new ArrayList();
103
        
87 104
	/*
88 105
	 * The language considered the origin of translations, which will
89 106
	 * (possibly) be stored in a property file without language suffix
......
386 403
			logger.warn("There is not preferred languages list. Maybe the Messages class was not initialized");
387 404
		}
388 405

  
406
                familyDescriptors.add( new FamilyDescriptor(family,loader,callerName));
407
                
389 408
		resourceFamilies.add(family);
390 409
		classLoaders.add(loader);
391 410

  
......
398 417
			addResourceFamily(lang, translations, family, loader, callerName);
399 418
		}
400 419
	}
401

  
420
        
402 421
	private static void addResourceFamily(Locale lang, Properties translations,
403 422
			String family, ClassLoader loader, String callerName) {
423
                //logger.debug("addResourceFamily "+lang.toString()+", "+family+", "+loader.toString());
424
                
404 425
		Properties properties = new Properties();
405 426
		String langCode = lang.toString();
406 427
		String resource = family.replace('.', '/') + "_" + langCode + ".properties";
428
                URL resourceURL = loader.getResource(resource);
407 429
		InputStream is = loader.getResourceAsStream(resource);
408 430
		if( is==null && langCode.contains("_") ) {
409 431
			try {
410 432
				langCode = langCode.split("_")[0];
411 433
				resource = family.replace('.', '/') + "_" + langCode + ".properties";
434
                                resourceURL = loader.getResource(resource);
412 435
				is = loader.getResourceAsStream(resource);
413 436
				if( is==null ) {
414 437
					resource = family.replace('.', '/') +  ".properties";
438
                                        resourceURL = loader.getResource(resource);
415 439
					is = loader.getResourceAsStream(resource);
416 440
				}
417 441
			} catch(Exception ex) {
......
437 461
			}
438 462

  
439 463
		}
464
                if( resourceURL!=null && logger.isDebugEnabled() ) {
465
                    logger.debug("Load resources from '"+resourceURL.toString()+"' with classloader {"+loader.toString()+"}.");
466
                }
440 467
		Enumeration keys = properties.keys();
441 468
		while (keys.hasMoreElements()) {
442 469
			String currentKey = (String) keys.nextElement();
443 470
			if (!translations.containsKey(currentKey)) {
444
				translations
445
						.put(currentKey, properties.getProperty(currentKey));
471
				translations.put(currentKey, properties.getProperty(currentKey));
446 472
			}
447 473
		}
448 474

  
......
499 525
	 * The ArrayList represents an ordered list of preferred locales
500 526
	 */
501 527
	public static void setPreferredLocales(ArrayList preferredLocalesList) {
528
                logger.info("setPreferredLocales "+preferredLocalesList.toString());
502 529
		// delete all existing locales
503 530
		Iterator oldLocales = preferredLocales.iterator();
504 531
		while (oldLocales.hasNext()) {
......
511 538
		}
512 539
	}
513 540

  
541
        public static Locale getCurrentLocale() {
542
            return currentLocale;
543
        }
544
        
545
        public static void setCurrentLocale(Locale locale) {
546
            logger.info("setCurrentLocale "+locale.toString());
547
            
548
            resourceFamilies = new HashSet();
549
            classLoaders = new HashSet();
550
            localeResources = new ArrayList();
551
            preferredLocales = new ArrayList();
552
            
553
            addLocale(locale);
554
            String localeStr = locale.getLanguage();
555
            if ( localeStr.equals("es") || localeStr.equals("ca")
556
                    || localeStr.equals("gl") || localeStr.equals("eu")
557
                    || localeStr.equals("va") ) {
558
                // prefer Spanish for languages spoken in Spain
559
                addLocale(new Locale("es"));
560
                addLocale(new Locale("en"));
561
            } else {
562
                // prefer English for the rest
563
                addLocale(new Locale("en"));
564
                addLocale(new Locale("es"));
565
            }
566
            
567
            for( int curlocale=0; curlocale<preferredLocales.size(); curlocale++) {
568
                for( int curfamily=0; curfamily<familyDescriptors.size(); curfamily++) {
569
                     FamilyDescriptor family = (FamilyDescriptor) familyDescriptors.get(curfamily);
570
                     addResourceFamily(
571
                             (Locale) preferredLocales.get(curlocale),
572
                             (Properties) localeResources.get(curlocale),
573
                             family.family,
574
                             family.loader,
575
                             family.callerName);
576
                }
577
            }
578
            currentLocale = locale;
579
            Locale.setDefault(locale);
580
        }
581

  
514 582
	/**
515 583
	 * Adds a Locale at the end of the ordered list of preferred locales.
516 584
	 * Note that calling this method does not load any translation, it just
......
522 590
	 */
523 591
	public static void addLocale(Locale lang) {
524 592
		if (!preferredLocales.contains(lang)) { // avoid duplicates
525
				preferredLocales.add(lang); // add the lang to the ordered list of preferred locales
526
				Properties dict = new Properties();
527
				localeResources.add(dict); // add a hashmap which will contain the translation for this language
593
                    logger.info("addLocale "+lang.toString());
594
                    preferredLocales.add(lang); // add the lang to the ordered list of preferred locales
595
                    Properties dict = new Properties();
596
                    localeResources.add(dict); // add a hashmap which will contain the translation for this language
528 597
		}
529 598
	}
530 599

  
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/impl/DefaultPluginsManager.java
10 10
 *
11 11
 * This program is distributed in the hope that it will be useful,
12 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14
 * GNU General Public License for more details.
15 15
 *
16 16
 * You should have received a copy of the GNU General Public License
17 17
 * along with this program; if not, write to the Free Software
18 18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
19
 * MA 02110-1301, USA.
20 20
 *
21 21
 * For any additional information, do not hesitate to contact us
22 22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
......
24 24
package org.gvsig.andami.impl;
25 25

  
26 26
import java.io.File;
27
import java.lang.reflect.InvocationTargetException;
27 28
import java.util.ArrayList;
28 29
import java.util.Collections;
29 30
import java.util.Enumeration;
30 31
import java.util.Iterator;
31 32
import java.util.List;
33
import java.util.Locale;
34
import java.util.logging.Level;
35
import javax.swing.JComponent;
32 36

  
33 37
import javax.swing.SwingUtilities;
34 38

  
......
43 47
import org.gvsig.installer.lib.api.PackageInfo;
44 48
import org.gvsig.tools.ToolsLocator;
45 49
import org.gvsig.tools.packageutils.PackageManager;
50
import org.gvsig.andami.ui.mdiFrame.MDIFrame;
46 51
import org.slf4j.Logger;
47 52
import org.slf4j.LoggerFactory;
48 53

  
49
public class DefaultPluginsManager implements PluginsManager{
54
public class DefaultPluginsManager implements PluginsManager {
50 55

  
51 56
    private class Task implements Comparable, Runnable {
52 57

  
......
84 89
                    } catch (InterruptedException ex) {
85 90
                        // Do nothing
86 91
                    } catch (Exception ex) {
87
                       logger.warn("Errors in execution of "+type+" task '"+name+"'.",ex);
92
                        logger.warn("Errors in execution of " + type + " task '" + name + "'.", ex);
88 93

  
89 94
                    }
90 95
                    return;
91 96
                }
92 97
            }
93
            logger.info("Running "+type+" task '"+name+"' (priority "+priority+").");
98
            logger.info("Running " + type + " task '" + name + "' (priority " + priority + ").");
94 99
            try {
95 100
                task.run();
96
            } catch(Exception ex) {
97
                logger.warn("Errors in execution of "+type+" task '"+name+"'.",ex);
101
                logger.info("Terminated " + type + " task '" + name + "'.");
102
            } catch (Exception ex) {
103
                logger.warn("Errors in execution of " + type + " task '" + name + "'.", ex);
98 104
            }
99 105
        }
100 106

  
101 107
    }
102 108

  
103
    private static Logger logger =
104
        LoggerFactory.getLogger(DefaultPluginsManager.class);
105
    
106
	private List<File> pluginsFolders = null;
107
	private List<Task> onStartupTasks = new ArrayList<Task>();
108
        private List<Task> onShutdownTasks = new ArrayList<Task>();
109
	
110
	public ExclusiveUIExtension getExclusiveUIExtension() {
111
		return PluginServices.getExclusiveUIExtension();
112
	}
109
    private static Logger logger
110
            = LoggerFactory.getLogger(DefaultPluginsManager.class);
113 111

  
114
	public IExtension getExtension(Class<? extends IExtension> extension) {
115
		return PluginServices.getExtension(extension);
116
	}
112
    private List<File> pluginsFolders = null;
113
    private List<Task> startupTasks = new ArrayList<Task>();
114
    private List<Task> shutdownTasks = new ArrayList<Task>();
117 115

  
118
	@SuppressWarnings("unchecked")
119
	public Iterator<IExtension> getExtensions() {
120
		return PluginServices.getExtensions();
121
	}
116
    public ExclusiveUIExtension getExclusiveUIExtension() {
117
        return PluginServices.getExclusiveUIExtension();
118
    }
122 119

  
123
	/**
124
	 * Return the associated pluginServices to the extension class passed as parameter.
125
	 *  
126
	 */
127
	public PluginServices getPlugin(Class<? extends IExtension> extension) {
128
            String pluginName = ((PluginClassLoader)extension.getClassLoader()).getPluginName();
129
            return  this.getPlugin(pluginName);
130
	}
120
    public IExtension getExtension(Class<? extends IExtension> extension) {
121
        return PluginServices.getExtension(extension);
122
    }
131 123

  
132
	public PluginServices getPlugin(Object obj) {
133
            if( obj instanceof IExtension ) {
134
                Class<? extends IExtension> klass = (Class<? extends IExtension>) obj.getClass();
135
                return this.getPlugin(klass);
136
            }
137
            PluginClassLoader loader = (PluginClassLoader) obj.getClass().getClassLoader();
138
            String pluginName = loader.getPluginName();
139
            return this.getPlugin(pluginName);
140
	}
124
    @SuppressWarnings("unchecked")
125
    public Iterator<IExtension> getExtensions() {
126
        return PluginServices.getExtensions();
127
    }
141 128

  
142
        public PluginServices getPlugin(String pluginName) {
143
		return Launcher.getPluginServices(pluginName);
144
	}
129
    /**
130
     * Return the associated pluginServices to the extension class passed as
131
     * parameter.
132
     *
133
     */
134
    public PluginServices getPlugin(Class<? extends IExtension> extension) {
135
        String pluginName = ((PluginClassLoader) extension.getClassLoader()).getPluginName();
136
        return this.getPlugin(pluginName);
137
    }
145 138

  
146
	public PackageInfo getPackageInfo(Class<? extends IExtension> extension) {
147
	    PackageManager pkgmgr = ToolsLocator.getPackageManager();
139
    public PluginServices getPlugin(Object obj) {
140
        if ( obj instanceof IExtension ) {
141
            Class<? extends IExtension> klass = (Class<? extends IExtension>) obj.getClass();
142
            return this.getPlugin(klass);
143
        }
144
        PluginClassLoader loader = (PluginClassLoader) obj.getClass().getClassLoader();
145
        String pluginName = loader.getPluginName();
146
        return this.getPlugin(pluginName);
147
    }
148

  
149
    public PluginServices getPlugin(String pluginName) {
150
        return Launcher.getPluginServices(pluginName);
151
    }
152

  
153
    public PackageInfo getPackageInfo(Class<? extends IExtension> extension) {
154
        PackageManager pkgmgr = ToolsLocator.getPackageManager();
148 155
        File pinfo_file = new File(this.getPlugin(extension).getPluginDirectory(), "package.info");
149
        
156

  
150 157
        PackageInfo packageInfo = null;
151 158
        try {
152 159
            packageInfo = pkgmgr.createPackageInfo(pinfo_file);
153 160
        } catch (Exception e) {
154
			logger.info("Error while reading package info file from "
155
					+ pinfo_file.toString(), e);
161
            logger.info("Error while reading package info file from "
162
                    + pinfo_file.toString(), e);
156 163
        }
157 164
        return packageInfo;
158
	}
159
	
160
	public PackageInfo getPackageInfo(String pluginName) {
161
		PackageManager pkgmgr = ToolsLocator.getPackageManager();
162
		File pinfo_file = new File(this.getPlugin(pluginName)
163
				.getPluginDirectory(), "package.info");
165
    }
164 166

  
165
		PackageInfo packageInfo = null;
166
		try {
167
			packageInfo = pkgmgr.createPackageInfo(pinfo_file);
168
		} catch (Exception e) {
169
			logger.info("Error while reading package info file from "
170
					+ pinfo_file.toString(), e);
171
		}
172
		return packageInfo;
173
	}
174
	
175
	public PackageInfo getPackageInfo() {
176
		PackageManager pkgmgr = ToolsLocator.getPackageManager();
177
		File pinfo_file = new File(
178
			    this.getApplicationFolder(), "package.info");
179
		PackageInfo packageInfo = null;
180
		try {
181
			packageInfo = pkgmgr.createPackageInfo(pinfo_file);
182
		} catch (Exception e) {
183
			logger.info("Error while reading package info file from "
184
					+ pinfo_file.toString(), e);
185
		}
186
		return packageInfo;
187
	}
188
	
189
	@SuppressWarnings("unchecked")
190
	public List<PluginServices> getPlugins() {
191
		List<PluginServices> pluginServices = new ArrayList<PluginServices>();
192
		
193
		AndamiConfig config = Launcher.getAndamiConfig();
194
		Enumeration<Plugin> plugins = config.enumeratePlugin();
195
		while( plugins.hasMoreElements()) {
196
			Plugin plugin =   plugins.nextElement();
197
			pluginServices.add(PluginServices.getPluginServices(plugin.getName()));
198
		}
199
		return pluginServices;
200
	}
167
    public PackageInfo getPackageInfo(String pluginName) {
168
        PackageManager pkgmgr = ToolsLocator.getPackageManager();
169
        File pinfo_file = new File(this.getPlugin(pluginName)
170
                .getPluginDirectory(), "package.info");
201 171

  
202
	public void setExclusiveUIExtension(ExclusiveUIExtension extension) {
203
		PluginServices.setExclusiveUIExtension(extension);
204
	}
172
        PackageInfo packageInfo = null;
173
        try {
174
            packageInfo = pkgmgr.createPackageInfo(pinfo_file);
175
        } catch (Exception e) {
176
            logger.info("Error while reading package info file from "
177
                    + pinfo_file.toString(), e);
178
        }
179
        return packageInfo;
180
    }
205 181

  
206
	public String getText(Object obj, String msg) {
207
	    return PluginServices.getText(obj, msg);
208
	}
209
	
210
	public String translate(String msg) {
211
	    return org.gvsig.i18n.Messages.translate(msg);
212
	}
213
	
182
    public PackageInfo getPackageInfo() {
183
        PackageManager pkgmgr = ToolsLocator.getPackageManager();
184
        File pinfo_file = new File(
185
                this.getApplicationFolder(), "package.info");
186
        PackageInfo packageInfo = null;
187
        try {
188
            packageInfo = pkgmgr.createPackageInfo(pinfo_file);
189
        } catch (Exception e) {
190
            logger.info("Error while reading package info file from "
191
                    + pinfo_file.toString(), e);
192
        }
193
        return packageInfo;
194
    }
195

  
196
    @SuppressWarnings("unchecked")
197
    public List<PluginServices> getPlugins() {
198
        List<PluginServices> pluginServices = new ArrayList<PluginServices>();
199

  
200
        AndamiConfig config = Launcher.getAndamiConfig();
201
        Enumeration<Plugin> plugins = config.enumeratePlugin();
202
        while ( plugins.hasMoreElements() ) {
203
            Plugin plugin = plugins.nextElement();
204
            pluginServices.add(PluginServices.getPluginServices(plugin.getName()));
205
        }
206
        return pluginServices;
207
    }
208

  
209
    public void setExclusiveUIExtension(ExclusiveUIExtension extension) {
210
        PluginServices.setExclusiveUIExtension(extension);
211
    }
212

  
213
    public String getText(Object obj, String msg) {
214
        return PluginServices.getText(obj, msg);
215
    }
216

  
217
    public String translate(String msg) {
218
        return org.gvsig.i18n.Messages.translate(msg);
219
    }
220

  
214 221
    public File getApplicationFolder() {
215
    	return Launcher.getApplicationFolder();
222
        return Launcher.getApplicationFolder();
216 223
    }
217 224

  
218
	/**
219
	 * @deprecated use {@link #getPluginsFolders()}
220
	 */
225
    /**
226
     * @deprecated use {@link #getPluginsFolders()}
227
     */
221 228
    public File getPluginsDirectory() {
222 229
        return getPluginsFolder();
223 230
    }
224 231

  
225
	/**
226
	 * @deprecated use {@link #getPluginsFolders()}
227
	 */
232
    /**
233
     * @deprecated use {@link #getPluginsFolders()}
234
     */
228 235
    public File getPluginsFolder() {
229
    	List<File> l = this.getPluginsFolders();
230
    	if( l==null || l.size()<1 ) {
231
    		return null;
232
    	}
233
    	return l.get(0);
236
        List<File> l = this.getPluginsFolders();
237
        if ( l == null || l.size() < 1 ) {
238
            return null;
239
        }
240
        return l.get(0);
234 241
    }
235 242

  
236 243
    public List<File> getPluginsFolders() {
237
    	if( this.pluginsFolders!=null ) {
238
    		return this.pluginsFolders;
239
    	}
240
    	String folder = "gvSIG/extensiones";
241
    	if( !(Launcher.getAndamiConfig() == null || Launcher.getAndamiConfig().getPluginsDirectory()==null) ) {
242
    		folder = Launcher.getAndamiConfig().getPluginsDirectory();
243
    	}
244
        if ( this.pluginsFolders != null ) {
245
            return this.pluginsFolders;
246
        }
247
        String folder = "gvSIG/extensiones";
248
        if ( !(Launcher.getAndamiConfig() == null || Launcher.getAndamiConfig().getPluginsDirectory() == null) ) {
249
            folder = Launcher.getAndamiConfig().getPluginsDirectory();
250
        }
244 251
        this.pluginsFolders = new ArrayList<File>();
245 252
        this.pluginsFolders.add(new File(getApplicationFolder(), folder));
246 253
        return this.pluginsFolders;
......
255 262
    }
256 263

  
257 264
    public void addStartupTask(String name, Runnable task, boolean in_event_thread, int priority) {
258
        this.onStartupTasks.add( new Task("startup", name, task, in_event_thread, priority));
265
        this.startupTasks.add(new Task("startup", name, task, in_event_thread, priority));
259 266
    }
260 267

  
261 268
    public void addShutdownTask(String name, Runnable task, boolean in_event_thread, int priority) {
262
        this.onShutdownTasks.add( new Task("shutdown",name, task, in_event_thread, priority));
269
        this.shutdownTasks.add(new Task("shutdown", name, task, in_event_thread, priority));
263 270
    }
264 271

  
265 272
    public void executeStartupTasks() {
......
268 275
            public void run() {
269 276
                try {
270 277
                    Thread.sleep(1000);
271
                } catch (Exception exc) { 
278
                } catch (Exception exc) {
272 279
                    // Ignore error
273 280
                }
274
                Collections.sort(onStartupTasks);
275
                for( int i=onStartupTasks.size()-1; i>=0; i--) {
276
                    Task task = onStartupTasks.get(i);
281
                Collections.sort(startupTasks);
282
                for ( int i = startupTasks.size() - 1; i >= 0; i-- ) {
283
                    Task task = startupTasks.get(i);
277 284
                    task.run();
278 285
                }
279 286
            }
280 287
        });
281 288
        th.start();
282 289
    }
283
    
290

  
284 291
    public void executeShutdownTasks() {
285 292
        logger.info("Executing shutdown tasks.");
286
        Collections.sort(onShutdownTasks);
287
        for( int i=onShutdownTasks.size()-1; i>=0; i--) {
288
            Task task = onShutdownTasks.get(i);
293
        Collections.sort(shutdownTasks);
294
        for ( int i = shutdownTasks.size() - 1; i >= 0; i-- ) {
295
            Task task = shutdownTasks.get(i);
289 296
            task.run();
290 297
        }
291 298
    }
292
    
299

  
293 300
    public File getApplicationI18nFolder() {
294
        return new File(this.getApplicationFolder(),"i18n");
301
        return new File(this.getApplicationFolder(), "i18n");
295 302
    }
296 303

  
304
    public Locale getCurrentLocale() {
305
        return org.gvsig.i18n.Messages.getCurrentLocale();
306
    }
307

  
308
    public void setCurrentLocale(final Locale locale) {
309
        org.gvsig.i18n.Messages.setCurrentLocale(locale);
310

  
311
        AndamiConfig config = Launcher.getAndamiConfig();
312
        config.setLocaleLanguage(locale.getLanguage());
313
        config.setLocaleCountry(locale.getCountry());
314
        config.setLocaleVariant(locale.getVariant());
315

  
316
        if( !SwingUtilities.isEventDispatchThread() ) {
317
            try {
318
                SwingUtilities.invokeAndWait(new Runnable() {
319
                    public void run() {
320
                        try {
321
                            JComponent.setDefaultLocale(locale);
322
                        } catch (Exception ex) {
323
                            // Do nothing
324
                        }
325
                        MDIFrame.getInstance().setLocale(locale);
326
                    }
327
                });
328
            } catch (Exception ex) {
329
                // Ignore
330
            }
331
        }
332
    }
333

  
297 334
}
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/ui/theme/Theme.java
33 33
import java.util.Map;
34 34

  
35 35
import javax.swing.ImageIcon;
36
import javax.swing.UIManager;
36 37
import org.apache.commons.io.IOUtils;
37 38
import org.apache.commons.lang.text.StrSubstitutor;
39
import org.apache.commons.lang3.StringUtils;
38 40

  
39 41
import org.gvsig.andami.Launcher;
40 42
import org.gvsig.andami.PluginServices;
......
71 73
    private static final String PRIORITY = "priority";
72 74
    private static final String VALUE = "value";
73 75
    private static final String BACKGROUND_IMAGE = "BackgroundImage";
76
    private static final String BACKGROUND_COLOR = "BackgroundColor";
74 77
    private static final String WALLPAPER_TYPE = "WallpaperType";
75 78

  
76 79
    private static final String VERSION = "version";
......
90 93
    private ArrayList<String> fontpositionsY = new ArrayList<String>();
91 94

  
92 95
    private String name = null;
93
    private String backgroundimage;
96
    private String backgroundimage = null;
97
    private Color backgroundColor = null;
94 98
    private String wallpaperType = CENTERED;
95 99
    private int priority = 0;
96 100

  
......
101 105
    private StrSubstitutor strSubstitutor = null;
102 106

  
103 107
    public Theme() {
104

  
105 108
    }
106 109

  
107 110
    public Theme(Map vars) {
111
        this();
108 112
        this.strSubstitutor = new StrSubstitutor(vars);
109 113
    }
110 114

  
......
121 125
        FileInputStream fis = null;
122 126
        try {
123 127
            String encoding = XMLUtils.getEncoding(file, "UTF-8");
124
            
128

  
125 129
            fis = new FileInputStream(file);
126 130
            KXmlParser parser = new KXmlParser();
127 131
            parser.setInput(fis, encoding);
......
171 175
                                    if ( parser.getName().compareTo(BACKGROUND_IMAGE) == 0 ) {
172 176
                                        backgroundimage = fixPath(file, parser.getAttributeValue("", PATH));
173 177
                                        tag = parser.next();
178
                                    } else if ( parser.getName().compareTo(BACKGROUND_COLOR) == 0 ) {
179
                                        backgroundColor = parseColor(parser.getAttributeValue("", "color"));
180
                                        tag = parser.next();
174 181
                                    } else if ( parser.getName().compareTo(ICON) == 0 ) {
175 182
                                        icon = fixPath(file, parser.getAttributeValue("", PATH));
176 183
                                        tag = parser.next();
......
191 198
                            String s = parser.getAttributeValue("", VALUE);
192 199
                            try {
193 200
                                this.priority = Integer.parseInt(s);
194
                            } catch(Exception ex) {
201
                            } catch (Exception ex) {
195 202
                                this.priority = 0;
196 203
                            }
197 204
                            tag = parser.next();
......
291 298
        }
292 299
    }
293 300

  
301
    public Color getBackgroundColor() {
302
        if ( this.backgroundColor == null ) {
303
            this.backgroundColor = (Color) UIManager.get("Desktop.background");
304
        }
305
        return this.backgroundColor;
306
    }
307

  
294 308
    /**
295 309
     * Return the time of the splash images.
296 310
     *
......
368 382
        for ( int i = 0; i < colors.length; i++ ) {
369 383
            try {
370 384
                String s = fontColors.get(i);
371
                String[] rgb = s.split(",");
372
                colors[i] = new Color(Integer.valueOf(rgb[0]), Integer.valueOf(rgb[1]), Integer.valueOf(rgb[2]));
385
                colors[i] = parseColor(s);
373 386
            } catch (Exception e) {
374 387
                NotificationManager.addInfo(PluginServices.getText(this, "incorrect_color"), e);
375 388
            }
......
377 390
        return colors;
378 391
    }
379 392

  
393
    private Color parseColor(String s) {
394
        if ( StringUtils.isEmpty(s) ) {
395
            return null;
396
        }
397
        String[] rgb = s.split(",");
398
        Color color = new Color(Integer.valueOf(rgb[0]), Integer.valueOf(rgb[1]), Integer.valueOf(rgb[2]));
399
        return color;
400
    }
401

  
380 402
    private String expand(String value) {
381 403
        if ( this.strSubstitutor == null ) {
382 404
            return value;
383 405
        }
384 406
        return strSubstitutor.replace(value);
385 407
    }
386
    
408

  
387 409
    public int getPriority() {
388 410
        return this.priority;
389 411
    }
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/ui/mdiFrame/JToolBarToggleButton.java
10 10
 *
11 11
 * This program is distributed in the hope that it will be useful,
12 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14
 * GNU General Public License for more details.
15 15
 *
16 16
 * You should have received a copy of the GNU General Public License
17 17
 * along with this program; if not, write to the Free Software
18 18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
19
 * MA 02110-1301, USA.
20 20
 *
21 21
 * For any additional information, do not hesitate to contact us
22 22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
......
25 25

  
26 26
import javax.swing.Action;
27 27
import javax.swing.Icon;
28
import org.gvsig.andami.ui.mdiFrame.TranslatableButtonHelper.TranslatableButton;
28 29

  
29
public class JToolBarToggleButton extends javax.swing.JToggleButton implements EnableTextSupport{
30
	/**
31
	 * 
32
	 */
33
	public JToolBarToggleButton() {
34
		super();
35
		// TODO Auto-generated constructor stub
36
	}
37
	/**
38
	 * @param text
39
	 */
40
	public JToolBarToggleButton(String text) {
41
		super(text);
42
		// TODO Auto-generated constructor stub
43
	}
44
	/**
45
	 * @param text
46
	 * @param selected
47
	 */
48
	public JToolBarToggleButton(String text, boolean selected) {
49
		super(text, selected);
50
		// TODO Auto-generated constructor stub
51
	}
52
	/**
53
	 * @param text
54
	 * @param icon
55
	 */
56
	public JToolBarToggleButton(String text, Icon icon) {
57
		super(text, icon);
58
		// TODO Auto-generated constructor stub
59
	}
60
	/**
61
	 * @param text
62
	 * @param icon
63
	 * @param selected
64
	 */
65
	public JToolBarToggleButton(String text, Icon icon, boolean selected) {
66
		super(text, icon, selected);
67
		// TODO Auto-generated constructor stub
68
	}
69
	/**
70
	 * @param a
71
	 */
72
	public JToolBarToggleButton(Action a) {
73
		super(a);
74
		// TODO Auto-generated constructor stub
75
	}
76
	/**
77
	 * @param icon
78
	 */
79
	public JToolBarToggleButton(Icon icon) {
80
		super(icon);
81
		// TODO Auto-generated constructor stub
82
	}
83
	/**
84
	 * @param icon
85
	 * @param selected
86
	 */
87
	public JToolBarToggleButton(Icon icon, boolean selected) {
88
		super(icon, selected);
89
		// TODO Auto-generated constructor stub
90
	}
91
	private String enableText;
92
	private String toolTip;
93
	
94
	
95
	/**
96
	 * @return Returns the enableText.
97
	 */
98
	public String getEnableText() {
99
		return enableText;
100
	}
101
	/**
102
	 * @param enableText The enableText to set.
103
	 */
104
	public void setEnableText(String enableText) {
105
		this.enableText = enableText;
106
	}
107
	
108
	
109
	/**
110
	 * @see java.awt.Component#setVisible(boolean)
111
	 */
112
	public void setEnabled(boolean aFlag) {
113
		super.setEnabled(aFlag);
114
		if (aFlag){
115
			setToolTipText(toolTip);
116
		}else{
117
			setToolTipText(enableText);
118
		}
119
	}
120
	/**
121
	 * @see javax.swing.JComponent#setToolTipText(java.lang.String)
122
	 */
123
	public void setToolTip(String text) {
124
		toolTip = text;
125
	}
30
public class JToolBarToggleButton extends javax.swing.JToggleButton implements EnableTextSupport, TranslatableButton {
31

  
32
    private TranslatableButtonHelper i18nHelper = new TranslatableButtonHelper();
33
    private String enableText;
34
    private String toolTip;
35

  
36
    public JToolBarToggleButton() {
37
        super();
38
    }
39

  
40
    public JToolBarToggleButton(String text) {
41
        super(text);
42
    }
43

  
44
    public JToolBarToggleButton(String text, boolean selected) {
45
        super(text, selected);
46
    }
47

  
48
    public JToolBarToggleButton(String text, Icon icon) {
49
        super(text, icon);
50
    }
51

  
52
    public JToolBarToggleButton(String text, Icon icon, boolean selected) {
53
        super(text, icon, selected);
54
    }
55

  
56
    public JToolBarToggleButton(Action a) {
57
        super(a);
58
    }
59

  
60
    public JToolBarToggleButton(Icon icon) {
61
        super(icon);
62
    }
63

  
64
    public JToolBarToggleButton(Icon icon, boolean selected) {
65
        super(icon, selected);
66
    }
67

  
68
    /**
69
     * @return Returns the enableText.
70
     */
71
    public String getEnableText() {
72
        return enableText;
73
    }
74

  
75
    /**
76
     * @param enableText The enableText to set.
77
     */
78
    public void setEnableText(String enableText) {
79
        this.enableText = enableText;
80
    }
81

  
82
    public void setEnabled(boolean aFlag) {
83
        super.setEnabled(aFlag);
84
        if ( aFlag ) {
85
            setToolTipText(toolTip);
86
        } else {
87
            setToolTipText(enableText);
88
        }
89
    }
90

  
91
    public void setToolTip(String text) {
92
        toolTip = text;
93
    }
94

  
95
    public void setToolTipKey(String key) {
96
        this.i18nHelper.setTooltip(key);
97
    }
98

  
99
    public void setTextKey(String key) {
100
        this.i18nHelper.setText(key);
101
    }
102

  
103
    public void translate() {
104
        if ( this.i18nHelper.needTranslation() ) {
105
            this.i18nHelper.translate();
106
            this.setText(this.i18nHelper.getText());
107
            this.setToolTip(this.i18nHelper.getTooltip());
108
        }
109
    }
110

  
126 111
}
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/ui/mdiFrame/MDIFrame.java
10 10
 *
11 11
 * This program is distributed in the hope that it will be useful,
12 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14
 * GNU General Public License for more details.
15 15
 *
16 16
 * You should have received a copy of the GNU General Public License
17 17
 * along with this program; if not, write to the Free Software
18 18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
19
 * MA 02110-1301, USA.
20 20
 *
21 21
 * For any additional information, do not hesitate to contact us
22 22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
......
44 44
import java.util.HashMap;
45 45
import java.util.Iterator;
46 46
import java.util.List;
47
import java.util.Locale;
47 48
import java.util.Map;
48
import java.util.Map.Entry;
49 49
import java.util.NoSuchElementException;
50 50
import java.util.StringTokenizer;
51 51
import java.util.Vector;
......
53 53
import javax.swing.AbstractButton;
54 54
import javax.swing.ButtonGroup;
55 55
import javax.swing.ImageIcon;
56
import javax.swing.JButton;
57 56
import javax.swing.JComponent;
58 57
import javax.swing.JFileChooser;
59 58
import javax.swing.JFrame;
......
73 72

  
74 73
import org.gvsig.andami.IconThemeHelper;
75 74
import org.gvsig.andami.Launcher;
76
import org.gvsig.andami.LibraryExtension;
77 75
import org.gvsig.andami.PluginServices;
78 76
import org.gvsig.andami.PluginsLocator;
79 77
import org.gvsig.andami.actioninfo.ActionInfo;
......
90 88
import org.gvsig.andami.plugins.config.generate.SelectableTool;
91 89
import org.gvsig.andami.plugins.config.generate.SkinExtensionType;
92 90
import org.gvsig.andami.plugins.config.generate.ToolBar;
91
import org.gvsig.andami.ui.mdiFrame.TranslatableButtonHelper.TranslatableButton;
93 92
import org.gvsig.andami.ui.mdiManager.MDIManager;
94 93
import org.gvsig.andami.ui.mdiManager.MDIManagerFactory;
95 94
import org.gvsig.gui.beans.controls.IControl;
......
102 101

  
103 102
/**
104 103
 * Main application window.
105
 * 
104
 *
105
 * Use Launcher.getMDIFrame to get the instance of this class.
106
 *
106 107
 * @version $Revision: 39484 $
107 108
 */
108 109
@SuppressWarnings("unchecked")
109 110
public class MDIFrame extends JFrame implements ComponentListener,
110
    ContainerListener, ActionListener, MainFrame {
111
        ContainerListener, ActionListener, MainFrame {
111 112

  
112 113
    private static final long serialVersionUID = -2472484309160847654L;
113 114

  
114 115
    private static Logger logger = LoggerFactory.getLogger(MDIFrame.class);
116

  
117
    private static MDIFrame instance = null;
118

  
115 119
    private MDIManager mdiManager = MDIManagerFactory.createManager();
116 120

  
117
    /** Elementos de la aplicaci�n */
121
    /**
122
     * Elementos de la aplicaci�n
123
     */
118 124
    private JMenuBar menuBar = new JMenuBar();
119 125

  
120
    /** Panel which contains the toolbars */
126
    /**
127
     * Panel which contains the toolbars
128
     */
121 129
    private JPanel toolBars = new JPanel();
122 130

  
123
    /** Status bar */
131
    /**
132
     * Status bar
133
     */
124 134
    private NewStatusBar bEstado = null;
125 135

  
126
    /** Asocia los nombres con las barras de herramientas */
136
    /**
137
     * Asocia los nombres con las barras de herramientas
138
     */
127 139
    private HashMap toolBarMap = new HashMap();
128 140

  
129
    /** Almacena los grupos de selectableTools */
141
    /**
142
     * Almacena los grupos de selectableTools
143
     */
130 144
    private HashMap buttonGroupMap = new HashMap();
131 145
    /**
132 146
     * Stores the initially selected tools.
......
142 156
    // this should be the same value defined at plugin-config.xsd
143 157
    private String defaultGroup = "unico";
144 158

  
145
    /** Asocia los nombres con los popupMenus */
159
    /**
160
     * Asocia los nombres con los popupMenus
161
     */
146 162
    private HashMap popupMap = new HashMap();
147 163

  
148
    /** Asocia controles con la clase de la extension asociada */
149
    private HashMap controlClass = new HashMap();
164
    /**
165
     * Asocia controles con la clase de la extension asociada
166
     */
167
    private List<JComponent> controls = new ArrayList<JComponent>();
150 168

  
151 169
    /**
152 170
     * Asocia la informaci�n sobre las etiquetas que van en la status bar con
......
155 173
    private HashMap classLabels = new HashMap();
156 174

  
157 175
    // private HashMap classControls = new HashMap();
158

  
159
    /** ProgressListeners (ver interfaz com.iver.mdiApp.ui.ProgressListener) */
176
    /**
177
     * ProgressListeners (ver interfaz com.iver.mdiApp.ui.ProgressListener)
178
     */
160 179
    private ArrayList progressListeners = new ArrayList();
161 180

  
162
    /** Timer para invocar los enventos de la interfaz anterior */
163
	private Timer progressTimer = null;
181
    /**
182
     * Timer para invocar los enventos de la interfaz anterior
183
     */
184
    private Timer progressTimer = null;
164 185

  
165
    /** Tabla hash que asocia las clases con las extensiones */
166
    private Map classesExtensions = new HashMap<Class<? extends IExtension>, ExtensionDecorator>();
167

  
168
    /** �ltima clase que activ� etiquetas */
186
    /**
187
     * Tabla hash que asocia las clases con las extensiones
188
     */
189
    // private Map classesExtensions = new HashMap<Class<? extends IExtension>, ExtensionDecorator>();
190
    /**
191
     * �ltima clase que activ� etiquetas
192
     */
169 193
    private Class lastLabelClass;
170 194

  
171
    /** Instancia que pone los tooltip en la barra de estado */
195
    /**
196
     * Instancia que pone los tooltip en la barra de estado
197
     */
172 198
    private TooltipListener tooltipListener = new TooltipListener();
173
    
174
	private HashMap infoCodedMenus = new HashMap();
175 199

  
200
    private HashMap infoCodedMenus = new HashMap();
201

  
176 202
    private String titlePrefix;
177 203

  
178 204
    private static final String noIcon = "no-icon";
179 205

  
206
    private MDIFrame() {
207

  
208
    }
209

  
210
    public static MDIFrame getInstance() {
211
        if ( instance == null ) {
212
            instance = new MDIFrame();
213
        }
214
        return instance;
215
    }
216

  
180 217
    /**
181 218
     * Makes some initialization tasks.
182
     * 
219
     *
183 220
     * @throws RuntimeException
184
     *             DOCUMENT ME!
185 221
     */
186 222
    public void init() {
187
    	JPopupMenu.setDefaultLightWeightPopupEnabled(false);
188
        if (!SwingUtilities.isEventDispatchThread()) {
223
        JPopupMenu.setDefaultLightWeightPopupEnabled(false);
224
        if ( !SwingUtilities.isEventDispatchThread() ) {
189 225
            throw new RuntimeException("Not Event Dispatch Thread");
190 226
        }
191 227

  
192
        // Se aaden los listeners del JFrame
228
        // Se a?aden los listeners del JFrame
193 229
        this.addWindowListener(new WindowAdapter() {
194 230

  
195 231
            @Override
......
207 243
        this.getContentPane().setLayout(new BorderLayout());
208 244

  
209 245
        /*
210
         * Se configura y se aade el JPanel de las barras de
246
         * Se configura y se a?ade el JPanel de las barras de
211 247
         * herramientas
212 248
         */
213 249
        FlowLayout layout = new FlowLayout(FlowLayout.LEFT);
......
216 252
        toolBars.setLayout(layout);
217 253
        getContentPane().add(toolBars, BorderLayout.PAGE_START);
218 254

  
219
        // Se a�ade la barra de estado a la aplicaci�n
255
        // Add the status bar of the application
220 256
        bEstado = new NewStatusBar();
221 257
        bEstado.message(Messages.getString("StatusBar.Aplicacion_iniciada"), JOptionPane.INFORMATION_MESSAGE);
222 258
        getContentPane().add(bEstado, BorderLayout.SOUTH);
......
229 265
         * afterwards
230 266
         */
231 267
        setSize(
232
            MainFrame.MAIN_FRAME_SIZE_DEFAULT[0],
233
            MainFrame.MAIN_FRAME_SIZE_DEFAULT[1]);
268
                MainFrame.MAIN_FRAME_SIZE_DEFAULT[0],
269
                MainFrame.MAIN_FRAME_SIZE_DEFAULT[1]);
234 270
        setLocation(
235
            MainFrame.MAIN_FRAME_POS_DEFAULT[0],
236
            MainFrame.MAIN_FRAME_POS_DEFAULT[1]);
271
                MainFrame.MAIN_FRAME_POS_DEFAULT[0],
272
                MainFrame.MAIN_FRAME_POS_DEFAULT[1]);
237 273
        setExtendedState(
238
            MainFrame.MAIN_FRAME_EXT_STATE_DEFAULT);
274
                MainFrame.MAIN_FRAME_EXT_STATE_DEFAULT);
239 275

  
240 276
        mdiManager.init(this);
241
        
242
        /*
243
         * pack() would resize the main frame
244
         * 
245
         */
246
        // pack();
247

  
248 277
    }
249
    
250
    
251 278

  
252
    /*
253
     * (non-javadoc)
254
     * 
255
     * @see java.awt.Frame.setTitle(String title)
256
     */
257 279
    @Override
258 280
    public void setTitle(final String title) {
259
        if (!SwingUtilities.isEventDispatchThread()) {
281
        if ( !SwingUtilities.isEventDispatchThread() ) {
260 282
            SwingUtilities.invokeLater(new Runnable() {
261 283
                public void run() {
262
                	setTitle(title);
284
                    setTitle(title);
263 285
                }
264 286
            });
265 287
            return;
......
267 289
        super.setTitle(titlePrefix + " : " + title);
268 290
    }
269 291

  
270
    /**
271
     * A�ade un modo de operaci�n a la caja de herramientas
272
     * 
273
     * @param ext
274
     *            Texto del boton, si es null no aparece texto
275
     * @param ext
276
     *            Icono del boton, si es null no aparece icono
277
     * @param ext
278
     *            Extensi�n asociada al control
279
     * @param selectableTool
280
     *            Enable text del control
281
     * 
282
     * @throws ClassNotFoundException
283
     * @throws RuntimeException
284
     *             DOCUMENT ME!
285
     */
286
    public void addTool(PluginClassLoader loader, SkinExtensionType ext,
287
        ToolBar toolBar, SelectableTool selectableTool)
288
        throws ClassNotFoundException {
289
        if (!SwingUtilities.isEventDispatchThread()) {
290
            throw new RuntimeException("No Event Dispatch Thread");
292
    public void addTool(final PluginClassLoader loader, final SkinExtensionType ext,
293
            final ToolBar toolBar, final SelectableTool selectableTool)
294
            throws ClassNotFoundException {
295
        if ( !SwingUtilities.isEventDispatchThread() ) {
296
            try {
297
                SwingUtilities.invokeAndWait(new Runnable() {
298
                    public void run() {
299
                        try {
300
                            addTool(loader, ext, toolBar, selectableTool);
301
                        } catch (ClassNotFoundException ex) {
302
                            logger.warn("??? Eehh????", ex);
303
                        }
304
                    }
305
                });
306
            } catch (Exception ex) {
307
                // Do nothing
308
            }
309
            return;
291 310
        }
292
        
293
        Class<? extends IExtension> classExtension = (Class<? extends IExtension>) loader.loadClass(ext.getClassName());
294
        
295
        // Para traducir
296
        PluginServices ps =
297
            PluginServices.getPluginServices(loader.getPluginName());
311
        I18nManager i18nManager = ToolsLocator.getI18nManager();
298 312

  
299 313
        JToolBarToggleButton btn;
300
        ImageIcon image =
301
            PluginServices.getIconTheme().get(selectableTool.getIcon());
314
        ImageIcon image
315
                = PluginServices.getIconTheme().get(selectableTool.getIcon());
302 316

  
303
        if (image != null) {
317
        if ( image != null ) {
304 318
            btn = new JToolBarToggleButton(selectableTool.getText(), image);
305 319
        } else {
306
            logger.error(PluginServices.getText(this, "Unable_to_find_icon")
307
                + ": " + selectableTool.getIcon());
308
            btn =
309
                new JToolBarToggleButton(selectableTool.getText(),
310
                    PluginServices.getIconTheme().get(noIcon));
320
            logger.warn("Unable to find icon '" + selectableTool.getIcon() + "'.");
321
            btn
322
                    = new JToolBarToggleButton(selectableTool.getText(),
323
                            PluginServices.getIconTheme().get(noIcon));
311 324
        }
312 325

  
313
        org.gvsig.andami.ui.mdiFrame.ToggleButtonModel buttonModel =
314
            new org.gvsig.andami.ui.mdiFrame.ToggleButtonModel();
326
        org.gvsig.andami.ui.mdiFrame.ToggleButtonModel buttonModel
327
                = new org.gvsig.andami.ui.mdiFrame.ToggleButtonModel();
315 328
        btn.setModel(buttonModel);
316 329
        btn.setMargin(new Insets(0, 0, 0, 0));
317 330
        btn.addMouseListener(tooltipListener);
......
325 338

  
326 339
        SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(name);
327 340

  
328
        if (jtb == null) {
341
        if ( jtb == null ) {
329 342
            jtb = new SelectableToolBar(name);
330 343
            jtb.setRollover(true);
331 344
            jtb.setAndamiVisibility(toolBar.getIsVisible());
......
334 347
        }
335 348

  
336 349
        ButtonGroup group;
337
        if (buttonGroupMap.containsKey(selectableTool.getGroup())) {
350
        if ( buttonGroupMap.containsKey(selectableTool.getGroup()) ) {
338 351
            group = (ButtonGroup) buttonGroupMap.get(selectableTool.getGroup());
339 352
        } else {
340 353
            group = new ButtonGroup();
......
344 357
        jtb.addButton(group, btn);
345 358
        buttonModel.setGroupName(selectableTool.getGroup());
346 359

  
347
        if (selectableTool.getIsDefault()) {
360
        if ( selectableTool.getIsDefault() ) {
348 361
            btn.setSelected(true);
349 362
            initialSelectedTools.put(selectableTool.getGroup(),
350
                btn.getActionCommand());
363
                    btn.getActionCommand());
351 364
        }
352 365

  
353
        controlClass.put(btn, classExtension);
366
        addControl(btn);
354 367

  
355
        if (selectableTool.getName() != null) {
368
        if ( selectableTool.getName() != null ) {
356 369
            btn.setName(selectableTool.getName());
357 370
        }
358 371

  
359
        if (selectableTool.getTooltip() != null) {
360
            btn.setToolTip(ps.getText(selectableTool.getTooltip()));
372
        if ( selectableTool.getTooltip() != null ) {
373
            btn.setToolTip(i18nManager.getTranslation(selectableTool.getTooltip()));
374
            btn.setToolTipKey(selectableTool.getTooltip());
361 375
        }
362 376

  
363
        if (selectableTool.getEnableText() != null) {
364
            btn.setEnableText(ps.getText(selectableTool.getEnableText()));
377
        if ( selectableTool.getEnableText() != null ) {
378
            btn.setEnableText(i18nManager.getTranslation(selectableTool.getEnableText()));
365 379
        }
366 380

  
367
        if (selectableTool.getLast() == true) {
381
        if ( selectableTool.getLast() == true ) {
368 382
            jtb.addSeparator();
369 383
        }
370 384
    }
371 385

  
372 386
    /**
373
     * A�ade un bot�n a la barra de herramientas
374
     * 
387
     * Add a button to the toolbar.
388
     *
375 389
     * @param ext
376
     *            Texto del boton, si es null no aparece texto
390
     * Texto del boton, si es null no aparece texto
377 391
     * @param ext
378
     *            Extensi�n asociada al control
392
     * Extension asociada al control
379 393
     * @param toolBar
380
     *            Icono del boton, si es null no aparece texto
394
     * Icono del boton, si es null no aparece texto
381 395
     * @param actionTool
382
     *            Tooltip de la barra de herramientas
383
     * 
396
     * Tooltip de la barra de herramientas
397
     *
384 398
     * @throws ClassNotFoundException
385 399
     * @throws RuntimeException
386
     *             DOCUMENT ME!
387 400
     */
388
    public void addTool(PluginClassLoader loader, SkinExtensionType ext,
389
        ToolBar toolBar, ActionTool actionTool) throws ClassNotFoundException {
390
        if (!SwingUtilities.isEventDispatchThread()) {
391
            throw new RuntimeException("No Event Dispatch Thread");
401
    public void addTool(final PluginClassLoader loader, final SkinExtensionType ext,
402
            final ToolBar toolBar, final ActionTool actionTool) throws ClassNotFoundException {
403
        if ( !SwingUtilities.isEventDispatchThread() ) {
404
            try {
405
                SwingUtilities.invokeAndWait(new Runnable() {
406
                    public void run() {
407
                        try {
408
                            addTool(loader, ext, toolBar, actionTool);
409
                        } catch (ClassNotFoundException ex) {
410
                            logger.warn("??? Eehh????", ex);
411
                        }
412
                    }
413
                });
414
            } catch (Exception ex) {
415
                // Do nothing
416
            }
417
            return;
392 418
        }
393
        Class<? extends IExtension> classExtension = (Class<? extends IExtension>) loader.loadClass(ext.getClassName());
394
        
395
        // Para traducir los textos que vengan
396
        PluginServices ps =
397
            PluginServices.getPluginServices(loader.getPluginName());
398 419

  
420
        I18nManager i18nManager = ToolsLocator.getI18nManager();
421

  
399 422
        JToolBarButton btn;
400 423
        ImageIcon image = IconThemeHelper.getImageIcon(actionTool.getIcon());
401 424

  
402
        if (image != null) {
425
        if ( image != null ) {
403 426
            btn = new JToolBarButton(actionTool.getText(), image);
404 427
        } else {
405
            logger.error(PluginServices.getText(this, "Unable_to_find_icon")
406
                + ": " + actionTool.getIcon());
407
            btn =
408
                new JToolBarButton(actionTool.getText(), PluginServices
409
                    .getIconTheme().get(noIcon));
428
            logger.warn("Unable to find icon '" + actionTool.getIcon() + "'.");
429
            btn
430
                    = new JToolBarButton(actionTool.getText(), PluginServices
431
                            .getIconTheme().get(noIcon));
410 432
        }
411 433

  
412 434
        btn.setMargin(new Insets(0, 0, 0, 0));
......
421 443

  
422 444
        SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(name);
423 445

  
424
        if (jtb == null) {
446
        if ( jtb == null ) {
425 447
            jtb = new SelectableToolBar(name);
426 448
            jtb.setRollover(true);
427 449
            jtb.setAndamiVisibility(toolBar.getIsVisible());
......
431 453

  
432 454
        jtb.add(btn);
433 455

  
434
        controlClass.put(btn, classExtension);
456
        addControl(btn);
435 457

  
436
        if (actionTool.getName() != null) {
458
        if ( actionTool.getName() != null ) {
437 459
            btn.setName(actionTool.getName());
438 460
        }
439 461

  
440
        if (actionTool.getTooltip() != null) {
441
            btn.setToolTip(ps.getText(actionTool.getTooltip()));
462
        if ( actionTool.getTooltip() != null ) {
463
            btn.setToolTip(i18nManager.getTranslation(actionTool.getTooltip()));
464
            btn.setToolTipKey(actionTool.getTooltip());
442 465
        }
443 466

  
444
        if (actionTool.getEnableText() != null) {
445
            btn.setEnableText(ps.getText(actionTool.getEnableText()));
467
        if ( actionTool.getEnableText() != null ) {
468
            btn.setEnableText(i18nManager.getTranslation(actionTool.getEnableText()));
446 469
        }
447 470

  
448
        if (actionTool.getLast() == true) {
471
        if ( actionTool.getLast() == true ) {
449 472
            jtb.addSeparator();
450 473
        }
451 474
    }
452 475

  
453
	public void addTool(final ActionInfo action, final String toolBarName) {
454
		I18nManager i18nManager = ToolsLocator.getI18nManager();
476
    public void addTool(final ActionInfo action, final String toolBarName) {
477
        I18nManager i18nManager = ToolsLocator.getI18nManager();
455 478

  
456
		if (!SwingUtilities.isEventDispatchThread()) {
457
			SwingUtilities.invokeLater(new Runnable() {
458
				public void run() {
459
					addTool(action, toolBarName);
460
				}
461
			});
462
			return;
463
		}
464
		JToolBarButton btn = new JToolBarButton(action.getIcon());
465
		btn.setMargin(new Insets(0, 0, 0, 0));
466
		btn.addMouseListener(tooltipListener);
467
		btn.addActionListener(this);
468
		btn.setFocusable(false);
469
		btn.setActionCommand(action.getCommand());
470
		btn.setEnabled(false);
471
		btn.setVisible(false);
472
		btn.setName(action.getName());
473
		if (action.getTooltip() != null) {
474
			btn.setToolTip(i18nManager.getTranslation(action.getTooltip()));
475
		}
479
        if ( !SwingUtilities.isEventDispatchThread() ) {
480
            SwingUtilities.invokeLater(new Runnable() {
481
                public void run() {
482
                    addTool(action, toolBarName);
483
                }
484
            });
485
            return;
486
        }
487
        JToolBarButton btn = new JToolBarButton(action.getIcon());
488
        btn.setMargin(new Insets(0, 0, 0, 0));
489
        btn.addMouseListener(tooltipListener);
490
        btn.addActionListener(this);
491
        btn.setFocusable(false);
492
        btn.setActionCommand(action.getCommand());
493
        btn.setEnabled(false);
494
        btn.setVisible(false);
495
        btn.setName(action.getName());
496
        if ( action.getTooltip() != null ) {
497
            btn.setToolTip(i18nManager.getTranslation(action.getTooltip()));
498
            btn.setToolTipKey(action.getTooltip());
499
        }
476 500

  
477
		SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(toolBarName);
478
		if (jtb == null) {
479
			jtb = new SelectableToolBar(toolBarName);
480
			jtb.setRollover(true);
481
			jtb.setAndamiVisibility(true);
482
			toolBarMap.put(toolBarName, jtb);
483
			toolBars.add(jtb);
484
		}
485
		jtb.add(btn);
501
        SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(toolBarName);
502
        if ( jtb == null ) {
503
            jtb = new SelectableToolBar(toolBarName);
504
            jtb.setRollover(true);
505
            jtb.setAndamiVisibility(true);
506
            toolBarMap.put(toolBarName, jtb);
507
            toolBars.add(jtb);
508
        }
509
        jtb.add(btn);
486 510

  
487
		controlClass.put(btn, action.getExtension().getClass());
488
	}
511
        addControl(btn);
489 512

  
513
    }
514

  
490 515
    /**
491 516
     * Creates the needed menu structure to add the menu to the bar.
492 517
     * Returns the father which must hold the menu which was
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff