Changeset 12796 in josm for trunk


Ignore:
Timestamp:
2017-09-09T13:34:52+02:00 (7 years ago)
Author:
Don-vip
Message:

see #15229 - see #15182 - remove GUI references from OsmUrlToBounds

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/coor/conversion/LatLonParser.java

    r12795 r12796  
    1717 * @since 12792
    1818 */
    19 public class LatLonParser {
     19public final class LatLonParser {
    2020
    2121    /** Character denoting South, as string */
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r12795 r12796  
    10721072        MessageNotifier.setNotifierCallback(MainApplication::notifyNewMessages);
    10731073        DeleteCommand.setDeletionCallback(DeleteAction.defaultDeletionCallback);
     1074        OsmUrlToBounds.setMapSizeSupplier(() -> {
     1075            if (isDisplayingMapView()) {
     1076                MapView mapView = getMap().mapView;
     1077                return new Dimension(mapView.getWidth(), mapView.getHeight());
     1078            } else {
     1079                return GuiHelper.getScreenSize();
     1080            }
     1081        });
    10741082    }
    10751083
  • trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java

    r12630 r12796  
    77import java.util.HashMap;
    88import java.util.Map;
     9import java.util.function.Supplier;
    910
    1011import org.openstreetmap.josm.Main;
     
    1516import org.openstreetmap.josm.data.projection.Projection;
    1617import org.openstreetmap.josm.data.projection.Projections;
    17 import org.openstreetmap.josm.gui.MainApplication;
    18 import org.openstreetmap.josm.gui.MapView;
    19 import org.openstreetmap.josm.gui.util.GuiHelper;
    2018
    2119/**
     
    2422public final class OsmUrlToBounds {
    2523    private static final String SHORTLINK_PREFIX = "http://osm.org/go/";
     24
     25    private static Supplier<Dimension> mapSize = () -> new Dimension(800, 600);
    2626
    2727    private OsmUrlToBounds() {
     
    205205    }
    206206
    207     private static Dimension getScreenSize() {
    208         if (MainApplication.isDisplayingMapView()) {
    209             MapView mapView = MainApplication.getMap().mapView;
    210             return new Dimension(mapView.getWidth(), mapView.getHeight());
    211         } else {
    212             return GuiHelper.getScreenSize();
    213         }
     207    /**
     208     * Sets the map size supplier.
     209     * @param mapSizeSupplier returns the map size in pixels
     210     * @since 12796
     211     */
     212    public static void setMapSizeSupplier(Supplier<Dimension> mapSizeSupplier) {
     213        mapSize = mapSizeSupplier;
    214214    }
    215215
     
    224224     */
    225225    public static Bounds positionToBounds(final double lat, final double lon, final int zoom) {
    226         final Dimension screenSize = getScreenSize();
     226        final Dimension screenSize = mapSize.get();
    227227        double scale = (1 << zoom) * TILE_SIZE_IN_PIXELS / (2 * Math.PI * Ellipsoid.WGS84.a);
    228228        double deltaX = screenSize.getWidth() / 2.0 / scale;
     
    246246        final EastNorth max = mercator.latlon2eastNorth(b.getMax());
    247247        final double deltaX = max.getX() - min.getX();
    248         final double scale = getScreenSize().getWidth() / deltaX;
     248        final double scale = mapSize.get().getWidth() / deltaX;
    249249        final double x = scale * (2 * Math.PI * Ellipsoid.WGS84.a) / TILE_SIZE_IN_PIXELS;
    250250        return (int) Math.round(Math.log(x) / Math.log(2));
Note: See TracChangeset for help on using the changeset viewer.