Changeset 34219 in osm
- Timestamp:
- 2018-05-27T02:55:44+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImageLayer.java
r33562 r34219 6 6 import java.awt.Graphics2D; 7 7 import java.awt.GraphicsEnvironment; 8 import java.awt.Image;9 8 import java.awt.event.ActionEvent; 10 9 import java.awt.image.BufferedImage; 10 import java.awt.image.RenderedImage; 11 11 import java.io.File; 12 12 import java.io.IOException; … … 39 39 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 40 40 import org.openstreetmap.josm.gui.layer.Layer; 41 import org.openstreetmap.josm.tools.Logging; 41 42 42 43 /** … … 75 76 76 77 this.imageFile = file; 77 this.image = (BufferedImage)createImage();78 URL iconURL = ImportImagePlugin.pluginClassLoader.getResource("images/layericon.png");78 this.image = createImage(); 79 URL iconURL = getClass().getResource("images/layericon.png"); 79 80 if (iconURL != null) { 80 81 layericon = new ImageIcon(iconURL); … … 85 86 * create spatial referenced image. 86 87 */ 87 private Image createImage() throws IOException {88 private BufferedImage createImage() throws IOException { 88 89 89 90 // geotools type for images and value coverages … … 144 145 logger.debug("Coverage created: " + coverage); 145 146 146 // TODO147 147 upperLeft = new EastNorth(coverage.getEnvelope2D().x, 148 148 coverage.getEnvelope2D().y + coverage.getEnvelope2D().height); … … 150 150 bbox = coverage.getEnvelope2D(); 151 151 152 // Refresh 153 // Main.map.mapView.repaint(); 154 // PlanarImage image = (PlanarImage) coverage.getRenderedImage(); 155 // logger.info("Color Model: " + coverage.getRenderedImage().getColorModel()); 156 ImageWorker worker = new ImageWorker(coverage.getRenderedImage()); 157 158 return worker.getBufferedImage(); 152 RenderedImage img = coverage.getRenderedImage(); 153 try { 154 BufferedImage bi = new ImageWorker(img).getBufferedImage(); 155 BufferedImage dst = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_ARGB); 156 Graphics2D g2d = dst.createGraphics(); 157 try { 158 // Check image can be drawn correctly 159 g2d.drawImage(bi, 0, 0, null); 160 } finally { 161 g2d.dispose(); 162 } 163 return bi; 164 } catch (ArrayIndexOutOfBoundsException e) { 165 Logging.debug(e); 166 // See #12108 - rescale to bytes in case of ComponentColorModel index error 167 return new ImageWorker(img).rescaleToBytes().getBufferedImage(); 168 } 159 169 } 160 170 -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImportImageFileImporter.java
r33562 r34219 7 7 import java.io.IOException; 8 8 import java.util.List; 9 9 10 import javax.swing.JOptionPane; 11 10 12 import org.apache.log4j.Logger; 11 13 import org.openstreetmap.josm.Main; 12 14 import org.openstreetmap.josm.actions.ExtensionFileFilter; 13 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;14 15 import org.openstreetmap.josm.gui.MainApplication; 15 16 import org.openstreetmap.josm.gui.io.importexport.FileImporter; 16 17 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 18 import org.openstreetmap.josm.gui.util.GuiHelper; 17 19 import org.openstreetmap.josm.io.IllegalDataException; 18 20 import org.openstreetmap.josm.plugins.ImportImagePlugin.ImageLayer.LayerCreationCanceledException; 21 import org.openstreetmap.josm.tools.Logging; 19 22 20 23 /** … … 42 45 @Override 43 46 public void importData(List<File> files, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { 44 if (null == files || files.isEmpty()) return;47 if (null == files) return; 45 48 46 49 for (File file: files) { … … 54 57 continue; 55 58 } catch (Exception e) { 56 logger.error("Error while creating image layer: \n" + e.getMessage()); 57 JOptionPane.showMessageDialog(null, tr("Error while creating image layer: {0}", e.getCause())); 59 Logging.error(e); 60 logger.error("Error while creating image layer: \n" + e.getMessage()); 61 GuiHelper.runInEDT(() -> 62 JOptionPane.showMessageDialog(Main.parent, tr("Error while creating image layer: {0}", e.getCause()))); 58 63 continue; 59 64 } 60 65 61 // Add layer:62 66 MainApplication.getLayerManager().addLayer(layer); 63 BoundingXYVisitor boundingXYVisitor = new BoundingXYVisitor();64 layer.visitBoundingBox(boundingXYVisitor);65 MainApplication.getMap().mapView.zoomTo(boundingXYVisitor);66 67 } 67 68 } -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImportImagePlugin.java
r33563 r34219 5 5 import java.io.FileWriter; 6 6 import java.io.IOException; 7 import java.net.MalformedURLException;8 7 import java.net.URL; 9 import java.net.URLClassLoader;10 8 import java.util.Properties; 11 9 … … 21 19 import org.openstreetmap.josm.plugins.Plugin; 22 20 import org.openstreetmap.josm.plugins.PluginInformation; 23 import org.openstreetmap.josm.tools.JosmRuntimeException;24 21 import org.openstreetmap.josm.tools.Utils; 25 22 … … 39 36 JosmAction loadFileAction = null; 40 37 41 // custom Classloader to load resources from the main JAR 42 static ClassLoader pluginClassLoader = createPluginClassLoader(); 43 44 // plugin proerties 38 // plugin properties 45 39 static Properties pluginProps; 46 40 … … 66 60 try { 67 61 // Initialize logger 68 initializeLogger( pluginClassLoader);62 initializeLogger(); 69 63 70 64 // Check whether plugin has already been installed. Otherwise install … … 94 88 throw e; 95 89 } 96 97 logger.info("Plugin successfully loaded.");98 90 } 99 91 … … 131 123 if (pluginProps == null || pluginProps.isEmpty()) { 132 124 try (FileWriter fw = new FileWriter(new File(PLUGINPROPERTIES_PATH))) { 133 URL propertiesURL = pluginClassLoader.getResource("resources/" + PLUGINPROPERTIES_FILENAME);125 URL propertiesURL = getClass().getResource("resources/" + PLUGINPROPERTIES_FILENAME); 134 126 pluginProps = new Properties(); 135 127 pluginProps.load(propertiesURL.openStream()); … … 141 133 if (!new File(LOGGING_PROPERTIES_FILEPATH).exists()) { 142 134 try (FileWriter fw = new FileWriter(new File(LOGGING_PROPERTIES_FILEPATH))) { 143 URL propertiesURL = pluginClassLoader.getResource("resources/log4j.properties");135 URL propertiesURL = getClass().getResource("resources/log4j.properties"); 144 136 Properties loggingProps = new Properties(); 145 137 loggingProps.load(propertiesURL.openStream()); … … 154 146 155 147 /** 156 * Initialize logger using plugin classloader.148 * Initialize logger. 157 149 */ 158 private void initializeLogger( ClassLoader cl) {150 private void initializeLogger() { 159 151 160 152 Properties props = new Properties(); … … 194 186 PropertyConfigurator.configure(props); 195 187 logger = Logger.getLogger(ImportImagePlugin.class); 196 logger.info("Logger successfully initialized with standard settings.");197 198 }199 200 /**201 * get a plugin-specific classloader.202 */203 private static ClassLoader createPluginClassLoader() {204 try {205 return URLClassLoader.newInstance(206 new URL[] {new File(Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin.jar").toURI().toURL()},207 ImportImagePlugin.class.getClassLoader()208 );209 } catch (MalformedURLException e) {210 throw new JosmRuntimeException(e);211 }212 188 } 213 189 } -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/LayerPropertiesDialog.java
r33563 r34219 33 33 import org.opengis.referencing.NoSuchAuthorityCodeException; 34 34 import org.opengis.referencing.crs.CoordinateReferenceSystem; 35 import org.openstreetmap.josm.Main;36 35 import org.openstreetmap.josm.tools.Logging; 37 36
Note:
See TracChangeset
for help on using the changeset viewer.