Changeset 36013 in osm for applications/editors/josm/plugins
- Timestamp:
- 2022-08-04T15:43:42+02:00 (2 years ago)
- Location:
- applications/editors/josm/plugins/ImportImagePlugin
- Files:
-
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ImportImagePlugin/.classpath
r34444 r36013 11 11 <classpathentry combineaccessrules="false" kind="src" path="/JOSM-GeoTools"/> 12 12 <classpathentry combineaccessrules="false" kind="src" path="/JOSM-jts"/> 13 <classpathentry combineaccessrules="false" kind="src" path="/JOSM- log4j"/>14 <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/ 4"/>13 <classpathentry combineaccessrules="false" kind="src" path="/JOSM-ejml"/> 14 <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/> 15 15 <classpathentry kind="output" path="bin"/> 16 16 </classpath> -
applications/editors/josm/plugins/ImportImagePlugin/build.xml
r34519 r36013 12 12 <property name="plugin.icon" value="images/layericon.png"/> 13 13 <property name="plugin.link" value="https://wiki.openstreetmap.org/wiki/JOSM/Plugins/ImportImagePlugin"/> 14 <property name="plugin.requires" value=" log4j;jts;ejml;geotools"/>14 <property name="plugin.requires" value="jts;ejml;geotools"/> 15 15 16 16 <!-- ** include targets that all plugins have in common ** --> … … 18 18 19 19 <fileset id="plugin.requires.jars" dir="${plugin.dist.dir}"> 20 <include name="log4j.jar"/>21 20 <include name="jts.jar"/> 22 21 <include name="ejml.jar"/> -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImageLayer.java
r34519 r36013 19 19 import javax.swing.ImageIcon; 20 20 21 import org.apache.log4j.Logger;22 21 import org.geotools.coverage.grid.GridCoverage2D; 23 22 import org.geotools.geometry.Envelope2D; … … 25 24 import org.geotools.referencing.CRS; 26 25 import org.opengis.referencing.FactoryException; 27 import org.opengis.referencing.NoSuchAuthorityCodeException;28 26 import org.opengis.referencing.crs.CoordinateReferenceSystem; 29 27 import org.openstreetmap.josm.actions.RenameLayerAction; … … 49 47 public class ImageLayer extends Layer { 50 48 51 private Logger logger = Logger.getLogger(ImageLayer.class); 52 53 private File imageFile; 54 55 private BufferedImage image = null; 49 private final File imageFile; 50 51 private BufferedImage image; 56 52 57 53 // coordinates of upper left corner 58 54 private EastNorth upperLeft; 59 55 // Angle of rotation of the image 60 private double angle = 0.0;56 private double angle; 61 57 62 58 // current bbox … … 64 60 65 61 // Layer icon 66 private Icon layericon = null;67 68 // reference system of the ori nginal image62 private Icon layericon; 63 64 // reference system of the original image 69 65 private CoordinateReferenceSystem sourceRefSys; 70 66 … … 89 85 90 86 // geotools type for images and value coverages 91 GridCoverage2D coverage = null;87 GridCoverage2D coverage; 92 88 try { 93 89 // create a grid coverage from the image … … 99 95 100 96 } catch (FactoryException e) { 101 logger.error("Error while creating GridCoverage:", e); 97 Logging.error("ImportImagePlugin ImageLayer: Error while creating GridCoverage: {0}", e); 98 Logging.error(e); 102 99 throw new IOException(e.getMessage()); 103 100 } catch (Exception e) { … … 105 102 int val = 2; 106 103 if (!GraphicsEnvironment.isHeadless()) { 107 ExtendedDialog ex = new ExtendedDialog(MainApplication.getMainFrame(), tr("Warning"), 108 new String[] {tr("Default image projection"), tr("JOSM''s current projection"), tr("Cancel")});104 ExtendedDialog ex = new ExtendedDialog(MainApplication.getMainFrame(), tr("Warning"), 105 tr("Default image projection"), tr("JOSM''s current projection"), tr("Cancel")); 109 106 // CHECKSTYLE.OFF: LineLength 110 107 ex.setContent(tr("No projection file (.prj) found.<br>" … … 115 112 val = ex.showDialog().getValue(); 116 113 if (val == 3) { 117 logger.debug("No projection and user declined un-projected use");114 Logging.debug("ImportImagePlugin ImageLayer: No projection and user declined un-projected use"); 118 115 throw new LayerCreationCanceledException(); 119 116 } 120 117 } 121 CoordinateReferenceSystem src = null;118 CoordinateReferenceSystem src; 122 119 try { 123 120 if (val == 1) { 124 121 src = PluginOperations.defaultSourceCRS; 125 122 } else { 126 logger.debug("Passing through image un-projected.");123 Logging.debug("ImportImagePlugin ImageLayer: Passing through image un-projected."); 127 124 src = CRS.decode(ProjectionRegistry.getProjection().toCode()); 128 125 } … … 134 131 } 135 132 } catch (Exception e1) { 136 logger.error("Error while creating GridCoverage:", e1); 133 Logging.error("ImportImagePlugin ImageLayer: Error while creating GridCoverage:"); 134 Logging.error(e1); 137 135 throw new IOException(e1); 138 136 } 139 137 } else { 140 logger.error("Error while creating GridCoverage:", e); 138 Logging.error("ImportImagePlugin ImageLayer: Error while creating GridCoverage:"); 139 Logging.error(e); 141 140 throw new IOException(e); 142 141 } 143 142 144 143 } 145 logger.debug("Coverage created: " +coverage);144 Logging.debug("ImportImagePlugin ImageLayer: Coverage created: {0}", coverage); 146 145 147 146 upperLeft = new EastNorth(coverage.getEnvelope2D().x, … … 213 212 214 213 if ((scalex > 10) || (scaley > 10)) { 215 logger.warn("Not drawing image - scale too big");214 Logging.warn("ImportImagePlugin ImageLayer: Not drawing image - scale too big"); 216 215 return; 217 216 } … … 227 226 228 227 } else { 229 logger.error("Error while dawing image: image == null or Graphics == null");228 Logging.error("ImportImagePlugin ImageLayer: Error while drawing image: image == null or Graphics == null"); 230 229 } 231 230 } … … 295 294 * calculated by the new reference system. 296 295 */ 297 void resample(CoordinateReferenceSystem refSys) throws IOException, NoSuchAuthorityCodeException,FactoryException {298 logger.debug("resample");296 void resample(CoordinateReferenceSystem refSys) throws IOException, FactoryException { 297 Logging.debug("ImportImagePlugin ImageLayer: resample"); 299 298 GridCoverage2D coverage = PluginOperations.createGridFromFile(this.imageFile, refSys, true); 300 299 coverage = PluginOperations.reprojectCoverage(coverage, CRS.decode(ProjectionRegistry.getProjection().toCode())); -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImportImageFileImporter.java
r34519 r36013 5 5 6 6 import java.io.File; 7 import java.io.IOException;8 7 import java.util.List; 9 8 10 9 import javax.swing.JOptionPane; 11 10 12 import org.apache.log4j.Logger;13 11 import org.openstreetmap.josm.actions.ExtensionFileFilter; 14 12 import org.openstreetmap.josm.gui.MainApplication; … … 16 14 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 17 15 import org.openstreetmap.josm.gui.util.GuiHelper; 18 import org.openstreetmap.josm.io.IllegalDataException;19 16 import org.openstreetmap.josm.plugins.ImportImagePlugin.ImageLayer.LayerCreationCanceledException; 20 17 import org.openstreetmap.josm.tools.Logging; … … 25 22 public class ImportImageFileImporter extends FileImporter { 26 23 27 private Logger logger = Logger.getLogger(LoadImageAction.class);28 29 24 public ImportImageFileImporter() { 30 25 super(new ExtensionFileFilter("tiff,tif,jpg,jpeg,bmp,png", "jpg", … … 43 38 44 39 @Override 45 public void importData(List<File> files, ProgressMonitor progressMonitor) throws IOException, IllegalDataException{40 public void importData(List<File> files, ProgressMonitor progressMonitor) { 46 41 if (null == files) return; 47 42 48 43 for (File file: files) { 49 44 if (file.isDirectory()) continue; 50 ImageLayer layer = null;51 logger.info("File choosen:" +file);45 ImageLayer layer; 46 Logging.info("ImportImageFileImporter: File chosen: {0}", file); 52 47 try { 53 48 layer = new ImageLayer(file); 54 49 } catch (LayerCreationCanceledException e) { 50 Logging.trace(e); 55 51 // if user decides that layer should not be created just return. 56 52 continue; 57 53 } catch (Exception e) { 54 Logging.error("ImportImageFileImporter: Error while creating image layer: \n{0}", e.getMessage()); 58 55 Logging.error(e); 59 logger.error("Error while creating image layer: \n" + e.getMessage());60 56 GuiHelper.runInEDT(() -> 61 57 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Error while creating image layer: {0}", e.getCause()))); -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImportImagePlugin.java
r34519 r36013 2 2 package org.openstreetmap.josm.plugins.ImportImagePlugin; 3 3 4 import java.io.BufferedWriter; 4 5 import java.io.File; 5 import java.io.FileWriter;6 6 import java.io.IOException; 7 import java.io.InputStream; 7 8 import java.net.URL; 9 import java.nio.file.Files; 10 import java.nio.file.Paths; 8 11 import java.util.Properties; 9 12 10 import javax.swing.JMenu;11 12 import org.apache.log4j.Logger;13 import org.apache.log4j.PropertyConfigurator;14 13 import org.openstreetmap.josm.actions.ExtensionFileFilter; 15 14 import org.openstreetmap.josm.actions.JosmAction; … … 19 18 import org.openstreetmap.josm.plugins.Plugin; 20 19 import org.openstreetmap.josm.plugins.PluginInformation; 20 import org.openstreetmap.josm.tools.JosmRuntimeException; 21 import org.openstreetmap.josm.tools.Logging; 21 22 import org.openstreetmap.josm.tools.Utils; 22 23 … … 25 26 * Provides basic routines for plugin installation and provides the plugin properties. 26 27 * 27 *28 28 * @author Christoph Beekmans, Fabian Kowitz, Anna Robaszkiewicz, Oliver Kuhn, Martin Ulitzny 29 29 * … … 31 31 public class ImportImagePlugin extends Plugin { 32 32 33 private static Logger logger; 34 35 JMenu mainmenu = null; 36 JosmAction loadFileAction = null; 33 JosmAction loadFileAction; 37 34 38 35 // plugin properties … … 44 41 static final String PLUGINPROPERTIES_PATH = PLUGIN_DIR + PLUGINPROPERTIES_FILENAME; 45 42 static final String PLUGINLIBRARIES_DIR = PLUGIN_DIR + "lib/"; 46 static final String LOGGING_PROPERTIES_FILEPATH = PLUGIN_DIR + "log4j.properties/";47 43 48 44 /** … … 64 60 65 61 try { 66 // Initialize logger67 initializeLogger();68 69 62 // Check whether plugin has already been installed. Otherwise install 70 63 checkInstallation(); 71 64 72 65 // If resources are available load properties from plugin directory 73 if (pluginProps == null || pluginProps.isEmpty()) { 74 pluginProps = new Properties(); 75 pluginProps.load(new File(PLUGINPROPERTIES_PATH).toURI().toURL().openStream()); 76 logger.debug("Plugin properties loaded"); 77 } 66 loadPluginProps(); 78 67 79 68 // load information about supported reference systems … … 88 77 89 78 } catch (IOException e) { 90 logger.fatal("Error while loading plugin", e); 91 throw e; 79 throw new JosmRuntimeException(e); 80 } 81 } 82 83 private static void loadPluginProps() throws IOException { 84 if (pluginProps == null || pluginProps.isEmpty()) { 85 pluginProps = new Properties(); 86 try (InputStream stream = Files.newInputStream(Paths.get(PLUGINPROPERTIES_PATH))) { 87 pluginProps.load(stream); 88 } 89 Logging.debug("ImportImagePlugin: Plugin properties loaded"); 92 90 } 93 91 } … … 97 95 * If not, start install procedure. 98 96 */ 99 private void checkInstallation() throws IOException {97 private static void checkInstallation() throws IOException { 100 98 // check plugin resource state 101 boolean isInstalled = true; 102 if (!new File(PLUGINPROPERTIES_PATH).exists() 103 || !new File(PLUGIN_DIR).exists() 104 || !new File(PLUGINLIBRARIES_DIR).exists()) 105 isInstalled = false; 99 boolean isInstalled = new File(PLUGINPROPERTIES_PATH).exists() 100 && new File(PLUGIN_DIR).exists() 101 && new File(PLUGINLIBRARIES_DIR).exists(); 106 102 107 103 … … 125 121 // create local properties file 126 122 if (pluginProps == null || pluginProps.isEmpty()) { 127 try ( FileWriter fw = new FileWriter(new File(PLUGINPROPERTIES_PATH))) {128 URL propertiesURL = getClass().getResource("resources/" + PLUGINPROPERTIES_FILENAME);123 try (BufferedWriter fw = Files.newBufferedWriter(Paths.get(PLUGINPROPERTIES_PATH))) { 124 URL propertiesURL = ImportImagePlugin.class.getResource("resources/" + PLUGINPROPERTIES_FILENAME); 129 125 if (propertiesURL != null) { 130 126 pluginProps = new Properties(); 131 pluginProps.load(propertiesURL.openStream()); 127 try (InputStream stream = propertiesURL.openStream()) { 128 pluginProps.load(stream); 129 } 132 130 pluginProps.store(fw, null); 133 131 } 132 134 133 } 135 logger.debug("Plugin properties loaded");134 Logging.debug("ImportImagePlugin: Plugin properties loaded"); 136 135 } 137 136 138 if (!new File(LOGGING_PROPERTIES_FILEPATH).exists()) { 139 try (FileWriter fw = new FileWriter(new File(LOGGING_PROPERTIES_FILEPATH))) { 140 URL propertiesURL = getClass().getResource("resources/log4j.properties"); 141 if (propertiesURL != null) { 142 Properties loggingProps = new Properties(); 143 loggingProps.load(propertiesURL.openStream()); 144 loggingProps.store(fw, null); 145 } 146 } 147 logger.debug("Logging properties created"); 148 } 149 150 logger.debug("Plugin successfully installed"); 137 Logging.debug("ImportImagePlugin: Plugin successfully installed"); 151 138 } 152 139 } 153 154 /**155 * Initialize logger.156 */157 private void initializeLogger() {158 159 Properties props = new Properties();160 try {161 props.load(new File(LOGGING_PROPERTIES_FILEPATH).toURI().toURL().openStream());162 163 // Set file for logging here:164 props.setProperty("log4j.appender.MyRoFiAppender.file",165 (Preferences.main().getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/" + "log.log"));166 167 PropertyConfigurator.configure(props);168 169 logger = Logger.getLogger(ImportImagePlugin.class);170 171 logger.info("Logger successfully initialized.");172 173 return;174 175 } catch (IOException e) {176 System.out.println("Logging properties file not found. Using standard settings.");177 }178 179 // if no log4j.properties file can be found, initialize manually:180 181 props.setProperty("log4j.rootLogger", "INFO, A");182 props.setProperty("log4j.appender.A", "org.apache.log4j.FileAppender");183 184 props.setProperty("log4j.appender.A.layout",185 "org.apache.log4j.PatternLayout ");186 props.setProperty("log4j.appender.A.layout.ConversionPattern",187 "%d{ISO8601} %-5p [%t] %c: %m%n");188 189 // Set file for logging here:190 props.setProperty("log4j.appender.A.file",191 (Preferences.main().getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/" + "log.log"));192 193 PropertyConfigurator.configure(props);194 logger = Logger.getLogger(ImportImagePlugin.class);195 }196 140 } -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/LayerPropertiesDialog.java
r34445 r36013 10 10 import java.awt.event.KeyAdapter; 11 11 import java.awt.event.KeyEvent; 12 import java.io.File; 13 import java.io.FileWriter; 12 import java.io.BufferedWriter; 14 13 import java.io.IOException; 15 import java.util.Iterator; 16 import java.util.Vector; 14 import java.nio.file.Files; 15 import java.nio.file.Paths; 16 import java.util.List; 17 17 18 18 import javax.swing.JButton; … … 38 38 * UI-Dialog which provides: 39 39 * - general and spatial information about the georeferenced image 40 * - a possiblitly to change the source reference system of the image 41 * 40 * - a possibility to change the source reference system of the image 42 41 * 43 42 * @author Christoph Beekmans, Fabian Kowitz, Anna Robaszkiewicz, Oliver Kuhn, Martin Ulitzny … … 46 45 public class LayerPropertiesDialog extends JFrame { 47 46 48 private Vector<String> supportedCRS;47 private final List<String> supportedCRS; 49 48 private ImageLayer imageLayer; 50 49 51 private JPanel mainPanel = null; 52 private JPanel jPanel = null; 53 private JPanel buttonPanel = null; 54 private JTabbedPane jTabbedPane = null; 55 private JPanel infoPanel = null; 56 private JPanel crsPanel = null; 57 private JButton okButton = null; 58 private JLabel layerNameLabel = null; 59 private JLabel layerNameValueLabel = null; 60 private JLabel imageFileLabel = null; 61 private JLabel imageFileValueLabel = null; 62 private JLabel sizeLabel = null; 63 private JLabel sizeValueLabel = null; 64 private JLabel crsLabel = null; 65 private JLabel crsValueLabel = null; 66 private JLabel extentLabel = null; 67 private JLabel defaultCRSDescriptorLabel = null; 68 private JLabel defaultCRSLabel = null; 69 private JTextField searchField = null; 70 private JScrollPane crsListScrollPane = null; 71 private JList<String> crsJList = null; 72 private JButton useDefaultCRSButton = null; 73 private JButton applySelectedCRSButton = null; 74 private JButton setSelectedCRSAsDefaultButton = null; 75 private JLabel searchFieldLabel = null; 76 private JCheckBox eastingFirstCheckBox = null; 77 private JLabel eastingFirstLabel = null; 78 private JLabel tabDescriptionLabel = null; 79 private JLabel upperLeftLabel = null; 80 private JLabel lowerLeftLabel = null; 81 private JLabel upperRightLabel = null; 82 private JLabel lowerRightLabel = null; 83 private JLabel upperLeftValueLabel = null; 84 private JLabel upperRightValueLabel = null; 85 private JLabel lowerLeftValueLabel = null; 86 private JLabel lowerRightValueLabel = null; 87 private JLabel currentCRSLabel = null; 88 private JLabel currentCRSValueLabel = null; 50 private JPanel mainPanel; 51 private JPanel jPanel; 52 private JPanel buttonPanel; 53 private JTabbedPane jTabbedPane; 54 private JPanel infoPanel; 55 private JPanel crsPanel; 56 private JButton okButton; 57 private JLabel defaultCRSLabel; 58 private JTextField searchField; 59 private JScrollPane crsListScrollPane; 60 private JList<String> crsJList; 61 private JButton useDefaultCRSButton; 62 private JButton applySelectedCRSButton; 63 private JButton setSelectedCRSAsDefaultButton; 64 private JCheckBox eastingFirstCheckBox; 89 65 90 66 /** … … 92 68 * 93 69 */ 94 public LayerPropertiesDialog(ImageLayer imageLayer, Vector<String> supportedCRS) {70 public LayerPropertiesDialog(ImageLayer imageLayer, List<String> supportedCRS) { 95 71 super(imageLayer.getName()); 96 72 this.supportedCRS = supportedCRS; … … 103 79 * 104 80 */ 105 public LayerPropertiesDialog( Vector<String> supportedCRS) {81 public LayerPropertiesDialog(List<String> supportedCRS) { 106 82 super(); 107 83 this.supportedCRS = supportedCRS; … … 191 167 private JPanel getInfoPanel() { 192 168 if (infoPanel == null) { 193 lowerRightValueLabel = new JLabel();169 JLabel lowerRightValueLabel = new JLabel(); 194 170 lowerRightValueLabel.setBounds(new Rectangle(210, 315, 134, 16)); 195 171 lowerRightValueLabel.setHorizontalAlignment(SwingConstants.RIGHT); 196 172 lowerRightValueLabel.setText((float) imageLayer.getBbox().getMinX() + ", " + (float) imageLayer.getBbox().getMaxY()); 197 lowerLeftValueLabel = new JLabel();173 JLabel lowerLeftValueLabel = new JLabel(); 198 174 lowerLeftValueLabel.setBounds(new Rectangle(30, 315, 133, 16)); 199 175 lowerLeftValueLabel.setHorizontalAlignment(SwingConstants.LEFT); 200 176 lowerLeftValueLabel.setText((float) imageLayer.getBbox().getMinX() + ", " + (float) imageLayer.getBbox().getMinY()); 201 upperRightValueLabel = new JLabel();177 JLabel upperRightValueLabel = new JLabel(); 202 178 upperRightValueLabel.setBounds(new Rectangle(210, 255, 138, 16)); 203 179 upperRightValueLabel.setHorizontalAlignment(SwingConstants.RIGHT); 204 180 upperRightValueLabel.setText((float) imageLayer.getBbox().getMaxX() + ", " + (float) imageLayer.getBbox().getMaxY()); 205 upperLeftValueLabel = new JLabel();181 JLabel upperLeftValueLabel = new JLabel(); 206 182 upperLeftValueLabel.setBounds(new Rectangle(30, 255, 133, 16)); 207 183 upperLeftValueLabel.setHorizontalAlignment(SwingConstants.LEFT); 208 184 upperLeftValueLabel.setText((float) imageLayer.getBbox().getMaxX() + ", " + (float) imageLayer.getBbox().getMinY()); 209 lowerRightLabel = new JLabel();185 JLabel lowerRightLabel = new JLabel(); 210 186 lowerRightLabel.setBounds(new Rectangle(287, 344, 74, 16)); 211 187 lowerRightLabel.setText("Lower Right"); 212 upperRightLabel = new JLabel();188 JLabel upperRightLabel = new JLabel(); 213 189 upperRightLabel.setBounds(new Rectangle(285, 225, 91, 16)); 214 190 upperRightLabel.setText("Upper Right"); 215 lowerLeftLabel = new JLabel();191 JLabel lowerLeftLabel = new JLabel(); 216 192 lowerLeftLabel.setBounds(new Rectangle(15, 345, 92, 16)); 217 193 lowerLeftLabel.setText("Lower Left"); 218 upperLeftLabel = new JLabel();194 JLabel upperLeftLabel = new JLabel(); 219 195 upperLeftLabel.setBounds(new Rectangle(15, 224, 91, 16)); 220 196 upperLeftLabel.setText("Upper Left"); 221 extentLabel = new JLabel();197 JLabel extentLabel = new JLabel(); 222 198 extentLabel.setBounds(new Rectangle(120, 195, 136, 16)); 223 199 extentLabel.setEnabled(false); … … 225 201 extentLabel.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED); 226 202 extentLabel.setText("Extent"); 227 crsValueLabel = new JLabel();203 JLabel crsValueLabel = new JLabel(); 228 204 crsValueLabel.setBounds(new Rectangle(150, 150, 226, 16)); 229 205 … … 236 212 crsValueLabel.setText(crsDescription + "(" + imageLayer.getBbox().getCoordinateReferenceSystem().getName().toString() + ")"); 237 213 238 crsLabel = new JLabel();214 JLabel crsLabel = new JLabel(); 239 215 crsLabel.setBounds(new Rectangle(15, 150, 118, 16)); 240 216 crsLabel.setText("Reference System"); 241 sizeValueLabel = new JLabel();217 JLabel sizeValueLabel = new JLabel(); 242 218 sizeValueLabel.setBounds(new Rectangle(150, 105, 226, 16)); 243 219 sizeValueLabel.setText(imageLayer.getImage().getHeight() + " x " + imageLayer.getImage().getWidth()); 244 sizeLabel = new JLabel();220 JLabel sizeLabel = new JLabel(); 245 221 sizeLabel.setBounds(new Rectangle(15, 105, 121, 16)); 246 222 sizeLabel.setText("Image size"); 247 imageFileValueLabel = new JLabel();223 JLabel imageFileValueLabel = new JLabel(); 248 224 imageFileValueLabel.setBounds(new Rectangle(150, 60, 226, 16)); 249 225 imageFileValueLabel.setText(imageLayer.getImageFile().getAbsolutePath()); 250 226 imageFileValueLabel.setToolTipText(imageLayer.getImageFile().getAbsolutePath()); 251 imageFileLabel = new JLabel();227 JLabel imageFileLabel = new JLabel(); 252 228 imageFileLabel.setBounds(new Rectangle(15, 60, 121, 16)); 253 229 imageFileLabel.setText("Image file"); 254 layerNameValueLabel = new JLabel();230 JLabel layerNameValueLabel = new JLabel(); 255 231 layerNameValueLabel.setBounds(new Rectangle(150, 15, 226, 16)); 256 232 layerNameValueLabel.setText(imageLayer.getName()); 257 layerNameLabel = new JLabel();233 JLabel layerNameLabel = new JLabel(); 258 234 layerNameLabel.setBounds(new Rectangle(15, 15, 121, 16)); 259 235 layerNameLabel.setText("Layer name"); … … 289 265 private JPanel getCrsPanel() { 290 266 if (crsPanel == null) { 291 currentCRSValueLabel = new JLabel();267 JLabel currentCRSValueLabel = new JLabel(); 292 268 currentCRSValueLabel.setBounds(new Rectangle(78, 33, 297, 16)); 293 269 String crsDescription = "unknown"; … … 299 275 currentCRSValueLabel.setText(crsDescription); 300 276 301 currentCRSLabel = new JLabel();277 JLabel currentCRSLabel = new JLabel(); 302 278 currentCRSLabel.setBounds(new Rectangle(15, 33, 52, 16)); 303 279 currentCRSLabel.setText("Current:"); 304 tabDescriptionLabel = new JLabel();280 JLabel tabDescriptionLabel = new JLabel(); 305 281 tabDescriptionLabel.setBounds(new Rectangle(15, 9, 361, 16)); 306 282 tabDescriptionLabel.setText("Set here the source reference system of the image"); 307 eastingFirstLabel = new JLabel();283 JLabel eastingFirstLabel = new JLabel(); 308 284 eastingFirstLabel.setBounds(new Rectangle(315, 210, 76, 46)); 309 285 eastingFirstLabel.setHorizontalTextPosition(SwingConstants.TRAILING); 310 286 eastingFirstLabel.setHorizontalAlignment(SwingConstants.CENTER); 311 287 eastingFirstLabel.setText("<html>Easting<br>first</html>"); 312 searchFieldLabel = new JLabel();288 JLabel searchFieldLabel = new JLabel(); 313 289 searchFieldLabel.setBounds(new Rectangle(298, 114, 84, 16)); 314 290 searchFieldLabel.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED); … … 319 295 defaultCRSLabel.setBounds(new Rectangle(15, 89, 361, 16)); 320 296 defaultCRSLabel.setText(PluginOperations.defaultSourceCRSDescription); 321 defaultCRSDescriptorLabel = new JLabel();297 JLabel defaultCRSDescriptorLabel = new JLabel(); 322 298 defaultCRSDescriptorLabel.setBounds(new Rectangle(15, 63, 226, 16)); 323 299 defaultCRSDescriptorLabel.setText("Default Reference System:"); … … 373 349 public void keyTyped(KeyEvent e) { 374 350 375 for (Iterator<String> iterator = supportedCRS.iterator(); iterator.hasNext();) { 376 String type = iterator.next(); 351 for (String type : supportedCRS) { 377 352 if (type.contains(searchField.getText())) { 378 353 crsJList.setSelectedIndex(supportedCRS.indexOf(type)); … … 409 384 private JList<String> getCrsJList() { 410 385 if (crsJList == null) { 411 crsJList = new JList<>(supportedCRS );386 crsJList = new JList<>(supportedCRS.toArray(new String[0])); 412 387 crsJList.addListSelectionListener(new ListSelectionHandler()); 413 388 } … … 497 472 "" + eastingFirstCheckBox.isSelected()); 498 473 ImportImagePlugin.pluginProps.setProperty("default_crs_srid", code); 499 try ( FileWriter fileWriter = new FileWriter(new File(ImportImagePlugin.PLUGINPROPERTIES_PATH))) {474 try (BufferedWriter fileWriter = Files.newBufferedWriter(Paths.get(ImportImagePlugin.PLUGINPROPERTIES_PATH))) { 500 475 ImportImagePlugin.pluginProps.store(fileWriter, null); 501 476 } -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/LoadImageAction.java
r34519 r36013 10 10 import javax.swing.JOptionPane; 11 11 12 import org.apache.log4j.Logger;13 12 import org.openstreetmap.josm.actions.JosmAction; 14 13 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; … … 16 15 import org.openstreetmap.josm.plugins.ImportImagePlugin.ImageLayer.LayerCreationCanceledException; 17 16 import org.openstreetmap.josm.spi.preferences.Config; 17 import org.openstreetmap.josm.tools.Logging; 18 18 19 19 /** … … 24 24 */ 25 25 public class LoadImageAction extends JosmAction { 26 27 private Logger logger = Logger.getLogger(LoadImageAction.class);28 26 29 27 /** … … 42 40 int result = fc.showOpenDialog(MainApplication.getMainFrame()); 43 41 44 ImageLayer layer = null;42 ImageLayer layer; 45 43 if (result == JFileChooser.APPROVE_OPTION) { 46 44 Config.getPref().put("plugins.importimage.importpath", fc.getCurrentDirectory().getAbsolutePath()); 47 logger.info("File chosen:" +fc.getSelectedFile());45 Logging.info("ImportImagePlugin LoadImageAction: File chosen: {0}", fc.getSelectedFile()); 48 46 try { 49 47 layer = new ImageLayer(fc.getSelectedFile()); 50 48 } catch (LayerCreationCanceledException e) { 49 Logging.trace(e); 51 50 // if user decides that layer should not be created just return. 52 51 return; 53 52 } catch (Exception e) { 54 logger.error("Error while creating image layer: \n" +e.getMessage());53 Logging.error("ImportImagePlugin LoadImageAction: Error while creating image layer: \n{0}", e.getMessage()); 55 54 JOptionPane.showMessageDialog(null, marktr("Error while creating image layer: " + e.getCause())); 56 55 return; -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/PluginOperations.java
r35125 r36013 7 7 import java.io.File; 8 8 import java.io.FileNotFoundException; 9 import java.io.FileReader;10 9 import java.io.IOException; 10 import java.nio.file.Files; 11 11 import java.util.Arrays; 12 import java.util. Iterator;12 import java.util.List; 13 13 import java.util.Properties; 14 14 import java.util.Set; … … 17 17 import javax.imageio.ImageIO; 18 18 19 import org.apache.log4j.Logger;20 19 import org.geotools.coverage.grid.GridCoverage2D; 21 20 import org.geotools.coverage.grid.GridCoverageFactory; … … 29 28 import org.opengis.parameter.ParameterValueGroup; 30 29 import org.opengis.referencing.FactoryException; 31 import org.opengis.referencing.NoSuchAuthorityCodeException;32 30 import org.opengis.referencing.crs.CRSAuthorityFactory; 33 31 import org.opengis.referencing.crs.CoordinateReferenceSystem; 34 32 import org.opengis.util.InternationalString; 33 import org.openstreetmap.josm.tools.Logging; 35 34 36 35 /** … … 42 41 public final class PluginOperations { 43 42 44 private static final Logger logger = Logger.getLogger(PluginOperations.class);45 46 43 // contains descriptions of all available CRS 47 static Vector<String> crsDescriptions;44 static List<String> crsDescriptions; 48 45 49 46 // the standard native CRS of user images … … 68 65 */ 69 66 public static GridCoverage2D reprojectCoverage(GridCoverage2D coverage, 70 CoordinateReferenceSystem targetCrs) throws NoSuchAuthorityCodeException, FactoryException{67 CoordinateReferenceSystem targetCrs) { 71 68 72 69 // TODO: add category for NO_DATA values in coverage (transparency in image) 73 70 74 GridCoverage2D destination = null;71 GridCoverage2D destination; 75 72 76 73 CoverageProcessor processor = new CoverageProcessor(); … … 88 85 89 86 /** 90 * Creates a org.geotools.coverage.grid.GridCoverage2D from a given file. 87 * Creates a {@link GridCoverage2D} from a given file. 88 * @param file The file to read from 89 * @param refSys The reference system to use 90 * @param failIfNoPrjFile {@code true} if we need to fail if no projection file is found 91 * @throws IOException if the file could not be read 92 * @return The 2d grid coverage of the file 91 93 */ 92 94 public static GridCoverage2D createGridFromFile(File file, CoordinateReferenceSystem refSys, boolean failIfNoPrjFile) throws IOException { 93 95 94 GridCoverage2D coverage = null;96 GridCoverage2D coverage; 95 97 96 98 if (!file.exists()) throw new FileNotFoundException("File not found."); 97 99 98 String extension = null;99 String fileNameWithoutExt = null;100 String extension; 101 String fileNameWithoutExt; 100 102 int dotPos = file.getAbsolutePath().lastIndexOf("."); 101 103 extension = file.getAbsolutePath().substring(dotPos); … … 103 105 104 106 /*------- switch for file type -----------*/ 105 if ( extension.equalsIgnoreCase(".tif") || extension.equalsIgnoreCase(".tiff")) {107 if (".tif".equalsIgnoreCase(extension) || ".tiff".equalsIgnoreCase(extension)) { 106 108 107 109 // try to read GeoTIFF: … … 111 113 } catch (DataSourceException dse) { 112 114 if (!dse.getMessage().contains("Coordinate Reference System is not available")) { 113 dse.printStackTrace(); 114 } 115 } catch (FactoryException facte) { 116 logger.fatal("Error while reading from GeoTIFF:", facte); 117 throw new IOException(facte); 115 Logging.error(dse); 116 } else { 117 Logging.trace(dse); 118 } 118 119 } 119 120 … … 122 123 // try to read Worldfile: 123 124 WorldFileReader tfwReader = null; 124 for ( int i = 0; i < postfixes.length; i++) {125 File prjFile = new File(fileNameWithoutExt + "." + postfix es[i]);125 for (String postfix : postfixes) { 126 File prjFile = new File(fileNameWithoutExt + "." + postfix); 126 127 if (prjFile.exists()) { 127 128 tfwReader = new WorldFileReader(prjFile); … … 138 139 if (refSys == null) { 139 140 if (failIfNoPrjFile) throw new IOException("No projection file found."); 140 logger.debug("no projection given, no projection file found; using unprojected file.");141 Logging.debug("no projection given, no projection file found; using unprojected file."); 141 142 } 142 143 } … … 155 156 coverage = createGridCoverage(img, bbox, refSys); 156 157 157 } else if ( extension.equalsIgnoreCase(".jpg")158 || extension.equalsIgnoreCase(".jpeg")) {158 } else if (".jpg".equalsIgnoreCase(extension) 159 || ".jpeg".equalsIgnoreCase(extension)) { 159 160 String[] postfixes = {"wld", "jgw", "jpgw"}; 160 161 // try to read Worldfile: 161 162 WorldFileReader tfwReader = null; 162 for ( int i = 0; i < postfixes.length; i++) {163 File prjFile = new File(fileNameWithoutExt + "." + postfix es[i]);163 for (String postfix : postfixes) { 164 File prjFile = new File(fileNameWithoutExt + "." + postfix); 164 165 if (prjFile.exists()) { 165 166 tfwReader = new WorldFileReader(prjFile); … … 173 174 if (refSys == null) { 174 175 if (failIfNoPrjFile) throw new IOException("No projection file found."); 175 logger.debug("no projection given, no projection file found; using unprojected file.");176 Logging.debug("no projection given, no projection file found; using unprojected file."); 176 177 } 177 178 } … … 187 188 coverage = createGridCoverage(img, bbox, refSys); 188 189 189 } else if ( extension.equalsIgnoreCase(".bmp")) {190 } else if (".bmp".equalsIgnoreCase(extension)) { 190 191 String[] postfixes = {"wld", "bmpw", "bpw"}; 191 192 // try to read Worldfile: 192 193 WorldFileReader tfwReader = null; 193 for ( int i = 0; i < postfixes.length; i++) {194 File prjFile = new File(fileNameWithoutExt + "." + postfix es[i]);194 for (String postfix : postfixes) { 195 File prjFile = new File(fileNameWithoutExt + "." + postfix); 195 196 if (prjFile.exists()) { 196 197 tfwReader = new WorldFileReader(prjFile); … … 204 205 if (refSys == null) { 205 206 if (failIfNoPrjFile) throw new IOException("No projection file found."); 206 logger.debug("no projection given, no projection file found; using unprojected file.");207 Logging.debug("no projection given, no projection file found; using unprojected file."); 207 208 } 208 209 } … … 218 219 coverage = createGridCoverage(img, bbox, refSys); 219 220 220 } else if ( extension.equalsIgnoreCase(".png")) {221 } else if (".png".equalsIgnoreCase(extension)) { 221 222 222 223 String[] postfixes = {"wld", "pgw", "pngw"}; 223 224 // try to read Worldfile: 224 225 WorldFileReader tfwReader = null; 225 for ( int i = 0; i < postfixes.length; i++) {226 File prjFile = new File(fileNameWithoutExt + "." + postfix es[i]);226 for (String postfix : postfixes) { 227 File prjFile = new File(fileNameWithoutExt + "." + postfix); 227 228 if (prjFile.exists()) { 228 229 tfwReader = new WorldFileReader(prjFile); … … 236 237 if (refSys == null) { 237 238 if (failIfNoPrjFile) throw new IOException("No projection file found."); 238 logger.debug("no projection given, no projection file found; using unprojected file.");239 Logging.debug("no projection given, no projection file found; using unprojected file."); 239 240 } 240 241 } … … 265 266 */ 266 267 public static CoordinateReferenceSystem readPrjFile(File file) throws IOException { 267 CoordinateReferenceSystem refSys = null;268 269 String prjFilename = null;268 CoordinateReferenceSystem refSys; 269 270 String prjFilename; 270 271 int dotPos = file.getAbsolutePath().lastIndexOf("."); 271 272 prjFilename = file.getAbsolutePath().substring(0, dotPos) + ".prj"; … … 273 274 File prjFile = new File(prjFilename); 274 275 if (!prjFile.exists()) return null; 275 logger.debug("Loading .prj file: " + prjFile.getAbsolutePath());276 277 try (BufferedReader br = new BufferedReader(new FileReader(prjFile))) {276 Logging.debug("Loading .prj file: " + prjFile.getAbsolutePath()); 277 278 try (BufferedReader br = Files.newBufferedReader(prjFile.toPath())) { 278 279 StringBuilder sb = new StringBuilder(); 279 String content = null;280 String content; 280 281 while ((content = br.readLine()) != null) { 281 282 sb.append(content); … … 283 284 refSys = CRS.parseWKT(sb.toString().trim()); 284 285 } catch (FactoryException e) { 285 throw new IOException("Unable to parse prj-file: '" + prjFile.getName() + "'" );286 throw new IOException("Unable to parse prj-file: '" + prjFile.getName() + "'", e); 286 287 } 287 288 … … 302 303 * @param refSys if delivered, the coverage will be forced to use this crs 303 304 */ 304 public static GridCoverage2D readGeoTiff(File file, CoordinateReferenceSystem refSys) throws IOException , FactoryException{305 GridCoverage2D coverage = null;305 public static GridCoverage2D readGeoTiff(File file, CoordinateReferenceSystem refSys) throws IOException { 306 GridCoverage2D coverage; 306 307 Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, true); 307 308 if (refSys != null) { … … 328 329 CRSAuthorityFactory fac = CRS.getAuthorityFactory(false); 329 330 330 for (Iterator<String> iterator = supportedCodes.iterator(); iterator.hasNext();) { 331 String string = iterator.next(); 331 for (String string : supportedCodes) { 332 332 try { 333 333 if ("WGS84(DD)".equals(string)) { … … 338 338 crsDescriptions.add(description); 339 339 if (defaultcrsString != null && defaultcrsString.equalsIgnoreCase("EPSG:" + string)) { 340 boolean isEastingFirst = Boolean. valueOf(pluginProps.getProperty("default_crs_eastingfirst"));340 boolean isEastingFirst = Boolean.parseBoolean(pluginProps.getProperty("default_crs_eastingfirst")); 341 341 defaultSourceCRS = CRS.decode("EPSG:" + string, isEastingFirst); 342 342 defaultSourceCRSDescription = description; … … 344 344 345 345 } catch (FactoryException e) { 346 logger.error("Error while loading EPSG data: " + e.getMessage()); 346 Logging.error("Error while loading EPSG data: " + e.getMessage()); 347 Logging.error(e); 347 348 } 348 349 } -
applications/editors/josm/plugins/ImportImagePlugin/test/unit/org/openstreetmap/josm/plugins/ImportImagePlugin/GeoTiffReaderTest.java
r33864 r36013 2 2 package org.openstreetmap.josm.plugins.ImportImagePlugin; 3 3 4 import static org.junit. Assert.assertNotNull;4 import static org.junit.jupiter.api.Assertions.assertNotNull; 5 5 6 6 import java.io.File; … … 15 15 16 16 import org.geotools.coverage.grid.GridCoverage2D; 17 import org.junit. Rule;18 import org.junit. Test;17 import org.junit.jupiter.api.Test; 18 import org.junit.jupiter.api.Timeout; 19 19 import org.openstreetmap.josm.TestUtils; 20 import org.openstreetmap.josm.testutils. JOSMTestRules;20 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 21 21 import org.openstreetmap.josm.tools.Logging; 22 22 … … 25 25 * Data downloaded from <a href="ftp://ftp.remotesensing.org/pub/geotiff/samples">remotesensing.org</a>. 26 26 */ 27 public class GeoTiffReaderTest { 28 29 /** 30 * Setup test. 31 */ 32 @Rule 33 public JOSMTestRules rules = new JOSMTestRules().preferences().timeout(20000); 34 27 @BasicPreferences 28 @Timeout(20) 29 class GeoTiffReaderTest { 35 30 @Test 36 publicvoid testReadGeoTiffFiles() throws IOException {31 void testReadGeoTiffFiles() throws IOException { 37 32 for (Path p : listDataFiles("tif")) { 38 33 File file = p.toFile(); … … 46 41 * Lists all datasets files matching given extension. 47 42 * @param ext file extension to search for 48 * @return sList of all datasets files matching given extension43 * @return List of all datasets files matching given extension 49 44 * @throws IOException in case of I/O error 50 45 */ -
applications/editors/josm/plugins/ImportImagePlugin/test/unit/org/openstreetmap/josm/plugins/ImportImagePlugin/ImageLayerTest.java
r33864 r36013 2 2 package org.openstreetmap.josm.plugins.ImportImagePlugin; 3 3 4 import static org.junit. Assert.assertEquals;5 import static org.junit. Assert.assertTrue;4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertTrue; 6 6 7 7 import java.io.File; 8 8 import java.io.InputStream; 9 9 10 import org.junit. Rule;11 import org.junit. Test;10 import org.junit.jupiter.api.Test; 11 import org.junit.jupiter.api.extension.RegisterExtension; 12 12 import org.openstreetmap.josm.TestUtils; 13 13 import org.openstreetmap.josm.gui.MainApplication; … … 15 15 import org.openstreetmap.josm.io.OsmReader; 16 16 import org.openstreetmap.josm.testutils.JOSMTestRules; 17 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 17 18 18 19 /** … … 20 21 * Data downloaded from <a href="ftp://ftp.remotesensing.org/pub/geotiff/samples">remotesensing.org</a>. 21 22 */ 22 public class ImageLayerTest { 23 @BasicPreferences 24 class ImageLayerTest { 23 25 24 26 /** 25 27 * Setup test. 26 28 */ 27 @R ule28 public JOSMTestRules rules = new JOSMTestRules().preferences().projection();29 @RegisterExtension 30 static JOSMTestRules rules = new JOSMTestRules().projection(); 29 31 30 32 /** … … 33 35 */ 34 36 @Test 35 publicvoid testTicket14894() throws Exception {37 void testTicket14894() throws Exception { 36 38 assertTrue(MainApplication.getLayerManager().getLayers().isEmpty()); 37 39 // Step 1: add .osm layer
Note:
See TracChangeset
for help on using the changeset viewer.