Changeset 159 in josm for src/org/openstreetmap/josm/tools


Ignore:
Timestamp:
2006-10-13T13:02:57+02:00 (19 years ago)
Author:
imi
Message:
  • moved translations into plugins
  • added main menu control to main
  • added ImageProvider access to plugins
Location:
src/org/openstreetmap/josm/tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/tools/I18n.java

    r158 r159  
    11package org.openstreetmap.josm.tools;
    22
    3 import java.io.File;
    4 import java.net.URL;
    5 import java.net.URLClassLoader;
    63import java.text.MessageFormat;
    7 import java.util.Locale;
    8 import java.util.MissingResourceException;
    9 
    10 import org.openstreetmap.josm.Main;
    11 import org.xnap.commons.i18n.I18nFactory;
    124
    135/**
     
    179 */
    1810public class I18n {
    19         private static org.xnap.commons.i18n.I18n i18n;
    20 
    21         static {
    22                 String localeFile = Main.pref.getPreferencesDir()+"lang/"+Locale.getDefault()+".jar";
    23                 Class<?> klass = Main.class;
    24                 if (new File(localeFile).exists()) {
    25                         try {
    26                                 String url = localeFile.replace('\\','/');
    27                                 if (System.getProperty("os.name").startsWith("Windows"))
    28                                         url = "file:/"+url;
    29                                 else
    30                                         url = "file://"+url;
    31                         URLClassLoader loader = new URLClassLoader(new URL[]{new URL(url)});
    32                         klass = Class.forName("org.openstreetmap.josm.Translation_"+Locale.getDefault(), true, loader);
    33                 } catch (Exception e) {
    34                         System.out.println("Couldn't load locale file "+localeFile);
    35                         e.printStackTrace();
    36                 }
    37                 }
    38                 try {
    39                         i18n = I18nFactory.getI18n(klass);
    40                 } catch (MissingResourceException e) {
    41                         System.out.println("Locale '"+Locale.getDefault()+"' not found. Using default.");
    42                 }
    43         }
     11        /**
     12         * Set by MainApplication. Changes here later will probably mess up everything, because
     13         * many strings are already loaded.
     14         */
     15        public static org.xnap.commons.i18n.I18n i18n;
    4416
    4517        public static String tr(String text, Object... objects) {
  • src/org/openstreetmap/josm/tools/ImageProvider.java

    r101 r159  
    1212import java.net.URL;
    1313import java.util.HashMap;
     14import java.util.LinkedList;
     15import java.util.List;
    1416import java.util.Map;
    1517
     
    3739
    3840        /**
     41         * Add here all ClassLoader whose ressource should be searched.
     42         * Plugin's class loaders are added by main.
     43         */
     44        public static final List<Class<?>> sources = new LinkedList<Class<?>>();
     45
     46        /**
    3947         * Return an image from the specified location.
    4048         *
     
    4755                        subdir += "/";
    4856                String ext = name.indexOf('.') != -1 ? "" : ".png";
    49                 URL path = Main.class.getResource("/images/"+subdir+name+ext);
     57                URL path = null;
     58                for (Class<?> source : sources) {
     59                        path = source.getResource("/images/"+subdir+name+ext);
     60                        if (path != null)
     61                                break;
     62                }
    5063                if (path == null)
    5164                        throw new NullPointerException("/images/"+subdir+name+ext+" not found");
     
    108121                return new ImageIcon(img);
    109122        }
     123
     124        static {
     125                sources.add(Main.class);
     126        }
    110127}
  • src/org/openstreetmap/josm/tools/UrlLabel.java

    r149 r159  
    2121                setContentType("text/html");
    2222                setText("<html><a href=\""+url+"\">"+description+"</a></html>");
     23                setToolTipText(url);
    2324                setEditable(false);
    2425                setOpaque(false);
Note: See TracChangeset for help on using the changeset viewer.