Changeset 33372 in osm
- Timestamp:
- 2017-06-05T23:42:44+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/ImportImagePlugin
- Files:
-
- 8 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImageLayer.java
r33028 r33372 5 5 6 6 import java.awt.Graphics2D; 7 import java.awt.GraphicsEnvironment; 7 8 import java.awt.Image; 8 9 import java.awt.event.ActionEvent; … … 10 11 import java.io.File; 11 12 import java.io.IOException; 13 import java.net.URL; 12 14 13 15 import javax.media.jai.PlanarImage; … … 73 75 this.imageFile = file; 74 76 this.image = (BufferedImage) createImage(); 75 layericon = new ImageIcon(ImportImagePlugin.pluginClassLoader.getResource("images/layericon.png")); 77 URL iconURL = ImportImagePlugin.pluginClassLoader.getResource("images/layericon.png"); 78 if (iconURL != null) { 79 layericon = new ImageIcon(iconURL); 80 } 76 81 } 77 82 … … 96 101 } catch (Exception e) { 97 102 if (e.getMessage().contains("No projection file found")) { 98 ExtendedDialog ex = new ExtendedDialog(Main.parent, tr("Warning"), 99 new String[] {tr("Default image projection"), tr("JOSM''s current projection"), tr("Cancel")}); 100 // CHECKSTYLE.OFF: LineLength 101 ex.setContent(tr("No projection file (.prj) found.<br>" 102 + "You can choose the default image projection ({0}) or JOSM''s current editor projection ({1}) as original image projection.<br>" 103 + "(It can be changed later from the right click menu of the image layer.)", 104 ImportImagePlugin.pluginProps.getProperty("default_crs_srid"), Main.getProjection().toCode())); 105 // CHECKSTYLE.ON: LineLength 106 ex.showDialog(); 107 int val = ex.getValue(); 108 if (val == 3) { 109 logger.debug("No projection and user declined un-projected use"); 110 throw new LayerCreationCanceledException(); 103 int val = 2; 104 if (!GraphicsEnvironment.isHeadless()) { 105 ExtendedDialog ex = new ExtendedDialog(Main.parent, tr("Warning"), 106 new String[] {tr("Default image projection"), tr("JOSM''s current projection"), tr("Cancel")}); 107 // CHECKSTYLE.OFF: LineLength 108 ex.setContent(tr("No projection file (.prj) found.<br>" 109 + "You can choose the default image projection ({0}) or JOSM''s current editor projection ({1}) as original image projection.<br>" 110 + "(It can be changed later from the right click menu of the image layer.)", 111 ImportImagePlugin.pluginProps.getProperty("default_crs_srid"), Main.getProjection().toCode())); 112 // CHECKSTYLE.ON: LineLength 113 val = ex.showDialog().getValue(); 114 if (val == 3) { 115 logger.debug("No projection and user declined un-projected use"); 116 throw new LayerCreationCanceledException(); 117 } 111 118 } 112 119 CoordinateReferenceSystem src = null; … … 299 306 * 300 307 */ 301 public class LayerPropertiesAction extends AbstractAction {308 public static class LayerPropertiesAction extends AbstractAction { 302 309 public ImageLayer imageLayer; 303 310 … … 307 314 } 308 315 316 @Override 309 317 public void actionPerformed(ActionEvent arg0) { 310 318 LayerPropertiesDialog layerProps = new LayerPropertiesDialog(imageLayer, PluginOperations.crsDescriptions); … … 317 325 * Exception which represents that the layer creation has been canceled by the user. 318 326 */ 319 class LayerCreationCanceledException extends IOException{327 static class LayerCreationCanceledException extends IOException{ 320 328 } 321 329 -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImportImagePlugin.java
r33028 r33372 20 20 import org.openstreetmap.josm.plugins.Plugin; 21 21 import org.openstreetmap.josm.plugins.PluginInformation; 22 import org.openstreetmap.josm.tools.JosmRuntimeException; 22 23 import org.openstreetmap.josm.tools.Utils; 23 24 … … 37 38 JosmAction loadFileAction = null; 38 39 39 // custom Classloader 40 static ClassLoader pluginClassLoader ;40 // custom Classloader to load resources from the main JAR 41 static ClassLoader pluginClassLoader = createPluginClassLoader(); 41 42 42 43 // plugin proerties … … 44 45 45 46 // path constants 46 static final String PLUGIN_DIR = 47 Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/"; 48 static final String PLUGINPROPERTIES_PATH = 49 Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/pluginProperties.properties"; 50 static final String PLUGINLIBRARIES_DIR = 51 Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/lib/"; 47 static final String PLUGIN_DIR = Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/"; 52 48 static final String PLUGINPROPERTIES_FILENAME = "pluginProperties.properties"; 53 static final String LOGGING_PROPERTIES_FILEPATH = 54 Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/log4j.properties/"; 49 static final String PLUGINPROPERTIES_PATH = PLUGIN_DIR + PLUGINPROPERTIES_FILENAME; 50 static final String PLUGINLIBRARIES_DIR = PLUGIN_DIR + "lib/"; 51 static final String LOGGING_PROPERTIES_FILEPATH = PLUGIN_DIR + "log4j.properties/"; 55 52 56 53 public Properties getPluginProps() { … … 67 64 68 65 try { 69 // First create custom ClassLoader to load resources from the main JAR70 pluginClassLoader = createPluginClassLoader();71 72 66 // Initialize logger 73 67 initializeLogger(pluginClassLoader); … … 206 200 * get a plugin-specific classloader. 207 201 */ 208 private ClassLoader createPluginClassLoader() throws MalformedURLException{209 ClassLoader loader = null;210 loader =URLClassLoader.newInstance(211 new URL[] {new File(Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin.jar").toURI().toURL()},212 ImportImagePlugin.class.getClassLoader()213 );214 215 return loader;216 }217 202 private static ClassLoader createPluginClassLoader() { 203 try { 204 return URLClassLoader.newInstance( 205 new URL[] {new File(Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin.jar").toURI().toURL()}, 206 ImportImagePlugin.class.getClassLoader() 207 ); 208 } catch (MalformedURLException e) { 209 throw new JosmRuntimeException(e); 210 } 211 } 218 212 }
Note:
See TracChangeset
for help on using the changeset viewer.