Changeset 10453 in josm for trunk/src/org


Ignore:
Timestamp:
2016-06-22T00:48:51+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13023 - Replace uses of hasEditLayer() with new layer manager (patch by michael2402, modified) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm
Files:
19 edited

Legend:

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

    r10446 r10453  
    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(
     
    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();
  • trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

    r10448 r10453  
    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."))
     
    144145        }
    145146
    146         final Collection<Way> selectedWays = Main.getLayerManager().getEditDataSet().getSelectedWays();
     147        final Collection<Way> selectedWays = dataSet.getSelectedWays();
    147148
    148149        if (selectedWays.isEmpty()) {
     
    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)
  • trunk/src/org/openstreetmap/josm/actions/ViewportFollowToggleAction.java

    r7937 r10453  
    4242    @Override
    4343    protected void updateEnabledState() {
    44         setEnabled(Main.main.hasEditLayer());
     44        setEnabled(Main.getLayerManager().getEditDataSet() != null);
    4545    }
    4646}
  • trunk/src/org/openstreetmap/josm/actions/WireframeToggleAction.java

    r8510 r10453  
    3737    @Override
    3838    protected void updateEnabledState() {
    39         setEnabled(Main.main.hasEditLayer());
     39        setEnabled(Main.getLayerManager().getEditLayer() != null);
    4040    }
    4141
  • trunk/src/org/openstreetmap/josm/actions/relation/DeleteRelationsAction.java

    r10428 r10453  
    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
     
    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)
     
    3841    @Override
    3942    public void actionPerformed(ActionEvent e) {
    40         if (!isEnabled() || !Main.main.hasEditLayer())
     43        if (!isEnabled())
    4144            return;
    4245        deleteRelation(relations);
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java

    r10446 r10453  
    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;
     
    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
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java

    r10446 r10453  
    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();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    r10413 r10453  
    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;
     
    268269    private void buildTrees() {
    269270        setTitle(tr("Command Stack"));
    270         if (!Main.main.hasEditLayer())
     271        if (Main.getLayerManager().getEditLayer() == null)
    271272            return;
    272273
     
    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
     
    417418        public void actionPerformed(ActionEvent e) {
    418419            super.actionPerformed(e);
    419             if (!Main.main.hasEditLayer()) return;
    420420            AutoScaleAction.autoScale("selection");
    421421        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r10446 r10453  
    339339        @Override
    340340        public void mouseClicked(MouseEvent e) {
    341             if (!Main.main.hasEditLayer()) return;
     341            if (Main.getLayerManager().getEditLayer() == null) return;
    342342            if (isDoubleClick(e)) {
    343343                if (e.isControlDown()) {
     
    371371
    372372        protected void updateEnabledState() {
    373             setEnabled(Main.main != null && Main.main.hasEditLayer());
     373            setEnabled(Main.getLayerManager().getEditLayer() != null);
    374374        }
    375375
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r10446 r10453  
    310310
    311311        protected void updateEnabledState() {
    312             setEnabled(Main.main != null && Main.main.hasEditLayer());
     312            setEnabled(Main.getLayerManager().getEditLayer() != null);
    313313        }
    314314
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java

    r10438 r10453  
    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()) {
     
    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
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java

    r10438 r10453  
    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()) {
     
    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
     
    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()) {
     
    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
  • trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java

    r10413 r10453  
    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    }
  • trunk/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java

    r10436 r10453  
    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) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java

    r10428 r10453  
    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
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchAction.java

    r8863 r10453  
    3030    public void actionPerformed(ActionEvent e) {
    3131
    32         if (!Main.main.hasEditLayer())
     32        if (Main.getLayerManager().getEditLayer() == null)
    3333            return;
    3434
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java

    r10446 r10453  
    4545        @Override
    4646        public void actionPerformed(ActionEvent e) {
    47             if (Main.main.hasEditLayer()) {
     47            if (Main.getLayerManager().getEditLayer() != null) {
    4848                TaggingPresetSearchPrimitiveDialog.getInstance().showDialog();
    4949            }
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java

    r10446 r10453  
    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        }
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java

    r10446 r10453  
    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        }
Note: See TracChangeset for help on using the changeset viewer.