Changeset 36385 in osm for applications/editors/josm/plugins
- Timestamp:
- 2025-02-07T15:20:40+01:00 (12 days ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr
- Files:
-
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/build.xml
r36344 r36385 16 16 <property name="plugin.stage" value="60"/> 17 17 <property name="plugin.requires" value="apache-commons;ejml;jts;geotools"/> 18 <property name="plugin.minimum.java.version" value="1 1"/>18 <property name="plugin.minimum.java.version" value="17"/> 19 19 20 20 <!-- ** include targets that all plugins have in common ** --> -
applications/editors/josm/plugins/cadastre-fr/pom.xml
r36344 r36385 29 29 <plugin.stage>60</plugin.stage> 30 30 <plugin.requires>apache-commons;ejml;jts;geotools</plugin.requires> 31 <plugin.minimum.java.version>11</plugin.minimum.java.version> 31 <java.lang.version>17</java.lang.version> 32 <plugin.minimum.java.version>${java.lang.version}</plugin.minimum.java.version> 32 33 </properties> 33 34 <dependencies> -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/CadastrePlugin.java
r35645 r36385 7 7 import static org.openstreetmap.josm.tools.I18n.tr; 8 8 9 import java.awt.event.ActionEvent;10 import java.awt.event.ActionListener;11 9 import java.awt.event.KeyEvent; 12 10 import java.io.File; … … 22 20 import javax.swing.JOptionPane; 23 21 import javax.swing.KeyStroke; 22 import javax.swing.WindowConstants; 24 23 25 24 import org.openstreetmap.josm.actions.ExtensionFileFilter; … … 178 177 179 178 // true if the checkbox "auto-sourcing" is set in the plugin menu 180 public static boolean autoSourcing = false;179 public static boolean autoSourcing; 181 180 182 181 // true when the plugin is first used, e.g. grab from WMS or download cache file 183 public static boolean pluginUsed = false;184 185 public static String cacheDir = null;186 187 public static boolean alterColors = false;188 189 public static boolean backgroundTransparent = false;182 public static boolean pluginUsed; 183 184 public static String cacheDir; 185 186 public static boolean alterColors; 187 188 public static boolean backgroundTransparent; 190 189 191 190 public static float transparency = 1.0f; 192 191 193 public static boolean drawBoundaries = false; 194 195 public static int imageWidth, imageHeight; 196 197 public static String grabLayers, grabStyles = null; 198 199 private static boolean menuEnabled = false; 192 public static boolean drawBoundaries; 193 194 public static int imageWidth; 195 public static int imageHeight; 196 197 public static String grabLayers; 198 public static String grabStyles; 199 200 private static boolean menuEnabled; 200 201 201 202 private static final String LAYER_BULDINGS = "CDIF:BATIMENT,CDIF:LS2"; … … 224 225 public CadastrePlugin(PluginInformation info) { 225 226 super(info); 226 Logging.info("Plugin gcadastre-fr v"+VERSION+" started...");227 Logging.info("Plugin cadastre-fr v"+VERSION+" started..."); 227 228 initCacheDir(); 228 229 … … 265 266 final JCheckBoxMenuItem menuSource = new JCheckBoxMenuItem(tr("Auto sourcing")); 266 267 menuSource.setSelected(autoSourcing); 267 menuSource.addActionListener(new ActionListener() { 268 @Override 269 public void actionPerformed(ActionEvent ev) { 270 Config.getPref().putBoolean("cadastrewms.autosourcing", menuSource.isSelected()); 271 autoSourcing = menuSource.isSelected(); 272 } 268 menuSource.addActionListener(ev -> { 269 Config.getPref().putBoolean("cadastrewms.autosourcing", menuSource.isSelected()); 270 autoSourcing = menuSource.isSelected(); 273 271 }); 274 272 … … 296 294 } 297 295 296 /** 297 * Update the configuration values 298 */ 298 299 public static void refreshConfiguration() { 299 300 source = checkSourceMillesime(); … … 309 310 } 310 311 String currentResolution = Config.getPref().get("cadastrewms.resolution", "high"); 311 if (currentResolution .equals("high")) {312 if ("high".equals(currentResolution)) { 312 313 imageWidth = 1000; imageHeight = 800; 313 } else if (currentResolution .equals("medium")) {314 } else if ("medium".equals(currentResolution)) { 314 315 imageWidth = 800; imageHeight = 600; 315 316 } else { … … 466 467 } catch (InterruptedException e) { 467 468 Logging.debug(e); 469 Thread.currentThread().interrupt(); 468 470 } 469 471 } … … 477 479 } catch (SecurityException e) { 478 480 Logging.warn(tr("Warning: failed to put option pane dialog always on top. Exception was: {0}", e.toString())); 481 Logging.trace(e); 479 482 } 480 483 } 481 484 dialog.setModal(true); 482 485 dialog.toFront(); 483 dialog.setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE);486 dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 484 487 } 485 488 … … 508 511 int currentYear = Calendar.getInstance().get(Calendar.YEAR); 509 512 String src = Config.getPref().get("cadastrewms.source", 510 "cadastre-dgi-fr source : Direction G \u00e9n\u00e9rale des Imp\u00f4ts - Cadastre. Mise\u00e0jour : AAAA");513 "cadastre-dgi-fr source : Direction Générale des Impôts - Cadastre. Mise à jour : AAAA"); 511 514 String srcYear = src.substring(src.lastIndexOf(" ")+1); 512 515 Integer year = null; … … 516 519 Logging.debug(e); 517 520 } 518 if ( srcYear.equals("AAAA") || (year != null && year < currentYear)) {521 if ("AAAA".equals(srcYear) || (year != null && year < currentYear)) { 519 522 Logging.info("Replace source year "+srcYear+" by current year "+currentYear); 520 523 src = src.substring(0, src.lastIndexOf(" ")+1)+currentYear; -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionBoundaries.java
r34668 r36385 22 22 23 23 private static final long serialVersionUID = 1L; 24 private WMSLayer wmsLayer = null;25 24 26 25 /** … … 33 32 @Override 34 33 public void actionPerformed(ActionEvent arg0) { 35 wmsLayer = WMSDownloadAction.getLayer(); 34 WMSLayer wmsLayer = WMSDownloadAction.getLayer(); 36 35 if (wmsLayer != null) { 37 36 if (wmsLayer.isRaster()) { -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionCancelGrab.java
r34668 r36385 17 17 private static final String NAME = marktr("Cancel current grab"); 18 18 19 private WMSLayer wmsLayer; 19 private final transient WMSLayer wmsLayer; 20 20 21 21 /** -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrabPlanImage.java
r34668 r36385 30 30 public static final String NAME = marktr("Georeference an image"); 31 31 32 private DownloadWMSPlanImage downloadWMSPlanImage; 33 private WMSLayer wmsLayer; 34 private RasterImageGeoreferencer rasterImageGeoreferencer; 32 private transient DownloadWMSPlanImage downloadWMSPlanImage; 33 private transient WMSLayer wmsLayer; 34 private transient RasterImageGeoreferencer rasterImageGeoreferencer; 35 35 36 36 /** … … 56 56 if (MainApplication.getMap() != null) { 57 57 if (CadastrePlugin.isCadastreProjection()) { 58 wmsLayer = new MenuActionNewLocation().addNewLayer(new ArrayList< WMSLayer>());58 wmsLayer = new MenuActionNewLocation().addNewLayer(new ArrayList<>()); 59 59 if (wmsLayer == null) return; 60 60 downloadWMSPlanImage = new DownloadWMSPlanImage(); … … 74 74 if (loadedFromCache) { 75 75 wmsLayer.invalidate(); 76 } else if (wmsLayer.getImages(). size() == 0) {76 } else if (wmsLayer.getImages().isEmpty()) { 77 77 // action canceled or image loaded from cache (and already georeferenced) 78 78 rasterImageGeoreferencer.actionInterrupted(); … … 90 90 } else { 91 91 rasterImageGeoreferencer.addListener(); 92 if (Config.getPref().getBoolean("cadastrewms.noImageCropping", false) == false)92 if (!Config.getPref().getBoolean("cadastrewms.noImageCropping", false)) 93 93 rasterImageGeoreferencer.startCropping(wmsLayer); 94 94 else -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionLoadFromCache.java
r34711 r36385 27 27 public class MenuActionLoadFromCache extends JosmAction { 28 28 private static final long serialVersionUID = 1L; 29 private static final String ERROR = marktr("Error"); 29 30 30 private static final String name= marktr("Load layer from cache");31 private static final String ACTION_NAME = marktr("Load layer from cache"); 31 32 32 33 /** … … 34 35 */ 35 36 public MenuActionLoadFromCache() { 36 super(tr( name), "cadastre_small",37 super(tr(ACTION_NAME), "cadastre_small", 37 38 tr("Load location from cache (only if cache is enabled)"), null, false, "cadastrefr/loadfromcache", true); 38 39 } … … 46 47 File[] files = fc.getSelectedFiles(); 47 48 int layoutZone = CadastrePlugin.getCadastreProjectionLayoutZone(); 48 nextFile:49 49 for (File file : files) { 50 50 if (file.exists()) { 51 51 String filename = file.getName(); 52 String ext = (filename.lastIndexOf('.') == -1) ? "" : filename.substring(filename.lastIndexOf('.')+1, filename.length()); 53 if ((ext.length() == 3 && ext.substring(0, CacheControl.C_LAMBERT_CC_9Z.length()).equals(CacheControl.C_LAMBERT_CC_9Z) && 54 !CadastrePlugin.isLambert_cc9()) 55 || (ext.length() == 4 && ext.substring(0, CacheControl.C_UTM20N.length()).equals(CacheControl.C_UTM20N) && 56 !CadastrePlugin.isUtm_france_dom()) 52 String ext = getExtension(filename); 53 if ((extIsLambertCC9Z(ext) && !CadastrePlugin.isLambert_cc9()) 54 || (extIsUTM20N(ext) && !CadastrePlugin.isUtm_france_dom()) 57 55 || (ext.length() == 1 && !CadastrePlugin.isLambert())) { 58 56 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 59 57 tr("{0} not allowed with the current projection", filename), 60 58 tr("Error"), JOptionPane.ERROR_MESSAGE); 61 continue;62 59 } else { 63 String location = filename.substring(0, filename.lastIndexOf('.')); 64 if (ext.length() == 3 && ext.substring(0, CacheControl.C_LAMBERT_CC_9Z.length()).equals(CacheControl.C_LAMBERT_CC_9Z)) 65 ext = ext.substring(2); 66 else if (ext.length() == 4 && ext.substring(0, CacheControl.C_UTM20N.length()).equals(CacheControl.C_UTM20N)) 67 ext = ext.substring(3); 68 // check the extension and its compatibility with current projection 69 try { 70 int cacheZone = Integer.parseInt(ext) - 1; 71 if (cacheZone >= 0 && cacheZone <= 9) { 72 if (cacheZone != layoutZone) { 73 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 74 tr("Cannot load cache {0} which is not compatible with current projection zone", filename), 75 tr("Error"), JOptionPane.ERROR_MESSAGE); 76 continue nextFile; 77 } else 78 Logging.info("Load cache " + filename); 79 } 80 } catch (NumberFormatException ex) { 81 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 82 tr("Selected file {0} is not a cache file from this plugin (invalid extension)", filename), 83 tr("Error"), JOptionPane.ERROR_MESSAGE); 84 continue nextFile; 85 } 86 // check if the selected cache is not already displayed 87 if (MainApplication.getMap() != null) { 88 for (Layer l : MainApplication.getLayerManager().getLayers()) { 89 if (l instanceof WMSLayer && l.getName().equals(location)) { 90 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 91 tr("The location {0} is already on screen. Cache not loaded.", filename), 92 tr("Error"), JOptionPane.ERROR_MESSAGE); 93 continue nextFile; 94 } 95 } 96 } 97 // create layer and load cache 98 WMSLayer wmsLayer = new WMSLayer("", "", Integer.parseInt(ext)-1); 99 if (wmsLayer.grabThread.getCacheControl().loadCache(file, layoutZone)) { 100 CadastrePlugin.addWMSLayer(wmsLayer); 101 } 60 actionPerformed(file, filename, ext, layoutZone); 102 61 } 103 62 } 104 63 } 64 } 65 66 private static String getExtension(String filename) { 67 return (filename.lastIndexOf('.') == -1) ? "" : filename.substring(filename.lastIndexOf('.')+1); 68 } 69 70 private static String simplifyExtension(String ext) { 71 if (extIsLambertCC9Z(ext)) 72 return ext.substring(2); 73 else if (extIsUTM20N(ext)) 74 return ext.substring(3); 75 return ext; 76 } 77 78 private static void actionPerformed(File file, String filename, String ext, int layoutZone) { 79 String location = filename.substring(0, filename.lastIndexOf('.')); 80 // check the extension and its compatibility with current projection 81 ext = simplifyExtension(ext); 82 try { 83 int cacheZone = Integer.parseInt(ext) - 1; 84 if (cacheZone >= 0 && cacheZone <= 9) { 85 if (cacheZone != layoutZone) { 86 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 87 tr("Cannot load cache {0} which is not compatible with current projection zone", filename), 88 tr(ERROR), JOptionPane.ERROR_MESSAGE); 89 return; 90 } else { 91 Logging.info("Load cache " + filename); 92 } 93 } 94 } catch (NumberFormatException ex) { 95 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 96 tr("Selected file {0} is not a cache file from this plugin (invalid extension)", filename), 97 tr(ERROR), JOptionPane.ERROR_MESSAGE); 98 return; 99 } 100 // check if the selected cache is not already displayed 101 if (MainApplication.getMap() != null) { 102 for (Layer l : MainApplication.getLayerManager().getLayers()) { 103 if (l instanceof WMSLayer && l.getName().equals(location)) { 104 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 105 tr("The location {0} is already on screen. Cache not loaded.", filename), 106 tr(ERROR), JOptionPane.ERROR_MESSAGE); 107 return; 108 } 109 } 110 } 111 // create layer and load cache 112 WMSLayer wmsLayer = new WMSLayer("", "", Integer.parseInt(ext)-1); 113 if (wmsLayer.grabThread.getCacheControl().loadCache(file, layoutZone)) { 114 CadastrePlugin.addWMSLayer(wmsLayer); 115 } 116 } 117 118 private static boolean extIsLambertCC9Z(String ext) { 119 return ext.length() == 3 && ext.startsWith(CacheControl.C_LAMBERT_CC_9Z); 120 } 121 122 private static boolean extIsUTM20N(String ext) { 123 return ext.length() == 4 && ext.startsWith(CacheControl.C_UTM20N); 105 124 } 106 125 -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionNewLocation.java
r34668 r36385 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.GridBagConstraints; 6 7 import java.awt.GridBagLayout; 7 8 import java.awt.event.ActionEvent; 8 9 import java.util.ArrayList; 10 import java.util.List; 11 import java.util.Locale; 9 12 10 13 import javax.swing.JComboBox; … … 30 33 31 34 private static final long serialVersionUID = 1L; 35 36 private static final String CADASTREWMS_CODE_DEPARTEMENT = "cadastrewms.codeDepartement"; 32 37 33 38 // CHECKSTYLE.OFF: LineLength … … 72 77 @Override 73 78 public void actionPerformed(ActionEvent e) { 74 WMSLayer wmsLayer = addNewLayer(new ArrayList< WMSLayer>());79 WMSLayer wmsLayer = addNewLayer(new ArrayList<>()); 75 80 if (wmsLayer != null) 76 81 DownloadWMSVectorImage.download(wmsLayer); 77 82 } 78 83 79 public WMSLayer addNewLayer(ArrayList<WMSLayer> existingLayers) { 80 String location = ""; 81 String codeDepartement = ""; 82 String codeCommune = ""; 84 public WMSLayer addNewLayer(List<WMSLayer> existingLayers) { 83 85 JLabel labelSectionNewLocation = new JLabel(tr("Add a new municipality layer")); 84 86 JPanel p = new JPanel(new GridBagLayout()); … … 93 95 } 94 96 inputDepartement.setToolTipText(tr("<html>Departement number (optional)</html>")); 95 if (!Config.getPref().get( "cadastrewms.codeDepartement").equals("")) {97 if (!"".equals(Config.getPref().get(CADASTREWMS_CODE_DEPARTEMENT))) { 96 98 for (int i = 0; i < departements.length; i += 2) { 97 if (departements[i].equals(Config.getPref().get( "cadastrewms.codeDepartement")))99 if (departements[i].equals(Config.getPref().get(CADASTREWMS_CODE_DEPARTEMENT))) 98 100 inputDepartement.setSelectedIndex(i/2); 99 101 } … … 101 103 p.add(labelSectionNewLocation, GBC.eol()); 102 104 p.add(labelLocation, GBC.std().insets(10, 0, 0, 0)); 103 p.add(inputTown, GBC.eol().fill(G BC.HORIZONTAL).insets(5, 0, 0, 5));105 p.add(inputTown, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5)); 104 106 p.add(labelDepartement, GBC.std().insets(10, 0, 0, 0)); 105 p.add(inputDepartement, GBC.eol().fill(G BC.HORIZONTAL).insets(5, 0, 0, 5));107 p.add(inputDepartement, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5)); 106 108 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null) { 107 109 private static final long serialVersionUID = 1L; … … 117 119 return null; 118 120 121 return getWmsLayer(inputTown, inputDepartement, existingLayers); 122 } 123 124 private static WMSLayer getWmsLayer(JTextField inputTown, JComboBox<String> inputDepartement, 125 List<WMSLayer> existingLayers) { 119 126 WMSLayer wmsLayer = null; 120 if (!inputTown.getText().equals("")) { 121 location = inputTown.getText().toUpperCase(); 122 codeDepartement = departements[inputDepartement.getSelectedIndex()*2]; 127 if (!"".equals(inputTown.getText())) { 128 String codeCommune = ""; 129 String location = inputTown.getText().toUpperCase(Locale.getDefault()); 130 String codeDepartement = departements[inputDepartement.getSelectedIndex()*2]; 123 131 Config.getPref().put("cadastrewms.location", location); 124 132 Config.getPref().put("cadastrewms.codeCommune", codeCommune); 125 Config.getPref().put( "cadastrewms.codeDepartement", codeDepartement);133 Config.getPref().put(CADASTREWMS_CODE_DEPARTEMENT, codeDepartement); 126 134 if (MainApplication.getMap() != null) { 127 135 for (Layer l : MainApplication.getLayerManager().getLayers()) { … … 137 145 CadastrePlugin.addWMSLayer(wmsLayer); 138 146 Logging.info("Add new layer with Location:" + inputTown.getText()); 139 } else if (existingLayers != null && existingLayers. size() > 0147 } else if (existingLayers != null && !existingLayers.isEmpty() 140 148 && MainApplication.getLayerManager().getActiveLayer() instanceof WMSLayer) { 141 149 wmsLayer = (WMSLayer) MainApplication.getLayerManager().getActiveLayer(); -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionRefineGeoRef.java
r34668 r36385 20 20 private static final String NAME = marktr("Refine georeferencing"); 21 21 22 private WMSLayer wmsLayer; 23 private RasterImageGeoreferencer rasterImageGeoreferencer; 22 private final transient WMSLayer wmsLayer; 23 private final transient RasterImageGeoreferencer rasterImageGeoreferencer; 24 24 25 25 /** -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionSaveRasterAs.java
r36176 r36385 9 9 import java.io.File; 10 10 import java.io.IOException; 11 import java.io.Serializable; 11 12 import java.util.Locale; 12 13 13 14 import javax.imageio.ImageIO; 15 import javax.imageio.ImageWriteParam; 14 16 import javax.swing.JFileChooser; 15 17 import javax.swing.filechooser.FileFilter; 16 18 19 import org.geotools.api.referencing.FactoryException; 17 20 import org.geotools.coverage.grid.GridCoverage2D; 18 21 import org.geotools.coverage.grid.GridCoverageFactory; … … 37 40 private static final String NAME = marktr("Save image as..."); 38 41 39 private final WMSLayer wmsLayer; 42 private final transient WMSLayer wmsLayer; 40 43 41 static class FiltrePng extends FileFilter { 44 static class FiltrePng extends FileFilter implements Serializable { 42 45 @Override 43 46 public boolean accept(File file) { … … 54 57 } 55 58 56 static class FiltreTiff extends FileFilter { 59 static class FiltreTiff extends FileFilter implements Serializable { 57 60 @Override 58 61 public boolean accept(File file) { … … 114 117 GeoTiffWriter gtwriter = new GeoTiffWriter(output); 115 118 GeoTiffWriteParams wp = new GeoTiffWriteParams(); 116 wp.setCompressionMode( GeoTiffWriteParams.MODE_EXPLICIT);119 wp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); 117 120 wp.setCompressionType("LZW"); 118 121 wp.setCompressionQuality(0.75F); … … 126 129 gtwriter.dispose(); 127 130 coverage.dispose(true); 128 } catch (Exception e) { 131 } catch (IOException | FactoryException e) { 129 132 Logging.error(e); 130 133 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/WMSDownloadAction.java
r34458 r36385 25 25 ArrayList<WMSLayer> existingWMSlayers = new ArrayList<>(); 26 26 if (MainApplication.getMap() != null) { 27 Layer activeLayer = MainApplication.getLayerManager().getActiveLayer(); 28 if (activeLayer instanceof WMSLayer) 29 return (WMSLayer) activeLayer; 30 for (Layer l : MainApplication.getLayerManager().getLayers()) { 31 if (l instanceof WMSLayer) { 32 existingWMSlayers.add((WMSLayer) l); 33 } 34 } 35 if (existingWMSlayers.size() == 1) 36 return existingWMSlayers.get(0); 37 if (existingWMSlayers.size() == 0) 38 return new MenuActionNewLocation().addNewLayer(existingWMSlayers); 39 if (Config.getPref().getBoolean("cadastrewms.autoFirstLayer", false)) { 40 return existingWMSlayers.get(0); 41 } else { 42 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 43 tr("More than one WMS layer present\nSelect one of them first, then retry")); 44 } 27 return getMapLayer(existingWMSlayers); 45 28 } else { 46 29 return new MenuActionNewLocation().addNewLayer(existingWMSlayers); 30 } 31 } 32 33 private static WMSLayer getMapLayer(ArrayList<WMSLayer> existingWMSlayers) { 34 Layer activeLayer = MainApplication.getLayerManager().getActiveLayer(); 35 if (activeLayer instanceof WMSLayer) 36 return (WMSLayer) activeLayer; 37 for (Layer l : MainApplication.getLayerManager().getLayers()) { 38 if (l instanceof WMSLayer) { 39 existingWMSlayers.add((WMSLayer) l); 40 } 41 } 42 if (existingWMSlayers.size() == 1) 43 return existingWMSlayers.get(0); 44 if (existingWMSlayers.isEmpty()) 45 return new MenuActionNewLocation().addNewLayer(existingWMSlayers); 46 if (Config.getPref().getBoolean("cadastrewms.autoFirstLayer", false)) { 47 return existingWMSlayers.get(0); 48 } else { 49 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 50 tr("More than one WMS layer present\nSelect one of them first, then retry")); 47 51 } 48 52 return null; -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/mapmode/Address.java
r35758 r36385 5 5 6 6 import java.awt.Cursor; 7 import java.awt.GridBagConstraints; 7 8 import java.awt.GridBagLayout; 8 9 import java.awt.Point; 9 10 import java.awt.Rectangle; 10 11 import java.awt.Toolkit; 11 import java.awt.event.ActionEvent;12 import java.awt.event.ActionListener;13 12 import java.awt.event.ComponentAdapter; 14 13 import java.awt.event.ComponentEvent; … … 39 38 import javax.swing.JRadioButton; 40 39 import javax.swing.JTextField; 41 import javax.swing.event.ChangeEvent;42 import javax.swing.event.ChangeListener;43 40 44 41 import org.openstreetmap.josm.actions.mapmode.MapMode; … … 70 67 public class Address extends MapMode { 71 68 69 private static final String MESSAGE_UNABLE_TO_PARSE_HOUSE_NUMBER = "Unable to parse house number \"{0}\""; 70 72 71 // perhaps make all these tags configurable in the future 73 private String tagHighway= "highway";74 private String tagHighwayName= "name";75 private String tagHouseNumber= "addr:housenumber";76 private String tagHouseStreet= "addr:street";77 private String tagBuilding= "building";78 private String relationAddrType= "associatedStreet";79 private String relationAddrName= "name";80 private String relationAddrStreetRole= "street";81 private String relationMemberHouse= "house";72 private static final String TAG_HIGHWAY = "highway"; 73 private static final String TAG_HIGHWAY_NAME = "name"; 74 private static final String TAG_HOUSE_NUMBER = "addr:housenumber"; 75 private static final String TAG_HOUSE_STREET = "addr:street"; 76 private static final String TAG_BUILDING = "building"; 77 private static final String RELATION_ADDR_TYPE = "associatedStreet"; 78 private static final String RELATION_ADDR_NAME = "name"; 79 private static final String RELATION_ADDR_STREET_ROLE = "street"; 80 private static final String RELATION_MEMBER_HOUSE = "house"; 82 81 83 82 private JRadioButton plusOne = new JRadioButton("+1", false); … … 134 133 MapView mv = MainApplication.getMap().mapView; 135 134 Point mousePos = e.getPoint(); 135 Node currentMouseNode = mv.getNearestNode(mousePos, OsmPrimitive::isSelectable); 136 if (currentMouseNode != null) { 137 mousePressedExistingNode(currentMouseNode); 138 } else { 139 mousePressedNoExistingNode(e, mousePos, mv); 140 } 141 } 142 143 private void mousePressedExistingNode(Node currentMouseNode) { 144 // click on existing node 145 setNewSelection(currentMouseNode); 146 String num = currentMouseNode.get(TAG_HOUSE_NUMBER); 147 if (num != null 148 && currentMouseNode.get(TAG_HOUSE_STREET) == null 149 && findWayInRelationAddr(currentMouseNode) == null 150 && !inputStreet.getText().isEmpty()) { 151 // house number already present but not linked to a street 152 Collection<Command> cmds = new LinkedList<>(); 153 addStreetNameOrRelation(currentMouseNode, cmds); 154 Command c = new SequenceCommand("Add node address", cmds); 155 UndoRedoHandler.getInstance().add(c); 156 setNewSelection(currentMouseNode); 157 } else { 158 if (num != null) { 159 try { 160 // add new address 161 Integer.parseInt(num); 162 inputNumber.setText(num); 163 applyInputNumberChange(); 164 } catch (NumberFormatException ex) { 165 Logging.warn(MESSAGE_UNABLE_TO_PARSE_HOUSE_NUMBER, num); 166 } 167 } 168 mousePressedExistingNode(currentMouseNode, num); 169 } 170 } 171 172 private void mousePressedExistingNode(Node currentMouseNode, String num) { 173 final boolean dontUseRelation = Config.getPref().getBoolean("cadastrewms.addr.dontUseRelation", false); 174 final String houseStreet = currentMouseNode.get(TAG_HOUSE_STREET); 175 if (houseStreet != null && dontUseRelation) { 176 inputStreet.setText(currentMouseNode.get(TAG_HOUSE_STREET)); 177 if (ctrl) { 178 Collection<Command> cmds = new LinkedList<>(); 179 addAddrToPrimitive(currentMouseNode, cmds); 180 if (num == null) 181 applyInputNumberChange(); 182 } 183 setSelectedWay(null); 184 } else if (houseStreet == null){ 185 // check if the node belongs to an associatedStreet relation 186 Way wayInRelationAddr = findWayInRelationAddr(currentMouseNode); 187 if (wayInRelationAddr == null) { 188 // node exists but doesn't carry address information : add tags like a new node 189 if (ctrl) { 190 applyInputNumberChange(); 191 } 192 Collection<Command> cmds = new LinkedList<>(); 193 addAddrToPrimitive(currentMouseNode, cmds); 194 } else { 195 inputStreet.setText(wayInRelationAddr.get(TAG_HIGHWAY_NAME)); 196 setSelectedWay(wayInRelationAddr); 197 } 198 } 199 } 200 201 private void mousePressedNoExistingNode(MouseEvent e, Point mousePos, MapView mv) { 136 202 List<Way> mouseOnExistingWays = new ArrayList<>(); 137 203 List<Way> mouseOnExistingBuildingWays = new ArrayList<>(); 138 Node currentMouseNode = mv.getNearestNode(mousePos, OsmPrimitive::isSelectable); 139 if (currentMouseNode != null) { 140 // click on existing node 141 setNewSelection(currentMouseNode); 142 String num = currentMouseNode.get(tagHouseNumber); 143 if (num != null 144 && currentMouseNode.get(tagHouseStreet) == null 145 && findWayInRelationAddr(currentMouseNode) == null 146 && !inputStreet.getText().isEmpty()) { 147 // house number already present but not linked to a street 148 Collection<Command> cmds = new LinkedList<>(); 149 addStreetNameOrRelation(currentMouseNode, cmds); 150 Command c = new SequenceCommand("Add node address", cmds); 151 UndoRedoHandler.getInstance().add(c); 152 setNewSelection(currentMouseNode); 204 List<WaySegment> wss = mv.getNearestWaySegments(mousePos, OsmPrimitive::isSelectable); 205 for (IWaySegment<Node, Way> ws : wss) { 206 if (ws.getWay().get(TAG_HIGHWAY) != null && ws.getWay().get(TAG_HIGHWAY_NAME) != null) 207 mouseOnExistingWays.add(ws.getWay()); 208 else if (ws.getWay().get(TAG_BUILDING) != null && ws.getWay().get(TAG_HOUSE_NUMBER) == null) 209 mouseOnExistingBuildingWays.add(ws.getWay()); 210 } 211 if (mouseOnExistingWays.size() == 1) { 212 // clicked on existing highway => set new street name 213 inputStreet.setText(mouseOnExistingWays.get(0).get(TAG_HIGHWAY_NAME)); 214 setSelectedWay(mouseOnExistingWays.get(0)); 215 inputNumber.setText(""); 216 setNewSelection(mouseOnExistingWays.get(0)); 217 } else if (mouseOnExistingWays.isEmpty()) { 218 mousePressedNoExistingNodeNoWays(e, mouseOnExistingBuildingWays); 219 } 220 } 221 222 private void mousePressedNoExistingNodeNoWays(MouseEvent e, List<Way> mouseOnExistingBuildingWays) { 223 // clicked a non highway and not a node => add the new address 224 if (inputStreet.getText().isEmpty() || inputNumber.getText().isEmpty()) { 225 Toolkit.getDefaultToolkit().beep(); 226 } else { 227 Collection<Command> cmds = new LinkedList<>(); 228 if (ctrl) { 229 applyInputNumberChange(); 230 } 231 if (tagPolygon.isSelected()) { 232 addAddrToPolygon(mouseOnExistingBuildingWays, cmds); 153 233 } else { 154 if (num != null) { 155 try { 156 // add new address 157 Integer.parseInt(num); 158 inputNumber.setText(num); 159 applyInputNumberChange(); 160 } catch (NumberFormatException ex) { 161 Logging.warn("Unable to parse house number \"" + num + "\""); 234 Node n = createNewNode(e, cmds); 235 addAddrToPrimitive(n, cmds); 236 } 237 } 238 } 239 240 private static Way findWayInRelationAddr(Node n) { 241 List<OsmPrimitive> l = n.getReferrers(); 242 for (OsmPrimitive osm : l) { 243 if (osm instanceof Relation && osm.hasKey("type") && osm.get("type").equals(RELATION_ADDR_TYPE)) { 244 for (RelationMember rm : ((Relation) osm).getMembers()) { 245 Way w = usableRelationRole(rm); 246 if (w != null) { 247 return w; 162 248 } 163 249 } 164 if (currentMouseNode.get(tagHouseStreet) != null) { 165 if (Config.getPref().getBoolean("cadastrewms.addr.dontUseRelation", false)) { 166 inputStreet.setText(currentMouseNode.get(tagHouseStreet)); 167 if (ctrl) { 168 Collection<Command> cmds = new LinkedList<>(); 169 addAddrToPrimitive(currentMouseNode, cmds); 170 if (num == null) 171 applyInputNumberChange(); 172 } 173 setSelectedWay((Way) null); 174 } 175 } else { 176 // check if the node belongs to an associatedStreet relation 177 Way wayInRelationAddr = findWayInRelationAddr(currentMouseNode); 178 if (wayInRelationAddr == null) { 179 // node exists but doesn't carry address information : add tags like a new node 180 if (ctrl) { 181 applyInputNumberChange(); 182 } 183 Collection<Command> cmds = new LinkedList<>(); 184 addAddrToPrimitive(currentMouseNode, cmds); 185 } else { 186 inputStreet.setText(wayInRelationAddr.get(tagHighwayName)); 187 setSelectedWay(wayInRelationAddr); 188 } 189 } 190 } 191 } else { 192 List<WaySegment> wss = mv.getNearestWaySegments(mousePos, OsmPrimitive::isSelectable); 193 for (IWaySegment<Node, Way> ws : wss) { 194 if (ws.getWay().get(tagHighway) != null && ws.getWay().get(tagHighwayName) != null) 195 mouseOnExistingWays.add(ws.getWay()); 196 else if (ws.getWay().get(tagBuilding) != null && ws.getWay().get(tagHouseNumber) == null) 197 mouseOnExistingBuildingWays.add(ws.getWay()); 198 } 199 if (mouseOnExistingWays.size() == 1) { 200 // clicked on existing highway => set new street name 201 inputStreet.setText(mouseOnExistingWays.get(0).get(tagHighwayName)); 202 setSelectedWay(mouseOnExistingWays.get(0)); 203 inputNumber.setText(""); 204 setNewSelection(mouseOnExistingWays.get(0)); 205 } else if (mouseOnExistingWays.isEmpty()) { 206 // clicked a non highway and not a node => add the new address 207 if (inputStreet.getText().isEmpty() || inputNumber.getText().isEmpty()) { 208 Toolkit.getDefaultToolkit().beep(); 209 } else { 210 Collection<Command> cmds = new LinkedList<>(); 211 if (ctrl) { 212 applyInputNumberChange(); 213 } 214 if (tagPolygon.isSelected()) { 215 addAddrToPolygon(mouseOnExistingBuildingWays, cmds); 216 } else { 217 Node n = createNewNode(e, cmds); 218 addAddrToPrimitive(n, cmds); 219 } 220 } 221 } 222 } 223 } 224 225 private Way findWayInRelationAddr(Node n) { 226 List<OsmPrimitive> l = n.getReferrers(); 227 for (OsmPrimitive osm : l) { 228 if (osm instanceof Relation && osm.hasKey("type") && osm.get("type").equals(relationAddrType)) { 229 for (RelationMember rm : ((Relation) osm).getMembers()) { 230 if (rm.getRole().equals(relationAddrStreetRole)) { 231 OsmPrimitive osp = rm.getMember(); 232 if (osp instanceof Way && osp.hasKey(tagHighwayName)) { 233 return (Way) osp; 234 } 235 } 236 } 250 } 251 } 252 return null; 253 } 254 255 private static Way usableRelationRole(RelationMember rm) { 256 if (rm.getRole().equals(RELATION_ADDR_STREET_ROLE)) { 257 OsmPrimitive osp = rm.getMember(); 258 if (osp instanceof Way && osp.hasKey(TAG_HIGHWAY_NAME)) { 259 return (Way) osp; 237 260 } 238 261 } … … 252 275 revertInputNumberChange(); 253 276 } catch (NumberFormatException ex) { 254 Logging.warn( "Unable to parse house number \"" +inputNumber.getText()+ "\"");277 Logging.warn(MESSAGE_UNABLE_TO_PARSE_HOUSE_NUMBER, inputNumber.getText()); 255 278 } 256 279 } 257 280 Map<String, String> tags = new HashMap<>(); 258 tags.put( tagHouseNumber, inputNumber.getText());281 tags.put(TAG_HOUSE_NUMBER, inputNumber.getText()); 259 282 cmds.add(new ChangePropertyCommand(OsmDataManager.getInstance().getEditDataSet(), Collections.singleton(osm), tags)); 260 283 addStreetNameOrRelation(osm, cmds); … … 265 288 setNewSelection(osm); 266 289 } catch (NumberFormatException ex) { 267 Logging.warn( "Unable to parse house number \"" +inputNumber.getText()+ "\"");268 } 269 } 270 271 private Relation findRelationAddr(Way w) { 290 Logging.warn(MESSAGE_UNABLE_TO_PARSE_HOUSE_NUMBER, inputNumber.getText()); 291 } 292 } 293 294 private static Relation findRelationAddr(Way w) { 272 295 List<OsmPrimitive> l = w.getReferrers(); 273 296 for (OsmPrimitive osm : l) { 274 if (osm instanceof Relation && osm.hasKey("type") && osm.get("type").equals( relationAddrType)) {297 if (osm instanceof Relation && osm.hasKey("type") && osm.get("type").equals(RELATION_ADDR_TYPE)) { 275 298 return (Relation) osm; 276 299 } … … 283 306 if (Config.getPref().getBoolean("cadastrewms.addr.dontUseRelation", false)) { 284 307 Map<String, String> tags = new HashMap<>(); 285 tags.put( tagHouseStreet, inputStreet.getText());308 tags.put(TAG_HOUSE_STREET, inputStreet.getText()); 286 309 cmds.add(new ChangePropertyCommand(ds, Arrays.asList(osm), tags)); 287 310 } else if (selectedWay != null) { … … 289 312 // add the node to its relation 290 313 if (selectedRelation != null) { 291 RelationMember rm = new RelationMember( relationMemberHouse, osm);314 RelationMember rm = new RelationMember(RELATION_MEMBER_HOUSE, osm); 292 315 Relation newRel = new Relation(selectedRelation); 293 316 newRel.addMember(rm); … … 296 319 // create new relation 297 320 Relation newRel = new Relation(); 298 newRel.put("type", relationAddrType);299 newRel.put( relationAddrName, selectedWay.get(tagHighwayName));300 newRel.addMember(new RelationMember( relationAddrStreetRole, selectedWay));301 newRel.addMember(new RelationMember( relationMemberHouse, osm));321 newRel.put("type", RELATION_ADDR_TYPE); 322 newRel.put(RELATION_ADDR_NAME, selectedWay.get(TAG_HIGHWAY_NAME)); 323 newRel.addMember(new RelationMember(RELATION_ADDR_STREET_ROLE, selectedWay)); 324 newRel.addMember(new RelationMember(RELATION_MEMBER_HOUSE, osm)); 302 325 cmds.add(new AddCommand(ds, newRel)); 303 326 } … … 355 378 Iterator<Pair<Node, Node>> i = segs.iterator(); 356 379 Pair<Node, Node> seg = i.next(); 357 EastNorth A = seg.a.getEastNorth(); 358 EastNorth B = seg.b.getEastNorth(); 380 EastNorth enA = seg.a.getEastNorth(); 381 EastNorth enB = seg.b.getEastNorth(); 359 382 seg = i.next(); 360 EastNorth C = seg.a.getEastNorth(); 361 EastNorth D = seg.b.getEastNorth(); 362 363 double u = det(B.east() - A.east(), B.north() - A.north(), C.east() - D.east(), C.north() - D.north()); 383 EastNorth enC = seg.a.getEastNorth(); 384 EastNorth enD = seg.b.getEastNorth(); 385 386 double u = det(enB.east() - enA.east(), enB.north() - enA.north(), enC.east() - enD.east(), enC.north() - enD.north()); 364 387 365 388 // Check for parallel segments and do nothing if they are … … 372 395 // if the segment is scaled to lenght 1 373 396 374 double q = det(B.north() - C.north(), B.east() - C.east(), D.north() - C.north(), D.east() - C.east()) / u; 397 double q = det(enB.north() - enC.north(), enB.east() - enC.east(), enD.north() - enC.north(), enD.east() - enC.east()) / u; 375 398 EastNorth intersection = new EastNorth( 376 B.east() + q * (A.east() - B.east()), 377 B.north() + q * (A.north() - B.north())); 399 enB.east() + q * (enA.east() - enB.east()), 400 enB.north() + q * (enA.north() - enB.north())); 378 401 379 402 int snapToIntersectionThreshold … … 390 413 // fall through 391 414 default: 392 EastNorth P = n.getEastNorth(); 415 EastNorth enP = n.getEastNorth(); 393 416 seg = segs.iterator().next(); 394 A = seg.a.getEastNorth(); 395 B = seg.b.getEastNorth(); 396 double a = P.distanceSq(B); 397 double b = P.distanceSq(A); 398 double c = A.distanceSq(B); 417 enA = seg.a.getEastNorth(); 418 enB = seg.b.getEastNorth(); 419 double a = enP.distanceSq(enB); 420 double b = enP.distanceSq(enA); 421 double c = enA.distanceSq(enB); 399 422 q = (a - b + c) / (2*c); 400 n.setEastNorth(new EastNorth(B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north()))); 423 n.setEastNorth(new EastNorth(enB.east() + q * (enA.east() - enB.east()), enB.north() + q * (enA.north() - enB.north()))); 401 424 } 402 425 } … … 462 485 JLabel street = new JLabel(tr("Street")); 463 486 p.add(number, GBC.std().insets(0, 0, 0, 0)); 464 p.add(inputNumber, GBC.eol().fill(G BC.HORIZONTAL).insets(5, 5, 0, 5));487 p.add(inputNumber, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 5, 0, 5)); 465 488 p.add(street, GBC.std().insets(0, 0, 0, 0)); 466 489 JPanel p2 = new JPanel(new GridBagLayout()); 467 490 inputStreet.setEditable(false); 468 p2.add(inputStreet, GBC.std().fill(G BC.HORIZONTAL).insets(5, 0, 0, 0));491 p2.add(inputStreet, GBC.std().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 0)); 469 492 p2.add(link, GBC.eol().insets(10, 0, 0, 0)); 470 p.add(p2, GBC.eol().fill(G BC.HORIZONTAL));493 p.add(p2, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 471 494 clearButton = new JButton("Clear"); 472 clearButton.addActionListener(new ActionListener() { 473 @Override 474 public void actionPerformed(ActionEvent e) { 475 inputNumber.setText(""); 476 inputStreet.setText(""); 477 setSelectedWay((Way) null); 478 } 495 clearButton.addActionListener(e -> { 496 inputNumber.setText(""); 497 inputStreet.setText(""); 498 setSelectedWay(null); 479 499 }); 480 500 ButtonGroup bgIncremental = new ButtonGroup(); … … 486 506 p.add(plusOne, GBC.std().insets(0, 0, 10, 0)); 487 507 tagPolygon.setSelected(Config.getPref().getBoolean("cadastrewms.addr.onBuilding", false)); 488 tagPolygon.addChangeListener(new ChangeListener() { 489 @Override 490 public void stateChanged(ChangeEvent arg0) { 491 Config.getPref().putBoolean("cadastrewms.addr.onBuilding", tagPolygon.isSelected()); 492 } 493 }); 494 p.add(tagPolygon, GBC.eol().fill(GBC.HORIZONTAL).insets(0, 0, 0, 0)); 508 tagPolygon.addChangeListener(ignored -> Config.getPref().putBoolean("cadastrewms.addr.onBuilding", tagPolygon.isSelected())); 509 p.add(tagPolygon, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(0, 0, 0, 0)); 495 510 p.add(minusTwo, GBC.std().insets(10, 0, 10, 0)); 496 511 p.add(plusTwo, GBC.std().insets(0, 0, 10, 0)); 497 p.add(clearButton, GBC.eol().fill(G BC.HORIZONTAL).insets(0, 0, 0, 0));512 p.add(clearButton, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(0, 0, 0, 0)); 498 513 499 514 final Object[] options = {}; … … 533 548 private void setSelectedWay(Way w) { 534 549 this.selectedWay = w; 535 if (w == null) { 536 link.setEnabled(false); 537 } else 538 link.setEnabled(true); 550 link.setEnabled(w != null); 539 551 link.repaint(); 540 552 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/mapmode/WMSAdjustAction.java
r33687 r36385 7 7 import java.awt.Cursor; 8 8 import java.awt.Graphics2D; 9 import java.awt.Toolkit;10 import java.awt.event.ActionEvent;11 9 import java.awt.event.MouseEvent; 12 import java.awt.event.MouseListener;13 import java.awt.event.MouseMotionListener;14 10 15 11 import javax.swing.JOptionPane; … … 24 20 import org.openstreetmap.josm.tools.Logging; 25 21 26 public class WMSAdjustAction extends MapMode implements 27 MouseListener, MouseMotionListener { 22 public class WMSAdjustAction extends MapMode { 28 23 29 24 private static final long serialVersionUID = 1L; 30 private WMSLayer modifiedLayer = null;25 private transient WMSLayer modifiedLayer; 31 26 private boolean rasterMoved; 32 27 private EastNorth prevEastNorth; 33 enum Mode { moveXY, moveZ, rotate}28 enum Mode {MOVE_XY, MOVE_Z, ROTATE} 34 29 35 private static Mode mode = null;36 private static EastNorth[] croppedRaster = new EastNorth[5] ;;30 private static Mode mode; 31 private static final EastNorth[] croppedRaster = new EastNorth[5]; 37 32 38 33 /** … … 95 90 return; 96 91 requestFocusInMapView(); 97 boolean ctrl = (e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0; 98 // boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0; 99 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 100 if (shift && !ctrl && modifiedLayer.isRaster()) 101 mode = Mode.moveZ; 102 else if (shift && ctrl && modifiedLayer.isRaster()) 103 mode = Mode.rotate; 104 else 105 mode = Mode.moveXY; 92 updateKeyModifiers(e); 93 if (shift && !ctrl && modifiedLayer.isRaster()) { 94 setMode(Mode.MOVE_Z); 95 } else if (shift && ctrl && modifiedLayer.isRaster()) { 96 setMode(Mode.ROTATE); 97 } else { 98 setMode(Mode.MOVE_XY); 99 } 106 100 rasterMoved = true; 107 101 prevEastNorth = MainApplication.getMap().mapView.getEastNorth(e.getX(), e.getY()); … … 111 105 @Override public void mouseDragged(MouseEvent e) { 112 106 EastNorth newEastNorth = MainApplication.getMap().mapView.getEastNorth(e.getX(), e.getY()); 113 if (mode == Mode. rotate) {114 rotateFrameOnly(prevEastNorth, newEastNorth); 107 if (mode == Mode.ROTATE) { 108 rotateFrameOnly(modifiedLayer, prevEastNorth, newEastNorth); 115 109 } else { 116 if (mode == Mode. moveXY) {110 if (mode == Mode.MOVE_XY) { 117 111 displace(prevEastNorth, newEastNorth); 118 } else if (mode == Mode. moveZ) {112 } else if (mode == Mode.MOVE_Z) { 119 113 resize(newEastNorth); 120 114 } … … 127 121 128 122 public static void paintAdjustFrames(Graphics2D g, final MapView mv) { 129 if (mode == Mode. rotate && croppedRaster != null) {123 if (mode == Mode.ROTATE) { 130 124 g.setColor(Color.red); 131 125 for (int i = 0; i < 4; i++) { … … 157 151 } 158 152 159 private void rotateFrameOnly(EastNorth start, EastNorth end) { 153 private static void rotateFrameOnly(WMSLayer modifiedLayer, EastNorth start, EastNorth end) { 160 154 if (start != null && end != null) { 161 155 EastNorth pivot = modifiedLayer.getRasterCenter(); … … 174 168 @Override 175 169 public void mouseReleased(MouseEvent e) { 176 if (mode == Mode. rotate) {170 if (mode == Mode.ROTATE) { 177 171 EastNorth newEastNorth = MainApplication.getMap().mapView.getEastNorth(e.getX(), e.getY()); 178 172 rotate(prevEastNorth, newEastNorth); … … 183 177 MainApplication.getMap().mapView.setCursor(Cursor.getDefaultCursor()); 184 178 prevEastNorth = null; 185 mode = null;179 setMode(null); 186 180 } 187 181 188 @Override 189 public void mouseEntered(MouseEvent e) { 190 } 191 192 @Override 193 public void mouseExited(MouseEvent e) { 194 } 195 196 @Override 197 public void mouseMoved(MouseEvent e) { 198 } 199 200 @Override public void mouseClicked(MouseEvent e) { 182 private static void setMode(Mode mode) { 183 WMSAdjustAction.mode = mode; 201 184 } 202 185 -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/upload/CheckSourceUploadHook.java
r34458 r36385 59 59 * @return true if one of keys is "source" 60 60 */ 61 private boolean tagSourceExist(OsmPrimitive osm) { 61 private static boolean tagSourceExist(OsmPrimitive osm) { 62 62 return osm.hasKey("source"); 63 63 } … … 68 68 * @param sel the list of elements added without a key "source" 69 69 */ 70 private void displaySource(Collection<OsmPrimitive> sel) { 70 private static void displaySource(Collection<OsmPrimitive> sel) { 71 71 if (!sel.isEmpty()) { 72 72 JPanel p = new JPanel(new GridBagLayout()); -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/download/CadastreDownloadSourcePanel.java
r35106 r36385 8 8 import java.awt.Dimension; 9 9 import java.awt.Font; 10 import java.awt.GridBagConstraints; 10 11 import java.awt.GridBagLayout; 11 12 import java.util.Arrays; … … 83 84 84 85 // adding the download tasks 85 add(new JLabel(tr("Objects:")), GBC.std().insets(5, 5, 1, 5).anchor(G BC.CENTER));86 add(new JLabel(tr("Objects:")), GBC.std().insets(5, 5, 1, 5).anchor(GridBagConstraints.CENTER)); 86 87 cbDownloadBuilding = createCheckBox(tr("building"), DOWNLOAD_BUILDING, 87 88 tr("Select to download buildings in the selected download area.")); -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/download/CadastreDownloadTask.java
r36021 r36385 63 63 try { 64 64 for (String id : CadastreAPI.getSheets(downloadArea)) { 65 String url = String.join("/", CADASTRE_URL, id.substring(0, id.startsWith("97") ? 3 : 2), id.substring(0, 5), "edigeo-"+id+".tar.bz2"); 65 String url = String.join("/", CADASTRE_URL, id.substring(0, id.startsWith("97") ? 3 : 2), 66 id.substring(0, 5), "edigeo-"+id+".tar.bz2"); 66 67 tasks.add(MainApplication.worker.submit(new InternalDownloadTask(settings, url, progressMonitor, zoomAfterDownload))); 67 68 } … … 75 76 try { 76 77 f.get(); 77 } catch ( InterruptedException |ExecutionException e) {78 } catch (ExecutionException e) { 78 79 Logging.error(e); 80 } catch (InterruptedException e) { 81 Logging.error(e); 82 Thread.currentThread().interrupt(); 79 83 } 80 84 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/download/CadastreServerReader.java
r36039 r36385 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.IOException; 6 7 import java.util.Objects; 7 8 8 9 import org.openstreetmap.josm.data.osm.DataSet; 9 10 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 11 import org.openstreetmap.josm.io.IllegalDataException; 10 12 import org.openstreetmap.josm.io.OsmServerReader; 11 13 import org.openstreetmap.josm.io.OsmTransferException; … … 35 37 progressMonitor.beginTask(tr("Contacting Server..."), 10); 36 38 return new EdigeoPciImporter().parseDataSet(url, data); 37 } catch (Exception e) { 39 } catch (IOException | IllegalDataException e) { 38 40 throw new OsmTransferException(e); 39 41 } finally { -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileVEC.java
r35185 r36385 354 354 @Override 355 355 void processRecord(EdigeoRecord r) { 356 switch(r.name) {357 case "REF":refPoint = safeGetEastNorth(r); break;358 default:356 if ("REF".equals(r.name)) { 357 refPoint = safeGetEastNorth(r); 358 } else { 359 359 super.processRecord(r); 360 360 } … … 558 558 List<OsmPrimitive> toPurge = new ArrayList<>(); 559 559 for (ObjectBlock obj : getObjects()) { 560 if ( !ignoredObjects.stream().anyMatch(p -> p.test(obj))) {560 if (ignoredObjects.stream().noneMatch(p -> p.test(obj))) { 561 561 OsmPrimitive p; 562 562 switch (obj.scdRef.kind) { 563 case POINT: p = fillPoint(ds, proj, obj, obj.getConstructionRelations() , obj.getSemanticRelations()); break;564 case LINE: p = fillLine(ds, proj, obj, obj.getConstructionRelations() , obj.getSemanticRelations()); break;565 case AREA: p = fillArea(ds, proj, obj, obj.getConstructionRelations() , obj.getSemanticRelations()); break;563 case POINT: p = fillPoint(ds, proj, obj, obj.getConstructionRelations()); break; 564 case LINE: p = fillLine(ds, proj, obj, obj.getConstructionRelations()); break; 565 case AREA: p = fillArea(ds, proj, obj, obj.getConstructionRelations()); break; 566 566 case COMPLEX: // TODO (not used in PCI) 567 567 default: throw new IllegalArgumentException(obj.toString()); … … 574 574 purged = toPurge.add(p); 575 575 if (p instanceof Relation) { 576 576 toPurge.addAll(((Relation) p).getMemberPrimitivesList()); 577 577 } 578 578 } else { … … 630 630 631 631 private static Node fillPoint(DataSet ds, Projection proj, ObjectBlock obj, 632 List<RelationBlock> constructionRelations , List<RelationBlock> semanticRelations) {632 List<RelationBlock> constructionRelations) { 633 633 assert constructionRelations.size() == 1 : constructionRelations; 634 634 List<NodeBlock> blocks = extract(NodeBlock.class, constructionRelations, RelationKind.IS_MADE_OF); … … 644 644 645 645 private static Way fillLine(DataSet ds, Projection proj, ObjectBlock obj, 646 List<RelationBlock> constructionRelations , List<RelationBlock> semanticRelations) {647 assert constructionRelations. size() >= 1: constructionRelations;646 List<RelationBlock> constructionRelations) { 647 assert !constructionRelations.isEmpty() : constructionRelations; 648 648 // Retrieve all arcs for the linear object 649 649 final List<ArcBlock> arcs = extract(ArcBlock.class, constructionRelations, RelationKind.IS_MADE_OF_ARC); 650 650 final double EPSILON = 1e-2; 651 assert arcs.size() >= 1;651 assert !arcs.isEmpty(); 652 652 // Some lines are made of several arcs, but they need to be sorted 653 653 if (arcs.size() > 1) { … … 693 693 694 694 private static OsmPrimitive fillArea(DataSet ds, Projection proj, ObjectBlock obj, 695 List<RelationBlock> constructionRelations , List<RelationBlock> semanticRelations) {696 assert constructionRelations. size() >= 1: constructionRelations;695 List<RelationBlock> constructionRelations) { 696 assert !constructionRelations.isEmpty() : constructionRelations; 697 697 List<FaceBlock> faces = extract(FaceBlock.class, constructionRelations, RelationKind.IS_MADE_OF); 698 assert faces.size() >= 1;698 assert !faces.isEmpty(); 699 699 if (faces.size() == 1) { 700 700 return addPrimitiveAndTags(ds, obj, faceToOsmPrimitive(ds, proj, faces.get(0))); … … 713 713 allArcs.addAll(extract(ArcBlock.class, face.getConstructionRelations(), RelationKind.HAS_FOR_LEFT_FACE)); 714 714 allArcs.addAll(extract(ArcBlock.class, face.getConstructionRelations(), RelationKind.HAS_FOR_RIGHT_FACE)); 715 assert allArcs. size() >= 1;715 assert !allArcs.isEmpty(); 716 716 if (allArcs.size() == 1) { 717 717 ArcBlock ab = allArcs.get(0); -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoLotFile.java
r34223 r36385 27 27 protected final ClassToInstancesMap<B> blocks = new MutableClassToInstancesMap<>(); 28 28 29 EdigeoLotFile(Lot lot, String subsetId, Path path) throws IOException{29 EdigeoLotFile(Lot lot, String subsetId, Path path) { 30 30 super(path); 31 31 this.lot = Objects.requireNonNull(lot, "lot"); -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/pci/EdigeoPciReader.java
r35194 r36385 20 20 import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; 21 21 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; 22 import org.apache.commons. compress.utils.IOUtils;22 import org.apache.commons.io.IOUtils; 23 23 import org.apache.commons.lang3.StringUtils; 24 24 import org.apache.commons.text.WordUtils; … … 40 40 */ 41 41 public class EdigeoPciReader extends AbstractReader { 42 private static final String SYM_ID = "SYM_id"; 43 private static final String HIGHWAY = "highway"; 44 private static final String TEX_ID = "TEX_id"; 45 private static final String TEX2_ID = "TEX2_id"; 46 private static final String IDU_ID = "IDU_id"; 42 47 43 48 private static final BiPredicate<CadastreDownloadData, OsmPrimitive> water = (x, p) -> !x.isDownloadWater(); … … 65 70 "CROIX_id", // Property boundary marker for Alsace and Moselle 66 71 "SYMBLIM_id"); // Common wall symbol 67 EdigeoFileVEC.addIgnoredObject( "SYM_id",72 EdigeoFileVEC.addIgnoredObject(SYM_ID, 68 73 "30", // Water stream arrow 69 74 "31", // Connecting arrows between parcelles and numbers … … 94 99 } 95 100 } 96 p.put( "highway", highwayValue);97 p.remove( "SYM_id");98 }, symbo, "SYM_id", "23"); // Path / Footway101 p.put(HIGHWAY, highwayValue); 102 p.remove(SYM_ID); 103 }, symbo, SYM_ID, "23"); // Path / Footway 99 104 EdigeoFileVEC.addObjectPostProcessor("24", symbo, "man_made=pipeline"); // Pipeline 100 105 EdigeoFileVEC.addObjectPostProcessor("25", symbo, "man_made=pipeline"); // Aqueduct … … 117 122 // Mapping TEX*_id => name (first step) 118 123 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 119 StringBu ffer sb = new StringBuffer(p.get("TEX_id").trim());120 p.remove( "TEX_id");121 for (String t : Arrays.asList( "TEX2_id", "TEX3_id", "TEX4_id", "TEX5_id", "TEX6_id", "TEX7_id", "TEX8_id", "TEX9_id")) {124 StringBuilder sb = new StringBuilder(p.get(TEX_ID).trim()); 125 p.remove(TEX_ID); 126 for (String t : Arrays.asList(TEX2_ID, "TEX3_id", "TEX4_id", "TEX5_id", "TEX6_id", "TEX7_id", "TEX8_id", "TEX9_id")) { 122 127 String v = p.get(t); 123 128 if (v == null) { … … 128 133 } 129 134 setName(p, sb.toString()); 130 }, (x, p) -> false, "TEX_id");135 }, (x, p) -> false, TEX_ID); 131 136 132 137 // Objects mapping 133 138 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 134 p.put( "highway", "road");139 p.put(HIGHWAY, "road"); 135 140 String name = p.get("name"); 136 141 if (name != null && name.contains(" ")) { 137 142 String[] words = name.split(" "); 138 if (!setCorrectHighway(p, words)) { 139 if (highways.values().stream().anyMatch(l -> l.contains(words[words.length - 1]))) { 140 String[] newWords = new String[words.length]; 141 newWords[0] = words[words.length - 1]; 142 System.arraycopy(words, 0, newWords, 1, words.length - 1); 143 p.put("name", String.join(" ", newWords)); 144 setCorrectHighway(p, newWords); 145 } 143 if (!setCorrectHighway(p, words) 144 && highways.values().stream().anyMatch(l -> l.contains(words[words.length - 1]))) { 145 String[] newWords = new String[words.length]; 146 newWords[0] = words[words.length - 1]; 147 System.arraycopy(words, 0, newWords, 1, words.length - 1); 148 p.put("name", String.join(" ", newWords)); 149 setCorrectHighway(p, newWords); 146 150 } 147 151 } … … 151 155 p.put("boundary", "administrative"); 152 156 p.put("admin_level", "8"); 153 p.put("ref:INSEE", "XX"+p.get( "IDU_id")); // TODO: find department number154 p.put("name", WordUtils.capitalizeFully(p.get( "TEX2_id")));155 p.remove( "IDU_id");156 p.remove( "TEX2_id");157 p.put("ref:INSEE", "XX"+p.get(IDU_ID)); // TODO: find department number 158 p.put("name", WordUtils.capitalizeFully(p.get(TEX2_ID))); 159 p.remove(IDU_ID); 160 p.remove(TEX2_ID); 157 161 }, o -> o.hasScdIdentifier("COMMUNE_id"), commu); 158 162 159 163 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 160 164 p.put("boundary", "cadastral"); 161 p.put("ref", p.get( "IDU_id"));162 p.remove( "IDU_id");165 p.put("ref", p.get(IDU_ID)); 166 p.remove(IDU_ID); 163 167 p.remove("ICL_id"); 164 168 p.remove("COAR_id"); … … 191 195 }, o -> o.hasScdIdentifier("LIEUDIT_id"), local); 192 196 193 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 194 p.remove("ORI_id"); 195 }, o -> o.hasScdIdentifier("TPOINT_id"), (x, p) -> false); 196 197 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 198 p.put("highway", "road"); 197 EdigeoFileVEC.addObjectPostProcessor((o, p) -> p.remove("ORI_id"), o -> o.hasScdIdentifier("TPOINT_id"), (x, p) -> false); 198 199 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 200 p.put(HIGHWAY, "road"); 199 201 p.put("area", "yes"); 200 202 }, o -> o.hasScdIdentifier("TRONROUTE_id"), symbo); 201 203 202 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 203 p.put("waterway", "riverbank"); 204 }, o -> o.hasScdIdentifier("TRONFLUV_id"), water); 204 EdigeoFileVEC.addObjectPostProcessor((o, p) -> p.put("waterway", "riverbank"), o -> o.hasScdIdentifier("TRONFLUV_id"), water); 205 205 206 206 // Mapping TEX*_id => name (last step) 207 for (String t : Arrays.asList( "TEX2_id", "TEX3_id", "TEX4_id", "TEX5_id", "TEX6_id", "TEX7_id", "TEX8_id", "TEX9_id")) {207 for (String t : Arrays.asList(TEX2_ID, "TEX3_id", "TEX4_id", "TEX5_id", "TEX6_id", "TEX7_id", "TEX8_id", "TEX9_id")) { 208 208 EdigeoFileVEC.addObjectPostProcessor((o, p) -> { 209 209 setName(p, p.get(t)); … … 239 239 private static void setName(OsmPrimitive p, String input) { 240 240 if (input != null) { 241 String name = input.replaceAll(" 241 String name = input.replaceAll(" {4}", " ").replaceAll(" {3}", " ").replaceAll(" {2}", " "); 242 242 if (name.matches("([A-Za-z] )+[A-Za-z]")) { 243 name = name.replace All(" ", "");244 } 245 if (name.length() > 2 && StringUtils.isAllUpperCase(name.replace All(" ", "").replaceAll("'", "").replaceAll("-", ""))) {243 name = name.replace(" ", ""); 244 } 245 if (name.length() > 2 && StringUtils.isAllUpperCase(name.replace(" ", "").replace("'", "").replace("-", ""))) { 246 246 name = WordUtils.capitalizeFully(name); 247 247 } … … 256 256 for (Entry<String, List<String>> e : highways.entrySet()) { 257 257 if (e.getValue().contains(type)) { 258 p.put( "highway", e.getKey());258 p.put(HIGHWAY, e.getKey()); 259 259 return true; 260 260 } … … 275 275 try { 276 276 return new EdigeoPciReader().parse(file.toPath(), data, instance); 277 } catch (IOException e) { 278 throw e; 279 } catch (Exception | AssertionError e) { 277 } catch (ReflectiveOperationException | AssertionError e) { 280 278 Logging.error(e); 281 279 throw new IOException(e); … … 295 293 TarArchiveEntry entry; 296 294 tmpDir = Files.createTempDirectory(Utils.getJosmTempDir().toPath(), "cadastre"); 297 while ((entry = tar.getNext TarEntry()) != null) {295 while ((entry = tar.getNextEntry()) != null) { 298 296 File file = tmpDir.resolve(entry.getName()).toFile(); 299 297 try (FileOutputStream out = new FileOutputStream(file)) { -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/utils/MutableClassToInstancesMap.java
r33649 r36385 11 11 */ 12 12 public class MutableClassToInstancesMap<B> extends HashMap<Class<? extends B>, List<B>> implements ClassToInstancesMap<B> { 13 private static final long serialVersionUID = 1L; 13 14 14 15 @Override -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/preferences/CadastrePreferenceSetting.java
r35308 r36385 2 2 package org.openstreetmap.josm.plugins.fr.cadastre.preferences; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 7 import java.awt.GridBagConstraints; 6 8 import java.awt.GridBagLayout; 7 import java.awt.event.ActionEvent;8 9 import java.awt.event.ActionListener; 9 10 … … 39 40 */ 40 41 public class CadastrePreferenceSetting extends DefaultTabPreferenceSetting { 41 42 static final int TRANS_MIN = 1; 43 static final int TRANS_MAX = 10; 44 private JSlider sliderTrans = new JSlider(JSlider.HORIZONTAL, TRANS_MIN, TRANS_MAX, TRANS_MAX); 45 46 private JTextField sourcing = new JTextField(20); 47 48 private JCheckBox alterColors = new JCheckBox(tr("Replace original background by JOSM background color.")); 49 50 private JCheckBox reversGrey = new JCheckBox(tr("Reverse grey colors (for black backgrounds).")); 51 52 private JCheckBox transparency = new JCheckBox(tr("Set background transparent.")); 53 54 private JCheckBox drawBoundaries = new JCheckBox(tr("Draw boundaries of downloaded data")); 55 56 private JComboBox<String> imageInterpolationMethod = new JComboBox<>(); 57 58 private JCheckBox disableImageCropping = new JCheckBox(tr("Disable image cropping during georeferencing.")); 59 60 private JCheckBox enableTableauAssemblage = new JCheckBox(tr("Use \"Tableau d''assemblage\"")); 61 62 private JCheckBox simplify2BitsColors = new JCheckBox(tr("Replace grey shades by white color only")); 63 64 private JCheckBox autoFirstLayer = new JCheckBox(tr("Select first WMS layer in list.")); 65 66 private JCheckBox dontUseRelation = new JCheckBox(tr("Don''t use relation for addresses (but \"addr:street\" on elements).")); 67 68 private JCheckBox mergeDataLayers = new JCheckBox(tr("Merge downloaded cadastre data layers together.")); 69 70 private JRadioButton grabMultiplier1 = new JRadioButton("", true); 71 72 private JRadioButton grabMultiplier2 = new JRadioButton("", true); 73 74 private JRadioButton grabMultiplier3 = new JRadioButton("", true); 75 76 private JRadioButton grabMultiplier4 = new JRadioButton("", true); 77 78 private JRadioButton crosspiece1 = new JRadioButton(tr("off")); 79 80 private JRadioButton crosspiece2 = new JRadioButton(tr("25 m")); 81 82 private JRadioButton crosspiece3 = new JRadioButton(tr("50 m")); 83 84 private JRadioButton crosspiece4 = new JRadioButton(tr("100 m")); 85 86 private JRadioButton grabRes1 = new JRadioButton(tr("high")); 87 private JRadioButton grabRes2 = new JRadioButton(tr("medium")); 88 private JRadioButton grabRes3 = new JRadioButton(tr("low")); 89 90 private JCheckBox layerLS3 = new JCheckBox(tr("water")); 91 private JCheckBox layerLS2 = new JCheckBox(tr("building")); 92 private JCheckBox layerLS1 = new JCheckBox(tr("symbol")); 93 private JCheckBox layerParcel = new JCheckBox(tr("parcel")); 94 private JCheckBox layerLabel = new JCheckBox(tr("parcel number")); 95 private JCheckBox layerNumero = new JCheckBox(tr("address")); 96 private JCheckBox layerLieudit = new JCheckBox(tr("locality")); 97 private JCheckBox layerSection = new JCheckBox(tr("section")); 98 private JCheckBox layerCommune = new JCheckBox(tr("commune")); 42 private static final int TRANS_MIN = 1; 43 private static final int TRANS_MAX = 10; 44 private static final String HIGH = marktr("high"); 45 private static final String MEDIUM = marktr("medium"); 46 private static final String LOW = marktr("low"); 47 private static final String CADASTREWMS_RESOLUTION = "cadastrewms.resolution"; 48 private static final String CADASTREWMS_IMAGE_INTERPOLATION = "cadastrewms.imageInterpolation"; 49 private static final String CADASTREWMS_SCALE = "cadastrewms.scale"; 50 private static final String CADASTREWMS_CROSSPIECES = "cadastrewms.crosspieces"; 51 private static final String PREFERENCES = "preferences"; 52 private final JSlider sliderTrans = new JSlider(SwingConstants.HORIZONTAL, TRANS_MIN, TRANS_MAX, TRANS_MAX); 53 54 private final JTextField sourcing = new JTextField(20); 55 56 private final JCheckBox alterColors = new JCheckBox(tr("Replace original background by JOSM background color.")); 57 58 private final JCheckBox reversGrey = new JCheckBox(tr("Reverse grey colors (for black backgrounds).")); 59 60 private final JCheckBox transparency = new JCheckBox(tr("Set background transparent.")); 61 62 private final JCheckBox drawBoundaries = new JCheckBox(tr("Draw boundaries of downloaded data")); 63 64 private final JComboBox<String> imageInterpolationMethod = new JComboBox<>(); 65 66 private final JCheckBox disableImageCropping = new JCheckBox(tr("Disable image cropping during georeferencing.")); 67 68 private final JCheckBox enableTableauAssemblage = new JCheckBox(tr("Use \"Tableau d''assemblage\"")); 69 70 private final JCheckBox simplify2BitsColors = new JCheckBox(tr("Replace grey shades by white color only")); 71 72 private final JCheckBox autoFirstLayer = new JCheckBox(tr("Select first WMS layer in list.")); 73 74 private final JCheckBox dontUseRelation = new JCheckBox(tr("Don''t use relation for addresses (but \"addr:street\" on elements).")); 75 76 private final JCheckBox mergeDataLayers = new JCheckBox(tr("Merge downloaded cadastre data layers together.")); 77 78 private final JRadioButton grabMultiplier1 = new JRadioButton("", true); 79 80 private final JRadioButton grabMultiplier2 = new JRadioButton("", true); 81 82 private final JRadioButton grabMultiplier3 = new JRadioButton("", true); 83 84 private final JRadioButton grabMultiplier4 = new JRadioButton("", true); 85 86 private final JRadioButton crosspiece1 = new JRadioButton(tr("off")); 87 88 private final JRadioButton crosspiece2 = new JRadioButton(tr("25 m")); 89 90 private final JRadioButton crosspiece3 = new JRadioButton(tr("50 m")); 91 92 private final JRadioButton crosspiece4 = new JRadioButton(tr("100 m")); 93 94 private final JRadioButton grabRes1 = new JRadioButton(tr(HIGH)); 95 private final JRadioButton grabRes2 = new JRadioButton(tr(MEDIUM)); 96 private final JRadioButton grabRes3 = new JRadioButton(tr(LOW)); 97 98 private final JCheckBox layerLS3 = new JCheckBox(tr("water")); 99 private final JCheckBox layerLS2 = new JCheckBox(tr("building")); 100 private final JCheckBox layerLS1 = new JCheckBox(tr("symbol")); 101 private final JCheckBox layerParcel = new JCheckBox(tr("parcel")); 102 private final JCheckBox layerLabel = new JCheckBox(tr("parcel number")); 103 private final JCheckBox layerNumero = new JCheckBox(tr("address")); 104 private final JCheckBox layerLieudit = new JCheckBox(tr("locality")); 105 private final JCheckBox layerSection = new JCheckBox(tr("section")); 106 private final JCheckBox layerCommune = new JCheckBox(tr("commune")); 99 107 100 108 public static final int DEFAULT_SQUARE_SIZE = 100; 101 private JTextField grabMultiplier4Size = new JTextField(5); 102 103 private JCheckBox enableCache = new JCheckBox(tr("Enable automatic caching.")); 109 private final JTextField grabMultiplier4Size = new JTextField(5); 110 111 private final JCheckBox enableCache = new JCheckBox(tr("Enable automatic caching.")); 104 112 105 113 public static final int DEFAULT_CACHE_SIZE = 0; // disabled by default 106 114 JLabel jLabelCacheSize = new JLabel(tr("Max. cache size (in MB)")); 107 private JTextField cacheSize = new JTextField(20); 115 private final JTextField cacheSize = new JTextField(20); 108 116 109 117 public static final String DEFAULT_RASTER_DIVIDER = "7"; 110 private JTextField rasterDivider = new JTextField(10); 118 private final JTextField rasterDivider = new JTextField(10); 111 119 112 120 static final int DEFAULT_CROSSPIECES = 0; … … 134 142 cadastrewms.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); 135 143 144 addGuiGenericOptions(cadastrewms); 145 // separator 146 addGuiSeparator(cadastrewms); 147 addGuiVectorImages(cadastrewms); 148 // separator 149 addGuiSeparator(cadastrewms); 150 addGuiRasterImages(cadastrewms); 151 // separator 152 addGuiSeparator(cadastrewms); 153 addGuiAutoCache(cadastrewms); 154 // option to fix the cache size(in MB) 155 addGuiCacheSize(cadastrewms); 156 // separator 157 addGuiSeparator(cadastrewms); 158 // option to select the first WMS layer 159 addGuiFirstWMSLayer(cadastrewms); 160 // separator 161 addGuiSeparator(cadastrewms); 162 addGuiUseRelationsInAddresses(cadastrewms); 163 // separator 164 addGuiSeparator(cadastrewms); 165 addGuiMergeDownloadedDataLayers(cadastrewms); 166 addGuiEndOfDialogScrollBar(cadastrewms, cadastrewmsMast); 167 } 168 169 private static void addGuiSeparator(JPanel cadastrewms) { 170 cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 171 } 172 173 private void addGuiGenericOptions(JPanel cadastrewms) { 136 174 // option to automatically set the source tag when uploading 137 175 sourcing.setText(CadastrePlugin.source); … … 139 177 JLabel jLabelSource = new JLabel(tr("Source")); 140 178 cadastrewms.add(jLabelSource, GBC.eop().insets(0, 0, 0, 0)); 141 cadastrewms.add(sourcing, GBC.eol().fill(G BC.HORIZONTAL).insets(5, 0, 0, 5));179 cadastrewms.add(sourcing, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5)); 142 180 143 181 // option to alter the original colors of the wms images … … 153 191 154 192 // option to enable transparency 155 transparency.addActionListener(new ActionListener() { 156 @Override 157 public void actionPerformed(ActionEvent e) { 158 sliderTrans.setEnabled(transparency.isSelected()); 159 } 160 }); 193 transparency.addActionListener(e -> sliderTrans.setEnabled(transparency.isSelected())); 161 194 transparency.setSelected(Config.getPref().getBoolean("cadastrewms.backgroundTransparent", false)); 162 195 transparency.setToolTipText(tr("Allows multiple layers stacking")); … … 172 205 sliderTrans.setPaintLabels(false); 173 206 sliderTrans.setEnabled(transparency.isSelected()); 174 cadastrewms.add(sliderTrans, GBC.eol().fill(G BC.HORIZONTAL).insets(20, 0, 250, 0));207 cadastrewms.add(sliderTrans, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(20, 0, 250, 0)); 175 208 176 209 // option to draw boundaries of downloaded data … … 189 222 bgResolution.add(grabRes2); 190 223 bgResolution.add(grabRes3); 191 String currentResolution = Config.getPref().get( "cadastrewms.resolution", "high");192 if(currentResolution.equals("high"))193 grabRes1.setSelected(true); 194 if (currentResolution.equals("medium"))195 grabRes2.setSelected(true);196 if (currentResolution.equals("low"))197 grabRes3.setSelected(true);224 String currentResolution = Config.getPref().get(CADASTREWMS_RESOLUTION, HIGH); 225 switch (currentResolution) { 226 case "high" -> grabRes1.setSelected(true); 227 case "medium" -> grabRes2.setSelected(true); 228 case "low" -> grabRes3.setSelected(true); 229 default -> { /* Do nothing */ } 230 } 198 231 cadastrewms.add(grabRes1, GBC.std().insets(5, 0, 5, 0)); 199 232 cadastrewms.add(grabRes2, GBC.std().insets(5, 0, 5, 0)); 200 cadastrewms.add(grabRes3, GBC.eol().fill(G BC.HORIZONTAL).insets(5, 5, 0, 5));233 cadastrewms.add(grabRes3, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 5, 0, 5)); 201 234 202 235 // option to select image zooming interpolation method … … 206 239 imageInterpolationMethod.addItem(tr("Bilinear (fast)")); 207 240 imageInterpolationMethod.addItem(tr("Bicubic (slow)")); 208 String savedImageInterpolationMethod = Config.getPref().get( "cadastrewms.imageInterpolation", "standard");209 if (savedImageInterpolationMethod .equals("bilinear"))241 String savedImageInterpolationMethod = Config.getPref().get(CADASTREWMS_IMAGE_INTERPOLATION, "standard"); 242 if ("bilinear".equals(savedImageInterpolationMethod)) { 210 243 imageInterpolationMethod.setSelectedIndex(1); 211 else if(savedImageInterpolationMethod.equals("bicubic"))244 } else if ("bicubic".equals(savedImageInterpolationMethod)) { 212 245 imageInterpolationMethod.setSelectedIndex(2); 213 else 246 } else 214 247 imageInterpolationMethod.setSelectedIndex(0); 215 cadastrewms.add(imageInterpolationMethod, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 200, 5)); 216 217 // separator 218 cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL)); 219 248 cadastrewms.add(imageInterpolationMethod, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 5, 200, 5)); 249 } 250 251 private void addGuiVectorImages(JPanel cadastrewms) { 220 252 // the vectorized images multiplier 221 253 JLabel jLabelScale = new JLabel(tr("Vector images grab multiplier:")); 222 254 cadastrewms.add(jLabelScale, GBC.std().insets(0, 5, 10, 0)); 223 255 ButtonGroup bgGrabMultiplier = new ButtonGroup(); 224 ActionListener multiplierActionListener = new ActionListener() { 225 @Override 226 public void actionPerformed(ActionEvent actionEvent) { 227 AbstractButton button = (AbstractButton) actionEvent.getSource(); 228 grabMultiplier4Size.setEnabled(button == grabMultiplier4); 229 } 230 }; 231 grabMultiplier1.setIcon(ImageProvider.get("preferences", "unsel_box_1")); 232 grabMultiplier1.setSelectedIcon(ImageProvider.get("preferences", "sel_box_1")); 256 ActionListener multiplierActionListener = actionEvent -> { 257 AbstractButton button = (AbstractButton) actionEvent.getSource(); 258 grabMultiplier4Size.setEnabled(button == grabMultiplier4); 259 }; 260 grabMultiplier1.setIcon(ImageProvider.get(PREFERENCES, "unsel_box_1")); 261 grabMultiplier1.setSelectedIcon(ImageProvider.get(PREFERENCES, "sel_box_1")); 233 262 grabMultiplier1.addActionListener(multiplierActionListener); 234 263 grabMultiplier1.setToolTipText(tr("Grab one image full screen")); 235 grabMultiplier2.setIcon(ImageProvider.get( "preferences", "unsel_box_2"));236 grabMultiplier2.setSelectedIcon(ImageProvider.get( "preferences", "sel_box_2"));264 grabMultiplier2.setIcon(ImageProvider.get(PREFERENCES, "unsel_box_2")); 265 grabMultiplier2.setSelectedIcon(ImageProvider.get(PREFERENCES, "sel_box_2")); 237 266 grabMultiplier2.addActionListener(multiplierActionListener); 238 267 grabMultiplier2.setToolTipText(tr("Grab smaller images (higher quality but use more memory)")); 239 grabMultiplier3.setIcon(ImageProvider.get( "preferences", "unsel_box_3"));240 grabMultiplier3.setSelectedIcon(ImageProvider.get( "preferences", "sel_box_3"));268 grabMultiplier3.setIcon(ImageProvider.get(PREFERENCES, "unsel_box_3")); 269 grabMultiplier3.setSelectedIcon(ImageProvider.get(PREFERENCES, "sel_box_3")); 241 270 grabMultiplier3.addActionListener(multiplierActionListener); 242 271 grabMultiplier3.setToolTipText(tr("Grab smaller images (higher quality but use more memory)")); 243 grabMultiplier4.setIcon(ImageProvider.get( "preferences", "unsel_box_4"));244 grabMultiplier4.setSelectedIcon(ImageProvider.get( "preferences", "sel_box_4"));272 grabMultiplier4.setIcon(ImageProvider.get(PREFERENCES, "unsel_box_4")); 273 grabMultiplier4.setSelectedIcon(ImageProvider.get(PREFERENCES, "sel_box_4")); 245 274 grabMultiplier4.addActionListener(multiplierActionListener); 246 275 grabMultiplier4.setToolTipText(tr("Fixed size square (default is 100m)")); … … 249 278 bgGrabMultiplier.add(grabMultiplier3); 250 279 bgGrabMultiplier.add(grabMultiplier4); 251 String currentScale = Config.getPref().get( "cadastrewms.scale", DEFAULT_GRAB_MULTIPLIER);280 String currentScale = Config.getPref().get(CADASTREWMS_SCALE, DEFAULT_GRAB_MULTIPLIER); 252 281 if (currentScale.equals(Scale.X1.value)) 253 282 grabMultiplier1.setSelected(true); … … 266 295 grabMultiplier4Size.setToolTipText(tr("Fixed size (from 25 to 1000 meters)")); 267 296 grabMultiplier4Size.setEnabled(currentScale.equals(Scale.SQUARE_100M.value)); 268 cadastrewms.add(grabMultiplier4Size, GBC.eol().fill(G BC.HORIZONTAL).insets(5, 5, 0, 5));297 cadastrewms.add(grabMultiplier4Size, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 5, 0, 5)); 269 298 270 299 // WMS layers selection … … 298 327 layerCommune.setToolTipText(tr("Municipality administrative borders.")); 299 328 cadastrewms.add(layerCommune, GBC.eop().insets(5, 0, 5, 0)); 300 301 // separator 302 cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL)); 303 329 } 330 331 private void addGuiRasterImages(JPanel cadastrewms) { 304 332 // for raster images (not vectorized), image grab divider (from 1 to 12) 305 333 String savedRasterDivider = Config.getPref().get("cadastrewms.rasterDivider", DEFAULT_RASTER_DIVIDER); … … 308 336 rasterDivider.setToolTipText("Raster image grab division, from 1 to 12; 12 is very high definition"); 309 337 cadastrewms.add(jLabelRasterDivider, GBC.std().insets(0, 5, 10, 0)); 310 cadastrewms.add(rasterDivider, GBC.eol().fill(G BC.HORIZONTAL).insets(5, 5, 200, 5));338 cadastrewms.add(rasterDivider, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 5, 200, 5)); 311 339 // option to disable image cropping during raster image georeferencing 312 340 disableImageCropping.setSelected(Config.getPref().getBoolean("cadastrewms.noImageCropping", false)); … … 325 353 cadastrewms.add(jLabelCrosspieces, GBC.std().insets(0, 0, 10, 0)); 326 354 ButtonGroup bgCrosspieces = new ButtonGroup(); 327 int crosspieces = getNumber( "cadastrewms.crosspieces", DEFAULT_CROSSPIECES);355 int crosspieces = getNumber(CADASTREWMS_CROSSPIECES, DEFAULT_CROSSPIECES); 328 356 if (crosspieces == 0) crosspiece1.setSelected(true); 329 357 if (crosspieces == 1) crosspiece2.setSelected(true); … … 337 365 cadastrewms.add(crosspiece2, GBC.std().insets(5, 0, 5, 0)); 338 366 cadastrewms.add(crosspiece3, GBC.std().insets(5, 0, 5, 0)); 339 cadastrewms.add(crosspiece4, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 0, 5)); 340 341 // separator 342 cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL)); 343 367 cadastrewms.add(crosspiece4, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 5, 0, 5)); 368 } 369 370 private void addGuiAutoCache(JPanel cadastrewms) { 344 371 // option to enable automatic caching 345 enableCache.addActionListener(new ActionListener() { 346 @Override 347 public void actionPerformed(ActionEvent e) { 348 jLabelCacheSize.setEnabled(enableCache.isSelected()); 349 cacheSize.setEnabled(enableCache.isSelected()); 350 } 372 enableCache.addActionListener(e -> { 373 jLabelCacheSize.setEnabled(enableCache.isSelected()); 374 cacheSize.setEnabled(enableCache.isSelected()); 351 375 }); 352 376 enableCache.setSelected(Config.getPref().getBoolean("cadastrewms.enableCaching", true)); 353 377 enableCache.setToolTipText(tr("Allows an automatic caching")); 354 378 cadastrewms.add(enableCache, GBC.eop().insets(0, 0, 0, 0)); 355 356 // option to fix the cache size(in MB) 379 } 380 381 private void addGuiCacheSize(JPanel cadastrewms) { 357 382 int size = getNumber("cadastrewms.cacheSize", DEFAULT_CACHE_SIZE); 358 383 cacheSize.setText(String.valueOf(size)); 359 384 cacheSize.setToolTipText(tr("Oldest files are automatically deleted when this size is exceeded")); 360 385 cadastrewms.add(jLabelCacheSize, GBC.std().insets(20, 0, 0, 0)); 361 cadastrewms.add(cacheSize, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 200, 5)); 362 363 // separator 364 cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL)); 365 366 // option to select the first WMS layer 386 cadastrewms.add(cacheSize, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 5, 200, 5)); 387 } 388 389 private void addGuiFirstWMSLayer(JPanel cadastrewms) { 367 390 autoFirstLayer.setSelected(Config.getPref().getBoolean("cadastrewms.autoFirstLayer", false)); 368 391 autoFirstLayer.setToolTipText(tr("Automatically selects the first WMS layer if multiple layers exist when grabbing.")); 369 392 cadastrewms.add(autoFirstLayer, GBC.eop().insets(0, 0, 0, 0)); 370 371 // separator 372 cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL)); 373 393 } 394 395 private void addGuiUseRelationsInAddresses(JPanel cadastrewms) { 374 396 // option to use or not relations in addresses 375 397 dontUseRelation.setSelected(Config.getPref().getBoolean("cadastrewms.addr.dontUseRelation", false)); 376 398 dontUseRelation.setToolTipText(tr("Enable this to use the tag \"add:street\" on nodes.")); 377 399 cadastrewms.add(dontUseRelation, GBC.eop().insets(0, 0, 0, 0)); 378 379 // separator 380 cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL)); 381 400 } 401 402 private void addGuiMergeDownloadedDataLayers(JPanel cadastrewms) { 382 403 // option to merge downloaded data layers 383 404 mergeDataLayers.setSelected(Config.getPref().getBoolean("cadastrewms.merge.data.layers", false)); 384 405 mergeDataLayers.setToolTipText(tr("Merge automatically all cadastre data layers in a single final layer.")); 385 406 cadastrewms.add(mergeDataLayers, GBC.eop().insets(0, 0, 0, 0)); 386 407 } 408 409 private static void addGuiEndOfDialogScrollBar(JPanel cadastrewms, JPanel cadastrewmsMast) { 387 410 // end of dialog, scroll bar 388 cadastrewms.add(Box.createVerticalGlue(), GBC.eol().fill(G BC.VERTICAL));411 cadastrewms.add(Box.createVerticalGlue(), GBC.eol().fill(GridBagConstraints.VERTICAL)); 389 412 JScrollPane scrollpane = new JScrollPane(cadastrewms); 390 413 scrollpane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); 391 cadastrewmsMast.add(scrollpane, GBC.eol().fill(G BC.BOTH));414 cadastrewmsMast.add(scrollpane, GBC.eol().fill(GridBagConstraints.BOTH)); 392 415 } 393 416 … … 402 425 Config.getPref().putBoolean("cadastrewms.drawBoundaries", drawBoundaries.isSelected()); 403 426 if (grabRes1.isSelected()) 404 Config.getPref().put( "cadastrewms.resolution", "high");427 Config.getPref().put(CADASTREWMS_RESOLUTION, HIGH); 405 428 else if (grabRes2.isSelected()) 406 Config.getPref().put( "cadastrewms.resolution", "medium");429 Config.getPref().put(CADASTREWMS_RESOLUTION, MEDIUM); 407 430 else if (grabRes3.isSelected()) 408 Config.getPref().put( "cadastrewms.resolution", "low");431 Config.getPref().put(CADASTREWMS_RESOLUTION, LOW); 409 432 if (imageInterpolationMethod.getSelectedIndex() == 2) 410 Config.getPref().put( "cadastrewms.imageInterpolation", "bicubic");433 Config.getPref().put(CADASTREWMS_IMAGE_INTERPOLATION, "bicubic"); 411 434 else if (imageInterpolationMethod.getSelectedIndex() == 1) 412 Config.getPref().put( "cadastrewms.imageInterpolation", "bilinear");435 Config.getPref().put(CADASTREWMS_IMAGE_INTERPOLATION, "bilinear"); 413 436 else 414 Config.getPref().put( "cadastrewms.imageInterpolation", "standard");437 Config.getPref().put(CADASTREWMS_IMAGE_INTERPOLATION, "standard"); 415 438 if (grabMultiplier1.isSelected()) 416 Config.getPref().put( "cadastrewms.scale", Scale.X1.toString());439 Config.getPref().put(CADASTREWMS_SCALE, Scale.X1.toString()); 417 440 else if (grabMultiplier2.isSelected()) 418 Config.getPref().put( "cadastrewms.scale", Scale.X2.toString());441 Config.getPref().put(CADASTREWMS_SCALE, Scale.X2.toString()); 419 442 else if (grabMultiplier3.isSelected()) 420 Config.getPref().put( "cadastrewms.scale", Scale.X3.toString());443 Config.getPref().put(CADASTREWMS_SCALE, Scale.X3.toString()); 421 444 else { 422 Config.getPref().put( "cadastrewms.scale", Scale.SQUARE_100M.toString());445 Config.getPref().put(CADASTREWMS_SCALE, Scale.SQUARE_100M.toString()); 423 446 try { 424 447 int squareSize = Integer.parseInt(grabMultiplier4Size.getText()); … … 448 471 Config.getPref().putBoolean("cadastrewms.useTA", enableTableauAssemblage.isSelected()); 449 472 Config.getPref().putBoolean("cadastrewms.raster2bitsColors", simplify2BitsColors.isSelected()); 450 if (crosspiece1.isSelected()) Config.getPref().put( "cadastrewms.crosspieces", "0");451 else if (crosspiece2.isSelected()) Config.getPref().put( "cadastrewms.crosspieces", "1");452 else if (crosspiece3.isSelected()) Config.getPref().put( "cadastrewms.crosspieces", "2");453 else if (crosspiece4.isSelected()) Config.getPref().put( "cadastrewms.crosspieces", "3");473 if (crosspiece1.isSelected()) Config.getPref().put(CADASTREWMS_CROSSPIECES, "0"); 474 else if (crosspiece2.isSelected()) Config.getPref().put(CADASTREWMS_CROSSPIECES, "1"); 475 else if (crosspiece3.isSelected()) Config.getPref().put(CADASTREWMS_CROSSPIECES, "2"); 476 else if (crosspiece4.isSelected()) Config.getPref().put(CADASTREWMS_CROSSPIECES, "3"); 454 477 Config.getPref().putBoolean("cadastrewms.enableCaching", enableCache.isSelected()); 455 478 … … 471 494 } 472 495 473 private int getNumber(String pref _parameter, int def_value) {496 private static int getNumber(String prefParameter, int defValue) { 474 497 try { 475 return Integer.parseInt(Config.getPref().get(pref _parameter, String.valueOf(def_value)));498 return Integer.parseInt(Config.getPref().get(prefParameter, String.valueOf(defValue))); 476 499 } catch (NumberFormatException e) { 477 return def _value;500 return defValue; 478 501 } 479 502 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/session/CadastreSessionExporter.java
r33638 r36385 3 3 4 4 import java.awt.Component; 5 import java.awt.GridBagConstraints; 5 6 import java.awt.GridBagLayout; 6 7 import java.io.IOException; … … 46 47 p.add(export, GBC.std()); 47 48 p.add(lbl, GBC.std()); 48 p.add(GBC.glue(1, 0), GBC.std().fill(G BC.HORIZONTAL));49 p.add(GBC.glue(1, 0), GBC.std().fill(GridBagConstraints.HORIZONTAL)); 49 50 return p; 50 51 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/session/CadastreSessionImporter.java
r33638 r36385 21 21 import org.openstreetmap.josm.plugins.fr.cadastre.wms.CacheControl; 22 22 import org.openstreetmap.josm.plugins.fr.cadastre.wms.WMSLayer; 23 import org.openstreetmap.josm.tools.JosmRuntimeException; 23 24 import org.w3c.dom.Element; 24 25 … … 61 62 62 63 } catch (XPathExpressionException e) { 63 throw new RuntimeException(e); 64 throw new JosmRuntimeException(e); 64 65 } 65 66 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CacheControl.java
r34668 r36385 13 13 import java.io.OutputStream; 14 14 import java.util.ArrayList; 15 import java.util.concurrent.Callable;16 15 import java.util.concurrent.locks.Lock; 17 16 import java.util.concurrent.locks.ReentrantLock; … … 116 115 File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + WMSFileExtension()); 117 116 if (file.exists()) { 118 int reply = GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() { 119 @Override 120 public Integer call() throws Exception { 121 JOptionPane pane = new JOptionPane( 122 tr("Location \"{0}\" found in cache.\n"+ 123 "Load cache first ?\n"+ 124 "(No = new cache)", wmsLayer.getName()), 125 JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null); 126 // this below is a temporary workaround to fix the "always on top" issue 127 JDialog dialog = pane.createDialog(MainApplication.getMainFrame(), tr("Select Feuille")); 128 CadastrePlugin.prepareDialog(dialog); 129 dialog.setVisible(true); 130 return (Integer) pane.getValue(); 131 // till here 132 } 117 int reply = GuiHelper.runInEDTAndWaitAndReturn(() -> { 118 JOptionPane pane = new JOptionPane( 119 tr("Location \"{0}\" found in cache.\n" + 120 "Load cache first ?\n" + 121 "(No = new cache)", wmsLayer.getName()), 122 JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null); 123 // this below is a temporary workaround to fix the "always on top" issue 124 JDialog dialog = pane.createDialog(MainApplication.getMainFrame(), tr("Select Feuille")); 125 CadastrePlugin.prepareDialog(dialog); 126 dialog.setVisible(true); 127 return (Integer) pane.getValue(); 128 // till here 133 129 }); 134 130 … … 159 155 try ( 160 156 FileInputStream fis = new FileInputStream(file); 161 ObjectInputStream ois = new ObjectInputStream(fis) ;157 ObjectInputStream ois = new ObjectInputStream(fis) 162 158 ) { 163 159 wmsLayer.setAssociatedFile(file); … … 232 228 } catch (InterruptedException e) { 233 229 Logging.error(e); 230 Thread.currentThread().interrupt(); 234 231 } 235 232 } -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CacheFileLambert4ZoneFilter.java
r34223 r36385 2 2 package org.openstreetmap.josm.plugins.fr.cadastre.wms; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 … … 10 11 11 12 public final class CacheFileLambert4ZoneFilter extends FileFilter { 13 private static final String LAMBERT_ZONE_MESSAGE = marktr("Lambert Zone {0} cache file (.{0})"); 12 14 13 15 /** … … 21 23 */ 22 24 public static final CacheFileLambert4ZoneFilter[] filters = { 23 new CacheFileLambert4ZoneFilter("1", tr( "Lambert Zone {0} cache file (.{0})", 1)),24 new CacheFileLambert4ZoneFilter("2", tr( "Lambert Zone {0} cache file (.{0})", 2)),25 new CacheFileLambert4ZoneFilter("3", tr( "Lambert Zone {0} cache file (.{0})", 3)),26 new CacheFileLambert4ZoneFilter("4", tr( "Lambert Zone {0} cache file (.{0})", 4))25 new CacheFileLambert4ZoneFilter("1", tr(LAMBERT_ZONE_MESSAGE, 1)), 26 new CacheFileLambert4ZoneFilter("2", tr(LAMBERT_ZONE_MESSAGE, 2)), 27 new CacheFileLambert4ZoneFilter("3", tr(LAMBERT_ZONE_MESSAGE, 3)), 28 new CacheFileLambert4ZoneFilter("4", tr(LAMBERT_ZONE_MESSAGE, 4)) 27 29 }; 28 30
Note:
See TracChangeset
for help on using the changeset viewer.