Ignore:
Timestamp:
2018-01-13T18:19:22+01:00 (8 years ago)
Author:
donvip
Message:

code cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/indoorhelper/src/org/openstreetmap/josm/plugins/indoorhelper/IndoorHelperPlugin.java

    r33997 r34005  
    4040import controller.IndoorHelperController;
    4141
    42 
    4342/**
    4443 * This is the main class for the indoorhelper plug-in.
     
    5049public class IndoorHelperPlugin extends Plugin implements PaintableInvalidationListener, ActiveLayerChangeListener {
    5150
    52 
    53         @SuppressWarnings("unused")
     51    @SuppressWarnings("unused")
    5452    private IndoorHelperController controller;
    5553    String sep = System.getProperty("file.separator");
     
    9189     * Exports the mapcss validator file to the preferences directory.
    9290     */
    93     @SuppressWarnings("deprecation")
    94         private void exportValidator(String resourceName) throws Exception {
     91    private void exportValidator(String resourceName) throws Exception {
    9592        InputStream stream = null;
    9693        OutputStream resStreamOut = null;
     
    107104            byte[] buffer = new byte[4096];
    108105
    109             String valDirPath = Main.pref.getUserDataDirectory() + sep + "validator";
     106            String valDirPath = Main.pref.getDirs().getUserDataDirectory(true) + sep + "validator";
    110107            File valDir = new File(valDirPath);
    111108            valDir.mkdirs();
     
    129126     */
    130127    private void exportStyleFile(String resourceName) throws Exception {
    131         InputStream stream = null;
    132         OutputStream resStreamOut = null;
    133 
    134         try {
    135             stream = IndoorHelperPlugin.class.getResourceAsStream("/data/" + resourceName);
     128        try (InputStream stream = IndoorHelperPlugin.class.getResourceAsStream("/data/" + resourceName)) {
    136129            if (stream == null) {
    137130                System.out.println("MapPaint: stream is null");
     
    143136            byte[] buffer = new byte[4096];
    144137
    145             @SuppressWarnings("deprecation")
    146                         String valDirPath = Main.pref.getUserDataDirectory() + sep + "styles";
     138            String valDirPath = Main.pref.getDirs().getUserDataDirectory(true) + sep + "styles";
    147139            File valDir = new File(valDirPath);
    148140            valDir.mkdirs();
    149141            outPath = valDir.getAbsolutePath() +sep+ resourceName;
    150             System.out.println("MapPaint"+outPath);
    151 
    152             resStreamOut = new FileOutputStream(outPath);
    153             while ((readBytes = stream.read(buffer)) > 0) {
    154                 resStreamOut.write(buffer, 0, readBytes);
    155             }
    156             resStreamOut.close();
     142
     143            try (OutputStream resStreamOut = new FileOutputStream(outPath)) {
     144                while ((readBytes = stream.read(buffer)) > 0) {
     145                    resStreamOut.write(buffer, 0, readBytes);
     146                }
     147            }
    157148        } catch (Exception ex) {
    158149            throw ex;
    159         } finally {
    160             stream.close();
    161         }
    162     }
    163 
    164         @Override
    165         public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    166                 OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
     150        }
     151    }
     152
     153    @Override
     154    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     155        OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    167156        if (editLayer != null) {
    168157            editLayer.addInvalidationListener(this);
    169158        }
    170         }
    171 
    172         @Override
    173         public void paintableInvalidated(PaintableInvalidationEvent event){
    174                 AutoFilter currentAutoFilter = AutoFilterManager.getInstance().getCurrentAutoFilter();
    175                 String currentFilterValue = new String();
    176 
    177                 if(currentAutoFilter != null) {
    178                         currentFilterValue = currentAutoFilter.getFilter().text.split("=")[1];
    179 
    180                         this.controller.setIndoorLevel(currentFilterValue);
    181                         this.controller.getIndoorLevel(currentFilterValue);
    182                         this.controller.unsetSpecificKeyFilter("repeat_on");
    183 
    184                 }else{
    185                         currentFilterValue = "";
    186                         this.controller.setIndoorLevel(currentFilterValue);
    187                         this.controller.getIndoorLevel(currentFilterValue);
    188                 };
    189 
    190         }
     159    }
     160
     161    @Override
     162    public void paintableInvalidated(PaintableInvalidationEvent event) {
     163        AutoFilter currentAutoFilter = AutoFilterManager.getInstance().getCurrentAutoFilter();
     164        String currentFilterValue = new String();
     165
     166        if (currentAutoFilter != null) {
     167            currentFilterValue = currentAutoFilter.getFilter().text.split("=")[1];
     168
     169            this.controller.setIndoorLevel(currentFilterValue);
     170            this.controller.getIndoorLevel(currentFilterValue);
     171            this.controller.unsetSpecificKeyFilter("repeat_on");
     172
     173        } else {
     174            currentFilterValue = "";
     175            this.controller.setIndoorLevel(currentFilterValue);
     176            this.controller.getIndoorLevel(currentFilterValue);
     177        }
     178    }
    191179
    192180    /**
     
    232220//        }
    233221//    }
    234 
    235 /**
    236  *
    237  *
    238  *
    239  *
    240  *
    241  *
    242  *
    243  *
    244  *
    245  */
    246222}
Note: See TracChangeset for help on using the changeset viewer.