Ticket #22263: 22263.2.patch
File 22263.2.patch, 51.2 KB (added by , 2 years ago) |
---|
-
.classpath
10 10 <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/> 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> -
build.xml
11 11 <property name="plugin.description" value="Plugin for importing spatial referenced images"/> 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 ** --> 17 17 <import file="../build-common.xml"/> 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"/> 23 22 <include name="geotools.jar"/> -
src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImageLayer.java
18 18 import javax.swing.Icon; 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; 24 23 import org.geotools.image.ImageWorker; … … 48 47 */ 49 48 public class ImageLayer extends Layer { 50 49 51 private Logger logger = Logger.getLogger(ImageLayer.class);52 53 50 private File imageFile; 54 51 55 52 private BufferedImage image = null; … … 98 95 coverage = PluginOperations.reprojectCoverage(coverage, CRS.decode(ProjectionRegistry.getProjection().toCode())); 99 96 100 97 } catch (FactoryException e) { 101 logger.error("Error while creating GridCoverage:", e); 98 Logging.error("ImportImagePlugin ImageLayer: Error while creating GridCoverage: {0}", e); 99 Logging.error(e); 102 100 throw new IOException(e.getMessage()); 103 101 } catch (Exception e) { 104 102 if (e.getMessage().contains("No projection file found")) { … … 114 112 // CHECKSTYLE.ON: LineLength 115 113 val = ex.showDialog().getValue(); 116 114 if (val == 3) { 117 logger.debug("No projection and user declined un-projected use");115 Logging.debug("ImportImagePlugin ImageLayer: No projection and user declined un-projected use"); 118 116 throw new LayerCreationCanceledException(); 119 117 } 120 118 } … … 123 121 if (val == 1) { 124 122 src = PluginOperations.defaultSourceCRS; 125 123 } else { 126 logger.debug("Passing through image un-projected.");124 Logging.debug("ImportImagePlugin ImageLayer: Passing through image un-projected."); 127 125 src = CRS.decode(ProjectionRegistry.getProjection().toCode()); 128 126 } 129 127 // create a grid coverage from the image … … 133 131 coverage = PluginOperations.reprojectCoverage(coverage, CRS.decode(ProjectionRegistry.getProjection().toCode())); 134 132 } 135 133 } catch (Exception e1) { 136 logger.error("Error while creating GridCoverage:", e1); 134 Logging.error("ImportImagePlugin ImageLayer: Error while creating GridCoverage:"); 135 Logging.error(e1); 137 136 throw new IOException(e1); 138 137 } 139 138 } else { 140 logger.error("Error while creating GridCoverage:", e); 139 Logging.error("ImportImagePlugin ImageLayer: Error while creating GridCoverage:"); 140 Logging.error(e); 141 141 throw new IOException(e); 142 142 } 143 143 144 144 } 145 logger.debug("Coverage created: " +coverage);145 Logging.debug("ImportImagePlugin ImageLayer: Coverage created: {0}", coverage); 146 146 147 147 upperLeft = new EastNorth(coverage.getEnvelope2D().x, 148 148 coverage.getEnvelope2D().y + coverage.getEnvelope2D().height); … … 212 212 double scaley = pixels4bbox_height / image.getHeight(); 213 213 214 214 if ((scalex > 10) || (scaley > 10)) { 215 logger.warn("Not drawing image - scale too big");215 Logging.warn("ImportImagePlugin ImageLayer: Not drawing image - scale too big"); 216 216 return; 217 217 } 218 218 g.scale(scalex, scaley); … … 226 226 } 227 227 228 228 } else { 229 logger.error("Error while dawing image: image == null or Graphics == null");229 Logging.error("ImportImagePlugin ImageLayer: Error while drawing image: image == null or Graphics == null"); 230 230 } 231 231 } 232 232 … … 295 295 * calculated by the new reference system. 296 296 */ 297 297 void resample(CoordinateReferenceSystem refSys) throws IOException, NoSuchAuthorityCodeException, FactoryException { 298 logger.debug("resample");298 Logging.debug("ImportImagePlugin ImageLayer: resample"); 299 299 GridCoverage2D coverage = PluginOperations.createGridFromFile(this.imageFile, refSys, true); 300 300 coverage = PluginOperations.reprojectCoverage(coverage, CRS.decode(ProjectionRegistry.getProjection().toCode())); 301 301 this.bbox = coverage.getEnvelope2D(); -
src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImportImageFileImporter.java
9 9 10 10 import javax.swing.JOptionPane; 11 11 12 import org.apache.log4j.Logger;13 12 import org.openstreetmap.josm.actions.ExtensionFileFilter; 14 13 import org.openstreetmap.josm.gui.MainApplication; 15 14 import org.openstreetmap.josm.gui.io.importexport.FileImporter; … … 24 23 */ 25 24 public class ImportImageFileImporter extends FileImporter { 26 25 27 private Logger logger = Logger.getLogger(LoadImageAction.class);28 29 26 public ImportImageFileImporter() { 30 27 super(new ExtensionFileFilter("tiff,tif,jpg,jpeg,bmp,png", "jpg", 31 28 "Georeferenced image file [by ImportImage plugin] (*.jpg, *.jpeg, *.tif, *.tiff, *.png, *.bmp)")); … … 47 44 48 45 for (File file: files) { 49 46 if (file.isDirectory()) continue; 50 ImageLayer layer = null;51 logger.info("File choosen:" +file);47 ImageLayer layer; 48 Logging.info("ImportImageFileImporter: File chosen: {0}", file); 52 49 try { 53 50 layer = new ImageLayer(file); 54 51 } catch (LayerCreationCanceledException e) { 52 Logging.trace(e); 55 53 // if user decides that layer should not be created just return. 56 54 continue; 57 55 } catch (Exception e) { 56 Logging.error("ImportImageFileImporter: Error while creating image layer: \n{0}", e.getMessage()); 58 57 Logging.error(e); 59 logger.error("Error while creating image layer: \n" + e.getMessage());60 58 GuiHelper.runInEDT(() -> 61 59 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Error while creating image layer: {0}", e.getCause()))); 62 60 continue; -
src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImportImagePlugin.java
1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.ImportImagePlugin; 3 3 4 import java.io.File;5 import java.io.FileWriter;6 import java.io.IOException;7 import java.net.URL;8 import java.util.Properties;9 10 import javax.swing.JMenu;11 12 import org.apache.log4j.Logger;13 import org.apache.log4j.PropertyConfigurator;14 4 import org.openstreetmap.josm.actions.ExtensionFileFilter; 15 5 import org.openstreetmap.josm.actions.JosmAction; 16 6 import org.openstreetmap.josm.data.Preferences; … … 18 8 import org.openstreetmap.josm.gui.MainMenu; 19 9 import org.openstreetmap.josm.plugins.Plugin; 20 10 import org.openstreetmap.josm.plugins.PluginInformation; 11 import org.openstreetmap.josm.tools.JosmRuntimeException; 12 import org.openstreetmap.josm.tools.Logging; 21 13 import org.openstreetmap.josm.tools.Utils; 22 14 15 import java.io.BufferedWriter; 16 import java.io.File; 17 import java.io.IOException; 18 import java.io.InputStream; 19 import java.net.URL; 20 import java.nio.file.Files; 21 import java.nio.file.Paths; 22 import java.util.Properties; 23 23 24 /** 24 25 * Plugin class. 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 * 30 30 */ 31 31 public class ImportImagePlugin extends Plugin { 32 32 33 private static Logger logger;33 JosmAction loadFileAction; 34 34 35 JMenu mainmenu = null;36 JosmAction loadFileAction = null;37 38 35 // plugin properties 39 36 static Properties pluginProps; 40 37 … … 43 40 static final String PLUGINPROPERTIES_FILENAME = "pluginProperties.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 /** 49 45 * Returns Import image plugin properties. … … 63 59 super(info); 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 80 69 PluginOperations.loadCRSData(pluginProps); … … 87 76 ExtensionFileFilter.addImporter(new ImportImageFileImporter()); 88 77 89 78 } catch (IOException e) { 90 logger.fatal("Error while loading plugin", e); 91 throw e; 79 throw new JosmRuntimeException(e); 92 80 } 93 81 } 94 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"); 90 } 91 } 92 93 private static void writePluginPropsToFileAndLoad() throws IOException { 94 if (pluginProps == null || pluginProps.isEmpty()) { 95 try (BufferedWriter fw = Files.newBufferedWriter(Paths.get(PLUGINPROPERTIES_PATH))) { 96 URL propertiesURL = ImportImagePlugin.class.getResource("resources/" + PLUGINPROPERTIES_FILENAME); 97 if (propertiesURL != null) { 98 pluginProps = new Properties(); 99 try (InputStream stream = propertiesURL.openStream()) { 100 pluginProps.load(stream); 101 } 102 pluginProps.store(fw, null); 103 } 104 105 } 106 Logging.debug("ImportImagePlugin: Plugin properties loaded"); 107 } 108 } 109 95 110 /** 96 111 * Checks whether plugin resources are available. 97 112 * If not, start install procedure. 98 113 */ 99 private void checkInstallation() throws IOException {114 private static void checkInstallation() throws IOException { 100 115 // 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; 116 boolean isInstalled = new File(PLUGINPROPERTIES_PATH).exists() 117 && new File(PLUGIN_DIR).exists() 118 && new File(PLUGINLIBRARIES_DIR).exists(); 106 119 107 120 108 121 // if properties file doesn't exist, install plugin … … 123 136 } 124 137 125 138 // create local properties file 126 if (pluginProps == null || pluginProps.isEmpty()) { 127 try (FileWriter fw = new FileWriter(new File(PLUGINPROPERTIES_PATH))) { 128 URL propertiesURL = getClass().getResource("resources/" + PLUGINPROPERTIES_FILENAME); 129 if (propertiesURL != null) { 130 pluginProps = new Properties(); 131 pluginProps.load(propertiesURL.openStream()); 132 pluginProps.store(fw, null); 133 } 134 } 135 logger.debug("Plugin properties loaded"); 136 } 139 writePluginPropsToFileAndLoad(); 137 140 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"); 141 Logging.debug("ImportImagePlugin: Plugin successfully installed"); 151 142 } 152 143 } 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 144 } -
src/org/openstreetmap/josm/plugins/ImportImagePlugin/LayerPropertiesDialog.java
1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.ImportImagePlugin; 3 3 4 import java.awt.Cursor; 5 import java.awt.Dimension; 6 import java.awt.Font; 7 import java.awt.GridBagConstraints; 8 import java.awt.GridBagLayout; 9 import java.awt.Rectangle; 10 import java.awt.event.KeyAdapter; 11 import java.awt.event.KeyEvent; 12 import java.io.File; 13 import java.io.FileWriter; 14 import java.io.IOException; 15 import java.util.Iterator; 16 import java.util.Vector; 4 import org.geotools.referencing.CRS; 5 import org.opengis.referencing.FactoryException; 6 import org.opengis.referencing.crs.CoordinateReferenceSystem; 7 import org.openstreetmap.josm.tools.Logging; 17 8 18 9 import javax.swing.JButton; 19 10 import javax.swing.JCheckBox; … … 28 19 import javax.swing.SwingConstants; 29 20 import javax.swing.event.ListSelectionEvent; 30 21 import javax.swing.event.ListSelectionListener; 22 import java.awt.Cursor; 23 import java.awt.Dimension; 24 import java.awt.Font; 25 import java.awt.GridBagConstraints; 26 import java.awt.GridBagLayout; 27 import java.awt.Rectangle; 28 import java.awt.event.KeyAdapter; 29 import java.awt.event.KeyEvent; 30 import java.io.BufferedWriter; 31 import java.io.IOException; 32 import java.nio.file.Files; 33 import java.nio.file.Paths; 34 import java.util.List; 31 35 32 import org.geotools.referencing.CRS;33 import org.opengis.referencing.FactoryException;34 import org.opengis.referencing.crs.CoordinateReferenceSystem;35 import org.openstreetmap.josm.tools.Logging;36 37 36 /** 38 37 * UI-Dialog which provides: 39 38 * - general and spatial information about the georeferenced image 40 * - a possib litly to change the source reference system of the image39 * - a possibility to change the source reference system of the image 41 40 * 42 *43 41 * @author Christoph Beekmans, Fabian Kowitz, Anna Robaszkiewicz, Oliver Kuhn, Martin Ulitzny 44 42 * 45 43 */ 46 44 public class LayerPropertiesDialog extends JFrame { 47 45 48 private Vector<String> supportedCRS;46 private final List<String> supportedCRS; 49 47 private ImageLayer imageLayer; 50 48 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; 49 private JPanel mainPanel; 50 private JPanel jPanel; 51 private JPanel buttonPanel; 52 private JTabbedPane jTabbedPane; 53 private JPanel infoPanel; 54 private JPanel crsPanel; 55 private JButton okButton; 56 private JLabel defaultCRSLabel; 57 private JTextField searchField; 58 private JScrollPane crsListScrollPane; 59 private JList<String> crsJList; 60 private JButton useDefaultCRSButton; 61 private JButton applySelectedCRSButton; 62 private JButton setSelectedCRSAsDefaultButton; 63 private JCheckBox eastingFirstCheckBox; 89 64 90 65 /** 91 66 * This method initializes 92 67 * 93 68 */ 94 public LayerPropertiesDialog(ImageLayer imageLayer, Vector<String> supportedCRS) {69 public LayerPropertiesDialog(ImageLayer imageLayer, List<String> supportedCRS) { 95 70 super(imageLayer.getName()); 96 71 this.supportedCRS = supportedCRS; 97 72 this.imageLayer = imageLayer; … … 102 77 * This method initializes 103 78 * 104 79 */ 105 public LayerPropertiesDialog( Vector<String> supportedCRS) {80 public LayerPropertiesDialog(List<String> supportedCRS) { 106 81 super(); 107 82 this.supportedCRS = supportedCRS; 108 83 initialize(); … … 190 165 */ 191 166 private JPanel getInfoPanel() { 192 167 if (infoPanel == null) { 193 lowerRightValueLabel = new JLabel();168 JLabel lowerRightValueLabel = new JLabel(); 194 169 lowerRightValueLabel.setBounds(new Rectangle(210, 315, 134, 16)); 195 170 lowerRightValueLabel.setHorizontalAlignment(SwingConstants.RIGHT); 196 171 lowerRightValueLabel.setText((float) imageLayer.getBbox().getMinX() + ", " + (float) imageLayer.getBbox().getMaxY()); 197 lowerLeftValueLabel = new JLabel();172 JLabel lowerLeftValueLabel = new JLabel(); 198 173 lowerLeftValueLabel.setBounds(new Rectangle(30, 315, 133, 16)); 199 174 lowerLeftValueLabel.setHorizontalAlignment(SwingConstants.LEFT); 200 175 lowerLeftValueLabel.setText((float) imageLayer.getBbox().getMinX() + ", " + (float) imageLayer.getBbox().getMinY()); 201 upperRightValueLabel = new JLabel();176 JLabel upperRightValueLabel = new JLabel(); 202 177 upperRightValueLabel.setBounds(new Rectangle(210, 255, 138, 16)); 203 178 upperRightValueLabel.setHorizontalAlignment(SwingConstants.RIGHT); 204 179 upperRightValueLabel.setText((float) imageLayer.getBbox().getMaxX() + ", " + (float) imageLayer.getBbox().getMaxY()); 205 upperLeftValueLabel = new JLabel();180 JLabel upperLeftValueLabel = new JLabel(); 206 181 upperLeftValueLabel.setBounds(new Rectangle(30, 255, 133, 16)); 207 182 upperLeftValueLabel.setHorizontalAlignment(SwingConstants.LEFT); 208 183 upperLeftValueLabel.setText((float) imageLayer.getBbox().getMaxX() + ", " + (float) imageLayer.getBbox().getMinY()); 209 lowerRightLabel = new JLabel();184 JLabel lowerRightLabel = new JLabel(); 210 185 lowerRightLabel.setBounds(new Rectangle(287, 344, 74, 16)); 211 186 lowerRightLabel.setText("Lower Right"); 212 upperRightLabel = new JLabel();187 JLabel upperRightLabel = new JLabel(); 213 188 upperRightLabel.setBounds(new Rectangle(285, 225, 91, 16)); 214 189 upperRightLabel.setText("Upper Right"); 215 lowerLeftLabel = new JLabel();190 JLabel lowerLeftLabel = new JLabel(); 216 191 lowerLeftLabel.setBounds(new Rectangle(15, 345, 92, 16)); 217 192 lowerLeftLabel.setText("Lower Left"); 218 upperLeftLabel = new JLabel();193 JLabel upperLeftLabel = new JLabel(); 219 194 upperLeftLabel.setBounds(new Rectangle(15, 224, 91, 16)); 220 195 upperLeftLabel.setText("Upper Left"); 221 extentLabel = new JLabel();196 JLabel extentLabel = new JLabel(); 222 197 extentLabel.setBounds(new Rectangle(120, 195, 136, 16)); 223 198 extentLabel.setEnabled(false); 224 199 extentLabel.setHorizontalAlignment(SwingConstants.CENTER); 225 200 extentLabel.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED); 226 201 extentLabel.setText("Extent"); 227 crsValueLabel = new JLabel();202 JLabel crsValueLabel = new JLabel(); 228 203 crsValueLabel.setBounds(new Rectangle(150, 150, 226, 16)); 229 204 230 205 String crsDescription = ""; … … 235 210 } 236 211 crsValueLabel.setText(crsDescription + "(" + imageLayer.getBbox().getCoordinateReferenceSystem().getName().toString() + ")"); 237 212 238 crsLabel = new JLabel();213 JLabel crsLabel = new JLabel(); 239 214 crsLabel.setBounds(new Rectangle(15, 150, 118, 16)); 240 215 crsLabel.setText("Reference System"); 241 sizeValueLabel = new JLabel();216 JLabel sizeValueLabel = new JLabel(); 242 217 sizeValueLabel.setBounds(new Rectangle(150, 105, 226, 16)); 243 218 sizeValueLabel.setText(imageLayer.getImage().getHeight() + " x " + imageLayer.getImage().getWidth()); 244 sizeLabel = new JLabel();219 JLabel sizeLabel = new JLabel(); 245 220 sizeLabel.setBounds(new Rectangle(15, 105, 121, 16)); 246 221 sizeLabel.setText("Image size"); 247 imageFileValueLabel = new JLabel();222 JLabel imageFileValueLabel = new JLabel(); 248 223 imageFileValueLabel.setBounds(new Rectangle(150, 60, 226, 16)); 249 224 imageFileValueLabel.setText(imageLayer.getImageFile().getAbsolutePath()); 250 225 imageFileValueLabel.setToolTipText(imageLayer.getImageFile().getAbsolutePath()); 251 imageFileLabel = new JLabel();226 JLabel imageFileLabel = new JLabel(); 252 227 imageFileLabel.setBounds(new Rectangle(15, 60, 121, 16)); 253 228 imageFileLabel.setText("Image file"); 254 layerNameValueLabel = new JLabel();229 JLabel layerNameValueLabel = new JLabel(); 255 230 layerNameValueLabel.setBounds(new Rectangle(150, 15, 226, 16)); 256 231 layerNameValueLabel.setText(imageLayer.getName()); 257 layerNameLabel = new JLabel();232 JLabel layerNameLabel = new JLabel(); 258 233 layerNameLabel.setBounds(new Rectangle(15, 15, 121, 16)); 259 234 layerNameLabel.setText("Layer name"); 260 235 infoPanel = new JPanel(); … … 288 263 */ 289 264 private JPanel getCrsPanel() { 290 265 if (crsPanel == null) { 291 currentCRSValueLabel = new JLabel();266 JLabel currentCRSValueLabel = new JLabel(); 292 267 currentCRSValueLabel.setBounds(new Rectangle(78, 33, 297, 16)); 293 268 String crsDescription = "unknown"; 294 269 try { … … 298 273 } 299 274 currentCRSValueLabel.setText(crsDescription); 300 275 301 currentCRSLabel = new JLabel();276 JLabel currentCRSLabel = new JLabel(); 302 277 currentCRSLabel.setBounds(new Rectangle(15, 33, 52, 16)); 303 278 currentCRSLabel.setText("Current:"); 304 tabDescriptionLabel = new JLabel();279 JLabel tabDescriptionLabel = new JLabel(); 305 280 tabDescriptionLabel.setBounds(new Rectangle(15, 9, 361, 16)); 306 281 tabDescriptionLabel.setText("Set here the source reference system of the image"); 307 eastingFirstLabel = new JLabel();282 JLabel eastingFirstLabel = new JLabel(); 308 283 eastingFirstLabel.setBounds(new Rectangle(315, 210, 76, 46)); 309 284 eastingFirstLabel.setHorizontalTextPosition(SwingConstants.TRAILING); 310 285 eastingFirstLabel.setHorizontalAlignment(SwingConstants.CENTER); 311 286 eastingFirstLabel.setText("<html>Easting<br>first</html>"); 312 searchFieldLabel = new JLabel();287 JLabel searchFieldLabel = new JLabel(); 313 288 searchFieldLabel.setBounds(new Rectangle(298, 114, 84, 16)); 314 289 searchFieldLabel.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED); 315 290 searchFieldLabel.setHorizontalTextPosition(SwingConstants.TRAILING); … … 318 293 defaultCRSLabel = new JLabel(); 319 294 defaultCRSLabel.setBounds(new Rectangle(15, 89, 361, 16)); 320 295 defaultCRSLabel.setText(PluginOperations.defaultSourceCRSDescription); 321 defaultCRSDescriptorLabel = new JLabel();296 JLabel defaultCRSDescriptorLabel = new JLabel(); 322 297 defaultCRSDescriptorLabel.setBounds(new Rectangle(15, 63, 226, 16)); 323 298 defaultCRSDescriptorLabel.setText("Default Reference System:"); 324 299 crsPanel = new JPanel(); … … 372 347 @Override 373 348 public void keyTyped(KeyEvent e) { 374 349 375 for (Iterator<String> iterator = supportedCRS.iterator(); iterator.hasNext();) { 376 String type = iterator.next(); 350 for (String type : supportedCRS) { 377 351 if (type.contains(searchField.getText())) { 378 352 crsJList.setSelectedIndex(supportedCRS.indexOf(type)); 379 353 crsJList.ensureIndexIsVisible(supportedCRS.indexOf(type)); … … 408 382 */ 409 383 private JList<String> getCrsJList() { 410 384 if (crsJList == null) { 411 crsJList = new JList<>(supportedCRS );385 crsJList = new JList<>(supportedCRS.toArray(new String[0])); 412 386 crsJList.addListSelectionListener(new ListSelectionHandler()); 413 387 } 414 388 return crsJList; … … 496 470 ImportImagePlugin.pluginProps.setProperty("default_crs_eastingfirst", 497 471 "" + eastingFirstCheckBox.isSelected()); 498 472 ImportImagePlugin.pluginProps.setProperty("default_crs_srid", code); 499 try ( FileWriter fileWriter = new FileWriter(new File(ImportImagePlugin.PLUGINPROPERTIES_PATH))) {473 try (BufferedWriter fileWriter = Files.newBufferedWriter(Paths.get(ImportImagePlugin.PLUGINPROPERTIES_PATH))) { 500 474 ImportImagePlugin.pluginProps.store(fileWriter, null); 501 475 } 502 476 -
src/org/openstreetmap/josm/plugins/ImportImagePlugin/LoadImageAction.java
9 9 import javax.swing.JFileChooser; 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; 15 14 import org.openstreetmap.josm.gui.MainApplication; 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 /** 20 20 * Class extends JosmAction and creates a new image layer. … … 24 24 */ 25 25 public class LoadImageAction extends JosmAction { 26 26 27 private Logger logger = Logger.getLogger(LoadImageAction.class);28 29 27 /** 30 28 * Constructor... 31 29 */ … … 41 39 fc.setAcceptAllFileFilterUsed(false); 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; 57 56 } -
src/org/openstreetmap/josm/plugins/ImportImagePlugin/PluginOperations.java
1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.ImportImagePlugin; 3 3 4 import java.awt.geom.Rectangle2D;5 import java.awt.image.BufferedImage;6 import java.io.BufferedReader;7 import java.io.File;8 import java.io.FileNotFoundException;9 import java.io.FileReader;10 import java.io.IOException;11 import java.util.Arrays;12 import java.util.Iterator;13 import java.util.Properties;14 import java.util.Set;15 import java.util.Vector;16 17 import javax.imageio.ImageIO;18 19 import org.apache.log4j.Logger;20 4 import org.geotools.coverage.grid.GridCoverage2D; 21 5 import org.geotools.coverage.grid.GridCoverageFactory; 22 6 import org.geotools.coverage.processing.CoverageProcessor; … … 28 12 import org.geotools.util.factory.Hints; 29 13 import org.opengis.parameter.ParameterValueGroup; 30 14 import org.opengis.referencing.FactoryException; 31 import org.opengis.referencing.NoSuchAuthorityCodeException;32 15 import org.opengis.referencing.crs.CRSAuthorityFactory; 33 16 import org.opengis.referencing.crs.CoordinateReferenceSystem; 34 17 import org.opengis.util.InternationalString; 18 import org.openstreetmap.josm.tools.Logging; 35 19 20 import javax.imageio.ImageIO; 21 import java.awt.geom.Rectangle2D; 22 import java.awt.image.BufferedImage; 23 import java.io.BufferedReader; 24 import java.io.File; 25 import java.io.FileNotFoundException; 26 import java.io.IOException; 27 import java.nio.file.Files; 28 import java.util.Arrays; 29 import java.util.List; 30 import java.util.Properties; 31 import java.util.Set; 32 import java.util.Vector; 33 36 34 /** 37 35 * Class provides methods for resampling operations, IO and stores important data. 38 36 * … … 41 39 */ 42 40 public final class PluginOperations { 43 41 44 private static final Logger logger = Logger.getLogger(PluginOperations.class);45 46 42 // contains descriptions of all available CRS 47 static Vector<String> crsDescriptions;43 static List<String> crsDescriptions; 48 44 49 45 // the standard native CRS of user images 50 46 static CoordinateReferenceSystem defaultSourceCRS; … … 67 63 * Reprojects a GridCoverage to a given CRS. 68 64 */ 69 65 public static GridCoverage2D reprojectCoverage(GridCoverage2D coverage, 70 CoordinateReferenceSystem targetCrs) throws NoSuchAuthorityCodeException, FactoryException{66 CoordinateReferenceSystem targetCrs) { 71 67 72 68 // TODO: add category for NO_DATA values in coverage (transparency in image) 73 69 74 GridCoverage2D destination = null;70 GridCoverage2D destination; 75 71 76 72 CoverageProcessor processor = new CoverageProcessor(); 77 73 ParameterValueGroup resampleParams = processor.getOperation("Resample").getParameters(); … … 87 83 } 88 84 89 85 /** 90 * Creates a org.geotools.coverage.grid.GridCoverage2D from a given file. 86 * Creates a {@link GridCoverage2D} from a given file. 87 * @param file The file to read from 88 * @param refSys The reference system to use 89 * @param failIfNoPrjFile {@code true} if we need to fail if no projection file is found 90 * @throws IOException if the file could not be read 91 * @return The 2d grid coverage of the file 91 92 */ 92 93 public static GridCoverage2D createGridFromFile(File file, CoordinateReferenceSystem refSys, boolean failIfNoPrjFile) throws IOException { 93 94 94 GridCoverage2D coverage = null;95 GridCoverage2D coverage; 95 96 96 97 if (!file.exists()) throw new FileNotFoundException("File not found."); 97 98 98 String extension = null;99 String fileNameWithoutExt = null;99 String extension; 100 String fileNameWithoutExt; 100 101 int dotPos = file.getAbsolutePath().lastIndexOf("."); 101 102 extension = file.getAbsolutePath().substring(dotPos); 102 103 fileNameWithoutExt = file.getAbsolutePath().substring(0, dotPos); 103 104 104 105 /*------- switch for file type -----------*/ 105 if ( extension.equalsIgnoreCase(".tif") || extension.equalsIgnoreCase(".tiff")) {106 if (".tif".equalsIgnoreCase(extension) || ".tiff".equalsIgnoreCase(extension)) { 106 107 107 108 // try to read GeoTIFF: 108 109 try { … … 110 111 return coverage; 111 112 } catch (DataSourceException dse) { 112 113 if (!dse.getMessage().contains("Coordinate Reference System is not available")) { 113 dse.printStackTrace(); 114 Logging.error(dse); 115 } else { 116 Logging.trace(dse); 114 117 } 115 } catch (FactoryException facte) {116 logger.fatal("Error while reading from GeoTIFF:", facte);117 throw new IOException(facte);118 118 } 119 119 120 120 // file is no GeoTiff, searching for Worldfile and projection file: … … 121 121 String[] postfixes = {"wld", "tfw", "tifw"}; 122 122 // try to read Worldfile: 123 123 WorldFileReader tfwReader = null; 124 for ( int i = 0; i < postfixes.length; i++) {125 File prjFile = new File(fileNameWithoutExt + "." + postfix es[i]);124 for (String postfix : postfixes) { 125 File prjFile = new File(fileNameWithoutExt + "." + postfix); 126 126 if (prjFile.exists()) { 127 127 tfwReader = new WorldFileReader(prjFile); 128 128 } … … 137 137 refSys = readPrjFile(file); 138 138 if (refSys == null) { 139 139 if (failIfNoPrjFile) throw new IOException("No projection file found."); 140 logger.debug("no projection given, no projection file found; using unprojected file.");140 Logging.debug("no projection given, no projection file found; using unprojected file."); 141 141 } 142 142 } 143 143 … … 154 154 Envelope2D bbox = new Envelope2D(null, new Rectangle2D.Double(lowerLeft_x, lowerLeft_y, width, height)); 155 155 coverage = createGridCoverage(img, bbox, refSys); 156 156 157 } else if ( extension.equalsIgnoreCase(".jpg")158 || extension.equalsIgnoreCase(".jpeg")) {157 } else if (".jpg".equalsIgnoreCase(extension) 158 || ".jpeg".equalsIgnoreCase(extension)) { 159 159 String[] postfixes = {"wld", "jgw", "jpgw"}; 160 160 // try to read Worldfile: 161 161 WorldFileReader tfwReader = null; 162 for ( int i = 0; i < postfixes.length; i++) {163 File prjFile = new File(fileNameWithoutExt + "." + postfix es[i]);162 for (String postfix : postfixes) { 163 File prjFile = new File(fileNameWithoutExt + "." + postfix); 164 164 if (prjFile.exists()) { 165 165 tfwReader = new WorldFileReader(prjFile); 166 166 } … … 172 172 refSys = readPrjFile(file); 173 173 if (refSys == null) { 174 174 if (failIfNoPrjFile) throw new IOException("No projection file found."); 175 logger.debug("no projection given, no projection file found; using unprojected file.");175 Logging.debug("no projection given, no projection file found; using unprojected file."); 176 176 } 177 177 } 178 178 … … 186 186 Envelope2D bbox = new Envelope2D(null, new Rectangle2D.Double(lowerLeft_x, lowerLeft_y, width, height)); 187 187 coverage = createGridCoverage(img, bbox, refSys); 188 188 189 } else if ( extension.equalsIgnoreCase(".bmp")) {189 } else if (".bmp".equalsIgnoreCase(extension)) { 190 190 String[] postfixes = {"wld", "bmpw", "bpw"}; 191 191 // try to read Worldfile: 192 192 WorldFileReader tfwReader = null; 193 for ( int i = 0; i < postfixes.length; i++) {194 File prjFile = new File(fileNameWithoutExt + "." + postfix es[i]);193 for (String postfix : postfixes) { 194 File prjFile = new File(fileNameWithoutExt + "." + postfix); 195 195 if (prjFile.exists()) { 196 196 tfwReader = new WorldFileReader(prjFile); 197 197 } … … 203 203 refSys = readPrjFile(file); 204 204 if (refSys == null) { 205 205 if (failIfNoPrjFile) throw new IOException("No projection file found."); 206 logger.debug("no projection given, no projection file found; using unprojected file.");206 Logging.debug("no projection given, no projection file found; using unprojected file."); 207 207 } 208 208 } 209 209 … … 217 217 Envelope2D bbox = new Envelope2D(null, new Rectangle2D.Double(lowerLeft_x, lowerLeft_y, width, height)); 218 218 coverage = createGridCoverage(img, bbox, refSys); 219 219 220 } else if ( extension.equalsIgnoreCase(".png")) {220 } else if (".png".equalsIgnoreCase(extension)) { 221 221 222 222 String[] postfixes = {"wld", "pgw", "pngw"}; 223 223 // try to read Worldfile: 224 224 WorldFileReader tfwReader = null; 225 for ( int i = 0; i < postfixes.length; i++) {226 File prjFile = new File(fileNameWithoutExt + "." + postfix es[i]);225 for (String postfix : postfixes) { 226 File prjFile = new File(fileNameWithoutExt + "." + postfix); 227 227 if (prjFile.exists()) { 228 228 tfwReader = new WorldFileReader(prjFile); 229 229 } … … 235 235 refSys = readPrjFile(file); 236 236 if (refSys == null) { 237 237 if (failIfNoPrjFile) throw new IOException("No projection file found."); 238 logger.debug("no projection given, no projection file found; using unprojected file.");238 Logging.debug("no projection given, no projection file found; using unprojected file."); 239 239 } 240 240 } 241 241 … … 264 264 * @param file image file, not the real world file (will be searched) 265 265 */ 266 266 public static CoordinateReferenceSystem readPrjFile(File file) throws IOException { 267 CoordinateReferenceSystem refSys = null;267 CoordinateReferenceSystem refSys; 268 268 269 String prjFilename = null;269 String prjFilename; 270 270 int dotPos = file.getAbsolutePath().lastIndexOf("."); 271 271 prjFilename = file.getAbsolutePath().substring(0, dotPos) + ".prj"; 272 272 273 273 File prjFile = new File(prjFilename); 274 274 if (!prjFile.exists()) return null; 275 logger.debug("Loading .prj file: " + prjFile.getAbsolutePath());275 Logging.debug("Loading .prj file: " + prjFile.getAbsolutePath()); 276 276 277 try (BufferedReader br = new BufferedReader(new FileReader(prjFile))) {277 try (BufferedReader br = Files.newBufferedReader(prjFile.toPath())) { 278 278 StringBuilder sb = new StringBuilder(); 279 String content = null;279 String content; 280 280 while ((content = br.readLine()) != null) { 281 281 sb.append(content); 282 282 } 283 283 refSys = CRS.parseWKT(sb.toString().trim()); 284 284 } catch (FactoryException e) { 285 throw new IOException("Unable to parse prj-file: '" + prjFile.getName() + "'" );285 throw new IOException("Unable to parse prj-file: '" + prjFile.getName() + "'", e); 286 286 } 287 287 288 288 return refSys; … … 301 301 * 302 302 * @param refSys if delivered, the coverage will be forced to use this crs 303 303 */ 304 public static GridCoverage2D readGeoTiff(File file, CoordinateReferenceSystem refSys) throws IOException , FactoryException{305 GridCoverage2D coverage = null;304 public static GridCoverage2D readGeoTiff(File file, CoordinateReferenceSystem refSys) throws IOException { 305 GridCoverage2D coverage; 306 306 Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, true); 307 307 if (refSys != null) { 308 308 hints.put(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, refSys); … … 327 327 Set<String> supportedCodes = CRS.getSupportedCodes("EPSG"); 328 328 CRSAuthorityFactory fac = CRS.getAuthorityFactory(false); 329 329 330 for (Iterator<String> iterator = supportedCodes.iterator(); iterator.hasNext();) { 331 String string = iterator.next(); 330 for (String string : supportedCodes) { 332 331 try { 333 332 if ("WGS84(DD)".equals(string)) { 334 333 continue; … … 337 336 String description = desc.toString() + " [-EPSG:" + string + "-]"; 338 337 crsDescriptions.add(description); 339 338 if (defaultcrsString != null && defaultcrsString.equalsIgnoreCase("EPSG:" + string)) { 340 boolean isEastingFirst = Boolean. valueOf(pluginProps.getProperty("default_crs_eastingfirst"));339 boolean isEastingFirst = Boolean.parseBoolean(pluginProps.getProperty("default_crs_eastingfirst")); 341 340 defaultSourceCRS = CRS.decode("EPSG:" + string, isEastingFirst); 342 341 defaultSourceCRSDescription = description; 343 342 } 344 343 345 344 } catch (FactoryException e) { 346 logger.error("Error while loading EPSG data: " + e.getMessage()); 345 Logging.error("Error while loading EPSG data: " + e.getMessage()); 346 Logging.error(e); 347 347 } 348 348 } 349 349 } -
test/unit/org/openstreetmap/josm/plugins/ImportImagePlugin/GeoTiffReaderTest.java
1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.ImportImagePlugin; 3 3 4 import static org.junit.Assert.assertNotNull;5 6 4 import java.io.File; 7 5 import java.io.IOException; 8 6 import java.nio.file.DirectoryIteratorException; … … 14 12 import java.util.Collection; 15 13 16 14 import org.geotools.coverage.grid.GridCoverage2D; 17 import org.junit. Rule;18 import org.junit. Test;15 import org.junit.jupiter.api.Test; 16 import org.junit.jupiter.api.Timeout; 19 17 import org.openstreetmap.josm.TestUtils; 20 import org.openstreetmap.josm.testutils. JOSMTestRules;18 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 21 19 import org.openstreetmap.josm.tools.Logging; 22 20 21 import static org.junit.jupiter.api.Assertions.assertNotNull; 22 23 23 /** 24 24 * Test that some geotiff sample files can be read. 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(); 39 34 Logging.info("Testing reading file "+file.getPath()); … … 45 40 /** 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 */ 51 46 public static Collection<Path> listDataFiles(String ext) throws IOException { -
test/unit/org/openstreetmap/josm/plugins/ImportImagePlugin/ImageLayerTest.java
1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.ImportImagePlugin; 3 3 4 import static org.junit.Assert.assertEquals;5 import static org.junit.Assert.assertTrue;6 7 4 import java.io.File; 8 5 import java.io.InputStream; 9 6 10 import org.junit. Rule;11 import org.junit. Test;7 import org.junit.jupiter.api.Test; 8 import org.junit.jupiter.api.extension.RegisterExtension; 12 9 import org.openstreetmap.josm.TestUtils; 13 10 import org.openstreetmap.josm.gui.MainApplication; 14 11 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 15 12 import org.openstreetmap.josm.io.OsmReader; 16 13 import org.openstreetmap.josm.testutils.JOSMTestRules; 14 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 17 15 16 import static org.junit.jupiter.api.Assertions.assertEquals; 17 import static org.junit.jupiter.api.Assertions.assertTrue; 18 18 19 /** 19 20 * Test that some geotiff sample files can be read. 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 /** 31 33 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/14894">#14894</a> … … 32 34 * @throws Exception if an error occurs during reading 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 38 40 try (InputStream in = TestUtils.getRegressionDataStream(14894, "14894.osm")) {