Changeset 293 in josm


Ignore:
Timestamp:
Jul 20, 2007 4:35:06 PM (6 years ago)
Author:
imi
Message:
  • changed the order which directories are searched for images (~/.josm/images goes first)
  • made the crosshair cursor configurable
Location:
src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/Main.java

    r290 r293  
    238238                jarUrls = allPluginLibraries.toArray(jarUrls); 
    239239                URLClassLoader pluginClassLoader = new URLClassLoader(jarUrls, Main.class.getClassLoader()); 
     240                ImageProvider.sources.add(0, pluginClassLoader); 
    240241 
    241242                for (Collection<PluginInformation> c : p.values()) { 
     
    243244                                try { 
    244245                                        Class<?> klass = info.loadClass(pluginClassLoader); 
    245                                         ImageProvider.sources.add(0, klass); 
    246                                         System.out.println("loading "+info.name); 
    247                                         Main.plugins.add(info.load(klass)); 
     246                                        if (klass != null) { 
     247                                                System.out.println("loading "+info.name); 
     248                                                Main.plugins.add(info.load(klass)); 
     249                                        } 
    248250                                } catch (PluginException e) { 
    249251                                        e.printStackTrace(); 
  • src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java

    r283 r293  
    2525import org.openstreetmap.josm.data.osm.Way; 
    2626import org.openstreetmap.josm.gui.MapFrame; 
     27import org.openstreetmap.josm.tools.ImageProvider; 
    2728 
    2829/** 
     
    5354 
    5455        public AddNodeAction(MapFrame mapFrame, String name, Mode mode, String desc) { 
    55                 super(name, "node/"+mode, desc, mapFrame, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); 
     56                super(name, "node/"+mode, desc, mapFrame, getCursor()); 
    5657                this.mode = mode; 
    5758                putValue("help", "Action/AddNode/"+Character.toUpperCase(mode.toString().charAt(0))+mode.toString().substring(1)); 
    5859        } 
     60 
     61        private static Cursor getCursor() { 
     62                try { 
     63                return ImageProvider.getCursor("crosshair", null); 
     64        } catch (Exception e) { 
     65        } 
     66            return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); 
     67    } 
    5968 
    6069        @Override public void enterMode() { 
  • src/org/openstreetmap/josm/plugins/PluginInformation.java

    r292 r293  
    11package org.openstreetmap.josm.plugins; 
     2 
     3import static org.openstreetmap.josm.tools.I18n.tr; 
    24 
    35import java.io.File; 
     
    810import java.util.ArrayList; 
    911import java.util.Collection; 
     12import java.util.LinkedList; 
    1013import java.util.List; 
    1114import java.util.Map; 
     
    3336        public final int stage; 
    3437        public final String version; 
    35         public final List<URL> libraries = new ArrayList<URL>(); 
     38        public final List<URL> libraries = new LinkedList<URL>(); 
    3639 
    3740        public final Map<String, String> attr = new TreeMap<String, String>(); 
     
    5255                this(file, file.getName().substring(0, file.getName().length()-4), null); 
    5356        } 
    54          
     57 
    5558        public PluginInformation(File file, String name, InputStream manifestStream) { 
    5659                this.name = name; 
     
    6871                        manifest.read(manifestStream); 
    6972                        } 
    70                         Attributes attr = manifest.getMainAttributes(); 
    71                         className = attr.getValue("Plugin-Class"); 
    72                         description = attr.getValue("Plugin-Description"); 
    73                         early = Boolean.parseBoolean(attr.getValue("Plugin-Early")); 
    74                         String stageStr = attr.getValue("Plugin-Stage"); 
    75                         stage = stageStr == null ? 50 : Integer.parseInt(stageStr); 
    76                         version = attr.getValue("Plugin-Version"); 
    77                         author = attr.getValue("Author"); 
     73                        if (manifest != null) { 
     74                                Attributes attr = manifest.getMainAttributes(); 
     75                                className = attr.getValue("Plugin-Class"); 
     76                                description = attr.getValue("Plugin-Description"); 
     77                                early = Boolean.parseBoolean(attr.getValue("Plugin-Early")); 
     78                                String stageStr = attr.getValue("Plugin-Stage"); 
     79                                stage = stageStr == null ? 50 : Integer.parseInt(stageStr); 
     80                                version = attr.getValue("Plugin-Version"); 
     81                                author = attr.getValue("Author"); 
     82 
     83                                String classPath = attr.getValue(Attributes.Name.CLASS_PATH); 
     84                                if (classPath != null) { 
     85                                        String[] cp = classPath.split(" "); 
     86                                        StringBuilder entry = new StringBuilder(); 
     87                                        for (String s : cp) { 
     88                                                entry.append(s); 
     89                                                if (s.endsWith("\\")) { 
     90                                                        entry.setLength(entry.length()-1); 
     91                                                        entry.append("%20"); // append the split character " " as html-encode 
     92                                                        continue; 
     93                                                } 
     94                                                s = entry.toString(); 
     95                                                entry = new StringBuilder(); 
     96                                                if (!s.startsWith("/") && !s.startsWith("\\") && !s.matches("^.\\:") && file != null) 
     97                                                        s = file.getParent() + File.separator + s; 
     98                                                libraries.add(new URL(getURLString(s))); 
     99                                        } 
     100                                } 
     101                                for (Object o : attr.keySet()) 
     102                                        this.attr.put(o.toString(), attr.getValue(o.toString())); 
     103                        } else { 
     104                                // resource-only plugin 
     105                                className = null; 
     106                                description = tr("unknown"); 
     107                                early = false; 
     108                                stage = 50; 
     109                                version = null; 
     110                                author = null; 
     111                        } 
    78112                        if (file != null) 
    79                                 libraries.add(new URL(getURLString(file.getAbsolutePath()))); 
    80                         String classPath = attr.getValue(Attributes.Name.CLASS_PATH); 
    81                         if (classPath != null) { 
    82                                 String[] cp = classPath.split(" "); 
    83                                 StringBuilder entry = new StringBuilder(); 
    84                                 for (String s : cp) { 
    85                                         entry.append(s); 
    86                                         if (s.endsWith("\\")) { 
    87                                                 entry.setLength(entry.length()-1); 
    88                                                 entry.append("%20"); // append the split character " " as html-encode 
    89                                                 continue; 
    90                                         } 
    91                                         s = entry.toString(); 
    92                                         entry = new StringBuilder(); 
    93                                         if (!s.startsWith("/") && !s.startsWith("\\") && !s.matches("^.\\:") && file != null) 
    94                                                 s = file.getParent() + File.separator + s; 
    95                                         libraries.add(new URL(getURLString(s))); 
    96                                 } 
    97                         } 
    98  
    99                         for (Object o : attr.keySet()) 
    100                                 this.attr.put(o.toString(), attr.getValue(o.toString())); 
     113                                libraries.add(0, new URL(getURLString(file.getAbsolutePath()))); 
     114 
    101115                        if (jar != null) 
    102116                                jar.close(); 
     
    122136         */ 
    123137        public Class<?> loadClass(ClassLoader classLoader) { 
     138                if (className == null) 
     139                        return null; 
    124140                try { 
    125141                        Class<?> realClass = Class.forName(className, true, classLoader); 
  • src/org/openstreetmap/josm/tools/ImageProvider.java

    r257 r293  
    4444         * Plugin's class loaders are added by main. 
    4545         */ 
    46         public static final List<Class<?>> sources = new LinkedList<Class<?>>(); 
     46        public static final List<ClassLoader> sources = new LinkedList<ClassLoader>(); 
    4747 
    4848        /** 
     
    8989        private static URL getImageUrl(String imageName) { 
    9090            URL path = null; 
    91             for (Class<?> source : sources) 
    92                         if ((path = source.getResource("/images/"+imageName)) != null) 
     91            // Try user-preference directory first 
     92        try { 
     93                if (new File(Main.pref.getPreferencesDir()+"images/"+imageName).exists()) 
     94                        return new URL("file", "", Main.pref.getPreferencesDir()+"images/"+imageName); 
     95        } catch (MalformedURLException e) { 
     96        } 
     97 
     98            // Try plugins and josm classloader 
     99            for (ClassLoader source : sources) 
     100                        if ((path = source.getResource("images/"+imageName)) != null) 
    93101                                return path; 
    94              
    95             // Try all ressource directories as well 
    96                 for (String location : Main.pref.getAllPossiblePreferenceDirs()) { 
    97                         try { 
    98                                 if (new File(location+"images/"+imageName).exists()) 
    99                                         return new URL("file", "", location+"images/"+imageName); 
    100             } catch (MalformedURLException e) { 
    101             } 
    102                 } 
     102 
     103            // Try all other ressource directories 
     104            for (String location : Main.pref.getAllPossiblePreferenceDirs()) { 
     105                try { 
     106                        if (new File(location+"images/"+imageName).exists()) 
     107                                return new URL("file", "", location+"images/"+imageName); 
     108                } catch (MalformedURLException e) { 
     109                } 
     110            } 
    103111            return null; 
    104112    } 
     
    112120 
    113121        public static Cursor getCursor(String name, String overlay) { 
    114                 ImageIcon img = overlay(get("cursor/"+name), "cursor/modifier/"+overlay, OverlayPosition.SOUTHEAST); 
     122                ImageIcon img = get("cursor",name); 
     123                if (overlay != null) 
     124                        img = overlay(img, "cursor/modifier/"+overlay, OverlayPosition.SOUTHEAST); 
    115125                Cursor c = Toolkit.getDefaultToolkit().createCustomCursor(img.getImage(), 
    116126                                name.equals("crosshair") ? new Point(10,10) : new Point(3,2), "Cursor"); 
     
    156166 
    157167        static { 
    158                 sources.add(Main.class); 
     168                sources.add(ClassLoader.getSystemClassLoader()); 
    159169        } 
    160170} 
Note: See TracChangeset for help on using the changeset viewer.