Ignore:
Timestamp:
2014-10-19T01:27:04+02:00 (10 years ago)
Author:
donvip
Message:

[josm_plugins] fix java 7 warnings / global usage of try-with-resource

Location:
applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/AutoSaveGpsLayerTimerTask.java

    r30646 r30738  
    6868            // @see LiveGpsLayer
    6969            PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(tmpFile)));
    70             GpxWriter gpxWriter = new GpxWriter(out);
    71             gpxWriter.write(gpsLayer.data);
    72             gpxWriter.close();
     70            try (GpxWriter gpxWriter = new GpxWriter(out)) {
     71                gpxWriter.write(gpsLayer.data);
     72            }
    7373            tmpFile.renameTo(file);
    7474        } catch (IOException ioExc) {
  • applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/SurveyorShowAction.java

    r30737 r30738  
    2626
    2727import org.openstreetmap.josm.Main;
     28import org.openstreetmap.josm.actions.JosmAction;
    2829import org.openstreetmap.josm.tools.Shortcut;
    2930import org.openstreetmap.josm.tools.XmlObjectParser;
    30 import org.openstreetmap.josm.actions.JosmAction;
    3131import org.xml.sax.SAXException;
    3232
     
    5050    }
    5151
    52     public void actionPerformed(ActionEvent e) {
     52    @Override
     53        public void actionPerformed(ActionEvent e) {
    5354        if(surveyorFrame == null) {
    5455            surveyorFrame = new JFrame();
     
    6465            // zoomout:
    6566            actionMap.put("zoomout", new AbstractAction() {
    66                 public void actionPerformed(ActionEvent e) {
     67                @Override
     68                                public void actionPerformed(ActionEvent e) {
    6769                    if(Main.map != null && Main.map.mapView != null) {
    6870                        Main.map.mapView.zoomToFactor(2);
     
    7375            // zoomin:
    7476            actionMap.put("zoomin", new AbstractAction() {
    75                 public void actionPerformed(ActionEvent e) {
     77                @Override
     78                                public void actionPerformed(ActionEvent e) {
    7679                    if(Main.map != null && Main.map.mapView != null) {
    7780                        Main.map.mapView.zoomToFactor(1/2);
     
    8285            // autocenter:
    8386            actionMap.put("autocenter", new AbstractAction() {
    84                 public void actionPerformed(ActionEvent e) {
     87                @Override
     88                                public void actionPerformed(ActionEvent e) {
    8589                    // toggle autocenter
    8690                    gpsPlugin.setAutoCenter(!gpsPlugin.isAutoCenter());
     
    105109
    106110    public SurveyorComponent createComponent() {
    107         InputStream in = null;
    108111        String source = Main.pref.get("surveyor.source");
    109112        if(source == null || source.length() == 0) {
     
    114117            // </FIXXME>
    115118        }
    116         SurveyorComponent component= null;
    117         try {
    118             in = ResourceLoader.getInputStream(source);
    119             component = createComponent(in);
    120             in.close();
    121             return component;
     119        try (InputStream in = ResourceLoader.getInputStream(source)) {
     120            return createComponent(in);
    122121        } catch (IOException e) {
    123             e.printStackTrace();
     122            Main.error(e);
    124123            JOptionPane.showMessageDialog(Main.parent, tr("Could not read surveyor definition: {0}",source));
    125124        } catch (SAXException e) {
    126             e.printStackTrace();
     125            Main.error(e);
    127126            JOptionPane.showMessageDialog(Main.parent, tr("Error parsing {0}: {1}", source, e.getMessage()));
    128127        }
    129         return component;
     128        return null;
    130129    }
    131130
  • applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/util/ResourceLoader.java

    r30646 r30738  
    2828     * @throws IOException if an error occurs on opening the url, or if the file is not found.
    2929     */
    30     public static InputStream getInputStream(String source) throws IOException {
     30    @SuppressWarnings("resource")
     31        public static InputStream getInputStream(String source) throws IOException {
    3132        InputStream in = null;
    3233        if (source.startsWith("http://") || source.startsWith("https://") || source.startsWith("ftp://") || source.startsWith("file:")) {
Note: See TracChangeset for help on using the changeset viewer.