Changeset 10192 in josm


Ignore:
Timestamp:
2016-05-11T20:42:43+02:00 (8 years ago)
Author:
Don-vip
Message:

see #12774 - robustness/cleanup in session loading

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/SessionLoadAction.java

    r9296 r10192  
    5252                Arrays.asList(SessionImporter.FILE_FILTER, FileFilterAllFiles.getInstance()),
    5353                SessionImporter.FILE_FILTER, JFileChooser.FILES_ONLY, "lastDirectory");
    54         if (fc == null) return;
     54        if (fc == null)
     55            return;
    5556        File file = fc.getSelectedFile();
    5657        boolean zip = Utils.hasExtension(file, "joz");
     
    114115                @Override
    115116                public void run() {
    116                     if (canceled) return;
    117                     if (!layers.isEmpty()) {
    118                         Layer firstLayer = layers.get(0);
    119                         boolean noMap = Main.map == null;
    120                         if (noMap) {
    121                             Main.main.createMapFrame(firstLayer, viewport);
    122                         }
    123                         for (Layer l : layers) {
    124                             if (canceled) return;
    125                             Main.main.addLayer(l, (ViewportData) null);
    126                         }
    127                         if (active != null) {
    128                             Main.map.mapView.setActiveLayer(active);
    129                         }
    130                         if (noMap) {
    131                             Main.map.setVisible(true);
    132                         }
    133                     }
    134                     for (Runnable task : postLoadTasks) {
    135                         if (canceled) return;
    136                         if (task == null) {
    137                             continue;
    138                         }
    139                         task.run();
    140                     }
     117                    if (canceled)
     118                        return;
     119                    addLayers();
     120                    runPostLoadTasks();
    141121                }
    142122            });
     123        }
     124
     125        private void addLayers() {
     126            if (layers != null && !layers.isEmpty()) {
     127                Layer firstLayer = layers.get(0);
     128                boolean noMap = Main.map == null;
     129                if (noMap) {
     130                    Main.main.createMapFrame(firstLayer, viewport);
     131                }
     132                for (Layer l : layers) {
     133                    if (canceled)
     134                        return;
     135                    Main.main.addLayer(l, (ViewportData) null);
     136                }
     137                if (active != null) {
     138                    Main.map.mapView.setActiveLayer(active);
     139                }
     140                if (noMap) {
     141                    Main.map.setVisible(true);
     142                }
     143            }
     144        }
     145
     146        private void runPostLoadTasks() {
     147            for (Runnable task : postLoadTasks) {
     148                if (canceled)
     149                    return;
     150                if (task == null) {
     151                    continue;
     152                }
     153                task.run();
     154            }
    143155        }
    144156
Note: See TracChangeset for help on using the changeset viewer.