Changeset 14120 in josm for trunk/src/org


Ignore:
Timestamp:
2018-08-11T17:29:48+02:00 (6 years ago)
Author:
Don-vip
Message:

see #15229 - deprecate all Main methods related to projections. New ProjectionRegistry class

Location:
trunk/src/org/openstreetmap/josm
Files:
2 added
45 edited

Legend:

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

    r14119 r14120  
    77import java.awt.GraphicsEnvironment;
    88import java.io.IOException;
    9 import java.lang.ref.WeakReference;
    109import java.net.URL;
    1110import java.nio.file.InvalidPathException;
     
    1615import java.util.List;
    1716import java.util.Map;
    18 import java.util.Objects;
    1917import java.util.Set;
    2018import java.util.concurrent.Callable;
    21 import java.util.concurrent.CopyOnWriteArrayList;
    2219import java.util.concurrent.ExecutionException;
    2320import java.util.concurrent.ExecutorService;
     
    2522import java.util.concurrent.Future;
    2623
    27 import org.openstreetmap.josm.data.Bounds;
    2824import org.openstreetmap.josm.data.Preferences;
    2925import org.openstreetmap.josm.data.UndoRedoHandler;
     
    3834import org.openstreetmap.josm.data.projection.Projection;
    3935import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
     36import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    4037import org.openstreetmap.josm.io.FileWatcher;
    4138import org.openstreetmap.josm.io.OnlineResource;
     
    364361    }
    365362
    366     /* ----------------------------------------------------------------------------------------- */
    367     /* projection handling  - Main is a registry for a single, global projection instance        */
    368     /*                                                                                           */
    369     /* TODO: For historical reasons the registry is implemented by Main. An alternative approach */
    370     /* would be a singleton org.openstreetmap.josm.data.projection.ProjectionRegistry class.     */
    371     /* ----------------------------------------------------------------------------------------- */
    372     /**
    373      * The projection method used.
    374      * Use {@link #getProjection()} and {@link #setProjection(Projection)} for access.
    375      * Use {@link #setProjection(Projection)} in order to trigger a projection change event.
    376      */
    377     private static volatile Projection proj;
    378 
    379363    /**
    380364     * Replies the current projection.
    381365     *
    382366     * @return the currently active projection
    383      */
     367     * @deprecated Use {@link ProjectionRegistry#getProjection}
     368     */
     369    @Deprecated
    384370    public static Projection getProjection() {
    385         return proj;
     371        return ProjectionRegistry.getProjection();
    386372    }
    387373
     
    390376     *
    391377     * @param p the projection
    392      */
     378     * @deprecated Use {@link ProjectionRegistry#setProjection}
     379     */
     380    @Deprecated
    393381    public static void setProjection(Projection p) {
    394         CheckParameterUtil.ensureParameterNotNull(p);
    395         Projection oldValue = proj;
    396         Bounds b = main != null ? main.getRealBounds() : null;
    397         proj = p;
    398         fireProjectionChanged(oldValue, proj, b);
    399     }
    400 
    401     /**
    402      * Returns the bounds for the current projection. Used for projection events.
    403      * @return the bounds for the current projection
    404      * @see #restoreOldBounds
    405      */
    406     protected Bounds getRealBounds() {
    407         // To be overriden
    408         return null;
    409     }
    410 
    411     /**
    412      * Restore clean state corresponding to old bounds after a projection change event.
    413      * @param oldBounds bounds previously returned by {@link #getRealBounds}, before the change of projection
    414      * @see #getRealBounds
    415      */
    416     protected void restoreOldBounds(Bounds oldBounds) {
    417         // To be overriden
    418     }
    419 
    420     /*
    421      * Keep WeakReferences to the listeners. This relieves clients from the burden of
    422      * explicitly removing the listeners and allows us to transparently register every
    423      * created dataset as projection change listener.
    424      */
    425     private static final List<WeakReference<ProjectionChangeListener>> listeners = new CopyOnWriteArrayList<>();
    426 
    427     private static void fireProjectionChanged(Projection oldValue, Projection newValue, Bounds oldBounds) {
    428         if ((newValue == null ^ oldValue == null)
    429                 || (newValue != null && oldValue != null && !Objects.equals(newValue.toCode(), oldValue.toCode()))) {
    430             listeners.removeIf(x -> x.get() == null);
    431             listeners.stream().map(WeakReference::get).filter(Objects::nonNull).forEach(x -> x.projectionChanged(oldValue, newValue));
    432             if (newValue != null && oldBounds != null && main != null) {
    433                 main.restoreOldBounds(oldBounds);
    434             }
    435             /* TODO - remove layers with fixed projection */
    436         }
     382        ProjectionRegistry.setProjection(p);
    437383    }
    438384
     
    442388     *
    443389     * @param listener the listener. Ignored if <code>null</code>.
    444      */
     390     * @deprecated Use {@link ProjectionRegistry#addProjectionChangeListener}
     391     */
     392    @Deprecated
    445393    public static void addProjectionChangeListener(ProjectionChangeListener listener) {
    446         if (listener == null) return;
    447         for (WeakReference<ProjectionChangeListener> wr : listeners) {
    448             // already registered ? => abort
    449             if (wr.get() == listener) return;
    450         }
    451         listeners.add(new WeakReference<>(listener));
     394        ProjectionRegistry.addProjectionChangeListener(listener);
    452395    }
    453396
     
    456399     *
    457400     * @param listener the listener. Ignored if <code>null</code>.
    458      */
     401     * @deprecated Use {@link ProjectionRegistry#removeProjectionChangeListener}
     402     */
     403    @Deprecated
    459404    public static void removeProjectionChangeListener(ProjectionChangeListener listener) {
    460         if (listener == null) return;
    461         // remove the listener - and any other listener which got garbage collected in the meantime
    462         listeners.removeIf(wr -> wr.get() == null || wr.get() == listener);
     405        ProjectionRegistry.removeProjectionChangeListener(listener);
    463406    }
    464407
     
    466409     * Remove all projection change listeners. For testing purposes only.
    467410     * @since 13322
    468      */
     411     * @deprecated Use {@link ProjectionRegistry#clearProjectionChangeListeners}
     412     */
     413    @Deprecated
    469414    public static void clearProjectionChangeListeners() {
    470         listeners.clear();
     415        ProjectionRegistry.clearProjectionChangeListeners();
    471416    }
    472417
  • trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java

    r13434 r14120  
    1818import javax.swing.JOptionPane;
    1919
    20 import org.openstreetmap.josm.Main;
    2120import org.openstreetmap.josm.command.AddCommand;
    2221import org.openstreetmap.josm.command.ChangeCommand;
     
    3029import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3130import org.openstreetmap.josm.data.osm.Way;
     31import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    3232import org.openstreetmap.josm.gui.MainApplication;
    3333import org.openstreetmap.josm.gui.Notification;
     
    180180
    181181        // see #10777
    182         LatLon ll1 = Main.getProjection().eastNorth2latlon(n1);
    183         LatLon ll2 = Main.getProjection().eastNorth2latlon(center);
     182        LatLon ll1 = ProjectionRegistry.getProjection().eastNorth2latlon(n1);
     183        LatLon ll2 = ProjectionRegistry.getProjection().eastNorth2latlon(center);
    184184
    185185        double radiusInMeters = ll1.greatCircleDistance(ll2);
     
    218218                double x = center.east() + r*Math.cos(alpha);
    219219                double y = center.north() + r*Math.sin(alpha);
    220                 LatLon ll = Main.getProjection().eastNorth2latlon(new EastNorth(x, y));
     220                LatLon ll = ProjectionRegistry.getProjection().eastNorth2latlon(new EastNorth(x, y));
    221221                if (ll.isOutSideWorld()) {
    222222                    notifyNodesNotOnCircle();
  • trunk/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java

    r13867 r14120  
    2626import org.openstreetmap.josm.data.coor.LatLon;
    2727import org.openstreetmap.josm.data.imagery.OffsetBookmark;
     28import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2829import org.openstreetmap.josm.gui.ExtendedDialog;
    2930import org.openstreetmap.josm.gui.MainApplication;
     
    7475        }
    7576        old = layer.getDisplaySettings().getOffsetBookmark();
    76         EastNorth curOff = old == null ? EastNorth.ZERO : old.getDisplacement(Main.getProjection());
     77        EastNorth curOff = old == null ? EastNorth.ZERO : old.getDisplacement(ProjectionRegistry.getProjection());
    7778        LatLon center;
    7879        if (MainApplication.isDisplayingMapView()) {
    79             center = Main.getProjection().eastNorth2latlon(MainApplication.getMap().mapView.getCenter());
     80            center = ProjectionRegistry.getProjection().eastNorth2latlon(MainApplication.getMap().mapView.getCenter());
    8081        } else {
    8182            center = LatLon.ZERO;
    8283        }
    8384        tempOffset = new OffsetBookmark(
    84                 Main.getProjection().toCode(),
     85                ProjectionRegistry.getProjection().toCode(),
    8586                layer.getInfo().getId(),
    8687                layer.getInfo().getName(),
     
    258259                    "You can also enter east and north offset in the {0} coordinates.\n" +
    259260                    "If you want to save the offset as bookmark, enter the bookmark name below",
    260                     Main.getProjection().toString())), GBC.eop());
     261                    ProjectionRegistry.getProjection().toString())), GBC.eop());
    261262            pnl.add(new JLabel(tr("Offset:")), GBC.std());
    262263            pnl.add(tOffset, GBC.eol().fill(GBC.HORIZONTAL).insets(0, 0, 0, 5));
     
    313314            if (layer != null) {
    314315                // Support projections with very small numbers (e.g. 4326)
    315                 int precision = Main.getProjection().getDefaultZoomInPPD() >= 1.0 ? 2 : 7;
     316                int precision = ProjectionRegistry.getProjection().getDefaultZoomInPPD() >= 1.0 ? 2 : 7;
    316317                // US locale to force decimal separator to be '.'
    317318                try (Formatter us = new Formatter(Locale.US)) {
  • trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java

    r13434 r14120  
    1919import java.util.TreeSet;
    2020
    21 import org.openstreetmap.josm.Main;
    2221import org.openstreetmap.josm.command.ChangeCommand;
    2322import org.openstreetmap.josm.command.Command;
     
    3029import org.openstreetmap.josm.data.osm.Way;
    3130import org.openstreetmap.josm.data.osm.WaySegment;
     31import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    3232import org.openstreetmap.josm.gui.MainApplication;
    3333import org.openstreetmap.josm.gui.MapView;
     
    143143                                node.getEastNorth());
    144144                        MoveCommand c = new MoveCommand(
    145                                 node, Main.getProjection().eastNorth2latlon(newPosition));
     145                                node, ProjectionRegistry.getProjection().eastNorth2latlon(newPosition));
    146146                        // Avoid moving a given node several times at the same position in case of overlapping ways
    147147                        if (!cmds.contains(c)) {
  • trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java

    r13712 r14120  
    3030import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3131import org.openstreetmap.josm.data.osm.Way;
     32import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    3233import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    3334import org.openstreetmap.josm.gui.MainApplication;
     
    148149        if (!isEnabled())
    149150            return;
    150         if ("EPSG:4326".equals(Main.getProjection().toString())) {
     151        if ("EPSG:4326".equals(ProjectionRegistry.getProjection().toString())) {
    151152            String msg = tr("<html>You are using the EPSG:4326 projection which might lead<br>" +
    152153                    "to undesirable results when doing rectangular alignments.<br>" +
     
    307308            throw new InvalidUserInputException("Unable to orthogonalize " + singleNode);
    308309        }
    309         return new MoveCommand(singleNode, Main.getProjection().eastNorth2latlon(Geometry.getCentroidEN(rightAnglePositions)));
     310        return new MoveCommand(singleNode, ProjectionRegistry.getProjection().eastNorth2latlon(Geometry.getCentroidEN(rightAnglePositions)));
    310311    }
    311312
  • trunk/src/org/openstreetmap/josm/actions/SessionLoadAction.java

    r13437 r14120  
    2020
    2121import org.openstreetmap.josm.Main;
     22import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2223import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    2324import org.openstreetmap.josm.gui.MainApplication;
     
    147148                }
    148149                if (noMap && viewport != null) {
    149                     MainApplication.getMap().mapView.scheduleZoomTo(viewport.getEastNorthViewport(Main.getProjection()));
     150                    MainApplication.getMap().mapView.scheduleZoomTo(viewport.getEastNorthViewport(ProjectionRegistry.getProjection()));
    150151                }
    151152            }
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

    r13434 r14120  
    2929import javax.swing.JMenuItem;
    3030
    31 import org.openstreetmap.josm.Main;
    3231import org.openstreetmap.josm.actions.JosmAction;
    3332import org.openstreetmap.josm.actions.MergeNodesAction;
     
    4645import org.openstreetmap.josm.data.osm.WaySegment;
    4746import org.openstreetmap.josm.data.preferences.NamedColorProperty;
     47import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    4848import org.openstreetmap.josm.gui.MainApplication;
    4949import org.openstreetmap.josm.gui.MainMenu;
     
    655655            //move existing node
    656656            Node n1Old = selectedSegment.getFirstNode();
    657             cmds.add(new MoveCommand(n1Old, Main.getProjection().eastNorth2latlon(newN1en)));
     657            cmds.add(new MoveCommand(n1Old, ProjectionRegistry.getProjection().eastNorth2latlon(newN1en)));
    658658            changedNodes.add(n1Old);
    659659        } else if (ignoreSharedNodes && segmentAngleZero && !alwaysCreateNodes && hasOtherWays) {
    660660            // replace shared node with new one
    661661            Node n1Old = selectedSegment.getFirstNode();
    662             Node n1New = new Node(Main.getProjection().eastNorth2latlon(newN1en));
     662            Node n1New = new Node(ProjectionRegistry.getProjection().eastNorth2latlon(newN1en));
    663663            wnew.addNode(insertionPoint, n1New);
    664664            wnew.removeNode(n1Old);
     
    668668        } else {
    669669            //introduce new node
    670             Node n1New = new Node(Main.getProjection().eastNorth2latlon(newN1en));
     670            Node n1New = new Node(ProjectionRegistry.getProjection().eastNorth2latlon(newN1en));
    671671            wnew.addNode(insertionPoint, n1New);
    672672            wayWasModified = true;
     
    685685            //move existing node
    686686            Node n2Old = selectedSegment.getSecondNode();
    687             cmds.add(new MoveCommand(n2Old, Main.getProjection().eastNorth2latlon(newN2en)));
     687            cmds.add(new MoveCommand(n2Old, ProjectionRegistry.getProjection().eastNorth2latlon(newN2en)));
    688688            changedNodes.add(n2Old);
    689689        } else if (ignoreSharedNodes && segmentAngleZero && !alwaysCreateNodes && hasOtherWays) {
    690690            // replace shared node with new one
    691691            Node n2Old = selectedSegment.getSecondNode();
    692             Node n2New = new Node(Main.getProjection().eastNorth2latlon(newN2en));
     692            Node n2New = new Node(ProjectionRegistry.getProjection().eastNorth2latlon(newN2en));
    693693            wnew.addNode(insertionPoint, n2New);
    694694            wnew.removeNode(n2Old);
     
    698698        } else {
    699699            //introduce new node
    700             Node n2New = new Node(Main.getProjection().eastNorth2latlon(newN2en));
     700            Node n2New = new Node(ProjectionRegistry.getProjection().eastNorth2latlon(newN2en));
    701701            wnew.addNode(insertionPoint, n2New);
    702702            wayWasModified = true;
     
    937937
    938938        // find out the movement distance, in metres
    939         double distance = Main.getProjection().eastNorth2latlon(initialN1en).greatCircleDistance(
    940                 Main.getProjection().eastNorth2latlon(n1movedEn));
     939        double distance = ProjectionRegistry.getProjection().eastNorth2latlon(initialN1en).greatCircleDistance(
     940                ProjectionRegistry.getProjection().eastNorth2latlon(n1movedEn));
    941941        MainApplication.getMap().statusLine.setDist(distance);
    942942        updateStatusLine();
  • trunk/src/org/openstreetmap/josm/command/MoveCommand.java

    r12778 r14120  
    1414import javax.swing.Icon;
    1515
    16 import org.openstreetmap.josm.Main;
    1716import org.openstreetmap.josm.data.coor.EastNorth;
    1817import org.openstreetmap.josm.data.coor.LatLon;
     
    2120import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2221import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor;
     22import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2323import org.openstreetmap.josm.tools.ImageProvider;
    2424
     
    7373    public MoveCommand(Node node, LatLon position) {
    7474        this(Collections.singleton((OsmPrimitive) node),
    75                 Main.getProjection().latlon2eastNorth(position).subtract(node.getEastNorth()));
     75                ProjectionRegistry.getProjection().latlon2eastNorth(position).subtract(node.getEastNorth()));
    7676    }
    7777
  • trunk/src/org/openstreetmap/josm/data/coor/CachedLatLon.java

    r12161 r14120  
    44import java.util.Objects;
    55
    6 import org.openstreetmap.josm.Main;
    76import org.openstreetmap.josm.data.projection.Projecting;
    87import org.openstreetmap.josm.data.projection.Projection;
     8import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    99
    1010/**
     
    4646     */
    4747    public CachedLatLon(EastNorth eastNorth) {
    48         this(eastNorth, Main.getProjection());
     48        this(eastNorth, ProjectionRegistry.getProjection());
    4949    }
    5050
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r14091 r14120  
    1717import java.util.Objects;
    1818
    19 import org.openstreetmap.josm.Main;
    2019import org.openstreetmap.josm.data.Bounds;
     20import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2121import org.openstreetmap.josm.tools.Logging;
    2222import org.openstreetmap.josm.tools.Utils;
     
    195195     */
    196196    public boolean isOutSideWorld() {
    197         Bounds b = Main.getProjection().getWorldBoundsLatLon();
     197        Bounds b = ProjectionRegistry.getProjection().getWorldBoundsLatLon();
    198198        return lat() < b.getMinLat() || lat() > b.getMaxLat() ||
    199199                lon() < b.getMinLon() || lon() > b.getMaxLon();
  • trunk/src/org/openstreetmap/josm/data/coor/conversion/ProjectedCoordinateFormat.java

    r12741 r14120  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import org.openstreetmap.josm.Main;
    76import org.openstreetmap.josm.data.coor.ILatLon;
     7import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    88
    99/**
     
    2525    @Override
    2626    public String latToString(ILatLon ll) {
    27         return cDdFormatter.format(ll.getEastNorth(Main.getProjection()).north());
     27        return cDdFormatter.format(ll.getEastNorth(ProjectionRegistry.getProjection()).north());
    2828    }
    2929
    3030    @Override
    3131    public String lonToString(ILatLon ll) {
    32         return cDdFormatter.format(ll.getEastNorth(Main.getProjection()).east());
     32        return cDdFormatter.format(ll.getEastNorth(ProjectionRegistry.getProjection()).east());
    3333    }
    3434}
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r13257 r14120  
    2020import java.util.stream.Stream;
    2121
    22 import org.openstreetmap.josm.Main;
    2322import org.openstreetmap.josm.data.Bounds;
    2423import org.openstreetmap.josm.data.Data;
     
    2625import org.openstreetmap.josm.data.coor.EastNorth;
    2726import org.openstreetmap.josm.data.gpx.GpxTrack.GpxTrackChangeListener;
     27import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2828import org.openstreetmap.josm.gui.MainApplication;
    2929import org.openstreetmap.josm.gui.layer.GpxLayer;
     
    539539                WayPoint r = null;
    540540                for (WayPoint wpSeg : seg.getWayPoints()) {
    541                     EastNorth en = wpSeg.getEastNorth(Main.getProjection());
     541                    EastNorth en = wpSeg.getEastNorth(ProjectionRegistry.getProjection());
    542542                    if (r == null) {
    543543                        r = wpSeg;
     
    586586                }
    587587                if (r != null) {
    588                     EastNorth c = r.getEastNorth(Main.getProjection());
     588                    EastNorth c = r.getEastNorth(ProjectionRegistry.getProjection());
    589589                    /* if there is only one point in the seg, it will do this twice, but no matter */
    590590                    rx = c.east();
     
    603603        if (bestEN == null)
    604604            return null;
    605         WayPoint best = new WayPoint(Main.getProjection().eastNorth2latlon(bestEN));
     605        WayPoint best = new WayPoint(ProjectionRegistry.getProjection().eastNorth2latlon(bestEN));
    606606        best.time = bestTime;
    607607        return best;
  • trunk/src/org/openstreetmap/josm/data/imagery/OffsetBookmark.java

    r13798 r14120  
    1010import java.util.stream.Collectors;
    1111
    12 import org.openstreetmap.josm.Main;
    1312import org.openstreetmap.josm.data.StructUtils;
    1413import org.openstreetmap.josm.data.StructUtils.StructEntry;
     
    1817import org.openstreetmap.josm.data.coor.LatLon;
    1918import org.openstreetmap.josm.data.projection.Projection;
     19import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2020import org.openstreetmap.josm.data.projection.Projections;
    2121import org.openstreetmap.josm.gui.MainApplication;
     
    4949    public boolean isUsable(ImageryLayer layer) {
    5050        if (projection_code == null) return false;
    51         if (!Main.getProjection().toCode().equals(projection_code) && !hasCenter()) return false;
     51        if (!ProjectionRegistry.getProjection().toCode().equals(projection_code) && !hasCenter()) return false;
    5252        ImageryInfo info = layer.getInfo();
    5353        return imagery_id != null ? Objects.equals(info.getId(), imagery_id) : Objects.equals(info.getName(), imagery_name);
     
    363363        LatLon center;
    364364        if (MainApplication.isDisplayingMapView()) {
    365             center = Main.getProjection().eastNorth2latlon(MainApplication.getMap().mapView.getCenter());
     365            center = ProjectionRegistry.getProjection().eastNorth2latlon(MainApplication.getMap().mapView.getCenter());
    366366        } else {
    367367            center = LatLon.ZERO;
    368368        }
    369369        OffsetBookmark nb = new OffsetBookmark(
    370                 Main.getProjection().toCode(), layer.getInfo().getId(), layer.getInfo().getName(),
     370                ProjectionRegistry.getProjection().toCode(), layer.getInfo().getId(), layer.getInfo().getName(),
    371371                name, layer.getDisplaySettings().getDisplacement(), center);
    372372        for (ListIterator<OffsetBookmark> it = allBookmarks.listIterator(); it.hasNext();) {
  • trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java

    r13733 r14120  
    1616
    1717import org.openstreetmap.gui.jmapviewer.interfaces.TemplatedTileSource;
    18 import org.openstreetmap.josm.Main;
    1918import org.openstreetmap.josm.data.coor.EastNorth;
    2019import org.openstreetmap.josm.data.projection.Projection;
     20import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2121import org.openstreetmap.josm.gui.layer.WMSLayer;
    2222import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    108108        } else if (baseUrl.toLowerCase(Locale.US).contains("crs=")) {
    109109            // assume WMS 1.3.0
    110             switchLatLon = Main.getProjection().switchXY();
     110            switchLatLon = ProjectionRegistry.getProjection().switchXY();
    111111        }
    112112        String bbox = getBbox(zoom, tilex, tiley, switchLatLon);
  • trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java

    r13879 r14120  
    5050import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
    5151import org.openstreetmap.josm.data.projection.Projection;
     52import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    5253import org.openstreetmap.josm.data.projection.Projections;
    5354import org.openstreetmap.josm.gui.ExtendedDialog;
     
    346347            List<Layer> ls = layerById.entrySet().iterator().next().getValue()
    347348                    .stream().filter(
    348                             u -> u.tileMatrixSet.crs.equals(Main.getProjection().toCode()))
     349                            u -> u.tileMatrixSet.crs.equals(ProjectionRegistry.getProjection().toCode()))
    349350                    .collect(Collectors.toList());
    350351            if (ls.size() == 1) {
     
    631632    private static TileMatrix parseTileMatrix(XMLStreamReader reader, String matrixCrs) throws XMLStreamException {
    632633        Projection matrixProj = Optional.ofNullable(Projections.getProjectionByCode(matrixCrs))
    633                 .orElseGet(Main::getProjection); // use current projection if none found. Maybe user is using custom string
     634                .orElseGet(ProjectionRegistry::getProjection); // use current projection if none found. Maybe user is using custom string
    634635        TileMatrix ret = new TileMatrix();
    635636        for (int event = reader.getEventType();
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r14119 r14120  
    2525import java.util.stream.Stream;
    2626
    27 import org.openstreetmap.josm.Main;
    2827import org.openstreetmap.josm.data.APIDataSet.APIOperation;
    2928import org.openstreetmap.josm.data.Bounds;
     
    5453import org.openstreetmap.josm.data.projection.Projection;
    5554import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
     55import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    5656import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    5757import org.openstreetmap.josm.spi.preferences.Config;
     
    175175        // Transparently register as projection change listener. No need to explicitly remove
    176176        // the listener, projection change listeners are managed as WeakReferences.
    177         Main.addProjectionChangeListener(this);
     177        ProjectionRegistry.addProjectionChangeListener(this);
    178178        addSelectionListener((DataSelectionListener) e -> fireSelectionChange(e.getSelection()));
    179179    }
     
    10451045     */
    10461046    public void invalidateEastNorthCache() {
    1047         if (Main.getProjection() == null)
     1047        if (ProjectionRegistry.getProjection() == null)
    10481048            return; // sanity check
    10491049        beginUpdate();
  • trunk/src/org/openstreetmap/josm/data/osm/INode.java

    r13669 r14120  
    66import org.openstreetmap.josm.data.coor.ILatLon;
    77import org.openstreetmap.josm.data.coor.LatLon;
     8import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    89
    910/**
     
    3435     */
    3536    default EastNorth getEastNorth() {
    36         return getEastNorth(Main.getProjection());
     37        return getEastNorth(ProjectionRegistry.getProjection());
    3738    }
    3839
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r13669 r14120  
    1010import java.util.function.Predicate;
    1111
    12 import org.openstreetmap.josm.Main;
    1312import org.openstreetmap.josm.data.coor.EastNorth;
    1413import org.openstreetmap.josm.data.coor.LatLon;
     
    1615import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
    1716import org.openstreetmap.josm.data.projection.Projecting;
     17import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    1818import org.openstreetmap.josm.tools.CheckParameterUtil;
    1919import org.openstreetmap.josm.tools.Utils;
     
    114114            invalidateEastNorthCache();
    115115        } else if (eastNorth != null) {
    116             LatLon ll = Main.getProjection().eastNorth2latlon(eastNorth);
     116            LatLon ll = ProjectionRegistry.getProjection().eastNorth2latlon(eastNorth);
    117117            this.lat = ll.lat();
    118118            this.lon = ll.lon();
    119119            this.east = eastNorth.east();
    120120            this.north = eastNorth.north();
    121             this.eastNorthCacheKey = Main.getProjection().getCacheKey();
     121            this.eastNorthCacheKey = ProjectionRegistry.getProjection().getCacheKey();
    122122        } else {
    123123            this.lat = Double.NaN;
  • trunk/src/org/openstreetmap/josm/data/osm/NodeData.java

    r13764 r14120  
    22package org.openstreetmap.josm.data.osm;
    33
    4 import org.openstreetmap.josm.Main;
    54import org.openstreetmap.josm.data.coor.EastNorth;
    65import org.openstreetmap.josm.data.coor.LatLon;
    76import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
     7import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    88
    99/**
     
    7777    @Override
    7878    public void setEastNorth(EastNorth eastNorth) {
    79         setCoor(Main.getProjection().eastNorth2latlon(eastNorth));
     79        setCoor(ProjectionRegistry.getProjection().eastNorth2latlon(eastNorth));
    8080    }
    8181
  • trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java

    r14098 r14120  
    2323import java.util.stream.Collectors;
    2424
    25 import org.openstreetmap.josm.Main;
    2625import org.openstreetmap.josm.data.Bounds;
    2726import org.openstreetmap.josm.data.coor.LatLon;
     
    3635import org.openstreetmap.josm.data.osm.search.PushbackTokenizer.Range;
    3736import org.openstreetmap.josm.data.osm.search.PushbackTokenizer.Token;
     37import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    3838import org.openstreetmap.josm.gui.mappaint.Environment;
    3939import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;
     
    18951895        protected Collection<Bounds> getBounds(OsmPrimitive primitive) {
    18961896            final Collection<Bounds> bounds = super.getBounds(primitive);
    1897             return bounds == null || bounds.isEmpty() ? Collections.singleton(Main.getProjection().getWorldBoundsLatLon()) : bounds;
     1897            return bounds == null || bounds.isEmpty() ?
     1898                    Collections.singleton(ProjectionRegistry.getProjection().getWorldBoundsLatLon()) : bounds;
    18981899        }
    18991900
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

    r13906 r14120  
    44import java.util.Collection;
    55
    6 import org.openstreetmap.josm.Main;
    76import org.openstreetmap.josm.data.Bounds;
    87import org.openstreetmap.josm.data.ProjectionBounds;
     
    1918import org.openstreetmap.josm.data.osm.Relation;
    2019import org.openstreetmap.josm.data.osm.Way;
     20import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2121import org.openstreetmap.josm.gui.MainApplication;
    2222import org.openstreetmap.josm.gui.MapFrame;
     
    7676    public void visit(Bounds b) {
    7777        if (b != null) {
    78             Main.getProjection().visitOutline(b, this::visit);
     78            ProjectionRegistry.getProjection().visitOutline(b, this::visit);
    7979        }
    8080    }
     
    9898    public void visit(ILatLon latlon) {
    9999        if (latlon != null) {
    100             visit(latlon.getEastNorth(Main.getProjection()));
     100            visit(latlon.getEastNorth(ProjectionRegistry.getProjection()));
    101101        }
    102102    }
     
    159159        if (bounds == null)
    160160            return;
    161         LatLon minLatlon = Main.getProjection().eastNorth2latlon(bounds.getMin());
    162         LatLon maxLatlon = Main.getProjection().eastNorth2latlon(bounds.getMax());
     161        LatLon minLatlon = ProjectionRegistry.getProjection().eastNorth2latlon(bounds.getMin());
     162        LatLon maxLatlon = ProjectionRegistry.getProjection().eastNorth2latlon(bounds.getMax());
    163163        bounds = new ProjectionBounds(new LatLon(
    164164                        Math.max(-90, minLatlon.lat() - enlargeDegree),
    165                         Math.max(-180, minLatlon.lon() - enlargeDegree)).getEastNorth(Main.getProjection()),
     165                        Math.max(-180, minLatlon.lon() - enlargeDegree)).getEastNorth(ProjectionRegistry.getProjection()),
    166166                new LatLon(
    167167                        Math.min(90, maxLatlon.lat() + enlargeDegree),
    168                         Math.min(180, maxLatlon.lon() + enlargeDegree)).getEastNorth(Main.getProjection()));
     168                        Math.min(180, maxLatlon.lon() + enlargeDegree)).getEastNorth(ProjectionRegistry.getProjection()));
    169169    }
    170170
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java

    r14000 r14120  
    99import java.util.concurrent.ConcurrentHashMap;
    1010
    11 import org.openstreetmap.josm.Main;
    1211import org.openstreetmap.josm.data.osm.DataSelectionListener;
    1312import org.openstreetmap.josm.data.osm.DataSet;
     
    2928import org.openstreetmap.josm.data.projection.Projection;
    3029import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
     30import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    3131import org.openstreetmap.josm.gui.MainApplication;
    3232import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     
    4949
    5050    private MultipolygonCache() {
    51         Main.addProjectionChangeListener(this);
     51        ProjectionRegistry.addProjectionChangeListener(this);
    5252        SelectionEventManager.getInstance().addSelectionListener(this);
    5353        MainApplication.getLayerManager().addLayerChangeListener(this);
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r13672 r14120  
    3131import org.openstreetmap.josm.Main;
    3232import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;
     33import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    3334import org.openstreetmap.josm.data.validation.tests.Addresses;
    3435import org.openstreetmap.josm.data.validation.tests.ApiCapabilitiesTest;
     
    352353     */
    353354    public static void initializeGridDetail() {
    354         String code = Main.getProjection().toCode();
     355        String code = ProjectionRegistry.getProjection().toCode();
    355356        if (Arrays.asList(ProjectionPreference.wgs84.allCodes()).contains(code)) {
    356357            OsmValidator.griddetail = 10_000;
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r14119 r14120  
    102102import org.openstreetmap.josm.data.preferences.JosmUrls;
    103103import org.openstreetmap.josm.data.preferences.sources.SourceType;
     104import org.openstreetmap.josm.data.projection.ProjectionBoundsProvider;
    104105import org.openstreetmap.josm.data.projection.ProjectionCLI;
     106import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    105107import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileSource;
    106108import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileWrapper;
     
    258260    };
    259261
     262    private static final ProjectionBoundsProvider mainBoundsProvider = new ProjectionBoundsProvider() {
     263        @Override
     264        public Bounds getRealBounds() {
     265            return isDisplayingMapView() ? map.mapView.getRealBounds() : null;
     266        }
     267
     268        @Override
     269        public void restoreOldBounds(Bounds oldBounds) {
     270            if (isDisplayingMapView()) {
     271                map.mapView.zoomTo(oldBounds);
     272            }
     273        }
     274    };
     275
    260276    private static final List<CLIModule> cliModules = new ArrayList<>();
    261277
     
    341357        undoRedo = super.undoRedo;
    342358        getLayerManager().addLayerChangeListener(undoRedoCleaner);
     359        ProjectionRegistry.setboundsProvider(mainBoundsProvider);
    343360    }
    344361
     
    511528        } catch (SecurityException e) {
    512529            Logging.log(Logging.LEVEL_ERROR, "Unable to shutdown worker", e);
    513         }
    514     }
    515 
    516     @Override
    517     protected Bounds getRealBounds() {
    518         return isDisplayingMapView() ? map.mapView.getRealBounds() : null;
    519     }
    520 
    521     @Override
    522     protected void restoreOldBounds(Bounds oldBounds) {
    523         if (isDisplayingMapView()) {
    524             map.mapView.zoomTo(oldBounds);
    525530        }
    526531    }
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r13890 r14120  
    3737import javax.swing.SwingUtilities;
    3838
    39 import org.openstreetmap.josm.Main;
    4039import org.openstreetmap.josm.actions.mapmode.MapMode;
    4140import org.openstreetmap.josm.data.Bounds;
     
    4847import org.openstreetmap.josm.data.osm.visitor.paint.Rendering;
    4948import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache;
     49import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    5050import org.openstreetmap.josm.gui.MapViewState.MapViewRectangle;
    5151import org.openstreetmap.josm.gui.autofilter.AutoFilterManager;
     
    358358
    359359                layer.addPropertyChangeListener(this);
    360                 Main.addProjectionChangeListener(layer);
     360                ProjectionRegistry.addProjectionChangeListener(layer);
    361361                invalidatedListener.addTo(layer);
    362362                AudioPlayer.reset();
     
    398398        }
    399399        painter.detachFromMapView(new MapViewEvent(this, false));
    400         Main.removeProjectionChangeListener(layer);
     400        ProjectionRegistry.removeProjectionChangeListener(layer);
    401401        layer.removePropertyChangeListener(this);
    402402        invalidatedListener.removeFrom(layer);
  • trunk/src/org/openstreetmap/josm/gui/MapViewState.java

    r14052 r14120  
    1616import javax.swing.JComponent;
    1717
    18 import org.openstreetmap.josm.Main;
    1918import org.openstreetmap.josm.data.Bounds;
    2019import org.openstreetmap.josm.data.ProjectionBounds;
     
    2524import org.openstreetmap.josm.data.projection.Projecting;
    2625import org.openstreetmap.josm.data.projection.Projection;
     26import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2727import org.openstreetmap.josm.gui.download.DownloadDialog;
    2828import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    394394     */
    395395    public static MapViewState createDefaultState(int width, int height) {
    396         Projection projection = Main.getProjection();
     396        Projection projection = ProjectionRegistry.getProjection();
    397397        double scale = projection.getDefaultZoomInPPD();
    398398        MapViewState state = new MapViewState(projection, width, height, scale, new EastNorth(0, 0));
     
    403403    private static EastNorth calculateDefaultCenter() {
    404404        Bounds b = Optional.ofNullable(DownloadDialog.getSavedDownloadBounds()).orElseGet(
    405                 () -> Main.getProjection().getWorldBoundsLatLon());
    406         return b.getCenter().getEastNorth(Main.getProjection());
     405                () -> ProjectionRegistry.getProjection().getWorldBoundsLatLon());
     406        return b.getCenter().getEastNorth(ProjectionRegistry.getProjection());
    407407    }
    408408
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r14052 r14120  
    3232import javax.swing.SwingUtilities;
    3333
    34 import org.openstreetmap.josm.Main;
    3534import org.openstreetmap.josm.data.Bounds;
    3635import org.openstreetmap.josm.data.ProjectionBounds;
     
    5352import org.openstreetmap.josm.data.projection.Projection;
    5453import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
     54import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    5555import org.openstreetmap.josm.gui.help.Helpful;
    5656import org.openstreetmap.josm.gui.layer.NativeScaleLayer;
     
    188188        setLayout(null);
    189189        state = MapViewState.createDefaultState(getWidth(), getHeight());
    190         Main.addProjectionChangeListener(projectionChangeListener);
     190        ProjectionRegistry.addProjectionChangeListener(projectionChangeListener);
    191191    }
    192192
     
    334334     */
    335335    public void fixProjection() {
    336         state = state.usingProjection(Main.getProjection());
     336        state = state.usingProjection(ProjectionRegistry.getProjection());
    337337        repaint();
    338338    }
     
    492492     */
    493493    public Bounds getLatLonBounds(Rectangle r) {
    494         return Main.getProjection().getLatLonBoundsBox(getProjectionBounds(r));
     494        return ProjectionRegistry.getProjection().getLatLonBoundsBox(getProjectionBounds(r));
    495495    }
    496496
     
    525525            return new Point();
    526526        } else {
    527             return getPoint2D(latlon.getEastNorth(Main.getProjection()));
     527            return getPoint2D(latlon.getEastNorth(ProjectionRegistry.getProjection()));
    528528        }
    529529    }
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/importers/PrimitiveDataPaster.java

    r13907 r14120  
    2323import org.openstreetmap.josm.data.osm.RelationMemberData;
    2424import org.openstreetmap.josm.data.osm.WayData;
     25import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2526import org.openstreetmap.josm.gui.ExtendedDialog;
    2627import org.openstreetmap.josm.gui.MainApplication;
     
    7374                if (data instanceof NodeData) {
    7475                    NodeData nodeData = (NodeData) data;
    75                     nodeData.setEastNorth(nodeData.getEastNorth(Main.getProjection()).add(offset));
     76                    nodeData.setEastNorth(nodeData.getEastNorth(ProjectionRegistry.getProjection()).add(offset));
    7677                } else if (data instanceof WayData) {
    7778                    updateNodes(newIds.get(OsmPrimitiveType.NODE), data);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDataText.java

    r13953 r14120  
    88import java.util.List;
    99
    10 import org.openstreetmap.josm.Main;
    1110import org.openstreetmap.josm.data.conflict.Conflict;
    1211import org.openstreetmap.josm.data.coor.EastNorth;
     
    2221import org.openstreetmap.josm.data.osm.OsmData;
    2322import org.openstreetmap.josm.data.osm.OsmPrimitive;
     23import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2424import org.openstreetmap.josm.data.projection.proj.TransverseMercator;
    2525import org.openstreetmap.josm.data.projection.proj.TransverseMercator.Hemisphere;
     
    171171            addBbox(o);
    172172            add(tr("Centroid: "),
    173                     toStringCSV(", ", Main.getProjection().eastNorth2latlon(
     173                    toStringCSV(", ", ProjectionRegistry.getProjection().eastNorth2latlon(
    174174                            Geometry.getCentroid(((IWay<?>) o).getNodes()))));
    175175            addWayNodes((IWay<?>) o);
     
    203203        if (bbox != null) {
    204204            add(tr("Bounding box: "), bbox.toStringCSV(", "));
    205             EastNorth bottomRigth = bbox.getBottomRight().getEastNorth(Main.getProjection());
    206             EastNorth topLeft = bbox.getTopLeft().getEastNorth(Main.getProjection());
     205            EastNorth bottomRigth = bbox.getBottomRight().getEastNorth(ProjectionRegistry.getProjection());
     206            EastNorth topLeft = bbox.getTopLeft().getEastNorth(ProjectionRegistry.getProjection());
    207207            add(tr("Bounding box (projected): "),
    208208                    Double.toString(topLeft.east()), ", ",
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LatLonDialog.java

    r13050 r14120  
    2323import javax.swing.event.DocumentListener;
    2424
    25 import org.openstreetmap.josm.Main;
    2625import org.openstreetmap.josm.data.coor.EastNorth;
    2726import org.openstreetmap.josm.data.coor.LatLon;
    2827import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager;
    2928import org.openstreetmap.josm.data.coor.conversion.LatLonParser;
     29import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    3030import org.openstreetmap.josm.gui.ExtendedDialog;
    3131import org.openstreetmap.josm.gui.util.WindowGeometry;
     
    196196        tfLatLon.setText(CoordinateFormatManager.getDefaultFormat().latToString(llc) + ' ' +
    197197                         CoordinateFormatManager.getDefaultFormat().lonToString(llc));
    198         EastNorth en = Main.getProjection().latlon2eastNorth(llc);
     198        EastNorth en = ProjectionRegistry.getProjection().latlon2eastNorth(llc);
    199199        tfEastNorth.setText(Double.toString(en.east()) + ' ' + Double.toString(en.north()));
    200200        // Both latLonCoordinates and eastNorthCoordinates may have been reset to null if ll is out of the world
     
    213213        } else {
    214214            if (eastNorthCoordinates == null) return null;
    215             return Main.getProjection().eastNorth2latlon(eastNorthCoordinates);
     215            return ProjectionRegistry.getProjection().eastNorth2latlon(eastNorthCoordinates);
    216216        }
    217217    }
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r13967 r14120  
    9191import org.openstreetmap.josm.data.preferences.IntegerProperty;
    9292import org.openstreetmap.josm.data.projection.Projection;
     93import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    9394import org.openstreetmap.josm.data.projection.Projections;
    9495import org.openstreetmap.josm.gui.ExtendedDialog;
     
    328329        if (coordinateConverter.requiresReprojection()) {
    329330            content.add(Arrays.asList(tr("Tile download projection"), tileSource.getServerCRS()));
    330             content.add(Arrays.asList(tr("Tile display projection"), Main.getProjection().toCode()));
     331            content.add(Arrays.asList(tr("Tile display projection"), ProjectionRegistry.getProjection().toCode()));
    331332        }
    332333        content.add(Arrays.asList(tr("Current zoom"), Integer.toString(currentZoomLevel)));
     
    449450                    content.add(Arrays.asList(tr("Reprojection"),
    450451                            tile.getTileSource().getServerCRS() +
    451                             " -> " + Main.getProjection().toCode()));
     452                            " -> " + ProjectionRegistry.getProjection().toCode()));
    452453                    BufferedImage img = tile.getImage();
    453454                    if (img != null) {
     
    566567            }
    567568            // check if projection is supported
    568             projectionChanged(null, Main.getProjection());
     569            projectionChanged(null, ProjectionRegistry.getProjection());
    569570            initTileSource(this.tileSource);
    570571        }
     
    14121413                    CoordinateConversion.projToEn(topLeftUnshifted),
    14131414                    CoordinateConversion.projToEn(botRightUnshifted));
    1414             ProjectionBounds bbox = projServer.getEastNorthBoundsBox(projBounds, Main.getProjection());
     1415            ProjectionBounds bbox = projServer.getEastNorthBoundsBox(projBounds, ProjectionRegistry.getProjection());
    14151416            t1 = tileSource.projectedToTileXY(CoordinateConversion.enToProj(bbox.getMin()), zoom);
    14161417            t2 = tileSource.projectedToTileXY(CoordinateConversion.enToProj(bbox.getMax()), zoom);
     
    19621963        @Override
    19631964        public boolean isActive() {
    1964             EastNorth offset = bookmark.getDisplacement(Main.getProjection());
     1965            EastNorth offset = bookmark.getDisplacement(ProjectionRegistry.getProjection());
    19651966            EastNorth active = getDisplaySettings().getDisplacement();
    19661967            return Utils.equalsEpsilon(offset.east(), active.east()) && Utils.equalsEpsilon(offset.north(), active.north());
  • trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

    r13967 r14120  
    2929import javax.swing.JTextField;
    3030
    31 import org.openstreetmap.josm.Main;
    3231import org.openstreetmap.josm.data.ProjectionBounds;
    3332import org.openstreetmap.josm.data.imagery.ImageryInfo;
    3433import org.openstreetmap.josm.data.preferences.IntegerProperty;
     34import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    3535import org.openstreetmap.josm.gui.MainApplication;
    3636import org.openstreetmap.josm.gui.MapView;
     
    8585    public double getPPD() {
    8686        if (!MainApplication.isDisplayingMapView())
    87             return Main.getProjection().getDefaultZoomInPPD();
     87            return ProjectionRegistry.getProjection().getDefaultZoomInPPD();
    8888        MapView mapView = MainApplication.getMap().mapView;
    8989        ProjectionBounds bounds = mapView.getProjectionBounds();
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r13742 r14120  
    1616import org.apache.commons.jcs.access.CacheAccess;
    1717import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
    18 import org.openstreetmap.josm.Main;
    1918import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
    2019import org.openstreetmap.josm.data.coor.LatLon;
     
    2928import org.openstreetmap.josm.data.preferences.IntegerProperty;
    3029import org.openstreetmap.josm.data.projection.Projection;
     30import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    3131import org.openstreetmap.josm.data.projection.Projections;
    3232import org.openstreetmap.josm.gui.MainApplication;
     
    9696        AbstractWMSTileSource tileSource;
    9797        if (info.getImageryType() == ImageryType.WMS) {
    98             tileSource = new TemplatedWMSTileSource(info, chooseProjection(Main.getProjection()));
     98            tileSource = new TemplatedWMSTileSource(info, chooseProjection(ProjectionRegistry.getProjection()));
    9999        } else {
    100100            /*
     
    107107             *  * we always use current definitions returned by server
    108108             */
    109             WMSEndpointTileSource endpointTileSource = new WMSEndpointTileSource(info, Main.getProjection());
     109            WMSEndpointTileSource endpointTileSource = new WMSEndpointTileSource(info, ProjectionRegistry.getProjection());
    110110            this.serverProjections = endpointTileSource.getServerProjections();
    111             endpointTileSource.setTileProjection(chooseProjection(Main.getProjection()));
     111            endpointTileSource.setTileProjection(chooseProjection(ProjectionRegistry.getProjection()));
    112112            tileSource = endpointTileSource;
    113113        }
     
    182182        Logging.info(tr("Reprojecting layer {0} from {1} to {2}. For best image quality and performance,"
    183183                + " switch to one of the supported projections: {3}",
    184                 getName(), proj.toCode(), Main.getProjection().toCode(), Utils.join(", ", getNativeProjections())));
     184                getName(), proj.toCode(), ProjectionRegistry.getProjection().toCode(), Utils.join(", ", getNativeProjections())));
    185185        return proj;
    186186    }
  • trunk/src/org/openstreetmap/josm/gui/layer/WMTSLayer.java

    r13733 r14120  
    77import org.apache.commons.jcs.access.CacheAccess;
    88import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
    9 import org.openstreetmap.josm.Main;
    109import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
    1110import org.openstreetmap.josm.data.imagery.ImageryInfo;
     
    1514import org.openstreetmap.josm.data.imagery.WMTSTileSource.WMTSGetCapabilitiesException;
    1615import org.openstreetmap.josm.data.projection.Projection;
     16import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    1717import org.openstreetmap.josm.gui.MainApplication;
    1818import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings;
     
    8181        double displayScale = MainApplication.getMap().mapView.getScale();
    8282        if (coordinateConverter.requiresReprojection()) {
    83             displayScale *= Main.getProjection().getMetersPerUnit();
     83            displayScale *= ProjectionRegistry.getProjection().getMetersPerUnit();
    8484        }
    8585        Scale snap = scaleList.getSnapScale(displayScale, false);
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java

    r13130 r14120  
    2525import org.openstreetmap.josm.data.gpx.GpxTrackSegment;
    2626import org.openstreetmap.josm.data.gpx.WayPoint;
     27import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2728import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    2829import org.openstreetmap.josm.gui.MainApplication;
     
    189190                    continue;
    190191                }
    191                 WayPoint wNear = layer.data.nearestPointOnTrack(w.getEastNorth(Main.getProjection()), snapDistance);
     192                WayPoint wNear = layer.data.nearestPointOnTrack(w.getEastNorth(ProjectionRegistry.getProjection()), snapDistance);
    192193                if (wNear != null) {
    193194                    WayPoint wc = new WayPoint(w.getCoor());
  • trunk/src/org/openstreetmap/josm/gui/layer/imagery/ReprojectionTile.java

    r12846 r14120  
    88import org.openstreetmap.gui.jmapviewer.Tile;
    99import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
    10 import org.openstreetmap.josm.Main;
    1110import org.openstreetmap.josm.data.ProjectionBounds;
    1211import org.openstreetmap.josm.data.coor.EastNorth;
    1312import org.openstreetmap.josm.data.imagery.CoordinateConversion;
    1413import org.openstreetmap.josm.data.projection.Projection;
     14import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    1515import org.openstreetmap.josm.data.projection.Projections;
    1616import org.openstreetmap.josm.gui.MainApplication;
     
    122122        }
    123123
    124         Projection projCurrent = Main.getProjection();
     124        Projection projCurrent = ProjectionRegistry.getProjection();
    125125        Projection projServer = Projections.getProjectionByCode(source.getServerCRS());
    126126        EastNorth en00Server = tileToEastNorth(xtile, ytile, zoom);
  • trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileCoordinateConverter.java

    r13387 r14120  
    1414import org.openstreetmap.gui.jmapviewer.interfaces.IProjected;
    1515import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
    16 import org.openstreetmap.josm.Main;
    1716import org.openstreetmap.josm.data.coor.EastNorth;
    1817import org.openstreetmap.josm.data.coor.LatLon;
    1918import org.openstreetmap.josm.data.imagery.CoordinateConversion;
    2019import org.openstreetmap.josm.data.projection.Projecting;
     20import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2121import org.openstreetmap.josm.data.projection.ShiftedProjecting;
    2222import org.openstreetmap.josm.gui.MapView;
     
    202202     */
    203203    public boolean requiresReprojection() {
    204         return !Objects.equals(tileSource.getServerCRS(), Main.getProjection().toCode());
     204        return !Objects.equals(tileSource.getServerCRS(), ProjectionRegistry.getProjection().toCode());
    205205    }
    206206}
  • trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileSourceDisplaySettings.java

    r13244 r14120  
    77
    88import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
    9 import org.openstreetmap.josm.Main;
    109import org.openstreetmap.josm.data.coor.EastNorth;
    1110import org.openstreetmap.josm.data.imagery.OffsetBookmark;
    1211import org.openstreetmap.josm.data.preferences.BooleanProperty;
     12import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    1313import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer;
    1414import org.openstreetmap.josm.io.session.SessionAwareReadApply;
     
    206206            setDisplacement(EastNorth.ZERO);
    207207        } else {
    208             setDisplacement(offsetBookmark.getDisplacement(Main.getProjection()));
     208            setDisplacement(offsetBookmark.getDisplacement(ProjectionRegistry.getProjection()));
    209209        }
    210210    }
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/PlayHeadMarker.java

    r13281 r14120  
    2222import org.openstreetmap.josm.data.gpx.GpxTrackSegment;
    2323import org.openstreetmap.josm.data.gpx.WayPoint;
     24import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2425import org.openstreetmap.josm.gui.MainApplication;
    2526import org.openstreetmap.josm.gui.MapFrame;
     
    215216            for (Marker m : recent.parentLayer.data) {
    216217                if (m instanceof AudioMarker) {
    217                     double distanceSquared = m.getEastNorth(Main.getProjection()).distanceSq(en);
     218                    double distanceSquared = m.getEastNorth(ProjectionRegistry.getProjection()).distanceSq(en);
    218219                    if (distanceSquared < closestAudioMarkerDistanceSquared) {
    219220                        ca = (AudioMarker) m;
     
    348349            return;
    349350        setEastNorth(w2 == null ?
    350                 w1.getEastNorth(Main.getProjection()) :
    351                     w1.getEastNorth(Main.getProjection()).interpolate(w2.getEastNorth(Main.getProjection()),
     351                w1.getEastNorth(ProjectionRegistry.getProjection()) :
     352                    w1.getEastNorth(ProjectionRegistry.getProjection()).interpolate(w2.getEastNorth(ProjectionRegistry.getProjection()),
    352353                            (audioTime - w1.time)/(w2.time - w1.time)));
    353354        time = audioTime;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingCLI.java

    r14119 r14120  
    2121
    2222import org.openstreetmap.gui.jmapviewer.OsmMercator;
    23 import org.openstreetmap.josm.Main;
    2423import org.openstreetmap.josm.cli.CLIModule;
    2524import org.openstreetmap.josm.data.Bounds;
     
    3231import org.openstreetmap.josm.data.preferences.JosmUrls;
    3332import org.openstreetmap.josm.data.projection.Projection;
     33import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    3434import org.openstreetmap.josm.data.projection.Projections;
    3535import org.openstreetmap.josm.gui.mappaint.RenderingHelper.StyleData;
     
    427427        Config.getPref().putBoolean("mappaint.auto_reload_local_styles", false); // unnecessary to listen for external changes
    428428        String projCode = Optional.ofNullable(argProjection).orElse("epsg:3857");
    429         Main.setProjection(Projections.getProjectionByCode(projCode.toUpperCase(Locale.US)));
     429        ProjectionRegistry.setProjection(Projections.getProjectionByCode(projCode.toUpperCase(Locale.US)));
    430430
    431431        RightAndLefthandTraffic.initialize();
     
    449449    RenderingArea determineRenderingArea(DataSet ds) {
    450450
    451         Projection proj = Main.getProjection();
     451        Projection proj = ProjectionRegistry.getProjection();
    452452        Double scale = null; // scale in east-north units per pixel
    453453        if (argZoom != null) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingHelper.java

    r12966 r14120  
    1616import java.util.Optional;
    1717
    18 import org.openstreetmap.josm.Main;
    1918import org.openstreetmap.josm.data.Bounds;
    2019import org.openstreetmap.josm.data.ProjectionBounds;
     
    2221import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
    2322import org.openstreetmap.josm.data.projection.Projection;
     23import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2424import org.openstreetmap.josm.gui.NavigatableComponent;
    2525import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
     
    6565        this.scale = scale;
    6666        this.styles = styles;
    67         Projection proj = Main.getProjection();
     67        Projection proj = ProjectionRegistry.getProjection();
    6868        projBounds = new ProjectionBounds();
    6969        projBounds.extend(proj.latlon2eastNorth(bounds.getMin()));
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java

    r14119 r14120  
    6262import org.openstreetmap.josm.data.imagery.Shape;
    6363import org.openstreetmap.josm.data.preferences.NamedColorProperty;
     64import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    6465import org.openstreetmap.josm.gui.MainApplication;
    6566import org.openstreetmap.josm.gui.download.DownloadDialog;
     
    856857            JButton add = new JButton(tr("Add"));
    857858            buttonPanel.add(add, GBC.std().insets(0, 5, 0, 0));
    858             add.addActionListener(e -> model.addRow(new OffsetBookmark(Main.getProjection().toCode(), "", "", "", 0, 0)));
     859            add.addActionListener(e -> model.addRow(new OffsetBookmark(ProjectionRegistry.getProjection().toCode(), "", "", "", 0, 0)));
    859860
    860861            JButton delete = new JButton(tr("Delete"));
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java

    r14005 r14120  
    3232import org.openstreetmap.josm.data.projection.CustomProjection;
    3333import org.openstreetmap.josm.data.projection.Projection;
     34import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    3435import org.openstreetmap.josm.data.projection.Projections;
    3536import org.openstreetmap.josm.gui.ExtendedDialog;
     
    493494        pc.setPreferences(pref);
    494495        Projection proj = pc.getProjection();
    495         Main.setProjection(proj);
     496        ProjectionRegistry.setProjection(proj);
    496497    }
    497498
  • trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java

    r13901 r14120  
    2626import javax.xml.transform.stream.StreamResult;
    2727
    28 import org.openstreetmap.josm.Main;
    2928import org.openstreetmap.josm.data.coor.EastNorth;
    3029import org.openstreetmap.josm.data.coor.LatLon;
     30import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    3131import org.openstreetmap.josm.gui.MainApplication;
    3232import org.openstreetmap.josm.gui.MapView;
     
    264264        MapView mapView = MainApplication.getMap().mapView;
    265265        EastNorth center = mapView.getCenter();
    266         LatLon centerLL = Main.getProjection().eastNorth2latlon(center);
     266        LatLon centerLL = ProjectionRegistry.getProjection().eastNorth2latlon(center);
    267267        centerEl.setAttribute("lat", Double.toString(centerLL.lat()));
    268268        centerEl.setAttribute("lon", Double.toString(centerLL.lon()));
     
    293293            }
    294294        }
    295         String code = Main.getProjection().toCode();
     295        String code = ProjectionRegistry.getProjection().toCode();
    296296        if (code != null) {
    297297            Element codeEl = doc.createElement("code");
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r13807 r14120  
    3737import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache;
    3838import org.openstreetmap.josm.data.projection.Projection;
     39import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    3940import org.openstreetmap.josm.data.projection.Projections;
    4041
     
    164165                                }
    165166
    166                                 Node newNode = new Node(Main.getProjection().eastNorth2latlon(intersection));
     167                                Node newNode = new Node(ProjectionRegistry.getProjection().eastNorth2latlon(intersection));
    167168                                Node intNode = newNode;
    168169                                boolean insertInSeg1 = false;
     
    10531054        double area = 0;
    10541055        double perimeter = 0;
    1055         Projection useProjection = projection == null ? Main.getProjection() : projection;
     1056        Projection useProjection = projection == null ? ProjectionRegistry.getProjection() : projection;
    10561057
    10571058        if (!nodes.isEmpty()) {
Note: See TracChangeset for help on using the changeset viewer.