Ticket #12906: patch-layer-manager-in-actions.patch

File patch-layer-manager-in-actions.patch, 16.7 KB (added by michael2402, 3 years ago)
  • src/org/openstreetmap/josm/actions/AddImageryLayerAction.java

    diff --git a/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java b/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
    index 9d20e99..f857d65 100644
    a b public class AddImageryLayerAction extends JosmAction implements AdaptableAction 
    168168            setEnabled(false);
    169169        } else if (type == ImageryType.TMS || type == ImageryType.BING || type == ImageryType.SCANEX) {
    170170            setEnabled(true);
    171         } else if (Main.isDisplayingMapView() && !Main.map.mapView.getAllLayers().isEmpty()) {
    172             setEnabled(true);
    173171        } else {
    174             setEnabled(false);
     172            setEnabled(!Main.getLayerManager().getLayers().isEmpty());
    175173        }
    176174    }
    177175}
  • src/org/openstreetmap/josm/actions/AutoScaleAction.java

    diff --git a/src/org/openstreetmap/josm/actions/AutoScaleAction.java b/src/org/openstreetmap/josm/actions/AutoScaleAction.java
    index 30798cb..ba02d71 100644
    a b public class AutoScaleAction extends JosmAction { 
    260260    }
    261261
    262262    private static BoundingXYVisitor modeData(BoundingXYVisitor v) {
    263         for (Layer l : Main.map.mapView.getAllLayers()) {
     263        for (Layer l : Main.getLayerManager().getLayers()) {
    264264            l.visitBoundingBox(v);
    265265        }
    266266        return v;
    public class AutoScaleAction extends JosmAction { 
    363363            setEnabled(Main.isDisplayingMapView() && Main.map.mapView.hasZoomRedoEntries());
    364364            break;
    365365        default:
    366             setEnabled(Main.isDisplayingMapView() && Main.map.mapView.hasLayers());
     366            setEnabled(!Main.getLayerManager().getLayers().isEmpty());
    367367        }
    368368    }
    369369
  • src/org/openstreetmap/josm/actions/DeleteLayerAction.java

    diff --git a/src/org/openstreetmap/josm/actions/DeleteLayerAction.java b/src/org/openstreetmap/josm/actions/DeleteLayerAction.java
    index 893449f..23bcdd8 100644
    a b  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.actions;
    33
    4 import static org.openstreetmap.josm.tools.I18n.tr;
    54import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
     5import static org.openstreetmap.josm.tools.I18n.tr;
    66
    77import java.awt.event.ActionEvent;
    88import java.awt.event.KeyEvent;
    99import java.util.Collections;
    1010
    1111import org.openstreetmap.josm.Main;
    12 import org.openstreetmap.josm.tools.Shortcut;
    1312import org.openstreetmap.josm.gui.layer.Layer;
     13import org.openstreetmap.josm.tools.Shortcut;
    1414
    1515/**
    1616 * Deletes the active layer.
    public final class DeleteLayerAction extends JosmAction { 
    4141
    4242    @Override
    4343    protected void updateEnabledState() {
    44         setEnabled(Main.isDisplayingMapView() && Main.map.mapView.getActiveLayer() != null);
     44        setEnabled(Main.getLayerManager().getActiveLayer() != null);
    4545    }
    4646}
  • src/org/openstreetmap/josm/actions/DownloadNotesInViewAction.java

    diff --git a/src/org/openstreetmap/josm/actions/DownloadNotesInViewAction.java b/src/org/openstreetmap/josm/actions/DownloadNotesInViewAction.java
    index 97a3a10..65c9e3b 100644
    a b public final class DownloadNotesInViewAction extends JosmAction { 
    4242
    4343    @Override
    4444    protected void updateEnabledState() {
    45         setEnabled(Main.isDisplayingMapView()
    46                 && Main.map.mapView.getActiveLayer() != null
     45        setEnabled(Main.getLayerManager().getActiveLayer() != null
    4746                && !Main.isOffline(OnlineResource.OSM_API));
    4847    }
    4948}
  • src/org/openstreetmap/josm/actions/GpxExportAction.java

    diff --git a/src/org/openstreetmap/josm/actions/GpxExportAction.java b/src/org/openstreetmap/josm/actions/GpxExportAction.java
    index 50a16d5..0fd1650 100644
    a b public class GpxExportAction extends DiskAccessAction { 
    4242     * @return The layer to export, either a {@link GpxLayer} or {@link OsmDataLayer}.
    4343     */
    4444    protected Layer getLayer() {
    45         if (!Main.isDisplayingMapView())
    46             return null;
    47         Layer layer = Main.map.mapView.getActiveLayer();
     45        Layer layer = Main.getLayerManager().getActiveLayer();
    4846        return (layer instanceof GpxLayer || layer instanceof OsmDataLayer) ? layer : null;
    4947    }
    5048
  • src/org/openstreetmap/josm/actions/MapRectifierWMSmenuAction.java

    diff --git a/src/org/openstreetmap/josm/actions/MapRectifierWMSmenuAction.java b/src/org/openstreetmap/josm/actions/MapRectifierWMSmenuAction.java
    index e15a6ca..a57e538 100644
    a b public class MapRectifierWMSmenuAction extends JosmAction { 
    238238
    239239    @Override
    240240    protected void updateEnabledState() {
    241         setEnabled(Main.isDisplayingMapView() && !Main.map.mapView.getAllLayers().isEmpty());
     241        setEnabled(!Main.getLayerManager().getLayers().isEmpty());
    242242    }
    243243}
  • src/org/openstreetmap/josm/actions/MergeLayerAction.java

    diff --git a/src/org/openstreetmap/josm/actions/MergeLayerAction.java b/src/org/openstreetmap/josm/actions/MergeLayerAction.java
    index 7e2e380..683285f 100644
    a b public class MergeLayerAction extends AbstractMergeAction { 
    6363                    }
    6464                }
    6565                if (layerMerged) {
    66                     Main.map.mapView.setActiveLayer(targetLayer);
     66                    Main.getLayerManager().setActiveLayer(targetLayer);
    6767                }
    6868            }
    6969        });
  • src/org/openstreetmap/josm/actions/SaveActionBase.java

    diff --git a/src/org/openstreetmap/josm/actions/SaveActionBase.java b/src/org/openstreetmap/josm/actions/SaveActionBase.java
    index e468f07..c812e1c 100644
    a b public abstract class SaveActionBase extends DiskAccessAction { 
    5151     * @return {@code true} if the save operation succeeds
    5252     */
    5353    public boolean doSave() {
    54         if (Main.isDisplayingMapView()) {
    55             Layer layer = Main.map.mapView.getActiveLayer();
    56             if (layer != null && layer.isSavable()) {
    57                 return doSave(layer);
    58             }
     54        Layer layer = Main.getLayerManager().getActiveLayer();
     55        if (layer != null && layer.isSavable()) {
     56            return doSave(layer);
    5957        }
    6058        return false;
    6159    }
    public abstract class SaveActionBase extends DiskAccessAction { 
    133131     */
    134132    @Override
    135133    protected void updateEnabledState() {
    136         boolean check = Main.isDisplayingMapView()
    137         && Main.map.mapView.getActiveLayer() != null;
    138         if (!check) {
    139             setEnabled(false);
    140             return;
    141         }
    142         Layer layer = Main.map.mapView.getActiveLayer();
    143         setEnabled(layer != null && layer.isSavable());
     134        Layer activeLayer = Main.getLayerManager().getActiveLayer();
     135        setEnabled(activeLayer != null && activeLayer.isSavable());
    144136    }
    145137
    146138    /**
  • src/org/openstreetmap/josm/actions/SessionLoadAction.java

    diff --git a/src/org/openstreetmap/josm/actions/SessionLoadAction.java b/src/org/openstreetmap/josm/actions/SessionLoadAction.java
    index 260ca4b..cd390f2 100644
    a b public class SessionLoadAction extends DiskAccessAction { 
    135135                    Main.main.addLayer(l, (ViewportData) null);
    136136                }
    137137                if (active != null) {
    138                     Main.map.mapView.setActiveLayer(active);
     138                    Main.getLayerManager().setActiveLayer(active);
    139139                }
    140140                if (noMap) {
    141141                    Main.map.setVisible(true);
  • src/org/openstreetmap/josm/actions/SessionSaveAsAction.java

    diff --git a/src/org/openstreetmap/josm/actions/SessionSaveAsAction.java b/src/org/openstreetmap/josm/actions/SessionSaveAsAction.java
    index 3990ce88..5e16b54 100644
    a b public class SessionSaveAsAction extends DiskAccessAction implements MapFrameLis 
    160160        }
    161161
    162162        int active = -1;
    163         Layer activeLayer = Main.map.mapView.getActiveLayer();
     163        Layer activeLayer = Main.getLayerManager().getActiveLayer();
    164164        if (activeLayer != null) {
    165165            active = layersOut.indexOf(activeLayer);
    166166        }
    public class SessionSaveAsAction extends DiskAccessAction implements MapFrameLis 
    203203         * Initializes action.
    204204         */
    205205        public final void initialize() {
    206             layers = new ArrayList<>(Main.map.mapView.getAllLayersAsList());
     206            layers = new ArrayList<>(Main.getLayerManager().getLayers());
    207207            exporters = new HashMap<>();
    208208            dependencies = new MultiMap<>();
    209209
  • src/org/openstreetmap/josm/actions/UploadNotesAction.java

    diff --git a/src/org/openstreetmap/josm/actions/UploadNotesAction.java b/src/org/openstreetmap/josm/actions/UploadNotesAction.java
    index b30f061..3a2f6d9 100644
    a b public class UploadNotesAction extends JosmAction { 
    3030
    3131    @Override
    3232    public void actionPerformed(ActionEvent e) {
    33         List<NoteLayer> noteLayers = null;
    34         if (Main.map != null) {
    35             noteLayers = Main.map.mapView.getLayersOfType(NoteLayer.class);
    36         }
     33        List<NoteLayer> noteLayers = Main.getLayerManager().getLayersOfType(NoteLayer.class);
    3734        NoteLayer layer;
    38         if (noteLayers != null && !noteLayers.isEmpty()) {
     35        if (!noteLayers.isEmpty()) {
    3936            layer = noteLayers.get(0);
    4037        } else {
    4138            Main.error("No note layer found");
    4239            return;
    4340        }
    44         if (Main.isDebugEnabled()) {
    45             Main.debug("uploading note changes");
    46         }
     41        Main.debug("uploading note changes");
    4742        NoteData noteData = layer.getNoteData();
    4843
    4944        if (noteData == null || !noteData.isModified()) {
    50             if (Main.isDebugEnabled()) {
    51                 Main.debug("No changed notes to upload");
    52             }
     45            Main.debug("No changed notes to upload");
    5346            return;
    5447        }
    5548        new UploadNotesTask().uploadNotes(noteData, new PleaseWaitProgressMonitor(tr("Uploading notes to server")));
  • src/org/openstreetmap/josm/actions/ZoomInAction.java

    diff --git a/src/org/openstreetmap/josm/actions/ZoomInAction.java b/src/org/openstreetmap/josm/actions/ZoomInAction.java
    index 20853e9..d690678 100644
    a b public final class ZoomInAction extends JosmAction { 
    5151
    5252    @Override
    5353    protected void updateEnabledState() {
    54         setEnabled(
    55                 Main.isDisplayingMapView()
    56                 && Main.map.mapView.hasLayers()
    57         );
     54        setEnabled(!Main.getLayerManager().getLayers().isEmpty());
    5855    }
    5956
    6057}
  • src/org/openstreetmap/josm/actions/ZoomOutAction.java

    diff --git a/src/org/openstreetmap/josm/actions/ZoomOutAction.java b/src/org/openstreetmap/josm/actions/ZoomOutAction.java
    index 98bb1c2..1eb440d 100644
    a b public final class ZoomOutAction extends JosmAction { 
    3737
    3838    @Override
    3939    protected void updateEnabledState() {
    40         setEnabled(
    41                 Main.isDisplayingMapView()
    42                 && Main.map.mapView.hasLayers()
    43         );
     40        setEnabled(!Main.getLayerManager().getLayers().isEmpty());
    4441    }
    4542}
  • src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java

    diff --git a/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java b/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
    index b1e1324..024b189 100644
    a b public class DownloadGpsTask extends AbstractDownloadTask<GpxData> { 
    154154        }
    155155
    156156        private GpxLayer findGpxMergeLayer() {
    157             if (!Main.isDisplayingMapView())
    158                 return null;
    159157            boolean merge = Main.pref.getBoolean("download.gps.mergeWithLocal", false);
    160             Layer active = Main.map.mapView.getActiveLayer();
     158            Layer active = Main.getLayerManager().getActiveLayer();
    161159            if (active instanceof GpxLayer && (merge || ((GpxLayer) active).data.fromServer))
    162160                return (GpxLayer) active;
    163             for (GpxLayer l : Main.map.mapView.getLayersOfType(GpxLayer.class)) {
     161            for (GpxLayer l : Main.getLayerManager().getLayersOfType(GpxLayer.class)) {
    164162                if (merge || l.data.fromServer)
    165163                    return l;
    166164            }
    public class DownloadGpsTask extends AbstractDownloadTask<GpxData> { 
    168166        }
    169167
    170168        private MarkerLayer findMarkerMergeLayer(GpxLayer fromLayer) {
    171             if (!Main.isDisplayingMapView())
    172                 return null;
    173             for (MarkerLayer l : Main.map.mapView.getLayersOfType(MarkerLayer.class)) {
     169            for (MarkerLayer l : Main.getLayerManager().getLayersOfType(MarkerLayer.class)) {
    174170                if (fromLayer != null && l.fromLayer == fromLayer)
    175171                    return l;
    176172            }
  • src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTask.java

    diff --git a/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTask.java b/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTask.java
    index 7f99e86..bdc48a4 100644
    a b public class DownloadNotesTask extends AbstractDownloadTask<NoteData> { 
    112112                Main.debug("Notes downloaded: " + notesData.size());
    113113            }
    114114
    115             List<NoteLayer> noteLayers = null;
    116             if (Main.map != null) {
    117                 noteLayers = Main.map.mapView.getLayersOfType(NoteLayer.class);
    118             }
    119             if (noteLayers != null && !noteLayers.isEmpty()) {
     115            List<NoteLayer> noteLayers = Main.getLayerManager().getLayersOfType(NoteLayer.class);
     116            if (!noteLayers.isEmpty()) {
    120117                noteLayers.get(0).getNoteData().addNotes(notesData);
    121118            } else {
    122119                Main.main.addLayer(new NoteLayer(notesData, tr("Notes")));
  • src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    diff --git a/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java b/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
    index 6499870..2fbbd13 100644
    a b import org.openstreetmap.josm.data.coor.LatLon; 
    1919import org.openstreetmap.josm.data.osm.DataSet;
    2020import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    2121import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    22 import org.openstreetmap.josm.gui.layer.Layer;
    2322import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2423import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    2524import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    public class DownloadOsmTask extends AbstractDownloadTask<DataSet> { 
    216215        }
    217216
    218217        protected int getNumDataLayers() {
    219             if (!Main.isDisplayingMapView()) return 0;
    220             return Utils.filteredCollection(Main.map.mapView.getAllLayers(), OsmDataLayer.class).size();
     218            return Main.getLayerManager().getLayersOfType(OsmDataLayer.class).size();
    221219        }
    222220
    223221        protected OsmDataLayer getFirstDataLayer() {
    224             if (!Main.isDisplayingMapView()) return null;
    225             Collection<Layer> layers = Main.map.mapView.getAllLayersAsList();
    226             for (Layer layer : layers) {
    227                 if (layer instanceof OsmDataLayer)
    228                     return (OsmDataLayer) layer;
    229             }
    230             return null;
     222            return Utils.find(Main.getLayerManager().getLayers(), OsmDataLayer.class);
    231223        }
    232224
    233225        protected OsmDataLayer createNewLayer(String layerName) {
  • src/org/openstreetmap/josm/actions/downloadtasks/DownloadTaskList.java

    diff --git a/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTaskList.java b/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTaskList.java
    index 4bcb3c9..42a7fd1 100644
    a b public class DownloadTaskList { 
    7272        if (newLayer) {
    7373            Layer l = new OsmDataLayer(new DataSet(), OsmDataLayer.createNewName(), null);
    7474            Main.main.addLayer(l);
    75             Main.map.mapView.setActiveLayer(l);
     75            Main.getLayerManager().setActiveLayer(l);
    7676        }
    7777
    7878        int n = (osmData && gpxData ? 2 : 1)*rects.size();