Ignore:
Timestamp:
2025-02-07T15:20:40+01:00 (12 days ago)
Author:
taylor.smock
Message:

Clean up a lot of lint issues in cadastre-fr

Location:
applications/editors/josm/plugins/cadastre-fr
Files:
26 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/build.xml

    r36344 r36385  
    1616    <property name="plugin.stage" value="60"/>
    1717    <property name="plugin.requires" value="apache-commons;ejml;jts;geotools"/>
    18     <property name="plugin.minimum.java.version" value="11"/>
     18    <property name="plugin.minimum.java.version" value="17"/>
    1919
    2020    <!-- ** include targets that all plugins have in common ** -->
  • applications/editors/josm/plugins/cadastre-fr/pom.xml

    r36344 r36385  
    2929        <plugin.stage>60</plugin.stage>
    3030        <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>
    3233    </properties>
    3334    <dependencies>
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/CadastrePlugin.java

    r35645 r36385  
    77import static org.openstreetmap.josm.tools.I18n.tr;
    88
    9 import java.awt.event.ActionEvent;
    10 import java.awt.event.ActionListener;
    119import java.awt.event.KeyEvent;
    1210import java.io.File;
     
    2220import javax.swing.JOptionPane;
    2321import javax.swing.KeyStroke;
     22import javax.swing.WindowConstants;
    2423
    2524import org.openstreetmap.josm.actions.ExtensionFileFilter;
     
    178177
    179178    // true if the checkbox "auto-sourcing" is set in the plugin menu
    180     public static boolean autoSourcing = false;
     179    public static boolean autoSourcing;
    181180
    182181    // 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;
    190189
    191190    public static float transparency = 1.0f;
    192191
    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;
    200201
    201202    private static final String LAYER_BULDINGS = "CDIF:BATIMENT,CDIF:LS2";
     
    224225    public CadastrePlugin(PluginInformation info) {
    225226        super(info);
    226         Logging.info("Pluging cadastre-fr v"+VERSION+" started...");
     227        Logging.info("Plugin cadastre-fr v"+VERSION+" started...");
    227228        initCacheDir();
    228229
     
    265266            final JCheckBoxMenuItem menuSource = new JCheckBoxMenuItem(tr("Auto sourcing"));
    266267            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();
    273271            });
    274272
     
    296294    }
    297295
     296    /**
     297     * Update the configuration values
     298     */
    298299    public static void refreshConfiguration() {
    299300        source = checkSourceMillesime();
     
    309310        }
    310311        String currentResolution = Config.getPref().get("cadastrewms.resolution", "high");
    311         if (currentResolution.equals("high")) {
     312        if ("high".equals(currentResolution)) {
    312313            imageWidth = 1000; imageHeight = 800;
    313         } else if (currentResolution.equals("medium")) {
     314        } else if ("medium".equals(currentResolution)) {
    314315            imageWidth = 800; imageHeight = 600;
    315316        } else {
     
    466467        } catch (InterruptedException e) {
    467468            Logging.debug(e);
     469            Thread.currentThread().interrupt();
    468470        }
    469471    }
     
    477479            } catch (SecurityException e) {
    478480                Logging.warn(tr("Warning: failed to put option pane dialog always on top. Exception was: {0}", e.toString()));
     481                Logging.trace(e);
    479482            }
    480483        }
    481484        dialog.setModal(true);
    482485        dialog.toFront();
    483         dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
     486        dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    484487    }
    485488
     
    508511        int currentYear = Calendar.getInstance().get(Calendar.YEAR);
    509512        String src = Config.getPref().get("cadastrewms.source",
    510             "cadastre-dgi-fr source : Direction G\u00e9n\u00e9rale des Imp\u00f4ts - Cadastre. Mise \u00e0 jour : AAAA");
     513            "cadastre-dgi-fr source : Direction Générale des Impôts - Cadastre. Mise à jour : AAAA");
    511514        String srcYear = src.substring(src.lastIndexOf(" ")+1);
    512515        Integer year = null;
     
    516519            Logging.debug(e);
    517520        }
    518         if (srcYear.equals("AAAA") || (year != null && year < currentYear)) {
     521        if ("AAAA".equals(srcYear) || (year != null && year < currentYear)) {
    519522            Logging.info("Replace source year "+srcYear+" by current year "+currentYear);
    520523            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  
    2222
    2323    private static final long serialVersionUID = 1L;
    24     private WMSLayer wmsLayer = null;
    2524
    2625    /**
     
    3332    @Override
    3433    public void actionPerformed(ActionEvent arg0) {
    35         wmsLayer = WMSDownloadAction.getLayer();
     34        WMSLayer wmsLayer = WMSDownloadAction.getLayer();
    3635        if (wmsLayer != null) {
    3736            if (wmsLayer.isRaster()) {
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionCancelGrab.java

    r34668 r36385  
    1717    private static final String NAME = marktr("Cancel current grab");
    1818
    19     private WMSLayer wmsLayer;
     19    private final transient WMSLayer wmsLayer;
    2020
    2121    /**
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionGrabPlanImage.java

    r34668 r36385  
    3030    public static final String NAME = marktr("Georeference an image");
    3131
    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;
    3535
    3636    /**
     
    5656        if (MainApplication.getMap() != null) {
    5757            if (CadastrePlugin.isCadastreProjection()) {
    58                 wmsLayer = new MenuActionNewLocation().addNewLayer(new ArrayList<WMSLayer>());
     58                wmsLayer = new MenuActionNewLocation().addNewLayer(new ArrayList<>());
    5959                if (wmsLayer == null) return;
    6060                downloadWMSPlanImage = new DownloadWMSPlanImage();
     
    7474        if (loadedFromCache) {
    7575            wmsLayer.invalidate();
    76         } else if (wmsLayer.getImages().size() == 0) {
     76        } else if (wmsLayer.getImages().isEmpty()) {
    7777            // action canceled or image loaded from cache (and already georeferenced)
    7878            rasterImageGeoreferencer.actionInterrupted();
     
    9090            } else {
    9191                rasterImageGeoreferencer.addListener();
    92                 if (Config.getPref().getBoolean("cadastrewms.noImageCropping", false) == false)
     92                if (!Config.getPref().getBoolean("cadastrewms.noImageCropping", false))
    9393                    rasterImageGeoreferencer.startCropping(wmsLayer);
    9494                else
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionLoadFromCache.java

    r34711 r36385  
    2727public class MenuActionLoadFromCache extends JosmAction {
    2828    private static final long serialVersionUID = 1L;
     29    private static final String ERROR = marktr("Error");
    2930
    30     private static final String name = marktr("Load layer from cache");
     31    private static final String ACTION_NAME = marktr("Load layer from cache");
    3132
    3233    /**
     
    3435     */
    3536    public MenuActionLoadFromCache() {
    36         super(tr(name), "cadastre_small",
     37        super(tr(ACTION_NAME), "cadastre_small",
    3738                tr("Load location from cache (only if cache is enabled)"), null, false, "cadastrefr/loadfromcache", true);
    3839    }
     
    4647        File[] files = fc.getSelectedFiles();
    4748        int layoutZone = CadastrePlugin.getCadastreProjectionLayoutZone();
    48         nextFile:
    4949        for (File file : files) {
    5050            if (file.exists()) {
    5151                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())
    5755                    || (ext.length() == 1 && !CadastrePlugin.isLambert())) {
    5856                        JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
    5957                                tr("{0} not allowed with the current projection", filename),
    6058                                tr("Error"), JOptionPane.ERROR_MESSAGE);
    61                         continue;
    6259                } 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);
    10261                }
    10362            }
    10463        }
     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);
    105124    }
    106125
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionNewLocation.java

    r34668 r36385  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.GridBagConstraints;
    67import java.awt.GridBagLayout;
    78import java.awt.event.ActionEvent;
    89import java.util.ArrayList;
     10import java.util.List;
     11import java.util.Locale;
    912
    1013import javax.swing.JComboBox;
     
    3033
    3134    private static final long serialVersionUID = 1L;
     35
     36    private static final String CADASTREWMS_CODE_DEPARTEMENT = "cadastrewms.codeDepartement";
    3237
    3338    // CHECKSTYLE.OFF: LineLength
     
    7277    @Override
    7378    public void actionPerformed(ActionEvent e) {
    74         WMSLayer wmsLayer = addNewLayer(new ArrayList<WMSLayer>());
     79        WMSLayer wmsLayer = addNewLayer(new ArrayList<>());
    7580        if (wmsLayer != null)
    7681            DownloadWMSVectorImage.download(wmsLayer);
    7782    }
    7883
    79     public WMSLayer addNewLayer(ArrayList<WMSLayer> existingLayers) {
    80         String location = "";
    81         String codeDepartement = "";
    82         String codeCommune = "";
     84    public WMSLayer addNewLayer(List<WMSLayer> existingLayers) {
    8385        JLabel labelSectionNewLocation = new JLabel(tr("Add a new municipality layer"));
    8486        JPanel p = new JPanel(new GridBagLayout());
     
    9395        }
    9496        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))) {
    9698            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)))
    98100                    inputDepartement.setSelectedIndex(i/2);
    99101            }
     
    101103        p.add(labelSectionNewLocation, GBC.eol());
    102104        p.add(labelLocation, GBC.std().insets(10, 0, 0, 0));
    103         p.add(inputTown, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
     105        p.add(inputTown, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
    104106        p.add(labelDepartement, GBC.std().insets(10, 0, 0, 0));
    105         p.add(inputDepartement, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
     107        p.add(inputDepartement, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
    106108        JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null) {
    107109            private static final long serialVersionUID = 1L;
     
    117119            return null;
    118120
     121        return getWmsLayer(inputTown, inputDepartement, existingLayers);
     122    }
     123
     124    private static WMSLayer getWmsLayer(JTextField inputTown, JComboBox<String> inputDepartement,
     125                                        List<WMSLayer> existingLayers) {
    119126        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];
    123131            Config.getPref().put("cadastrewms.location", location);
    124132            Config.getPref().put("cadastrewms.codeCommune", codeCommune);
    125             Config.getPref().put("cadastrewms.codeDepartement", codeDepartement);
     133            Config.getPref().put(CADASTREWMS_CODE_DEPARTEMENT, codeDepartement);
    126134            if (MainApplication.getMap() != null) {
    127135                for (Layer l : MainApplication.getLayerManager().getLayers()) {
     
    137145            CadastrePlugin.addWMSLayer(wmsLayer);
    138146            Logging.info("Add new layer with Location:" + inputTown.getText());
    139         } else if (existingLayers != null && existingLayers.size() > 0
     147        } else if (existingLayers != null && !existingLayers.isEmpty()
    140148                && MainApplication.getLayerManager().getActiveLayer() instanceof WMSLayer) {
    141149            wmsLayer = (WMSLayer) MainApplication.getLayerManager().getActiveLayer();
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionRefineGeoRef.java

    r34668 r36385  
    2020    private static final String NAME = marktr("Refine georeferencing");
    2121
    22     private WMSLayer wmsLayer;
    23     private RasterImageGeoreferencer rasterImageGeoreferencer;
     22    private final transient WMSLayer wmsLayer;
     23    private final transient RasterImageGeoreferencer rasterImageGeoreferencer;
    2424
    2525    /**
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/MenuActionSaveRasterAs.java

    r36176 r36385  
    99import java.io.File;
    1010import java.io.IOException;
     11import java.io.Serializable;
    1112import java.util.Locale;
    1213
    1314import javax.imageio.ImageIO;
     15import javax.imageio.ImageWriteParam;
    1416import javax.swing.JFileChooser;
    1517import javax.swing.filechooser.FileFilter;
    1618
     19import org.geotools.api.referencing.FactoryException;
    1720import org.geotools.coverage.grid.GridCoverage2D;
    1821import org.geotools.coverage.grid.GridCoverageFactory;
     
    3740    private static final String NAME = marktr("Save image as...");
    3841
    39     private final WMSLayer wmsLayer;
     42    private final transient WMSLayer wmsLayer;
    4043
    41     static class FiltrePng extends FileFilter {
     44    static class FiltrePng extends FileFilter implements Serializable {
    4245        @Override
    4346        public boolean accept(File file) {
     
    5457    }
    5558
    56     static class FiltreTiff extends FileFilter {
     59    static class FiltreTiff extends FileFilter implements Serializable {
    5760        @Override
    5861        public boolean accept(File file) {
     
    114117                    GeoTiffWriter gtwriter = new GeoTiffWriter(output);
    115118                    GeoTiffWriteParams wp = new GeoTiffWriteParams();
    116                     wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT);
     119                    wp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    117120                    wp.setCompressionType("LZW");
    118121                    wp.setCompressionQuality(0.75F);
     
    126129                    gtwriter.dispose();
    127130                    coverage.dispose(true);
    128                 } catch (Exception e) {
     131                } catch (IOException | FactoryException e) {
    129132                    Logging.error(e);
    130133                }
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/WMSDownloadAction.java

    r34458 r36385  
    2525        ArrayList<WMSLayer> existingWMSlayers = new ArrayList<>();
    2626        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);
    4528        } else {
    4629            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"));
    4751        }
    4852        return null;
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/mapmode/Address.java

    r35758 r36385  
    55
    66import java.awt.Cursor;
     7import java.awt.GridBagConstraints;
    78import java.awt.GridBagLayout;
    89import java.awt.Point;
    910import java.awt.Rectangle;
    1011import java.awt.Toolkit;
    11 import java.awt.event.ActionEvent;
    12 import java.awt.event.ActionListener;
    1312import java.awt.event.ComponentAdapter;
    1413import java.awt.event.ComponentEvent;
     
    3938import javax.swing.JRadioButton;
    4039import javax.swing.JTextField;
    41 import javax.swing.event.ChangeEvent;
    42 import javax.swing.event.ChangeListener;
    4340
    4441import org.openstreetmap.josm.actions.mapmode.MapMode;
     
    7067public class Address extends MapMode {
    7168
     69    private static final String MESSAGE_UNABLE_TO_PARSE_HOUSE_NUMBER = "Unable to parse house number \"{0}\"";
     70
    7271    // 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";
    8281
    8382    private JRadioButton plusOne = new JRadioButton("+1", false);
     
    134133        MapView mv = MainApplication.getMap().mapView;
    135134        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) {
    136202        List<Way> mouseOnExistingWays = new ArrayList<>();
    137203        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);
    153233            } 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;
    162248                    }
    163249                }
    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;
    237260            }
    238261        }
     
    252275                revertInputNumberChange();
    253276            } catch (NumberFormatException ex) {
    254                 Logging.warn("Unable to parse house number \"" + inputNumber.getText() + "\"");
     277                Logging.warn(MESSAGE_UNABLE_TO_PARSE_HOUSE_NUMBER, inputNumber.getText());
    255278            }
    256279        }
    257280        Map<String, String> tags = new HashMap<>();
    258         tags.put(tagHouseNumber, inputNumber.getText());
     281        tags.put(TAG_HOUSE_NUMBER, inputNumber.getText());
    259282        cmds.add(new ChangePropertyCommand(OsmDataManager.getInstance().getEditDataSet(), Collections.singleton(osm), tags));
    260283        addStreetNameOrRelation(osm, cmds);
     
    265288            setNewSelection(osm);
    266289        } 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) {
    272295        List<OsmPrimitive> l = w.getReferrers();
    273296        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)) {
    275298                return (Relation) osm;
    276299            }
     
    283306        if (Config.getPref().getBoolean("cadastrewms.addr.dontUseRelation", false)) {
    284307            Map<String, String> tags = new HashMap<>();
    285             tags.put(tagHouseStreet, inputStreet.getText());
     308            tags.put(TAG_HOUSE_STREET, inputStreet.getText());
    286309            cmds.add(new ChangePropertyCommand(ds, Arrays.asList(osm), tags));
    287310        } else if (selectedWay != null) {
     
    289312            // add the node to its relation
    290313            if (selectedRelation != null) {
    291                 RelationMember rm = new RelationMember(relationMemberHouse, osm);
     314                RelationMember rm = new RelationMember(RELATION_MEMBER_HOUSE, osm);
    292315                Relation newRel = new Relation(selectedRelation);
    293316                newRel.addMember(rm);
     
    296319                // create new relation
    297320                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));
    302325                cmds.add(new AddCommand(ds, newRel));
    303326            }
     
    355378            Iterator<Pair<Node, Node>> i = segs.iterator();
    356379            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();
    359382            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());
    364387
    365388            // Check for parallel segments and do nothing if they are
     
    372395            // if the segment is scaled to lenght 1
    373396
    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;
    375398            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()));
    378401
    379402            int snapToIntersectionThreshold
     
    390413            // fall through
    391414        default:
    392             EastNorth P = n.getEastNorth();
     415            EastNorth enP = n.getEastNorth();
    393416            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);
    399422            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())));
    401424        }
    402425    }
     
    462485        JLabel street = new JLabel(tr("Street"));
    463486        p.add(number, GBC.std().insets(0, 0, 0, 0));
    464         p.add(inputNumber, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 0, 5));
     487        p.add(inputNumber, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 5, 0, 5));
    465488        p.add(street, GBC.std().insets(0, 0, 0, 0));
    466489        JPanel p2 = new JPanel(new GridBagLayout());
    467490        inputStreet.setEditable(false);
    468         p2.add(inputStreet, GBC.std().fill(GBC.HORIZONTAL).insets(5, 0, 0, 0));
     491        p2.add(inputStreet, GBC.std().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 0));
    469492        p2.add(link, GBC.eol().insets(10, 0, 0, 0));
    470         p.add(p2, GBC.eol().fill(GBC.HORIZONTAL));
     493        p.add(p2, GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    471494        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);
    479499        });
    480500        ButtonGroup bgIncremental = new ButtonGroup();
     
    486506        p.add(plusOne, GBC.std().insets(0, 0, 10, 0));
    487507        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));
    495510        p.add(minusTwo, GBC.std().insets(10, 0, 10, 0));
    496511        p.add(plusTwo, GBC.std().insets(0, 0, 10, 0));
    497         p.add(clearButton, GBC.eol().fill(GBC.HORIZONTAL).insets(0, 0, 0, 0));
     512        p.add(clearButton, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(0, 0, 0, 0));
    498513
    499514        final Object[] options = {};
     
    533548    private void setSelectedWay(Way w) {
    534549        this.selectedWay = w;
    535         if (w == null) {
    536             link.setEnabled(false);
    537         } else
    538             link.setEnabled(true);
     550        link.setEnabled(w != null);
    539551        link.repaint();
    540552    }
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/mapmode/WMSAdjustAction.java

    r33687 r36385  
    77import java.awt.Cursor;
    88import java.awt.Graphics2D;
    9 import java.awt.Toolkit;
    10 import java.awt.event.ActionEvent;
    119import java.awt.event.MouseEvent;
    12 import java.awt.event.MouseListener;
    13 import java.awt.event.MouseMotionListener;
    1410
    1511import javax.swing.JOptionPane;
     
    2420import org.openstreetmap.josm.tools.Logging;
    2521
    26 public class WMSAdjustAction extends MapMode implements
    27         MouseListener, MouseMotionListener {
     22public class WMSAdjustAction extends MapMode {
    2823
    2924    private static final long serialVersionUID = 1L;
    30     private WMSLayer modifiedLayer = null;
     25    private transient WMSLayer modifiedLayer;
    3126    private boolean rasterMoved;
    3227    private EastNorth prevEastNorth;
    33     enum Mode { moveXY, moveZ, rotate }
     28    enum Mode {MOVE_XY, MOVE_Z, ROTATE}
    3429
    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];
    3732
    3833    /**
     
    9590            return;
    9691        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        }
    106100        rasterMoved = true;
    107101        prevEastNorth = MainApplication.getMap().mapView.getEastNorth(e.getX(), e.getY());
     
    111105    @Override public void mouseDragged(MouseEvent e) {
    112106        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);
    115109        } else {
    116             if (mode == Mode.moveXY) {
     110            if (mode == Mode.MOVE_XY) {
    117111                displace(prevEastNorth, newEastNorth);
    118             } else if (mode == Mode.moveZ) {
     112            } else if (mode == Mode.MOVE_Z) {
    119113                resize(newEastNorth);
    120114            }
     
    127121
    128122    public static void paintAdjustFrames(Graphics2D g, final MapView mv) {
    129         if (mode == Mode.rotate && croppedRaster != null) {
     123        if (mode == Mode.ROTATE) {
    130124            g.setColor(Color.red);
    131125            for (int i = 0; i < 4; i++) {
     
    157151    }
    158152
    159     private void rotateFrameOnly(EastNorth start, EastNorth end) {
     153    private static void rotateFrameOnly(WMSLayer modifiedLayer, EastNorth start, EastNorth end) {
    160154        if (start != null && end != null) {
    161155            EastNorth pivot = modifiedLayer.getRasterCenter();
     
    174168    @Override
    175169    public void mouseReleased(MouseEvent e) {
    176         if (mode == Mode.rotate) {
     170        if (mode == Mode.ROTATE) {
    177171            EastNorth newEastNorth = MainApplication.getMap().mapView.getEastNorth(e.getX(), e.getY());
    178172            rotate(prevEastNorth, newEastNorth);
     
    183177        MainApplication.getMap().mapView.setCursor(Cursor.getDefaultCursor());
    184178        prevEastNorth = null;
    185         mode = null;
     179        setMode(null);
    186180    }
    187181
    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;
    201184    }
    202185
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/actions/upload/CheckSourceUploadHook.java

    r34458 r36385  
    5959     * @return true if one of keys is "source"
    6060     */
    61     private boolean tagSourceExist(OsmPrimitive osm) {
     61    private static boolean tagSourceExist(OsmPrimitive osm) {
    6262        return osm.hasKey("source");
    6363    }
     
    6868     * @param sel the list of elements added without a key "source"
    6969     */
    70     private void displaySource(Collection<OsmPrimitive> sel) {
     70    private static void displaySource(Collection<OsmPrimitive> sel) {
    7171        if (!sel.isEmpty()) {
    7272            JPanel p = new JPanel(new GridBagLayout());
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/download/CadastreDownloadSourcePanel.java

    r35106 r36385  
    88import java.awt.Dimension;
    99import java.awt.Font;
     10import java.awt.GridBagConstraints;
    1011import java.awt.GridBagLayout;
    1112import java.util.Arrays;
     
    8384
    8485        // adding the download tasks
    85         add(new JLabel(tr("Objects:")), GBC.std().insets(5, 5, 1, 5).anchor(GBC.CENTER));
     86        add(new JLabel(tr("Objects:")), GBC.std().insets(5, 5, 1, 5).anchor(GridBagConstraints.CENTER));
    8687        cbDownloadBuilding = createCheckBox(tr("building"), DOWNLOAD_BUILDING,
    8788                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  
    6363        try {
    6464            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");
    6667                tasks.add(MainApplication.worker.submit(new InternalDownloadTask(settings, url, progressMonitor, zoomAfterDownload)));
    6768            }
     
    7576                try {
    7677                    f.get();
    77                 } catch (InterruptedException | ExecutionException e) {
     78                } catch (ExecutionException e) {
    7879                    Logging.error(e);
     80                } catch (InterruptedException e) {
     81                    Logging.error(e);
     82                    Thread.currentThread().interrupt();
    7983                }
    8084            }
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/download/CadastreServerReader.java

    r36039 r36385  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.io.IOException;
    67import java.util.Objects;
    78
    89import org.openstreetmap.josm.data.osm.DataSet;
    910import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     11import org.openstreetmap.josm.io.IllegalDataException;
    1012import org.openstreetmap.josm.io.OsmServerReader;
    1113import org.openstreetmap.josm.io.OsmTransferException;
     
    3537            progressMonitor.beginTask(tr("Contacting Server..."), 10);
    3638            return new EdigeoPciImporter().parseDataSet(url, data);
    37         } catch (Exception e) {
     39        } catch (IOException | IllegalDataException e) {
    3840            throw new OsmTransferException(e);
    3941        } finally {
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoFileVEC.java

    r35185 r36385  
    354354        @Override
    355355        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 {
    359359                super.processRecord(r);
    360360            }
     
    558558        List<OsmPrimitive> toPurge = new ArrayList<>();
    559559        for (ObjectBlock obj : getObjects()) {
    560             if (!ignoredObjects.stream().anyMatch(p -> p.test(obj))) {
     560            if (ignoredObjects.stream().noneMatch(p -> p.test(obj))) {
    561561                OsmPrimitive p;
    562562                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;
    566566                    case COMPLEX: // TODO (not used in PCI)
    567567                    default: throw new IllegalArgumentException(obj.toString());
     
    574574                                purged = toPurge.add(p);
    575575                                if (p instanceof Relation) {
    576                                                                         toPurge.addAll(((Relation) p).getMemberPrimitivesList());
     576                                    toPurge.addAll(((Relation) p).getMemberPrimitivesList());
    577577                                }
    578578                            } else {
     
    630630
    631631    private static Node fillPoint(DataSet ds, Projection proj, ObjectBlock obj,
    632             List<RelationBlock> constructionRelations, List<RelationBlock> semanticRelations) {
     632            List<RelationBlock> constructionRelations) {
    633633        assert constructionRelations.size() == 1 : constructionRelations;
    634634        List<NodeBlock> blocks = extract(NodeBlock.class, constructionRelations, RelationKind.IS_MADE_OF);
     
    644644
    645645    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;
    648648        // Retrieve all arcs for the linear object
    649649        final List<ArcBlock> arcs = extract(ArcBlock.class, constructionRelations, RelationKind.IS_MADE_OF_ARC);
    650650        final double EPSILON = 1e-2;
    651         assert arcs.size() >= 1;
     651        assert !arcs.isEmpty();
    652652        // Some lines are made of several arcs, but they need to be sorted
    653653        if (arcs.size() > 1) {
     
    693693
    694694    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;
    697697        List<FaceBlock> faces = extract(FaceBlock.class, constructionRelations, RelationKind.IS_MADE_OF);
    698         assert faces.size() >= 1;
     698        assert !faces.isEmpty();
    699699        if (faces.size() == 1) {
    700700            return addPrimitiveAndTags(ds, obj, faceToOsmPrimitive(ds, proj, faces.get(0)));
     
    713713        allArcs.addAll(extract(ArcBlock.class, face.getConstructionRelations(), RelationKind.HAS_FOR_LEFT_FACE));
    714714        allArcs.addAll(extract(ArcBlock.class, face.getConstructionRelations(), RelationKind.HAS_FOR_RIGHT_FACE));
    715         assert allArcs.size() >= 1;
     715        assert !allArcs.isEmpty();
    716716        if (allArcs.size() == 1) {
    717717            ArcBlock ab = allArcs.get(0);
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/edigeo/EdigeoLotFile.java

    r34223 r36385  
    2727    protected final ClassToInstancesMap<B> blocks = new MutableClassToInstancesMap<>();
    2828
    29     EdigeoLotFile(Lot lot, String subsetId, Path path) throws IOException {
     29    EdigeoLotFile(Lot lot, String subsetId, Path path) {
    3030        super(path);
    3131        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  
    2020import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
    2121import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
    22 import org.apache.commons.compress.utils.IOUtils;
     22import org.apache.commons.io.IOUtils;
    2323import org.apache.commons.lang3.StringUtils;
    2424import org.apache.commons.text.WordUtils;
     
    4040 */
    4141public 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";
    4247
    4348    private static final BiPredicate<CadastreDownloadData, OsmPrimitive> water = (x, p) -> !x.isDownloadWater();
     
    6570                "CROIX_id",    // Property boundary marker for Alsace and Moselle
    6671                "SYMBLIM_id"); // Common wall symbol
    67         EdigeoFileVEC.addIgnoredObject("SYM_id",
     72        EdigeoFileVEC.addIgnoredObject(SYM_ID,
    6873                "30", // Water stream arrow
    6974                "31", // Connecting arrows between parcelles and numbers
     
    9499                }
    95100            }
    96             p.put("highway", highwayValue);
    97             p.remove("SYM_id");
    98         }, symbo, "SYM_id", "23"); // Path / Footway
     101            p.put(HIGHWAY, highwayValue);
     102            p.remove(SYM_ID);
     103        }, symbo, SYM_ID, "23"); // Path / Footway
    99104        EdigeoFileVEC.addObjectPostProcessor("24", symbo, "man_made=pipeline"); // Pipeline
    100105        EdigeoFileVEC.addObjectPostProcessor("25", symbo, "man_made=pipeline"); // Aqueduct
     
    117122        // Mapping TEX*_id => name (first step)
    118123        EdigeoFileVEC.addObjectPostProcessor((o, p) -> {
    119             StringBuffer 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")) {
    122127                String v = p.get(t);
    123128                if (v == null) {
     
    128133            }
    129134            setName(p, sb.toString());
    130         }, (x, p) -> false, "TEX_id");
     135        }, (x, p) -> false, TEX_ID);
    131136
    132137        // Objects mapping
    133138        EdigeoFileVEC.addObjectPostProcessor((o, p) -> {
    134             p.put("highway", "road");
     139            p.put(HIGHWAY, "road");
    135140            String name = p.get("name");
    136141            if (name != null && name.contains(" ")) {
    137142                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);
    146150                }
    147151            }
     
    151155            p.put("boundary", "administrative");
    152156            p.put("admin_level", "8");
    153             p.put("ref:INSEE", "XX"+p.get("IDU_id")); // TODO: find department number
    154             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);
    157161        }, o -> o.hasScdIdentifier("COMMUNE_id"), commu);
    158162
    159163        EdigeoFileVEC.addObjectPostProcessor((o, p) -> {
    160164            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);
    163167            p.remove("ICL_id");
    164168            p.remove("COAR_id");
     
    191195        }, o -> o.hasScdIdentifier("LIEUDIT_id"), local);
    192196
    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");
    199201            p.put("area", "yes");
    200202        }, o -> o.hasScdIdentifier("TRONROUTE_id"), symbo);
    201203
    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);
    205205
    206206        // 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")) {
    208208            EdigeoFileVEC.addObjectPostProcessor((o, p) -> {
    209209                setName(p, p.get(t));
     
    239239    private static void setName(OsmPrimitive p, String input) {
    240240        if (input != null) {
    241             String name = input.replaceAll("    ", " ").replaceAll("   ", " ").replaceAll("  ", " ");
     241            String name = input.replaceAll(" {4}", " ").replaceAll(" {3}", " ").replaceAll(" {2}", " ");
    242242            if (name.matches("([A-Za-z] )+[A-Za-z]")) {
    243                 name = name.replaceAll(" ", "");
    244             }
    245             if (name.length() > 2 && StringUtils.isAllUpperCase(name.replaceAll(" ", "").replaceAll("'", "").replaceAll("-", ""))) {
     243                name = name.replace(" ", "");
     244            }
     245            if (name.length() > 2 && StringUtils.isAllUpperCase(name.replace(" ", "").replace("'", "").replace("-", ""))) {
    246246                name = WordUtils.capitalizeFully(name);
    247247            }
     
    256256        for (Entry<String, List<String>> e : highways.entrySet()) {
    257257            if (e.getValue().contains(type)) {
    258                 p.put("highway", e.getKey());
     258                p.put(HIGHWAY, e.getKey());
    259259                return true;
    260260            }
     
    275275        try {
    276276            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) {
    280278            Logging.error(e);
    281279            throw new IOException(e);
     
    295293                    TarArchiveEntry entry;
    296294                    tmpDir = Files.createTempDirectory(Utils.getJosmTempDir().toPath(), "cadastre");
    297                     while ((entry = tar.getNextTarEntry()) != null) {
     295                    while ((entry = tar.getNextEntry()) != null) {
    298296                        File file = tmpDir.resolve(entry.getName()).toFile();
    299297                        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  
    1111 */
    1212public class MutableClassToInstancesMap<B> extends HashMap<Class<? extends B>, List<B>> implements ClassToInstancesMap<B> {
     13    private static final long serialVersionUID = 1L;
    1314
    1415    @Override
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/preferences/CadastrePreferenceSetting.java

    r35308 r36385  
    22package org.openstreetmap.josm.plugins.fr.cadastre.preferences;
    33
     4import static org.openstreetmap.josm.tools.I18n.marktr;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56
     7import java.awt.GridBagConstraints;
    68import java.awt.GridBagLayout;
    7 import java.awt.event.ActionEvent;
    89import java.awt.event.ActionListener;
    910
     
    3940 */
    4041public 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"));
    99107
    100108    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."));
    104112
    105113    public static final int DEFAULT_CACHE_SIZE = 0; // disabled by default
    106114    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);
    108116
    109117    public static final String DEFAULT_RASTER_DIVIDER = "7";
    110     private JTextField rasterDivider = new JTextField(10);
     118    private final JTextField rasterDivider = new JTextField(10);
    111119
    112120    static final int DEFAULT_CROSSPIECES = 0;
     
    134142        cadastrewms.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    135143
     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) {
    136174        // option to automatically set the source tag when uploading
    137175        sourcing.setText(CadastrePlugin.source);
     
    139177        JLabel jLabelSource = new JLabel(tr("Source"));
    140178        cadastrewms.add(jLabelSource, GBC.eop().insets(0, 0, 0, 0));
    141         cadastrewms.add(sourcing, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
     179        cadastrewms.add(sourcing, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
    142180
    143181        // option to alter the original colors of the wms images
     
    153191
    154192        // 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()));
    161194        transparency.setSelected(Config.getPref().getBoolean("cadastrewms.backgroundTransparent", false));
    162195        transparency.setToolTipText(tr("Allows multiple layers stacking"));
     
    172205        sliderTrans.setPaintLabels(false);
    173206        sliderTrans.setEnabled(transparency.isSelected());
    174         cadastrewms.add(sliderTrans, GBC.eol().fill(GBC.HORIZONTAL).insets(20, 0, 250, 0));
     207        cadastrewms.add(sliderTrans, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(20, 0, 250, 0));
    175208
    176209        // option to draw boundaries of downloaded data
     
    189222        bgResolution.add(grabRes2);
    190223        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        }
    198231        cadastrewms.add(grabRes1, GBC.std().insets(5, 0, 5, 0));
    199232        cadastrewms.add(grabRes2, GBC.std().insets(5, 0, 5, 0));
    200         cadastrewms.add(grabRes3, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 0, 5));
     233        cadastrewms.add(grabRes3, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 5, 0, 5));
    201234
    202235        // option to select image zooming interpolation method
     
    206239        imageInterpolationMethod.addItem(tr("Bilinear (fast)"));
    207240        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)) {
    210243            imageInterpolationMethod.setSelectedIndex(1);
    211         else if (savedImageInterpolationMethod.equals("bicubic"))
     244        } else if ("bicubic".equals(savedImageInterpolationMethod)) {
    212245            imageInterpolationMethod.setSelectedIndex(2);
    213         else
     246        } else
    214247            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) {
    220252        // the vectorized images multiplier
    221253        JLabel jLabelScale = new JLabel(tr("Vector images grab multiplier:"));
    222254        cadastrewms.add(jLabelScale, GBC.std().insets(0, 5, 10, 0));
    223255        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"));
    233262        grabMultiplier1.addActionListener(multiplierActionListener);
    234263        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"));
    237266        grabMultiplier2.addActionListener(multiplierActionListener);
    238267        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"));
    241270        grabMultiplier3.addActionListener(multiplierActionListener);
    242271        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"));
    245274        grabMultiplier4.addActionListener(multiplierActionListener);
    246275        grabMultiplier4.setToolTipText(tr("Fixed size square (default is 100m)"));
     
    249278        bgGrabMultiplier.add(grabMultiplier3);
    250279        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);
    252281        if (currentScale.equals(Scale.X1.value))
    253282            grabMultiplier1.setSelected(true);
     
    266295        grabMultiplier4Size.setToolTipText(tr("Fixed size (from 25 to 1000 meters)"));
    267296        grabMultiplier4Size.setEnabled(currentScale.equals(Scale.SQUARE_100M.value));
    268         cadastrewms.add(grabMultiplier4Size, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 0, 5));
     297        cadastrewms.add(grabMultiplier4Size, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 5, 0, 5));
    269298
    270299        // WMS layers selection
     
    298327        layerCommune.setToolTipText(tr("Municipality administrative borders."));
    299328        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) {
    304332        // for raster images (not vectorized), image grab divider (from 1 to 12)
    305333        String savedRasterDivider = Config.getPref().get("cadastrewms.rasterDivider", DEFAULT_RASTER_DIVIDER);
     
    308336        rasterDivider.setToolTipText("Raster image grab division, from 1 to 12; 12 is very high definition");
    309337        cadastrewms.add(jLabelRasterDivider, GBC.std().insets(0, 5, 10, 0));
    310         cadastrewms.add(rasterDivider, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 200, 5));
     338        cadastrewms.add(rasterDivider, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 5, 200, 5));
    311339        // option to disable image cropping during raster image georeferencing
    312340        disableImageCropping.setSelected(Config.getPref().getBoolean("cadastrewms.noImageCropping", false));
     
    325353        cadastrewms.add(jLabelCrosspieces, GBC.std().insets(0, 0, 10, 0));
    326354        ButtonGroup bgCrosspieces = new ButtonGroup();
    327         int crosspieces = getNumber("cadastrewms.crosspieces", DEFAULT_CROSSPIECES);
     355        int crosspieces = getNumber(CADASTREWMS_CROSSPIECES, DEFAULT_CROSSPIECES);
    328356        if (crosspieces == 0) crosspiece1.setSelected(true);
    329357        if (crosspieces == 1) crosspiece2.setSelected(true);
     
    337365        cadastrewms.add(crosspiece2, GBC.std().insets(5, 0, 5, 0));
    338366        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) {
    344371        // 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());
    351375        });
    352376        enableCache.setSelected(Config.getPref().getBoolean("cadastrewms.enableCaching", true));
    353377        enableCache.setToolTipText(tr("Allows an automatic caching"));
    354378        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) {
    357382        int size = getNumber("cadastrewms.cacheSize", DEFAULT_CACHE_SIZE);
    358383        cacheSize.setText(String.valueOf(size));
    359384        cacheSize.setToolTipText(tr("Oldest files are automatically deleted when this size is exceeded"));
    360385        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) {
    367390        autoFirstLayer.setSelected(Config.getPref().getBoolean("cadastrewms.autoFirstLayer", false));
    368391        autoFirstLayer.setToolTipText(tr("Automatically selects the first WMS layer if multiple layers exist when grabbing."));
    369392        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) {
    374396        // option to use or not relations in addresses
    375397        dontUseRelation.setSelected(Config.getPref().getBoolean("cadastrewms.addr.dontUseRelation", false));
    376398        dontUseRelation.setToolTipText(tr("Enable this to use the tag \"add:street\" on nodes."));
    377399        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) {
    382403        // option to merge downloaded data layers
    383404        mergeDataLayers.setSelected(Config.getPref().getBoolean("cadastrewms.merge.data.layers", false));
    384405        mergeDataLayers.setToolTipText(tr("Merge automatically all cadastre data layers in a single final layer."));
    385406        cadastrewms.add(mergeDataLayers, GBC.eop().insets(0, 0, 0, 0));
    386 
     407    }
     408
     409    private static void addGuiEndOfDialogScrollBar(JPanel cadastrewms, JPanel cadastrewmsMast) {
    387410        // end of dialog, scroll bar
    388         cadastrewms.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
     411        cadastrewms.add(Box.createVerticalGlue(), GBC.eol().fill(GridBagConstraints.VERTICAL));
    389412        JScrollPane scrollpane = new JScrollPane(cadastrewms);
    390413        scrollpane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    391         cadastrewmsMast.add(scrollpane, GBC.eol().fill(GBC.BOTH));
     414        cadastrewmsMast.add(scrollpane, GBC.eol().fill(GridBagConstraints.BOTH));
    392415    }
    393416
     
    402425        Config.getPref().putBoolean("cadastrewms.drawBoundaries", drawBoundaries.isSelected());
    403426        if (grabRes1.isSelected())
    404             Config.getPref().put("cadastrewms.resolution", "high");
     427            Config.getPref().put(CADASTREWMS_RESOLUTION, HIGH);
    405428        else if (grabRes2.isSelected())
    406             Config.getPref().put("cadastrewms.resolution", "medium");
     429            Config.getPref().put(CADASTREWMS_RESOLUTION, MEDIUM);
    407430        else if (grabRes3.isSelected())
    408             Config.getPref().put("cadastrewms.resolution", "low");
     431            Config.getPref().put(CADASTREWMS_RESOLUTION, LOW);
    409432        if (imageInterpolationMethod.getSelectedIndex() == 2)
    410             Config.getPref().put("cadastrewms.imageInterpolation", "bicubic");
     433            Config.getPref().put(CADASTREWMS_IMAGE_INTERPOLATION, "bicubic");
    411434        else if (imageInterpolationMethod.getSelectedIndex() == 1)
    412             Config.getPref().put("cadastrewms.imageInterpolation", "bilinear");
     435            Config.getPref().put(CADASTREWMS_IMAGE_INTERPOLATION, "bilinear");
    413436        else
    414             Config.getPref().put("cadastrewms.imageInterpolation", "standard");
     437            Config.getPref().put(CADASTREWMS_IMAGE_INTERPOLATION, "standard");
    415438        if (grabMultiplier1.isSelected())
    416             Config.getPref().put("cadastrewms.scale", Scale.X1.toString());
     439            Config.getPref().put(CADASTREWMS_SCALE, Scale.X1.toString());
    417440        else if (grabMultiplier2.isSelected())
    418             Config.getPref().put("cadastrewms.scale", Scale.X2.toString());
     441            Config.getPref().put(CADASTREWMS_SCALE, Scale.X2.toString());
    419442        else if (grabMultiplier3.isSelected())
    420             Config.getPref().put("cadastrewms.scale", Scale.X3.toString());
     443            Config.getPref().put(CADASTREWMS_SCALE, Scale.X3.toString());
    421444        else {
    422             Config.getPref().put("cadastrewms.scale", Scale.SQUARE_100M.toString());
     445            Config.getPref().put(CADASTREWMS_SCALE, Scale.SQUARE_100M.toString());
    423446            try {
    424447                int squareSize = Integer.parseInt(grabMultiplier4Size.getText());
     
    448471        Config.getPref().putBoolean("cadastrewms.useTA", enableTableauAssemblage.isSelected());
    449472        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");
    454477        Config.getPref().putBoolean("cadastrewms.enableCaching", enableCache.isSelected());
    455478
     
    471494    }
    472495
    473     private int getNumber(String pref_parameter, int def_value) {
     496    private static int getNumber(String prefParameter, int defValue) {
    474497        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)));
    476499        } catch (NumberFormatException e) {
    477             return def_value;
     500            return defValue;
    478501        }
    479502    }
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/session/CadastreSessionExporter.java

    r33638 r36385  
    33
    44import java.awt.Component;
     5import java.awt.GridBagConstraints;
    56import java.awt.GridBagLayout;
    67import java.io.IOException;
     
    4647        p.add(export, GBC.std());
    4748        p.add(lbl, GBC.std());
    48         p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));
     49        p.add(GBC.glue(1, 0), GBC.std().fill(GridBagConstraints.HORIZONTAL));
    4950        return p;
    5051    }
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/session/CadastreSessionImporter.java

    r33638 r36385  
    2121import org.openstreetmap.josm.plugins.fr.cadastre.wms.CacheControl;
    2222import org.openstreetmap.josm.plugins.fr.cadastre.wms.WMSLayer;
     23import org.openstreetmap.josm.tools.JosmRuntimeException;
    2324import org.w3c.dom.Element;
    2425
     
    6162
    6263        } catch (XPathExpressionException e) {
    63             throw new RuntimeException(e);
     64            throw new JosmRuntimeException(e);
    6465        }
    6566    }
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CacheControl.java

    r34668 r36385  
    1313import java.io.OutputStream;
    1414import java.util.ArrayList;
    15 import java.util.concurrent.Callable;
    1615import java.util.concurrent.locks.Lock;
    1716import java.util.concurrent.locks.ReentrantLock;
     
    116115        File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + WMSFileExtension());
    117116        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
    133129            });
    134130
     
    159155        try (
    160156            FileInputStream fis = new FileInputStream(file);
    161             ObjectInputStream ois = new ObjectInputStream(fis);
     157            ObjectInputStream ois = new ObjectInputStream(fis)
    162158        ) {
    163159            wmsLayer.setAssociatedFile(file);
     
    232228            } catch (InterruptedException e) {
    233229                Logging.error(e);
     230                Thread.currentThread().interrupt();
    234231            }
    235232        }
  • applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CacheFileLambert4ZoneFilter.java

    r34223 r36385  
    22package org.openstreetmap.josm.plugins.fr.cadastre.wms;
    33
     4import static org.openstreetmap.josm.tools.I18n.marktr;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56
     
    1011
    1112public final class CacheFileLambert4ZoneFilter extends FileFilter {
     13    private static final String LAMBERT_ZONE_MESSAGE = marktr("Lambert Zone {0} cache file (.{0})");
    1214
    1315    /**
     
    2123     */
    2224    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))
    2729        };
    2830
Note: See TracChangeset for help on using the changeset viewer.