Changeset 293 in josm
- Timestamp:
- 2007-07-20T16:35:06+02:00 (17 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r290 r293 238 238 jarUrls = allPluginLibraries.toArray(jarUrls); 239 239 URLClassLoader pluginClassLoader = new URLClassLoader(jarUrls, Main.class.getClassLoader()); 240 ImageProvider.sources.add(0, pluginClassLoader); 240 241 241 242 for (Collection<PluginInformation> c : p.values()) { … … 243 244 try { 244 245 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 } 248 250 } catch (PluginException e) { 249 251 e.printStackTrace(); -
src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java
r283 r293 25 25 import org.openstreetmap.josm.data.osm.Way; 26 26 import org.openstreetmap.josm.gui.MapFrame; 27 import org.openstreetmap.josm.tools.ImageProvider; 27 28 28 29 /** … … 53 54 54 55 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()); 56 57 this.mode = mode; 57 58 putValue("help", "Action/AddNode/"+Character.toUpperCase(mode.toString().charAt(0))+mode.toString().substring(1)); 58 59 } 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 } 59 68 60 69 @Override public void enterMode() { -
src/org/openstreetmap/josm/plugins/PluginInformation.java
r292 r293 1 1 package org.openstreetmap.josm.plugins; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 2 4 3 5 import java.io.File; … … 8 10 import java.util.ArrayList; 9 11 import java.util.Collection; 12 import java.util.LinkedList; 10 13 import java.util.List; 11 14 import java.util.Map; … … 33 36 public final int stage; 34 37 public final String version; 35 public final List<URL> libraries = new ArrayList<URL>();38 public final List<URL> libraries = new LinkedList<URL>(); 36 39 37 40 public final Map<String, String> attr = new TreeMap<String, String>(); … … 52 55 this(file, file.getName().substring(0, file.getName().length()-4), null); 53 56 } 54 57 55 58 public PluginInformation(File file, String name, InputStream manifestStream) { 56 59 this.name = name; … … 68 71 manifest.read(manifestStream); 69 72 } 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 } 78 112 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 101 115 if (jar != null) 102 116 jar.close(); … … 122 136 */ 123 137 public Class<?> loadClass(ClassLoader classLoader) { 138 if (className == null) 139 return null; 124 140 try { 125 141 Class<?> realClass = Class.forName(className, true, classLoader); -
src/org/openstreetmap/josm/tools/ImageProvider.java
r257 r293 44 44 * Plugin's class loaders are added by main. 45 45 */ 46 public static final List<Class <?>> sources = new LinkedList<Class<?>>();46 public static final List<ClassLoader> sources = new LinkedList<ClassLoader>(); 47 47 48 48 /** … … 89 89 private static URL getImageUrl(String imageName) { 90 90 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) 93 101 return path; 94 95 // Try all ressource directories as well96 97 98 99 100 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 } 103 111 return null; 104 112 } … … 112 120 113 121 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); 115 125 Cursor c = Toolkit.getDefaultToolkit().createCustomCursor(img.getImage(), 116 126 name.equals("crosshair") ? new Point(10,10) : new Point(3,2), "Cursor"); … … 156 166 157 167 static { 158 sources.add( Main.class);168 sources.add(ClassLoader.getSystemClassLoader()); 159 169 } 160 170 }
Note:
See TracChangeset
for help on using the changeset viewer.