Changeset 10486 in josm


Ignore:
Timestamp:
2016-06-25T11:14:09+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #13049 - Inform map view of Projection updates (patch by michael2402) - gsoc-core

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

Legend:

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

    r10463 r10486  
    14311431        if (newValue == null ^ oldValue == null
    14321432                || (newValue != null && oldValue != null && !Objects.equals(newValue.toCode(), oldValue.toCode()))) {
    1433 
     1433            if (Main.map != null) {
     1434                // This needs to be called first
     1435                Main.map.mapView.fixProjection();
     1436            }
    14341437            synchronized (Main.class) {
    14351438                Iterator<WeakReference<ProjectionChangeListener>> it = listeners.iterator();
  • trunk/src/org/openstreetmap/josm/gui/MapViewState.java

    r10462 r10486  
    100100    }
    101101
     102    private MapViewState(Projection projection, MapViewState mapViewState) {
     103        this.projection = projection;
     104        this.scale = mapViewState.scale;
     105        this.topLeft = mapViewState.topLeft;
     106
     107        viewWidth = mapViewState.viewWidth;
     108        viewHeight = mapViewState.viewHeight;
     109        topLeftInWindow = mapViewState.topLeftInWindow;
     110        topLeftOnScreen = mapViewState.topLeftOnScreen;
     111    }
     112
    102113    /**
    103114     * The scale in east/north units per pixel.
     
    236247
    237248    /**
     249     * Creates a state that uses the projection.
     250     * @param projection The projection to use.
     251     * @return The new state.
     252     * @since 10486
     253     */
     254    public MapViewState usingProjection(Projection projection) {
     255        if (projection.equals(this.projection)) {
     256            return this;
     257        } else {
     258            return new MapViewState(projection, this);
     259        }
     260    }
     261
     262    /**
    238263     * Create the default {@link MapViewState} object for the given map view. The screen position won't be set so that this method can be used
    239264     * before the view was added to the hirarchy.
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r10466 r10486  
    5151import org.openstreetmap.josm.data.preferences.IntegerProperty;
    5252import org.openstreetmap.josm.data.projection.Projection;
     53import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
    5354import org.openstreetmap.josm.data.projection.Projections;
    5455import org.openstreetmap.josm.gui.help.Helpful;
     
    177178        setLayout(null);
    178179        state = MapViewState.createDefaultState(getWidth(), getHeight());
     180        // uses weak link.
     181        Main.addProjectionChangeListener(new ProjectionChangeListener() {
     182            @Override
     183            public void projectionChanged(Projection oldValue, Projection newValue) {
     184                fixProjection();
     185            }
     186        });
    179187    }
    180188
     
    324332    protected boolean isVisibleOnScreen() {
    325333        return SwingUtilities.getWindowAncestor(this) != null && isShowing();
     334    }
     335
     336    /**
     337     * Changes the projection settings used for this map view.
     338     * <p>
     339     * Made public temporarely, will be made private later.
     340     */
     341    public void fixProjection() {
     342        state = state.usingProjection(Main.getProjection());
     343        repaint();
    326344    }
    327345
Note: See TracChangeset for help on using the changeset viewer.