Changeset 32211 in osm for applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java
- Timestamp:
- 2016-06-01T00:55:28+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java
r32163 r32211 13 13 import java.io.OutputStream; 14 14 import java.util.ArrayList; 15 import java.util.concurrent.Callable; 15 16 import java.util.concurrent.locks.Lock; 16 17 import java.util.concurrent.locks.ReentrantLock; … … 33 34 public class CacheControl implements Runnable { 34 35 35 public static final String cLambertCC9Z = "CC";36 37 public static final String cUTM20N = "UTM";38 39 public class ObjectOutputStreamAppend extends ObjectOutputStream { 36 public static final String C_LAMBERT_CC_9Z = "CC"; 37 38 public static final String C_UTM20N = "UTM"; 39 40 public static class ObjectOutputStreamAppend extends ObjectOutputStream { 40 41 public ObjectOutputStreamAppend(OutputStream out) throws IOException { 41 42 super(out); … … 51 52 public static int cacheSize = 500; 52 53 53 public WMSLayer wmsLayer = null;54 public WMSLayer wmsLayer; 54 55 55 56 private ArrayList<GeorefImage> imagesToSave = new ArrayList<>(); … … 79 80 } 80 81 81 private void checkDirSize(File path) { 82 private static void checkDirSize(File path) { 82 83 if (cacheSize != 0) { 83 84 long size = 0; … … 105 106 CadastrePlugin.askToChangeProjection(); 106 107 } 107 try { 108 File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + WMSFileExtension()); 109 if (file.exists()) { 110 JOptionPane pane = new JOptionPane( 111 tr("Location \"{0}\" found in cache.\n"+ 112 "Load cache first ?\n"+ 113 "(No = new cache)", wmsLayer.getName()), 114 JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null); 115 // this below is a temporary workaround to fix the "always on top" issue 116 JDialog dialog = pane.createDialog(Main.parent, tr("Select Feuille")); 117 CadastrePlugin.prepareDialog(dialog); 118 dialog.setVisible(true); 119 int reply = (Integer)pane.getValue(); 120 // till here 121 122 if (reply == JOptionPane.OK_OPTION && loadCache(file, wmsLayer.getLambertZone())) { 123 return true; 124 } else { 125 delete(file); 126 } 127 } 128 } catch (Exception e) { 129 Main.error(e); 108 File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + WMSFileExtension()); 109 if (file.exists()) { 110 int reply = GuiHelper.runInEDTAndWaitAndReturn(new Callable<Integer>() { 111 @Override 112 public Integer call() throws Exception { 113 JOptionPane pane = new JOptionPane( 114 tr("Location \"{0}\" found in cache.\n"+ 115 "Load cache first ?\n"+ 116 "(No = new cache)", wmsLayer.getName()), 117 JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null); 118 // this below is a temporary workaround to fix the "always on top" issue 119 JDialog dialog = pane.createDialog(Main.parent, tr("Select Feuille")); 120 CadastrePlugin.prepareDialog(dialog); 121 dialog.setVisible(true); 122 return (Integer)pane.getValue(); 123 // till here 124 } 125 }); 126 127 if (reply == JOptionPane.OK_OPTION && loadCache(file, wmsLayer.getLambertZone())) { 128 return true; 129 } else { 130 delete(file); 131 } 130 132 } 131 133 return false; … … 133 135 134 136 public void deleteCacheFile() { 135 try { 136 delete(new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + WMSFileExtension())); 137 } catch (Exception e) { 138 Main.error(e); 139 } 140 } 141 142 private void delete(File file) { 137 delete(new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + WMSFileExtension())); 138 } 139 140 private static void delete(File file) { 143 141 Main.info("Delete file "+file); 144 142 if (file.exists()) … … 155 153 ) { 156 154 successfulRead = wmsLayer.read(file, ois, currentLambertZone); 157 } catch (Exception ex) { 155 } catch (IOException | ClassNotFoundException ex) { 158 156 Main.error(ex); 159 157 GuiHelper.runInEDTAndWait(new Runnable() { … … 176 174 imagesLock.lock(); 177 175 this.imagesToSave.add(image); 178 this.notify(); 176 this.notifyAll(); 179 177 imagesLock.unlock(); 180 178 } … … 224 222 225 223 private String WMSFileExtension() { 226 String ext = String.valueOf( (wmsLayer.getLambertZone() + 1));224 String ext = String.valueOf(wmsLayer.getLambertZone() + 1); 227 225 if (CadastrePlugin.isLambert_cc9()) 228 ext = cLambertCC9Z + ext;226 ext = C_LAMBERT_CC_9Z + ext; 229 227 else if (CadastrePlugin.isUtm_france_dom()) 230 ext = cUTM20N + ext;228 ext = C_UTM20N + ext; 231 229 return ext; 232 230 }
Note:
See TracChangeset
for help on using the changeset viewer.
