Changeset 6336 in josm


Ignore:
Timestamp:
2013-10-27T05:35:41+01:00 (11 years ago)
Author:
Don-vip
Message:

code cleanup / robustness in edit layer handling

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

Legend:

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

    r6333 r6336  
    544544     */
    545545    public OsmDataLayer getEditLayer() {
    546         if (map == null) return null;
    547         if (map.mapView == null) return null;
     546        if (!isDisplayingMapView()) return null;
    548547        return map.mapView.getEditLayer();
    549548    }
     
    565564     */
    566565    public Layer getActiveLayer() {
    567         if (map == null) return null;
    568         if (map.mapView == null) return null;
     566        if (!isDisplayingMapView()) return null;
    569567        return map.mapView.getActiveLayer();
    570568    }
     
    762760     */
    763761    public static boolean saveUnsavedModifications() {
    764         if (map == null || map.mapView == null) return true;
     762        if (!isDisplayingMapView()) return true;
    765763        return saveUnsavedModifications(map.mapView.getLayersOfType(OsmDataLayer.class), true);
    766764    }
  • trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r6333 r6336  
    6262     */
    6363    public static void zoomToSelection() {
    64         if (Main.main == null || Main.main.getEditLayer() == null) return;
    65         if (Main.map == null || Main.map.mapView == null) return;
     64        if (Main.main == null || !Main.main.hasEditLayer()) return;
    6665        Collection<OsmPrimitive> sel = Main.main.getEditLayer().data.getSelected();
    6766        if (sel.isEmpty()) {
  • trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

    r6258 r6336  
    6767    @Override
    6868    public void actionPerformed(ActionEvent e) {
    69         if (Main.main.getEditLayer() == null) {
     69        if (!Main.main.hasEditLayer()) {
    7070            new Notification(
    7171                    tr("No data loaded."))
  • trunk/src/org/openstreetmap/josm/actions/DownloadReferrersAction.java

    r6084 r6336  
    8181    @Override
    8282    public void actionPerformed(ActionEvent e) {
    83         if (!isEnabled() || ! Main.isDisplayingMapView())
     83        if (!isEnabled())
    8484            return;
    85         OsmDataLayer layer = Main.map.mapView.getEditLayer();
     85        OsmDataLayer layer = Main.main.getEditLayer();
    8686        if (layer == null)
    8787            return;
  • trunk/src/org/openstreetmap/josm/actions/InfoAction.java

    r5925 r6336  
    1 //License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.actions;
    33
     
    1717public class InfoAction extends JosmAction {
    1818
     19    /**
     20     * Constructs a new {@code InfoAction}.
     21     */
    1922    public InfoAction() {
    2023        super(tr("Advanced info"), "about",
     
    3033        DataSet set = getCurrentDataSet();
    3134        if (set != null) {
    32             new InspectPrimitiveDialog(set.getAllSelected(), Main.map.mapView.getEditLayer()).showDialog();
     35            new InspectPrimitiveDialog(set.getAllSelected(), Main.main.getEditLayer()).showDialog();
    3336        }
    3437    }
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r6316 r6336  
    519519        // Delete the discarded inner ways
    520520        if (!discardedWays.isEmpty()) {
    521             Command deleteCmd = DeleteCommand.delete(Main.map.mapView.getEditLayer(), discardedWays, true);
     521            Command deleteCmd = DeleteCommand.delete(Main.main.getEditLayer(), discardedWays, true);
    522522            if (deleteCmd != null) {
    523523                cmds.add(deleteCmd);
     
    835835
    836836        if (chunks.size() > 1) {
    837             SplitWayResult split = SplitWayAction.splitWay(Main.map.mapView.getEditLayer(), way, chunks, Collections.<OsmPrimitive>emptyList());
     837            SplitWayResult split = SplitWayAction.splitWay(Main.main.getEditLayer(), way, chunks, Collections.<OsmPrimitive>emptyList());
    838838
    839839            //execute the command, we need the results
  • trunk/src/org/openstreetmap/josm/actions/PasteAction.java

    r6227 r6336  
    131131            if (data instanceof NodeData) {
    132132                NodeData nodeData = (NodeData)data;
    133                 if (Main.map.mapView.getEditLayer() == source) {
     133                if (Main.main.getEditLayer() == source) {
    134134                    nodeData.setEastNorth(nodeData.getEastNorth().add(offsetEast, offsetNorth));
    135135                }
  • trunk/src/org/openstreetmap/josm/actions/PurgeAction.java

    r6084 r6336  
    9090
    9191        Collection<OsmPrimitive> sel = getCurrentDataSet().getAllSelected();
    92         layer = Main.map.mapView.getEditLayer();
     92        layer = Main.main.getEditLayer();
    9393
    9494        toPurge = new HashSet<OsmPrimitive>(sel);
     
    209209        Main.pref.put("purge.clear_undo_redo", cbClearUndoRedo.isSelected());
    210210
    211         Main.main.undoRedo.add(new PurgeCommand(Main.map.mapView.getEditLayer(), toPurgeChecked, makeIncomplete));
     211        Main.main.undoRedo.add(new PurgeCommand(Main.main.getEditLayer(), toPurgeChecked, makeIncomplete));
    212212
    213213        if (cbClearUndoRedo.isSelected()) {
  • trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java

    r6296 r6336  
    4848
    4949    protected boolean confirmWayWithNodesOutsideBoundingBox(List<? extends OsmPrimitive> primitives) {
    50         return DeleteCommand.checkAndConfirmOutlyingDelete(Main.map.mapView.getEditLayer(), primitives, null);
     50        return DeleteCommand.checkAndConfirmOutlyingDelete(Main.main.getEditLayer(), primitives, null);
    5151    }
    5252
  • trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java

    r6046 r6336  
    4040        try {
    4141            DataSet ds = reader.parseOsm(NullProgressMonitor.INSTANCE);
    42             Main.map.mapView.getEditLayer().mergeFrom(ds);
     42            Main.main.getEditLayer().mergeFrom(ds);
    4343        } catch(Exception e) {
    4444            ExceptionDialogUtil.explainException(e);
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r6316 r6336  
    269269        }
    270270        APIDataSet apiData = new APIDataSet(Main.main.getCurrentDataSet());
    271         uploadData(Main.map.mapView.getEditLayer(), apiData);
     271        uploadData(Main.main.getEditLayer(), apiData);
    272272    }
    273273}
  • trunk/src/org/openstreetmap/josm/actions/ViewportFollowToggleAction.java

    r6327 r6336  
    4242    @Override
    4343    protected void updateEnabledState() {
    44         setEnabled(Main.isDisplayingMapView() && Main.main.getEditLayer() != null);
     44        setEnabled(Main.main.hasEditLayer());
    4545    }
    4646}
  • trunk/src/org/openstreetmap/josm/actions/WireframeToggleAction.java

    r6327 r6336  
    3737    @Override
    3838    protected void updateEnabledState() {
    39         setEnabled(Main.isDisplayingMapView() && Main.main.getEditLayer() != null);
     39        setEnabled(Main.main.hasEditLayer());
    4040    }
    4141
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r6272 r6336  
    223223        protected OsmDataLayer getEditLayer() {
    224224            if (!Main.isDisplayingMapView()) return null;
    225             return Main.map.mapView.getEditLayer();
     225            return Main.main.getEditLayer();
    226226        }
    227227
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTaskList.java

    r6316 r6336  
    291291                }
    292292            }
    293             final OsmDataLayer editLayer = Main.map.mapView.getEditLayer();
     293            final OsmDataLayer editLayer = Main.main.getEditLayer();
    294294            if (editLayer != null && osmData) {
    295295                final Set<OsmPrimitive> myPrimitives = getCompletePrimitives(editLayer.data);
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r6317 r6336  
    283283    @Override
    284284    public void eventDispatched(AWTEvent event) {
    285         if(Main.map == null || Main.map.mapView == null || !Main.map.mapView.isActiveLayerDrawable())
     285        if (!Main.isDisplayingMapView() || !Main.map.mapView.isActiveLayerDrawable())
    286286            return;
    287287        if (event instanceof KeyEvent) {
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

    r6310 r6336  
    156156        @Override
    157157        public void eventDispatched(AWTEvent e) {
    158             if(Main.map == null || Main.map.mapView == null || !Main.map.mapView.isActiveLayerDrawable())
     158            if (!Main.isDisplayingMapView() || !Main.map.mapView.isActiveLayerDrawable())
    159159                return;
    160160            InputEvent ie = (InputEvent) e;
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java

    r6316 r6336  
    323323    @Override
    324324    public void eventDispatched(AWTEvent event) {
    325         if (Main.map == null || Main.map.mapView == null
    326                 || !Main.map.mapView.isActiveLayerDrawable()) {
     325        if (!Main.isDisplayingMapView() || !Main.map.mapView.isActiveLayerDrawable()) {
    327326            return;
    328327        }
  • trunk/src/org/openstreetmap/josm/actions/relation/DeleteRelationsAction.java

    r5799 r6336  
    3939    @Override
    4040    public void actionPerformed(ActionEvent e) {
    41         if (!isEnabled() || Main.main.getEditLayer() == null)
     41        if (!isEnabled() || !Main.main.hasEditLayer())
    4242            return;
    4343        for (Relation r : relations) {
  • trunk/src/org/openstreetmap/josm/actions/relation/DownloadMembersAction.java

    r5821 r6336  
    3434    @Override
    3535    public void actionPerformed(ActionEvent e) {
    36         if (!isEnabled() || relations.isEmpty() || Main.map==null || Main.map.mapView==null) return;
    37         Main.worker.submit(new DownloadRelationTask(relations, Main.map.mapView.getEditLayer()));
     36        if (!isEnabled() || relations.isEmpty() || !Main.isDisplayingMapView()) return;
     37        Main.worker.submit(new DownloadRelationTask(relations, Main.main.getEditLayer()));
    3838    }
    3939
  • trunk/src/org/openstreetmap/josm/actions/relation/DownloadSelectedIncompleteMembersAction.java

    r5821 r6336  
    4747    @Override
    4848    public void actionPerformed(ActionEvent e) {
    49         if (!isEnabled() || relations.isEmpty() || Main.map==null || Main.map.mapView==null) return;
     49        if (!isEnabled() || relations.isEmpty() || !Main.isDisplayingMapView()) return;
    5050        Main.worker.submit(new DownloadRelationMemberTask(
    5151                relations,
    5252                buildSetOfIncompleteMembers(relations),
    53                 Main.map.mapView.getEditLayer()));
     53                Main.main.getEditLayer()));
    5454    }
    5555
  • trunk/src/org/openstreetmap/josm/actions/relation/EditRelationAction.java

    r6333 r6336  
    4040        Set<RelationMember> members = new HashSet<RelationMember>();
    4141        if (Main.isDisplayingMapView()) {
    42             OsmDataLayer editLayer = Main.map.mapView.getEditLayer();
     42            OsmDataLayer editLayer = Main.main.getEditLayer();
    4343            if (editLayer != null && editLayer.data != null) {
    4444                Collection<OsmPrimitive> selection = editLayer.data.getSelected();
     
    5858     */
    5959    public static void launchEditor(Relation toEdit) {
    60         if (toEdit == null || Main.map==null || Main.map.mapView==null) return;
    61         RelationEditor.getEditor(Main.map.mapView.getEditLayer(), toEdit,
     60        if (toEdit == null || !Main.isDisplayingMapView()) return;
     61        RelationEditor.getEditor(Main.main.getEditLayer(), toEdit,
    6262                getMembersForCurrentSelection(toEdit)).setVisible(true);
    6363    }
  • trunk/src/org/openstreetmap/josm/actions/relation/SelectMembersAction.java

    r5794 r6336  
    3434    @Override
    3535    public void actionPerformed(ActionEvent e) {
    36         if (!isEnabled() || relations.isEmpty() || Main.map==null || Main.map.mapView==null) return;
     36        if (!isEnabled() || relations.isEmpty() || !Main.isDisplayingMapView()) return;
    3737       
    3838        HashSet<OsmPrimitive> members = new HashSet<OsmPrimitive>();
     
    4141        }
    4242        if (add) {
    43             Main.map.mapView.getEditLayer().data.addSelected(members);
     43            Main.main.getEditLayer().data.addSelected(members);
    4444        } else {
    45             Main.map.mapView.getEditLayer().data.setSelected(members);
     45            Main.main.getEditLayer().data.setSelected(members);
    4646        }
    4747    }
  • trunk/src/org/openstreetmap/josm/actions/relation/SelectRelationAction.java

    r6069 r6336  
    3131    @Override
    3232    public void actionPerformed(ActionEvent e) {
    33         if (!isEnabled() || relations.isEmpty() || Main.map==null || Main.map.mapView==null) return;
    34         OsmDataLayer editLayer = Main.map.mapView.getEditLayer();
     33        if (!isEnabled() || relations.isEmpty()) return;
     34        OsmDataLayer editLayer = Main.main.getEditLayer();
    3535        if (editLayer==null || editLayer.data==null) return;
    3636        if (add) {
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r6265 r6336  
    11341134        @Override
    11351135        protected Bounds getBounds() {
    1136             if (Main.map == null || Main.map.mapView == null) {
     1136            if (!Main.isDisplayingMapView()) {
    11371137                return null;
    11381138            }
     
    11501150    }
    11511151
    1152     public static Match compile(String searchStr, boolean caseSensitive, boolean regexSearch)
    1153             throws ParseError {
     1152    public static Match compile(String searchStr, boolean caseSensitive, boolean regexSearch) throws ParseError {
    11541153        return new SearchCompiler(caseSensitive, regexSearch,
    11551154                new PushbackTokenizer(
  • trunk/src/org/openstreetmap/josm/command/Command.java

    r6333 r6336  
    8686     */
    8787    public Command() {
    88         this.layer = Main.isDisplayingMapView() ? Main.map.mapView.getEditLayer() : null;
     88        this.layer = Main.main.getEditLayer();
    8989    }
    9090
  • trunk/src/org/openstreetmap/josm/command/RelationMemberConflictResolverCommand.java

    r6248 r6336  
    6868
    6969        // remember the layer
    70         layer = Main.map.mapView.getEditLayer();
     70        layer = Main.main.getEditLayer();
    7171        return true;
    7272    }
     
    8989
    9090        Main.map.mapView.setActiveLayer(layer);
    91         OsmDataLayer editLayer = Main.map.mapView.getEditLayer();
     91        OsmDataLayer editLayer = Main.main.getEditLayer();
    9292
    9393        // restore the former state
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryDataSet.java

    r6317 r6336  
    175175    @Override
    176176    public void layerRemoved(Layer oldLayer) {
    177         if (Main.map == null || Main.map.mapView == null) return;
     177        if (!Main.isDisplayingMapView()) return;
    178178        if (Main.map.mapView.getNumLayers() == 0) {
    179179            data.clear();
  • trunk/src/org/openstreetmap/josm/data/validation/Test.java

    r6069 r6336  
    240240        }
    241241        if (!primitivesToDelete.isEmpty()) {
    242             return DeleteCommand.delete(Main.map.mapView.getEditLayer(), primitivesToDelete);
     242            return DeleteCommand.delete(Main.main.getEditLayer(), primitivesToDelete);
    243243        } else {
    244244            return null;
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Coastlines.java

    r6162 r6336  
    5252        super.startTest(monitor);
    5353
    54         OsmDataLayer layer = Main.map.mapView.getEditLayer();
     54        OsmDataLayer layer = Main.main.getEditLayer();
    5555
    5656        if (layer != null) {
  • trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java

    r6246 r6336  
    179179
    180180    private JMenuItem getNewOffsetMenu(){
    181         if (Main.map == null || Main.map.mapView == null) {
     181        if (!Main.isDisplayingMapView()) {
    182182            offsetAction.setEnabled(false);
    183183            return singleOffset;
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r6253 r6336  
    752752        /**
    753753         * Refreshes the enabled state
    754          *
    755754         */
    756755        protected void refreshEnabled() {
    757             presetsMenu.setEnabled(Main.isDisplayingMapView()
    758                     && Main.map.mapView.getEditLayer() != null
    759             );
     756            presetsMenu.setEnabled(Main.main.hasEditLayer());
    760757        }
    761758
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java

    r6313 r6336  
    5252import org.openstreetmap.josm.gui.help.HelpUtil;
    5353import org.openstreetmap.josm.gui.io.CloseChangesetTask;
     54import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5455import org.openstreetmap.josm.gui.widgets.ListPopupMenu;
    5556import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     
    120121        ChangesetCache.getInstance().addChangesetCacheListener(inActiveDataLayerModel);
    121122        MapView.addEditLayerChangeListener(inActiveDataLayerModel);
    122         if (Main.main.getEditLayer() != null) {
    123             Main.main.getEditLayer().data.addDataSetListener(inActiveDataLayerModel);
    124             inActiveDataLayerModel.initFromDataSet(Main.main.getEditLayer().data);
    125             inSelectionModel.initFromPrimitives(Main.main.getEditLayer().data.getAllSelected());
     123        OsmDataLayer editLayer = Main.main.getEditLayer();
     124        if (editLayer != null) {
     125            editLayer.data.addDataSetListener(inActiveDataLayerModel);
     126            inActiveDataLayerModel.initFromDataSet(editLayer.data);
     127            inSelectionModel.initFromPrimitives(editLayer.data.getAllSelected());
    126128        }
    127129    }
     
    132134        ChangesetCache.getInstance().removeChangesetCacheListener(inActiveDataLayerModel);
    133135        MapView.removeEditLayerChangeListener(inActiveDataLayerModel);
    134         if (Main.main.getEditLayer() != null) {
    135             Main.main.getEditLayer().data.removeDataSetListener(inActiveDataLayerModel);
     136        OsmDataLayer editLayer = Main.main.getEditLayer();
     137        if (editLayer != null) {
     138            editLayer.data.removeDataSetListener(inActiveDataLayerModel);
    136139        }
    137140
     
    233236
    234237    protected void initWithCurrentData() {
    235         if (Main.main.getEditLayer() != null) {
    236             inSelectionModel.initFromPrimitives(Main.main.getEditLayer().data.getAllSelected());
    237             inActiveDataLayerModel.initFromDataSet(Main.main.getEditLayer().data);
     238        OsmDataLayer editLayer = Main.main.getEditLayer();
     239        if (editLayer != null) {
     240            inSelectionModel.initFromPrimitives(editLayer.data.getAllSelected());
     241            inActiveDataLayerModel.initFromDataSet(editLayer.data);
    238242        }
    239243    }
     
    308312        @Override
    309313        public void actionPerformed(ActionEvent e) {
    310             if (Main.main.getEditLayer() == null)
     314            if (!Main.main.hasEditLayer())
    311315                return;
    312316            ChangesetListModel model = getCurrentChangesetListModel();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    r6084 r6336  
    243243    private void buildTrees() {
    244244        setTitle(tr("Command Stack"));
    245         if (Main.map == null || Main.map.mapView == null || Main.map.mapView.getEditLayer() == null)
     245        if (!Main.main.hasEditLayer())
    246246            return;
    247247
     
    317317    protected static FilteredCollection<OsmPrimitive> getAffectedPrimitives(TreePath path) {
    318318        PseudoCommand c = ((CommandListMutableTreeNode) path.getLastPathComponent()).getCommand();
    319         final OsmDataLayer currentLayer = Main.map.mapView.getEditLayer();
     319        final OsmDataLayer currentLayer = Main.main.getEditLayer();
    320320        FilteredCollection<OsmPrimitive> prims = new FilteredCollection<OsmPrimitive>(
    321321                c.getParticipatingPrimitives(),
     
    359359                throw new IllegalStateException();
    360360
    361             if (Main.map == null || Main.map.mapView == null || Main.map.mapView.getEditLayer() == null) return;
    362             Main.map.mapView.getEditLayer().data.setSelected( getAffectedPrimitives(path));
     361            OsmDataLayer editLayer = Main.main.getEditLayer();
     362            if (editLayer == null) return;
     363            editLayer.data.setSelected( getAffectedPrimitives(path));
    363364        }
    364365
     
    367368            setEnabled(!undoTree.isSelectionEmpty() || !redoTree.isSelectionEmpty());
    368369        }
    369 
    370370    }
    371371
    372372    public class SelectAndZoomAction extends SelectAction {
     373        /**
     374         * Constructs a new {@code SelectAndZoomAction}.
     375         */
    373376        public SelectAndZoomAction() {
    374             super();
    375377            putValue(NAME,tr("Select and zoom"));
    376378            putValue(SHORT_DESCRIPTION, tr("Selects the objects that take part in this command (unless currently deleted), then and zooms to it"));
     
    381383        public void actionPerformed(ActionEvent e) {
    382384            super.actionPerformed(e);
    383             if (Main.map == null || Main.map.mapView == null || Main.map.mapView.getEditLayer() == null) return;
     385            if (!Main.main.hasEditLayer()) return;
    384386            AutoScaleAction.autoScale("selection");
    385387        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r6316 r6336  
    680680
    681681        protected boolean isActiveLayer(Layer layer) {
    682             if (Main.map == null) return false;
    683             if (Main.map.mapView == null) return false;
     682            if (!Main.isDisplayingMapView()) return false;
    684683            return Main.map.mapView.getActiveLayer() == layer;
    685684        }
     
    776775
    777776        protected boolean isActiveLayer(Layer layer) {
    778             if (Main.map == null) return false;
    779             if (Main.map.mapView == null) return false;
     777            if (!Main.isDisplayingMapView()) return false;
    780778            return Main.map.mapView.getActiveLayer() == layer;
    781779        }
     
    832830
    833831        private void duplicate(Layer layer) {
    834             if (Main.map == null || Main.map.mapView == null)
     832            if (!Main.isDisplayingMapView())
    835833                return;
    836834
     
    863861
    864862        protected boolean isActiveLayer(Layer layer) {
    865             if (Main.map == null || Main.map.mapView == null)
     863            if (!Main.isDisplayingMapView())
    866864                return false;
    867865            return Main.map.mapView.getActiveLayer() == layer;
     
    974972
    975973        protected boolean isActiveLayer(Layer layer) {
    976             if (Main.map == null) return false;
    977             if (Main.map.mapView == null) return false;
     974            if (!Main.isDisplayingMapView()) return false;
    978975            return Main.map.mapView.getActiveLayer() == layer;
    979976        }
     
    14041401         */
    14051402        public List<Layer> getLayers() {
    1406             if (Main.map == null || Main.map.mapView == null)
     1403            if (!Main.isDisplayingMapView())
    14071404                return Collections.<Layer>emptyList();
    14081405            return Main.map.mapView.getAllLayersAsList();
     
    14371434         */
    14381435        protected Layer getActiveLayer() {
    1439             if (Main.map == null || Main.map.mapView == null) return null;
     1436            if (!Main.isDisplayingMapView()) return null;
    14401437            return Main.map.mapView.getActiveLayer();
    14411438        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r6316 r6336  
    324324
    325325        @Override public void mouseClicked(MouseEvent e) {
    326             if (Main.main.getEditLayer() == null) return;
     326            if (!Main.main.hasEditLayer()) return;
    327327            if (isDoubleClick(e)) {
    328328                if (e.isControlDown()) {
     
    357357
    358358        protected void updateEnabledState() {
    359             setEnabled(Main.main != null && Main.main.getEditLayer() != null);
     359            setEnabled(Main.main != null && Main.main.hasEditLayer());
    360360        }
    361361
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r6070 r6336  
    168168        MapView.addEditLayerChangeListener(actSearch);
    169169        // editLayerChanged also gets the selection history of the level
    170         model.editLayerChanged(null, Main.map.mapView.getEditLayer());
    171         if (Main.map.mapView.getEditLayer() != null) {
    172             model.setJOSMSelection(Main.map.mapView.getEditLayer().data.getAllSelected());
     170        OsmDataLayer editLayer = Main.main.getEditLayer();
     171        model.editLayerChanged(null, editLayer);
     172        if (editLayer != null) {
     173            model.setJOSMSelection(editLayer.data.getAllSelected());
    173174        }
    174175        actSearch.updateEnabledState();
     
    285286
    286287        public void updateEnabledState() {
    287             setEnabled(Main.main != null && Main.main.getEditLayer() != null);
     288            setEnabled(Main.main != null && !Main.main.hasEditLayer());
    288289        }
    289290
     
    310311            Collection<OsmPrimitive> sel = model.getSelected();
    311312            if (sel.isEmpty())return;
    312             if (Main.map == null || Main.map.mapView == null || Main.map.mapView.getEditLayer() == null) return;
    313             Main.map.mapView.getEditLayer().data.setSelected(sel);
     313            OsmDataLayer editLayer = Main.main.getEditLayer();
     314            if (editLayer == null) return;
     315            editLayer.data.setSelected(sel);
    314316        }
    315317
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java

    r6316 r6336  
    325325            if (!isEnabled())
    326326                return;
    327             if (Main.main == null || Main.main.getEditLayer() == null) return;
     327            if (Main.main == null || !Main.main.hasEditLayer()) return;
    328328            OsmDataLayer layer = Main.main.getEditLayer();
    329329            Set<HistoryOsmPrimitive> selected = model.getSelectedPrimitives();
     
    343343
    344344        public void updateEnabledState() {
    345             if (Main.main == null || Main.main.getEditLayer() == null){
     345            if (Main.main == null || !Main.main.hasEditLayer()) {
    346346                setEnabled(false);
    347347                return;
     
    390390            if (!isEnabled())
    391391                return;
    392             if (Main.main == null || Main.main.getEditLayer() == null) return;
     392            if (Main.main == null || !Main.main.hasEditLayer()) return;
    393393            OsmDataLayer layer = Main.main.getEditLayer();
    394394            Set<HistoryOsmPrimitive> selected = model.getSelectedPrimitives();
     
    409409
    410410        public void updateEnabledState() {
    411             if (Main.main == null || Main.main.getEditLayer() == null){
     411            if (Main.main == null || !Main.main.hasEditLayer()) {
    412412                setEnabled(false);
    413413                return;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java

    r6084 r6336  
    386386            if (!isEnabled())
    387387                return;
    388             if (Main.main == null || Main.main.getEditLayer() == null) return;
     388            if (Main.main == null || !Main.main.hasEditLayer()) return;
    389389            OsmDataLayer layer = Main.main.getEditLayer();
    390390            Set<OsmPrimitive> target = new HashSet<OsmPrimitive>();
     
    402402
    403403        public void updateEnabledState() {
    404             if (Main.main == null || Main.main.getEditLayer() == null){
     404            if (Main.main == null || !Main.main.hasEditLayer()) {
    405405                setEnabled(false);
    406406                return;
     
    447447            if (!isEnabled())
    448448                return;
    449             if (Main.main == null || Main.main.getEditLayer() == null) return;
     449            if (Main.main == null || !Main.main.hasEditLayer()) return;
    450450            OsmDataLayer layer = Main.main.getEditLayer();
    451451            Set<OsmPrimitive> target = new HashSet<OsmPrimitive>();
     
    464464
    465465        public void updateEnabledState() {
    466             if (Main.main == null || Main.main.getEditLayer() == null){
     466            if (Main.main == null || !Main.main.hasEditLayer()) {
    467467                setEnabled(false);
    468468                return;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/query/BasicChangesetQueryPanel.java

    r6267 r6336  
    158158        // map view
    159159        lbl = lblQueries.get(BasicQuery.CHANGESETS_IN_MAP_VIEW);
    160         if (Main.map == null || Main.map.mapView == null) {
     160        if (!Main.isDisplayingMapView()) {
    161161            rbQueries.get(BasicQuery.CHANGESETS_IN_MAP_VIEW).setEnabled(false);
    162162            lbl.setText(tr("<html>Download changesets in the current map view.<br><em>Disabled. There is currently no map view active.</em></html>"));
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r6324 r6336  
    484484        Main.map.relationListDialog.selectRelation(relation);
    485485        RelationEditor.getEditor(
    486                 Main.map.mapView.getEditLayer(),
     486                Main.main.getEditLayer(),
    487487                relation,
    488488                ((MemberInfo) membershipData.getValueAt(row, 1)).role).setVisible(true);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r6316 r6336  
    655655     */
    656656    protected boolean isActiveLayer() {
    657         if (Main.map == null || Main.map.mapView == null) return false;
     657        if (!Main.isDisplayingMapView()) return false;
    658658        return Main.map.mapView.getActiveLayer() == layer;
    659659    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableModel.java

    r6316 r6336  
    5252    @Override
    5353    public int getRowCount() {
    54         if (Main.map.mapView.getEditLayer() != layer)
     54        if (Main.main.getEditLayer() != layer)
    5555            return 0;
    5656        return cache.size();
     
    8989    @Override
    9090    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    91         if (layer == Main.map.mapView.getEditLayer()) {
     91        if (layer == Main.main.getEditLayer()) {
    9292            cache.clear();
    9393            cache.addAll(newSelection);
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java

    r6316 r6336  
    104104        referenceRelationMemberTableModel = new DiffTableModel();
    105105
    106         if (getEditLayer() != null) {
    107             getEditLayer().data.addDataSetListener(this);
     106        OsmDataLayer editLayer = Main.main.getEditLayer();
     107        if (editLayer != null) {
     108            editLayer.data.addDataSetListener(this);
    108109        }
    109110        MapView.addLayerChangeListener(this);
     
    120121        CheckParameterUtil.ensureParameterNotNull(history, "history");
    121122        setHistory(history);
    122     }
    123 
    124     /**
    125      * Replies the current edit layer; null, if there isn't a current edit layer
    126      * of type {@link OsmDataLayer}.
    127      *
    128      * @return the current edit layer
    129      */
    130     protected OsmDataLayer getEditLayer() {
    131         try {
    132             return Main.map.mapView.getEditLayer();
    133         } catch(NullPointerException e) {
    134             return null;
    135         }
    136123    }
    137124
     
    187174        if (history.getNumVersions() > 0) {
    188175            HistoryOsmPrimitive newLatest = null;
    189             if (getEditLayer() != null) {
    190                 OsmPrimitive p = getEditLayer().data.getPrimitiveById(history.getId(), history.getType());
     176            OsmDataLayer editLayer = Main.main.getEditLayer();
     177            if (editLayer != null) {
     178                OsmPrimitive p = editLayer.data.getPrimitiveById(history.getId(), history.getType());
    191179                if (canShowAsLatest(p)) {
    192180                    newLatest = new HistoryPrimitiveBuilder().build(p);
     
    536524        public OsmPrimitive getLatest() {
    537525            if (latest == null) return null;
    538             if (getEditLayer() == null) return null;
    539             OsmPrimitive p = getEditLayer().data.getPrimitiveById(latest.getId(), latest.getType());
     526            OsmDataLayer editLayer = Main.main.getEditLayer();
     527            if (editLayer == null) return null;
     528            OsmPrimitive p = editLayer.data.getPrimitiveById(latest.getId(), latest.getType());
    540529            return p;
    541530        }
     
    674663     */
    675664    public void unlinkAsListener() {
    676         if (getEditLayer() != null) {
    677             getEditLayer().data.removeDataSetListener(this);
     665        OsmDataLayer editLayer = Main.main.getEditLayer();
     666        if (editLayer != null) {
     667            editLayer.data.removeDataSetListener(this);
    678668        }
    679669        MapView.removeLayerChangeListener(this);
  • trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java

    r6147 r6336  
    207207            if (!isEnabled()) return;
    208208            OsmPrimitive p = getPrimitiveToZoom();
    209             if (p!= null) {
    210                 getEditLayer().data.setSelected(p.getPrimitiveId());
    211                 AutoScaleAction.autoScale("selection");
     209            if (p != null) {
     210                OsmDataLayer editLayer = Main.main.getEditLayer();
     211                if (editLayer != null) {
     212                    editLayer.data.setSelected(p.getPrimitiveId());
     213                    AutoScaleAction.autoScale("selection");
     214                }
    212215            }
    213216        }
     
    218221        }
    219222
    220         protected OsmDataLayer getEditLayer() {
    221             try {
    222                 return Main.map.mapView.getEditLayer();
    223             } catch(NullPointerException e) {
    224                 return null;
    225             }
    226         }
    227 
    228223        protected OsmPrimitive getPrimitiveToZoom() {
    229224            if (primitiveId == null) return null;
    230             OsmPrimitive p = getEditLayer().data.getPrimitiveById(primitiveId);
     225            OsmDataLayer editLayer = Main.main.getEditLayer();
     226            if (editLayer == null) return null;
     227            OsmPrimitive p = editLayer.data.getPrimitiveById(primitiveId);
    231228            return p;
    232229        }
    233230
    234231        public void updateEnabledState() {
    235             if (getEditLayer() == null) {
     232            if (!Main.main.hasEditLayer()) {
    236233                setEnabled(false);
    237234                return;
  • trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java

    r6267 r6336  
    7373    }
    7474
    75     protected OsmDataLayer getEditLayer() {
    76         try {
    77             return Main.map.mapView.getEditLayer();
    78         } catch(NullPointerException e) {
    79             return null;
    80         }
    81     }
    82 
    8375    protected String getInfoText() {
    8476        HistoryOsmPrimitive primitive = getPrimitive();
     
    8779        String text;
    8880        if (model.isLatest(primitive)) {
     81            OsmDataLayer editLayer = Main.main.getEditLayer();
    8982            text = tr("<html>Version <strong>{0}</strong> currently edited in layer ''{1}''</html>",
    9083                    Long.toString(primitive.getVersion()),
    91                     getEditLayer() == null ? tr("unknown") : getEditLayer().getName()
     84                    editLayer == null ? tr("unknown") : editLayer.getName()
    9285                    );
    9386        } else {
  • trunk/src/org/openstreetmap/josm/gui/io/AbstractUploadTask.java

    r6248 r6336  
    240240);
    241241        if (ret == 0) {
    242             DownloadReferrersAction.downloadReferrers(Main.map.mapView.getEditLayer(), Arrays.asList(conflict.a));
     242            DownloadReferrersAction.downloadReferrers(Main.main.getEditLayer(), Arrays.asList(conflict.a));
    243243        }
    244244    }
  • trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

    r6070 r6336  
    8383
    8484    public double getPPD(){
    85         if (Main.map == null || Main.map.mapView == null) return Main.getProjection().getDefaultZoomInPPD();
     85        if (!Main.isDisplayingMapView()) return Main.getProjection().getDefaultZoomInPPD();
    8686        ProjectionBounds bounds = Main.map.mapView.getProjectionBounds();
    8787        return Main.map.mapView.getWidth() / (bounds.maxEast - bounds.minEast);
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r6316 r6336  
    439439     */
    440440    private double getScaleFactor(int zoom) {
    441         if (Main.map == null || Main.map.mapView == null) return 1;
     441        if (!Main.isDisplayingMapView()) return 1;
    442442        MapView mv = Main.map.mapView;
    443443        LatLon topLeft = mv.getLatLon(0, 0);
  • trunk/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java

    r6333 r6336  
    156156    @Override
    157157    public void layerRemoved(Layer oldLayer) {
    158         if (oldLayer instanceof OsmDataLayer && Main.isDisplayingMapView() && Main.map.mapView.getEditLayer() == null) {
     158        if (oldLayer instanceof OsmDataLayer && Main.isDisplayingMapView() && !Main.main.hasEditLayer()) {
    159159            Main.main.removeLayer(this);
    160160        } else if (oldLayer == this) {
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

    r6310 r6336  
    432432    private static void playAdjacentMarker(Marker startMarker, boolean next) {
    433433        Marker m = null;
    434         if (Main.map == null || Main.map.mapView == null)
     434        if (!Main.isDisplayingMapView())
    435435            return;
    436436        Layer l = Main.map.mapView.getActiveLayer();
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java

    r6075 r6336  
    6565        @Override
    6666        public void updateEnabledState() {
    67             setEnabled(Main.isDisplayingMapView() && (Main.main.getEditLayer() != null || mapHasGpxorMarkerLayer()));
     67            setEnabled(Main.isDisplayingMapView() && (Main.main.hasEditLayer() || mapHasGpxorMarkerLayer()));
    6868        }
    6969
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItem.java

    r6198 r6336  
    2828        }
    2929        AutoCompletionList list = new AutoCompletionList();
    30         Main.main.getEditLayer().data.getAutoCompletionManager().populateWithTagValues(list, key);
     30        layer.data.getAutoCompletionManager().populateWithTagValues(list, key);
    3131        field.setAutoCompletionList(list);
    3232    }
Note: See TracChangeset for help on using the changeset viewer.