Changeset 18720 in osm for applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionLoadFromCache.java
- Timestamp:
- 2009-11-21T00:18:50+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionLoadFromCache.java
r18544 r18720 13 13 import org.openstreetmap.josm.data.projection.Lambert; 14 14 import org.openstreetmap.josm.data.projection.LambertCC9Zones; 15 import org.openstreetmap.josm.data.projection.UTM_20N_France_DOM; 15 16 import org.openstreetmap.josm.gui.layer.Layer; 16 17 … … 30 31 31 32 File[] files = fc.getSelectedFiles(); 33 int layoutZone = getCurrentProjZone(); 32 34 nextFile: 33 35 for (File file : files) { … … 35 37 String filename = file.getName(); 36 38 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) && 38 40 !(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)) 39 43 || (ext.length() == 1) && !(Main.proj instanceof Lambert)) { 40 44 JOptionPane.showMessageDialog(Main.parent, tr("{0} not allowed with the current projection", filename), tr("Error"), JOptionPane.ERROR_MESSAGE); … … 42 46 } else { 43 47 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)) 45 49 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 47 53 try { 48 54 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); 56 58 continue nextFile; 57 59 } else … … 59 61 } 60 62 } catch (NumberFormatException ex) { 61 System.out.println("Selected file\"" + filename + "\"is not aWMScache 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; 63 65 } 64 66 // check if the selected cache is not already displayed … … 66 68 for (Layer l : Main.map.mapView.getAllLayers()) { 67 69 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); 69 71 continue nextFile; 70 72 } … … 73 75 // create layer and load cache 74 76 WMSLayer wmsLayer = new WMSLayer("", "", Integer.parseInt(ext)-1); 75 if (wmsLayer.getCacheControl().loadCache(file, Lambert.layoutZone))77 if (wmsLayer.getCacheControl().loadCache(file, layoutZone)) 76 78 Main.main.addLayer(wmsLayer); 77 79 … … 85 87 JFileChooser fc = new JFileChooser(new File(CadastrePlugin.cacheDir)); 86 88 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 } 89 98 fc.setAcceptAllFileFilterUsed(false); 90 99 … … 96 105 } 97 106 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 } 98 117 }
Note:
See TracChangeset
for help on using the changeset viewer.
