Ticket #13023: patch-layer-manager-has-edit-layer.patch

File patch-layer-manager-has-edit-layer.patch, 18.7 KB (added by michael2402, 9 years ago)
  • 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 7438bdd..fd8fcf8 100644
    a b public class AutoScaleAction extends JosmAction {  
    7373     *
    7474     */
    7575    public static void zoomToSelection() {
    76         if (Main.main == null || !Main.main.hasEditLayer())
     76        DataSet dataSet = Main.getLayerManager().getEditDataSet();
     77        if (dataSet == null) {
    7778            return;
    78         Collection<OsmPrimitive> sel = Main.getLayerManager().getEditLayer().data.getSelected();
     79        }
     80        Collection<OsmPrimitive> sel = dataSet.getSelected();
    7981        if (sel.isEmpty()) {
    8082            JOptionPane.showMessageDialog(
    8183                    Main.parent,
    public class AutoScaleAction extends JosmAction {  
    278280    private BoundingXYVisitor modeSelectionOrConflict(BoundingXYVisitor v) {
    279281        Collection<OsmPrimitive> sel = new HashSet<>();
    280282        if ("selection".equals(mode)) {
    281             sel = getLayerManager().getEditDataSet().getSelected();
     283            DataSet dataSet = getLayerManager().getEditDataSet();
     284            if (dataSet != null) {
     285                sel = dataSet.getSelected();
     286            }
    282287        } else {
    283288            Conflict<? extends OsmPrimitive> c = Main.map.conflictDialog.getSelectedConflict();
    284289            if (c != null) {
  • src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

    diff --git a/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java b/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java
    index db225a0..1ff34ab 100644
    a b public class CreateMultipolygonAction extends JosmAction {  
    134134
    135135    @Override
    136136    public void actionPerformed(ActionEvent e) {
    137         if (!Main.main.hasEditLayer()) {
     137        DataSet dataSet = Main.getLayerManager().getEditDataSet();
     138        if (dataSet == null) {
    138139            new Notification(
    139140                    tr("No data loaded."))
    140141                    .setIcon(JOptionPane.WARNING_MESSAGE)
    public class CreateMultipolygonAction extends JosmAction {  
    143144            return;
    144145        }
    145146
    146         final Collection<Way> selectedWays = Main.getLayerManager().getEditDataSet().getSelectedWays();
     147        final Collection<Way> selectedWays = dataSet.getSelectedWays();
    147148
    148149        if (selectedWays.isEmpty()) {
    149150            // Sometimes it make sense creating multipoly of only one way (so it will form outer way)
    public class CreateMultipolygonAction extends JosmAction {  
    156157            return;
    157158        }
    158159
    159         final Collection<Relation> selectedRelations = Main.getLayerManager().getEditDataSet().getSelectedRelations();
     160        final Collection<Relation> selectedRelations = dataSet.getSelectedRelations();
    160161        final Relation multipolygonRelation = update
    161162                ? getSelectedMultipolygonRelation(selectedWays, selectedRelations)
    162163                : null;
  • src/org/openstreetmap/josm/actions/ViewportFollowToggleAction.java

    diff --git a/src/org/openstreetmap/josm/actions/ViewportFollowToggleAction.java b/src/org/openstreetmap/josm/actions/ViewportFollowToggleAction.java
    index 1c96710..13c232a 100644
    a b public class ViewportFollowToggleAction extends ToggleAction {  
    4141
    4242    @Override
    4343    protected void updateEnabledState() {
    44         setEnabled(Main.main.hasEditLayer());
     44        setEnabled(Main.getLayerManager().getEditDataSet() != null);
    4545    }
    4646}
  • src/org/openstreetmap/josm/actions/WireframeToggleAction.java

    diff --git a/src/org/openstreetmap/josm/actions/WireframeToggleAction.java b/src/org/openstreetmap/josm/actions/WireframeToggleAction.java
    index 474cb7e..95c7cb8 100644
    a b public class WireframeToggleAction extends ToggleAction {  
    3636
    3737    @Override
    3838    protected void updateEnabledState() {
    39         setEnabled(Main.main.hasEditLayer());
     39        setEnabled(Main.getLayerManager().getEditLayer() != null);
    4040    }
    4141
    4242    @Override
  • src/org/openstreetmap/josm/actions/relation/DeleteRelationsAction.java

    diff --git a/src/org/openstreetmap/josm/actions/relation/DeleteRelationsAction.java b/src/org/openstreetmap/josm/actions/relation/DeleteRelationsAction.java
    index 530213b..fb49dfe 100644
    a b import java.util.Collection;  
    99import org.openstreetmap.josm.Main;
    1010import org.openstreetmap.josm.actions.mapmode.DeleteAction;
    1111import org.openstreetmap.josm.data.osm.Relation;
     12import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1213import org.openstreetmap.josm.tools.ImageProvider;
    1314
    1415/**
    public class DeleteRelationsAction extends AbstractRelationAction {  
    2728    }
    2829
    2930    protected void deleteRelation(Collection<Relation> toDelete) {
    30         if (toDelete == null)
     31        OsmDataLayer layer = Main.getLayerManager().getEditLayer();
     32        if (toDelete == null || layer == null)
    3133            return;
    32         DeleteAction.deleteRelations(Main.getLayerManager().getEditLayer(), toDelete);
     34
     35        DeleteAction.deleteRelations(layer, toDelete);
    3336        // clear selection after deletion
    3437        if (Main.map.relationListDialog != null)
    3538                Main.map.relationListDialog.selectRelations(null);
    public class DeleteRelationsAction extends AbstractRelationAction {  
    3740
    3841    @Override
    3942    public void actionPerformed(ActionEvent e) {
    40         if (!isEnabled() || !Main.main.hasEditLayer())
     43        if (!isEnabled())
    4144            return;
    4245        deleteRelation(relations);
    4346    }
  • src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java

    diff --git a/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java b/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java
    index 5fbef85..411a734 100644
    a b import org.openstreetmap.josm.Main;  
    2020import org.openstreetmap.josm.data.coor.EastNorth;
    2121import org.openstreetmap.josm.data.coor.LatLon;
    2222import org.openstreetmap.josm.data.osm.BBox;
     23import org.openstreetmap.josm.data.osm.DataSet;
    2324import org.openstreetmap.josm.data.osm.Node;
    2425import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2526import org.openstreetmap.josm.data.osm.QuadBuckets;
    public abstract class UnconnectedWays extends Test {  
    163164        othernodes = new HashSet<>();
    164165        mindist = Main.pref.getDouble(PREFIX + ".node_way_distance", 10.0);
    165166        minmiddledist = Main.pref.getDouble(PREFIX + ".way_way_distance", 0.0);
    166         dsArea = Main.main == null || !Main.main.hasEditLayer() ? null : Main.getLayerManager().getEditDataSet().getDataSourceArea();
     167        DataSet dataSet = Main.getLayerManager().getEditDataSet();
     168        dsArea = dataSet == null ? null : dataSet.getDataSourceArea();
    167169    }
    168170
    169171    protected Map<Node, Way> getWayEndNodesNearOtherHighway() {
  • src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java b/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java
    index 03b2cef..e882c95 100644
    a b public class ChangesetDialog extends ToggleDialog {  
    315315
    316316        @Override
    317317        public void actionPerformed(ActionEvent e) {
    318             if (!Main.main.hasEditLayer())
     318            if (Main.getLayerManager().getEditLayer() == null)
    319319                return;
    320320            ChangesetListModel model = getCurrentChangesetListModel();
    321321            Set<Integer> sel = model.getSelectedChangesetIds();
  • src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java b/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
    index 2059f50..d084a4f 100644
    a b import org.openstreetmap.josm.Main;  
    3838import org.openstreetmap.josm.actions.AutoScaleAction;
    3939import org.openstreetmap.josm.command.Command;
    4040import org.openstreetmap.josm.command.PseudoCommand;
     41import org.openstreetmap.josm.data.osm.DataSet;
    4142import org.openstreetmap.josm.data.osm.OsmPrimitive;
    4243import org.openstreetmap.josm.gui.SideButton;
    4344import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    public class CommandStackDialog extends ToggleDialog implements CommandQueueList  
    388389            } else
    389390                throw new IllegalStateException();
    390391
    391             OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
    392             if (editLayer == null) return;
    393             editLayer.data.setSelected(getAffectedPrimitives(path));
     392            DataSet dataSet = Main.getLayerManager().getEditDataSet();
     393            if (dataSet == null) return;
     394            dataSet.setSelected(getAffectedPrimitives(path));
    394395        }
    395396
    396397        @Override
    public class CommandStackDialog extends ToggleDialog implements CommandQueueList  
    416417        @Override
    417418        public void actionPerformed(ActionEvent e) {
    418419            super.actionPerformed(e);
    419             if (!Main.main.hasEditLayer()) return;
    420420            AutoScaleAction.autoScale("selection");
    421421        }
    422422    }
  • src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java b/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
    index fdaedd2..59e0cae 100644
    a b public class RelationListDialog extends ToggleDialog  
    370370        }
    371371
    372372        protected void updateEnabledState() {
    373             setEnabled(Main.main != null && Main.main.hasEditLayer());
     373            setEnabled(Main.getLayerManager().getEditLayer() != null);
    374374        }
    375375
    376376        @Override
  • src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java b/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
    index a192b92..3f56870 100644
    a b public class SelectionListDialog extends ToggleDialog {  
    309309        }
    310310
    311311        protected void updateEnabledState() {
    312             setEnabled(Main.main != null && Main.main.hasEditLayer());
     312            setEnabled(Main.getLayerManager().getEditLayer() != null);
    313313        }
    314314
    315315        @Override
  • src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java b/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java
    index fe959a9..ca0b830 100644
    a b public class ChangesetContentPanel extends JPanel implements PropertyChangeListe  
    332332    abstract class SelectionBasedAction extends AbstractAction implements ListSelectionListener, ActiveLayerChangeListener {
    333333
    334334        protected Set<OsmPrimitive> getTarget() {
    335             if (!isEnabled() || Main.main == null || !Main.main.hasEditLayer()) {
     335            if (!isEnabled()) {
    336336                return null;
    337337            }
    338338            OsmDataLayer layer = Main.getLayerManager().getEditLayer();
     339            if (layer == null) {
     340                return null;
     341            }
    339342            Set<OsmPrimitive> target = new HashSet<>();
    340343            for (HistoryOsmPrimitive p : model.getSelectedPrimitives()) {
    341344                OsmPrimitive op = layer.data.getPrimitiveById(p.getPrimitiveId());
    public class ChangesetContentPanel extends JPanel implements PropertyChangeListe  
    347350        }
    348351
    349352        public final void updateEnabledState() {
    350             if (Main.main == null || !Main.main.hasEditLayer()) {
    351                 setEnabled(false);
    352                 return;
    353             }
    354             setEnabled(model.hasSelectedPrimitives());
     353            setEnabled(Main.getLayerManager().getEditLayer() != null && model.hasSelectedPrimitives());
    355354        }
    356355
    357356        @Override
  • src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java b/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java
    index 51272fc..c875d2d 100644
    a b public class ChangesetDetailPanel extends JPanel implements PropertyChangeListen  
    346346        public void actionPerformed(ActionEvent arg0) {
    347347            if (!isEnabled())
    348348                return;
    349             if (Main.main == null || !Main.main.hasEditLayer()) return;
    350349            OsmDataLayer layer = Main.getLayerManager().getEditLayer();
     350            if (layer == null) {
     351                return;
     352            }
    351353            Set<OsmPrimitive> target = new HashSet<>();
    352354            for (OsmPrimitive p: layer.data.allPrimitives()) {
    353355                if (p.isUsable() && p.getChangesetId() == currentChangeset.getId()) {
    public class ChangesetDetailPanel extends JPanel implements PropertyChangeListen  
    362364        }
    363365
    364366        public void updateEnabledState() {
    365             if (Main.main == null || !Main.main.hasEditLayer()) {
    366                 setEnabled(false);
    367                 return;
    368             }
    369             setEnabled(currentChangeset != null);
     367            setEnabled(Main.getLayerManager().getEditLayer() != null && currentChangeset != null);
    370368        }
    371369
    372370        @Override
    public class ChangesetDetailPanel extends JPanel implements PropertyChangeListen  
    407405        public void actionPerformed(ActionEvent arg0) {
    408406            if (!isEnabled())
    409407                return;
    410             if (Main.main == null || !Main.main.hasEditLayer()) return;
    411408            OsmDataLayer layer = Main.getLayerManager().getEditLayer();
     409            if (layer == null) {
     410                return;
     411            }
    412412            Set<OsmPrimitive> target = new HashSet<>();
    413413            for (OsmPrimitive p: layer.data.allPrimitives()) {
    414414                if (p.isUsable() && p.getChangesetId() == currentChangeset.getId()) {
    public class ChangesetDetailPanel extends JPanel implements PropertyChangeListen  
    424424        }
    425425
    426426        public void updateEnabledState() {
    427             if (Main.main == null || !Main.main.hasEditLayer()) {
    428                 setEnabled(false);
    429                 return;
    430             }
    431             setEnabled(currentChangeset != null);
     427            setEnabled(Main.getLayerManager().getEditLayer() != null && currentChangeset != null);
    432428        }
    433429
    434430        @Override
  • src/org/openstreetmap/josm/gui/history/NodeListViewer.java

    diff --git a/src/org/openstreetmap/josm/gui/history/NodeListViewer.java b/src/org/openstreetmap/josm/gui/history/NodeListViewer.java
    index dc37a0a..d3c7f7b 100644
    a b public class NodeListViewer extends JPanel {  
    265265        }
    266266
    267267        public void updateEnabledState() {
    268             if (!Main.main.hasEditLayer()) {
    269                 setEnabled(false);
    270                 return;
    271             }
    272             setEnabled(getPrimitiveToZoom() != null);
     268            setEnabled(Main.getLayerManager().getEditLayer() != null && getPrimitiveToZoom() != null);
    273269        }
    274270    }
    275271
  • src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java

    diff --git a/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java b/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java
    index 642e05d..a72a581 100644
    a b public class ValidatorLayer extends Layer implements LayerChangeListener {  
    162162     */
    163163    @Override
    164164    public void layerRemoving(LayerRemoveEvent e) {
    165         if (e.getRemovedLayer() instanceof OsmDataLayer && Main.isDisplayingMapView() && !Main.main.hasEditLayer()) {
     165        // Removed layer is still in that list.
     166        if (e.getRemovedLayer() instanceof OsmDataLayer && e.getSource().getLayersOfType(OsmDataLayer.class).size() <= 1) {
    166167            Main.getLayerManager().removeLayer(this);
    167168        } else if (e.getRemovedLayer() == this) {
    168169            Main.getLayerManager().removeLayerChangeListener(this);
  • src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java

    diff --git a/src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java b/src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java
    index 7a470a5..9f64c14 100644
    a b public class MapPaintMenu extends JMenu implements MapPaintSylesUpdateListener {  
    6565
    6666        @Override
    6767        public void updateEnabledState() {
    68             setEnabled(Main.isDisplayingMapView() && (Main.main.hasEditLayer() || mapHasGpxorMarkerLayer()));
     68            setEnabled(Main.isDisplayingMapView() && (Main.getLayerManager().getEditLayer() != null || mapHasGpxorMarkerLayer()));
    6969        }
    7070
    7171        private static boolean mapHasGpxorMarkerLayer() {
  • src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java

    diff --git a/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java b/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java
    index 74c52c3..8d8dd68 100644
    a b public class AddNodeHandler extends RequestHandler {  
    119119        } catch (NumberFormatException e) {
    120120            throw new RequestHandlerBadRequestException("NumberFormatException ("+e.getMessage()+')', e);
    121121        }
    122         if (!Main.main.hasEditLayer()) {
     122        if (Main.getLayerManager().getEditLayer() == null) {
    123123             throw new RequestHandlerBadRequestException(tr("There is no layer opened to add node"));
    124124        }
    125125    }
  • src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java

    diff --git a/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java b/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java
    index 58c2f4b..75488ac 100644
    a b public class AddWayHandler extends RequestHandler {  
    113113        } else if (allCoordinates.size() == 1) {
    114114            throw new RequestHandlerBadRequestException(tr("One node ways"));
    115115        }
    116         if (!Main.main.hasEditLayer()) {
     116        if (Main.getLayerManager().getEditLayer() == null) {
    117117             throw new RequestHandlerBadRequestException(tr("There is no layer opened to add way"));
    118118        }
    119119    }