Ignore:
Timestamp:
2009-11-21T00:18:50+01:00 (16 years ago)
Author:
pieren
Message:

Add subprojection handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionLoadFromCache.java

    r18544 r18720  
    1313import org.openstreetmap.josm.data.projection.Lambert;
    1414import org.openstreetmap.josm.data.projection.LambertCC9Zones;
     15import org.openstreetmap.josm.data.projection.UTM_20N_France_DOM;
    1516import org.openstreetmap.josm.gui.layer.Layer;
    1617
     
    3031
    3132        File[] files = fc.getSelectedFiles();
     33        int layoutZone = getCurrentProjZone();
    3234        nextFile:
    3335        for (File file : files) {
     
    3537                String filename = file.getName();
    3638                String ext = (filename.lastIndexOf(".")==-1)?"":filename.substring(filename.lastIndexOf(".")+1,filename.length());
    37                 if ((ext.length() > 2 && ext.substring(0, CacheControl.cLambertCC9Z.length()).equals(CacheControl.cLambertCC9Z) &&
     39                if ((ext.length() == 3 && ext.substring(0, CacheControl.cLambertCC9Z.length()).equals(CacheControl.cLambertCC9Z) &&
    3840                    !(Main.proj instanceof LambertCC9Zones))
     41                    || (ext.length() == 4 && ext.substring(0, CacheControl.cUTM20N.length()).equals(CacheControl.cUTM20N) &&
     42                            !(Main.proj instanceof UTM_20N_France_DOM))
    3943                    || (ext.length() == 1) && !(Main.proj instanceof Lambert)) {
    4044                        JOptionPane.showMessageDialog(Main.parent, tr("{0} not allowed with the current projection", filename), tr("Error"), JOptionPane.ERROR_MESSAGE);
     
    4246                } else {
    4347                    String location = filename.substring(0, filename.lastIndexOf("."));
    44                     if (ext.length() > 2 && ext.substring(0, CacheControl.cLambertCC9Z.length()).equals(CacheControl.cLambertCC9Z))
     48                    if (ext.length() == 3 && ext.substring(0, CacheControl.cLambertCC9Z.length()).equals(CacheControl.cLambertCC9Z))
    4549                        ext = ext.substring(2);
    46                     // check the extension and its Lambert zone consistency
     50                    else if (ext.length() == 4 && ext.substring(0, CacheControl.cUTM20N.length()).equals(CacheControl.cUTM20N))
     51                        ext = ext.substring(3);
     52                    // check the extension and its compatibility with current projection
    4753                    try {
    4854                        int cacheZone = Integer.parseInt(ext) - 1;
    49                         if (cacheZone >=0 && cacheZone <= 3) {
    50                             if (Lambert.layoutZone == -1) {
    51                                 Lambert.layoutZone = cacheZone;
    52                                 System.out.println("Load cache \"" + filename + "\" in Lambert Zone " + (Lambert.layoutZone+1));
    53                             } else if (cacheZone != Lambert.layoutZone) {
    54                                 System.out.println("Cannot load cache \"" + filename + "\" which is not in current Lambert Zone "
    55                                         + Lambert.layoutZone);
     55                        if (cacheZone >=0 && cacheZone <= 9) {
     56                            if (cacheZone != layoutZone) {
     57                                JOptionPane.showMessageDialog(Main.parent, tr("Cannot load cache {0} which is not compatible with current projection zone", filename), tr("Error"), JOptionPane.ERROR_MESSAGE);
    5658                                continue nextFile;
    5759                            } else
     
    5961                        }
    6062                    } catch (NumberFormatException ex) {
    61                         System.out.println("Selected file \"" + filename + "\" is not a WMS cache file (invalid extension)");
    62                         continue;
     63                        JOptionPane.showMessageDialog(Main.parent, tr("Selected file {0} is not a cache file from this plugin (invalid extension)", filename), tr("Error"), JOptionPane.ERROR_MESSAGE);
     64                        continue nextFile;
    6365                    }
    6466                    // check if the selected cache is not already displayed
     
    6668                        for (Layer l : Main.map.mapView.getAllLayers()) {
    6769                            if (l instanceof WMSLayer && l.getName().equals(location)) {
    68                                 System.out.println("The location " + filename + " is already on screen. Cache not loaded.");
     70                                JOptionPane.showMessageDialog(Main.parent, tr("The location {0} is already on screen. Cache not loaded.", filename), tr("Error"), JOptionPane.ERROR_MESSAGE);
    6971                                continue nextFile;
    7072                            }
     
    7375                    // create layer and load cache
    7476                    WMSLayer wmsLayer = new WMSLayer("", "", Integer.parseInt(ext)-1);
    75                     if (wmsLayer.getCacheControl().loadCache(file, Lambert.layoutZone))
     77                    if (wmsLayer.getCacheControl().loadCache(file, layoutZone))
    7678                        Main.main.addLayer(wmsLayer);
    7779                   
     
    8587        JFileChooser fc = new JFileChooser(new File(CadastrePlugin.cacheDir));
    8688        fc.setMultiSelectionEnabled(true);
    87         if (Lambert.layoutZone != -1)
    88             fc.addChoosableFileFilter(CacheFileFilter.filters[Lambert.layoutZone]);
     89        int layoutZone = new MenuActionLoadFromCache().getCurrentProjZone();
     90        if (layoutZone != -1) {
     91            if (Main.proj instanceof Lambert)
     92                fc.addChoosableFileFilter(CacheFileLambert4ZoneFilter.filters[layoutZone]);
     93            else if (Main.proj instanceof LambertCC9Zones)
     94                fc.addChoosableFileFilter(CacheFileLambert9ZoneFilter.filters[layoutZone]);
     95            else if (Main.proj instanceof UTM_20N_France_DOM)
     96                fc.addChoosableFileFilter(CacheFileUTM20NFilter.filters[layoutZone]);
     97        }
    8998        fc.setAcceptAllFileFilterUsed(false);
    9099
     
    96105    }
    97106
     107    private int getCurrentProjZone() {
     108        int zone = -1;
     109        if (Main.proj instanceof LambertCC9Zones)
     110            zone = ((LambertCC9Zones)Main.proj).getLayoutZone();
     111        else if (Main.proj instanceof Lambert)
     112            zone = ((Lambert)Main.proj).getLayoutZone();
     113        else if (Main.proj instanceof UTM_20N_France_DOM)
     114            zone = ((UTM_20N_France_DOM)Main.proj).getCurrentGeodesic();
     115        return zone;
     116    }
    98117}
Note: See TracChangeset for help on using the changeset viewer.