Ignore:
Timestamp:
2016-06-01T00:55:28+02:00 (10 years ago)
Author:
donvip
Message:

sonar - fix many issues

File:
1 edited

Legend:

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

    r32163 r32211  
    1313import java.io.OutputStream;
    1414import java.util.ArrayList;
     15import java.util.concurrent.Callable;
    1516import java.util.concurrent.locks.Lock;
    1617import java.util.concurrent.locks.ReentrantLock;
     
    3334public class CacheControl implements Runnable {
    3435
    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 {
    4041        public ObjectOutputStreamAppend(OutputStream out) throws IOException {
    4142            super(out);
     
    5152    public static int cacheSize = 500;
    5253
    53     public WMSLayer wmsLayer = null;
     54    public WMSLayer wmsLayer;
    5455
    5556    private ArrayList<GeorefImage> imagesToSave = new ArrayList<>();
     
    7980    }
    8081
    81     private void checkDirSize(File path) {
     82    private static void checkDirSize(File path) {
    8283        if (cacheSize != 0) {
    8384            long size = 0;
     
    105106            CadastrePlugin.askToChangeProjection();
    106107        }
    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            }
    130132        }
    131133        return false;
     
    133135
    134136    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) {
    143141        Main.info("Delete file "+file);
    144142        if (file.exists())
     
    155153        ) {
    156154            successfulRead = wmsLayer.read(file, ois, currentLambertZone);
    157         } catch (Exception ex) {
     155        } catch (IOException | ClassNotFoundException ex) {
    158156            Main.error(ex);
    159157            GuiHelper.runInEDTAndWait(new Runnable() {
     
    176174        imagesLock.lock();
    177175        this.imagesToSave.add(image);
    178         this.notify();
     176        this.notifyAll();
    179177        imagesLock.unlock();
    180178    }
     
    224222
    225223    private String WMSFileExtension() {
    226         String ext = String.valueOf((wmsLayer.getLambertZone() + 1));
     224        String ext = String.valueOf(wmsLayer.getLambertZone() + 1);
    227225        if (CadastrePlugin.isLambert_cc9())
    228             ext = cLambertCC9Z + ext;
     226            ext = C_LAMBERT_CC_9Z + ext;
    229227        else if (CadastrePlugin.isUtm_france_dom())
    230             ext = cUTM20N + ext;
     228            ext = C_UTM20N + ext;
    231229        return ext;
    232230    }
Note: See TracChangeset for help on using the changeset viewer.