Changeset 30731 in osm for applications/editors/josm/plugins/opendata/src/org/openstreetmap
- Timestamp:
- 2014-10-18T15:31:53+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/AbstractModule.java
r30723 r30731 10 10 import java.util.List; 11 11 12 import org.openstreetmap.josm.Main; 12 13 import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry; 13 14 import org.openstreetmap.josm.gui.preferences.SourceEntry; … … 24 25 25 26 protected final ModuleInformation info; 26 27 27 28 public AbstractModule(ModuleInformation info) { 28 29 this.info = info; … … 50 51 ExtendedSourceEntry src; 51 52 if (handler != null && (src = handler.getMapPaintStyle()) != null) { 52 try { 53 // Copy style sheet to disk to allow JOSM to load it at startup (even making the plugin "early" does not allow it) 54 String path = OdPlugin.getInstance().getResourcesDirectory()+File.separator+src.url.replace(OdConstants.PROTO_RSRC, "").replace('/', File.separatorChar); 55 56 int n = 0; 57 byte[] buffer = new byte[4096]; 58 InputStream in = getClass().getResourceAsStream(src.url.substring(OdConstants.PROTO_RSRC.length()-1)); 59 new File(path.substring(0, path.lastIndexOf(File.separatorChar))).mkdirs(); 60 FileOutputStream out = new FileOutputStream(path); 53 // Copy style sheet to disk to allow JOSM to load it at startup 54 // (even making the plugin "early" does not allow it) 55 String path = OdPlugin.getInstance().getResourcesDirectory() + File.separator 56 + src.url.replace(OdConstants.PROTO_RSRC, "").replace('/', File.separatorChar); 57 58 int n = 0; 59 byte[] buffer = new byte[4096]; 60 try (InputStream in = getClass().getResourceAsStream( 61 src.url.substring(OdConstants.PROTO_RSRC.length()-1)); 62 FileOutputStream out = new FileOutputStream(path)) { 63 String dir = path.substring(0, path.lastIndexOf(File.separatorChar)); 64 if (new File(dir).mkdirs() && Main.isDebugEnabled()) { 65 Main.debug("Created directory: "+dir); 66 } 61 67 while ((n = in.read(buffer)) > 0) { 62 68 out.write(buffer, 0, n); 63 69 } 64 out.close();65 in.close();66 67 70 // Add source pointing to the local file 68 71 src.url = OdConstants.PROTO_FILE+path; 69 72 sources.add(src); 70 73 } catch (IOException e) { 71 System.err.println(e.getMessage());74 Main.error(e.getMessage()); 72 75 } 73 76 } … … 96 99 }; 97 100 } 98 101 99 102 @Override 100 103 public final List<AbstractDataSetHandler> getNewlyInstanciatedHandlers() { … … 104 107 try { 105 108 result.add(handlerClass.newInstance()); 106 } catch ( Throwablet) {107 System.err.println("Cannot instantiate "+handlerClass+" because of "+t.getClass().getName()+": "+t.getMessage());109 } catch (InstantiationException | IllegalAccessException t) { 110 Main.error("Cannot instantiate "+handlerClass+" because of "+t.getClass().getName()+": "+t.getMessage()); 108 111 } 109 112 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/ModuleHandler.java
r30723 r30731 247 247 + "Delete from preferences?</html>", module.name, module.className); 248 248 } 249 } catch ( Throwablee) {250 e.printStackTrace();249 } catch (Exception e) { 250 Main.error(e); 251 251 } 252 252 if (msg != null && confirmDisableModule(parent, msg, module.name)) { … … 550 550 551 551 final File[] files = moduleDir.listFiles(new FilenameFilter() { 552 @Override 552 553 public boolean accept(File dir, String name) { 553 554 return name.endsWith(".jar.new"); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/ModuleInformation.java
r30723 r30731 143 143 this.attr.putAll(other.attr); 144 144 } 145 145 146 146 private static final ImageIcon extractIcon(String iconPath, File jarFile, boolean suppressWarnings) { 147 147 return new ImageProvider(iconPath).setArchive(jarFile).setMaxWidth(24).setMaxHeight(24).setOptional(true).setSuppressWarnings(suppressWarnings).get(); … … 234 234 try { 235 235 return klass.getConstructor(ModuleInformation.class).newInstance(this); 236 } catch ( Throwablet) {236 } catch (Exception t) { 237 237 throw new ModuleException(name, t); 238 238 } … … 251 251 try{ 252 252 return (Class<? extends Module>) Class.forName(className, true, classLoader); 253 } catch ( Throwablet) {253 } catch (Exception t) { 254 254 throw new ModuleException(name, t); 255 255 } … … 260 260 return f.toURI().toURL(); 261 261 } catch (MalformedURLException ex) { 262 Main.warn(ex.getMessage()); 262 263 return null; 263 264 } … … 337 338 } 338 339 339 /**340 * Sets the name341 * @param name342 */343 /*public void setName(String name) {344 this.name = name;345 }*/346 347 340 public ImageIcon getScaledIcon() { 348 341 if (icon == null)
Note:
See TracChangeset
for help on using the changeset viewer.