Changeset 12631 in josm


Ignore:
Timestamp:
2017-08-24T01:24:27+02:00 (3 months ago)
Author:
Don-vip
Message:

see #15182 - remove last calls to Main.map

Location:
trunk
Files:
3 edited

Legend:

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

    r12630 r12631  
    124124    @Deprecated
    125125    public static boolean isDisplayingMapView() {
    126         return map != null && map.mapView != null;
     126        return MainApplication.isDisplayingMapView();
    127127    }
    128128
     
    681681     */
    682682    public Collection<OsmPrimitive> getInProgressSelection() {
    683         if (map != null && map.mapMode instanceof DrawAction) {
    684             return ((DrawAction) map.mapMode).getInProgressSelection();
    685         } else {
    686             DataSet ds = getLayerManager().getEditDataSet();
    687             if (ds == null) return null;
    688             return ds.getSelected();
    689         }
     683        DataSet ds = getLayerManager().getEditDataSet();
     684        if (ds == null) return null;
     685        return ds.getSelected();
    690686    }
    691687
     
    906902            ImageProvider.shutdown(false);
    907903            JCSCacheManager.shutdown();
    908         }
    909         if (map != null) {
    910             map.rememberToggleDialogWidth();
    911904        }
    912905        // Remove all layers because somebody may rely on layerRemoved events (like AutosaveTask)
     
    10901083    /**
    10911084     * The projection method used.
    1092      * use {@link #getProjection()} and {@link #setProjection(Projection)} for access.
     1085     * Use {@link #getProjection()} and {@link #setProjection(Projection)} for access.
    10931086     * Use {@link #setProjection(Projection)} in order to trigger a projection change event.
    10941087     */
     
    11121105        CheckParameterUtil.ensureParameterNotNull(p);
    11131106        Projection oldValue = proj;
    1114         Bounds b = isDisplayingMapView() ? map.mapView.getRealBounds() : null;
     1107        Bounds b = main != null ? main.getRealBounds() : null;
    11151108        proj = p;
    11161109        fireProjectionChanged(oldValue, proj, b);
     1110    }
     1111
     1112    /**
     1113     * Returns the bounds for the current projection. Used for projection events.
     1114     * @return the bounds for the current projection
     1115     * @see #restoreOldBounds
     1116     */
     1117    protected Bounds getRealBounds() {
     1118        // To be overriden
     1119        return null;
     1120    }
     1121
     1122    /**
     1123     * Restore clean state corresponding to old bounds after a projection change event.
     1124     * @param oldBounds bounds previously returned by {@link #getRealBounds}, before the change of projection
     1125     * @see #getRealBounds
     1126     */
     1127    protected void restoreOldBounds(Bounds oldBounds) {
     1128        // To be overriden
    11171129    }
    11181130
     
    11391151                }
    11401152            }
    1141             if (newValue != null && oldBounds != null) {
    1142                 MainApplication.getMap().mapView.zoomTo(oldBounds);
     1153            if (newValue != null && oldBounds != null && main != null) {
     1154                main.restoreOldBounds(oldBounds);
    11431155            }
    11441156            /* TODO - remove layers with fixed projection */
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r12630 r12631  
    5151import org.openstreetmap.josm.actions.PreferencesAction;
    5252import org.openstreetmap.josm.actions.RestartAction;
     53import org.openstreetmap.josm.actions.mapmode.DrawAction;
    5354import org.openstreetmap.josm.data.AutosaveTask;
     55import org.openstreetmap.josm.data.Bounds;
    5456import org.openstreetmap.josm.data.CustomConfigurator;
    5557import org.openstreetmap.josm.data.Version;
     58import org.openstreetmap.josm.data.osm.OsmPrimitive;
    5659import org.openstreetmap.josm.data.validation.OsmValidator;
    5760import org.openstreetmap.josm.gui.ProgramArguments.Option;
     
    220223            mainFrame.storeState();
    221224        }
     225        if (map != null) {
     226            map.rememberToggleDialogWidth();
     227        }
    222228        super.shutdown();
     229    }
     230
     231    @Override
     232    protected Bounds getRealBounds() {
     233        return isDisplayingMapView() ? map.mapView.getRealBounds() : null;
     234    }
     235
     236    @Override
     237    protected void restoreOldBounds(Bounds oldBounds) {
     238        if (isDisplayingMapView()) {
     239            map.mapView.zoomTo(oldBounds);
     240        }
     241    }
     242
     243    @Override
     244    public Collection<OsmPrimitive> getInProgressSelection() {
     245        if (map != null && map.mapMode instanceof DrawAction) {
     246            return ((DrawAction) map.mapMode).getInProgressSelection();
     247        } else {
     248            return super.getInProgressSelection();
     249        }
    223250    }
    224251
  • trunk/test/unit/org/openstreetmap/josm/io/session/SessionReaderTest.java

    r12564 r12631  
    1414import org.openstreetmap.josm.Main;
    1515import org.openstreetmap.josm.TestUtils;
     16import org.openstreetmap.josm.gui.MainApplication;
    1617import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer;
    1718import org.openstreetmap.josm.gui.layer.GpxLayer;
     
    140141    @Test
    141142    public void testReadNotes() throws IOException, IllegalDataException {
    142         if (Main.isDisplayingMapView()) {
     143        if (MainApplication.isDisplayingMapView()) {
    143144            for (NoteLayer nl : Main.getLayerManager().getLayersOfType(NoteLayer.class)) {
    144145                Main.getLayerManager().removeLayer(nl);
Note: See TracChangeset for help on using the changeset viewer.