001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.preferences.projection;
003
004import static org.openstreetmap.josm.data.SystemOfMeasurement.ALL_SYSTEMS;
005import static org.openstreetmap.josm.tools.I18n.tr;
006
007import java.awt.Component;
008import java.awt.GridBagLayout;
009import java.awt.event.ActionListener;
010import java.util.ArrayList;
011import java.util.Collection;
012import java.util.Collections;
013import java.util.HashMap;
014import java.util.List;
015import java.util.Map;
016
017import javax.swing.BorderFactory;
018import javax.swing.JButton;
019import javax.swing.JLabel;
020import javax.swing.JOptionPane;
021import javax.swing.JPanel;
022import javax.swing.JSeparator;
023
024import org.openstreetmap.josm.actions.ExpertToggleAction;
025import org.openstreetmap.josm.data.Bounds;
026import org.openstreetmap.josm.data.SystemOfMeasurement;
027import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager;
028import org.openstreetmap.josm.data.coor.conversion.ICoordinateFormat;
029import org.openstreetmap.josm.data.preferences.ListProperty;
030import org.openstreetmap.josm.data.preferences.StringProperty;
031import org.openstreetmap.josm.data.projection.CustomProjection;
032import org.openstreetmap.josm.data.projection.Projection;
033import org.openstreetmap.josm.data.projection.ProjectionRegistry;
034import org.openstreetmap.josm.data.projection.Projections;
035import org.openstreetmap.josm.gui.ExtendedDialog;
036import org.openstreetmap.josm.gui.MainApplication;
037import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
038import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
039import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
040import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
041import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
042import org.openstreetmap.josm.gui.widgets.JosmComboBox;
043import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
044import org.openstreetmap.josm.spi.preferences.Config;
045import org.openstreetmap.josm.tools.GBC;
046import org.openstreetmap.josm.tools.JosmRuntimeException;
047import org.openstreetmap.josm.tools.Logging;
048
049/**
050 * Projection preferences.
051 *
052 * How to add new Projections:
053 *  - Find EPSG code for the projection.
054 *  - Look up the parameter string for Proj4, e.g. on http://spatialreference.org/
055 *      and add it to the file 'data/projection/epsg' in JOSM trunk
056 *  - Search for official references and verify the parameter values. These
057 *      documents are often available in the local language only.
058 *  - Use {@link #registerProjectionChoice}, to make the entry known to JOSM.
059 *
060 * In case there is no EPSG code:
061 *  - override {@link AbstractProjectionChoice#getProjection()} and provide
062 *    a manual implementation of the projection. Use {@link CustomProjection}
063 *    if possible.
064 */
065public class ProjectionPreference implements SubPreferenceSetting {
066
067    /**
068     * Factory used to create a new {@code ProjectionPreference}.
069     */
070    public static class Factory implements PreferenceSettingFactory {
071        @Override
072        public PreferenceSetting createPreferenceSetting() {
073            return new ProjectionPreference();
074        }
075    }
076
077    private static final List<ProjectionChoice> projectionChoices = new ArrayList<>();
078    private static final Map<String, ProjectionChoice> projectionChoicesById = new HashMap<>();
079
080    /**
081     * WGS84: Directly use latitude / longitude values as x/y.
082     */
083    public static final ProjectionChoice wgs84 = registerProjectionChoice(tr("WGS84 Geographic"), "core:wgs84", 4326);
084
085    /**
086     * Mercator Projection.
087     *
088     * The center of the mercator projection is always the 0 grad coordinate.
089     *
090     * See also USGS Bulletin 1532 (http://pubs.usgs.gov/bul/1532/report.pdf)
091     * initially EPSG used 3785 but that has been superseded by 3857, see https://www.epsg-registry.org/
092     */
093    public static final ProjectionChoice mercator = registerProjectionChoice(tr("Mercator"), "core:mercator", 3857);
094
095    /**
096     * Lambert conic conform 4 zones using the French geodetic system NTF.
097     *
098     * This newer version uses the grid translation NTF&lt;-&gt;RGF93 provided by IGN for a submillimetric accuracy.
099     * (RGF93 is the French geodetic system similar to WGS84 but not mathematically equal)
100     *
101     * Source: http://geodesie.ign.fr/contenu/fichiers/Changement_systeme_geodesique.pdf
102     */
103    public static final ProjectionChoice lambert = new LambertProjectionChoice();
104
105    /**
106     * French departements in the Caribbean Sea and Indian Ocean.
107     *
108     * Using the UTM transvers Mercator projection and specific geodesic settings.
109     */
110    public static final ProjectionChoice utm_france_dom = new UTMFranceDOMProjectionChoice();
111
112    /**
113     * Lambert Conic Conform 9 Zones projection.
114     *
115     * As specified by the IGN in this document
116     * http://geodesie.ign.fr/contenu/fichiers/documentation/rgf93/cc9zones.pdf
117     */
118    public static final ProjectionChoice lambert_cc9 = new LambertCC9ZonesProjectionChoice();
119
120    static {
121
122        /************************
123         * Global projections.
124         */
125
126        /**
127         * UTM.
128         */
129        registerProjectionChoice(new UTMProjectionChoice());
130
131        /************************
132         * Regional - alphabetical order by country code.
133         */
134
135        /**
136         * Belgian Lambert 72 projection.
137         *
138         * As specified by the Belgian IGN in this document:
139         * http://www.ngi.be/Common/Lambert2008/Transformation_Geographic_Lambert_FR.pdf
140         *
141         * @author Don-vip
142         */
143        registerProjectionChoice(tr("Belgian Lambert 1972"), "core:belgianLambert1972", 31370);     // BE
144
145        /**
146         * Belgian Lambert 2008 projection.
147         *
148         * As specified by the Belgian IGN in this document:
149         * http://www.ngi.be/Common/Lambert2008/Transformation_Geographic_Lambert_FR.pdf
150         *
151         * @author Don-vip
152         */
153        registerProjectionChoice(tr("Belgian Lambert 2008"), "core:belgianLambert2008", 3812);      // BE
154
155        /**
156         * SwissGrid CH1903 / L03, see https://en.wikipedia.org/wiki/Swiss_coordinate_system.
157         *
158         * Actually, what we have here, is CH1903+ (EPSG:2056), but without
159         * the additional false easting of 2000km and false northing 1000 km.
160         *
161         * To get to CH1903, a shift file is required. So currently, there are errors
162         * up to 1.6m (depending on the location).
163         */
164        registerProjectionChoice(new SwissGridProjectionChoice());                                  // CH
165
166        registerProjectionChoice(new GaussKruegerProjectionChoice());                               // DE
167
168        /**
169         * Estonian Coordinate System of 1997.
170         *
171         * Thanks to Johan Montagnat and its geoconv java converter application
172         * (https://www.i3s.unice.fr/~johan/gps/ , published under GPL license)
173         * from which some code and constants have been reused here.
174         */
175        registerProjectionChoice(tr("Lambert Zone (Estonia)"), "core:lambertest", 3301);            // EE
176
177        /**
178         * Lambert conic conform 4 zones using the French geodetic system NTF.
179         *
180         * This newer version uses the grid translation NTF<->RGF93 provided by IGN for a submillimetric accuracy.
181         * (RGF93 is the French geodetic system similar to WGS84 but not mathematically equal)
182         *
183         * Source: http://geodesie.ign.fr/contenu/fichiers/Changement_systeme_geodesique.pdf
184         * @author Pieren
185         */
186        registerProjectionChoice(lambert);                                                          // FR
187
188        /**
189         * Lambert 93 projection.
190         *
191         * As specified by the IGN in this document
192         * http://geodesie.ign.fr/contenu/fichiers/documentation/rgf93/Lambert-93.pdf
193         * @author Don-vip
194         */
195        registerProjectionChoice(tr("Lambert 93 (France)"), "core:lambert93", 2154);                // FR
196
197        /**
198         * Lambert Conic Conform 9 Zones projection.
199         *
200         * As specified by the IGN in this document
201         * http://geodesie.ign.fr/contenu/fichiers/documentation/rgf93/cc9zones.pdf
202         * @author Pieren
203         */
204        registerProjectionChoice(lambert_cc9);                                                      // FR
205
206        /**
207         * French departements in the Caribbean Sea and Indian Ocean.
208         *
209         * Using the UTM transvers Mercator projection and specific geodesic settings.
210         */
211        registerProjectionChoice(utm_france_dom);                                                   // FR
212
213        /**
214         * LKS-92/ Latvia TM projection.
215         *
216         * Based on data from spatialreference.org.
217         * http://spatialreference.org/ref/epsg/3059/
218         *
219         * @author Viesturs Zarins
220         */
221        registerProjectionChoice(tr("LKS-92 (Latvia TM)"), "core:tmerclv", 3059);                   // LV
222
223        /**
224         * Netherlands RD projection
225         *
226         * @author vholten
227         */
228        registerProjectionChoice(tr("Rijksdriehoekscoördinaten (Netherlands)"), "core:dutchrd", 28992); // NL
229
230        /**
231         * PUWG 1992 and 2000 are the official cordinate systems in Poland.
232         *
233         * They use the same math as UTM only with different constants.
234         *
235         * @author steelman
236         */
237        registerProjectionChoice(new PuwgProjectionChoice());                                       // PL
238
239        /**
240         * SWEREF99 13 30 projection. Based on data from spatialreference.org.
241         * http://spatialreference.org/ref/epsg/3008/
242         *
243         * @author Hanno Hecker
244         */
245        registerProjectionChoice(tr("SWEREF99 13 30 / EPSG:3008 (Sweden)"), "core:sweref99", 3008); // SE
246
247        /************************
248         * Projection by Code.
249         */
250        registerProjectionChoice(new CodeProjectionChoice());
251
252        /************************
253         * Custom projection.
254         */
255        registerProjectionChoice(new CustomProjectionChoice());
256    }
257
258    public static void registerProjectionChoice(ProjectionChoice c) {
259        projectionChoices.add(c);
260        projectionChoicesById.put(c.getId(), c);
261        for (String code : c.allCodes()) {
262            Projections.registerProjectionSupplier(code, () -> {
263                Collection<String> pref = c.getPreferencesFromCode(code);
264                c.setPreferences(pref);
265                try {
266                    return c.getProjection();
267                } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) {
268                    Logging.log(Logging.LEVEL_WARN, "Unable to get projection "+code+" with "+c+':', e);
269                    return null;
270                }
271            });
272        }
273    }
274
275    /**
276     * Registers a new projection choice.
277     * @param name short name of the projection choice as shown in the GUI
278     * @param id short name of the projection choice as shown in the GUI
279     * @param epsg the unique numeric EPSG identifier for the projection
280     * @return the registered {@link ProjectionChoice}
281     */
282    private static ProjectionChoice registerProjectionChoice(String name, String id, Integer epsg) {
283        ProjectionChoice pc = new SingleProjectionChoice(name, id, "EPSG:"+epsg);
284        registerProjectionChoice(pc);
285        return pc;
286    }
287
288    public static List<ProjectionChoice> getProjectionChoices() {
289        return Collections.unmodifiableList(projectionChoices);
290    }
291
292    private static String projectionChoice;
293
294    private static final StringProperty PROP_PROJECTION_DEFAULT = new StringProperty("projection.default", mercator.getId());
295    private static final StringProperty PROP_COORDINATES = new StringProperty("coordinates", null);
296    private static final ListProperty PROP_SUB_PROJECTION_DEFAULT = new ListProperty("projection.default.sub", null);
297    private static final String[] unitsValues = ALL_SYSTEMS.keySet().toArray(new String[ALL_SYSTEMS.size()]);
298    private static final String[] unitsValuesTr = new String[unitsValues.length];
299    static {
300        for (int i = 0; i < unitsValues.length; ++i) {
301            unitsValuesTr[i] = tr(unitsValues[i]);
302        }
303    }
304
305    /**
306     * Combobox with all projections available
307     */
308    private final JosmComboBox<ProjectionChoice> projectionCombo;
309
310    /**
311     * Combobox with all coordinate display possibilities
312     */
313    private final JosmComboBox<ICoordinateFormat> coordinatesCombo;
314
315    private final JosmComboBox<String> unitsCombo = new JosmComboBox<>(unitsValuesTr);
316
317    /**
318     * This variable holds the JPanel with the projection's preferences. If the
319     * selected projection does not implement this, it will be set to an empty
320     * Panel.
321     */
322    private JPanel projSubPrefPanel;
323    private final JPanel projSubPrefPanelWrapper = new JPanel(new GridBagLayout());
324
325    private final JLabel projectionCodeLabel = new JLabel(tr("Projection code"));
326    private final Component projectionCodeGlue = GBC.glue(5, 0);
327    private final JLabel projectionCode = new JLabel();
328    private final JLabel projectionNameLabel = new JLabel(tr("Projection name"));
329    private final Component projectionNameGlue = GBC.glue(5, 0);
330    private final JLabel projectionName = new JLabel();
331    private final JLabel bounds = new JLabel();
332
333    /**
334     * This is the panel holding all projection preferences
335     */
336    private final VerticallyScrollablePanel projPanel = new VerticallyScrollablePanel(new GridBagLayout());
337
338    /**
339     * The GridBagConstraints for the Panel containing the ProjectionSubPrefs.
340     * This is required twice in the code, creating it here keeps both occurrences
341     * in sync
342     */
343    private static final GBC projSubPrefPanelGBC = GBC.std().fill(GBC.BOTH).weight(1.0, 1.0);
344
345    public ProjectionPreference() {
346        this.projectionCombo = new JosmComboBox<>(
347            projectionChoices.toArray(new ProjectionChoice[0]));
348        this.coordinatesCombo = new JosmComboBox<>(
349                CoordinateFormatManager.getCoordinateFormats().toArray(new ICoordinateFormat[0]));
350    }
351
352    @Override
353    public void addGui(PreferenceTabbedPane gui) {
354        final ProjectionChoice pc = setupProjectionCombo();
355
356        for (int i = 0; i < coordinatesCombo.getItemCount(); ++i) {
357            if (coordinatesCombo.getItemAt(i).getId().equals(PROP_COORDINATES.get())) {
358                coordinatesCombo.setSelectedIndex(i);
359                break;
360            }
361        }
362
363        for (int i = 0; i < unitsValues.length; ++i) {
364            if (unitsValues[i].equals(SystemOfMeasurement.PROP_SYSTEM_OF_MEASUREMENT.get())) {
365                unitsCombo.setSelectedIndex(i);
366                break;
367            }
368        }
369
370        projPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
371        projPanel.add(new JLabel(tr("Projection method")), GBC.std().insets(5, 5, 0, 5));
372        projPanel.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
373        projPanel.add(projectionCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0, 5, 5, 5));
374        projPanel.add(projectionCodeLabel, GBC.std().insets(25, 5, 0, 5));
375        projPanel.add(projectionCodeGlue, GBC.std().fill(GBC.HORIZONTAL));
376        projPanel.add(projectionCode, GBC.eop().fill(GBC.HORIZONTAL).insets(0, 5, 5, 5));
377        projPanel.add(projectionNameLabel, GBC.std().insets(25, 5, 0, 5));
378        projPanel.add(projectionNameGlue, GBC.std().fill(GBC.HORIZONTAL));
379        projPanel.add(projectionName, GBC.eop().fill(GBC.HORIZONTAL).insets(0, 5, 5, 5));
380        projPanel.add(new JLabel(tr("Bounds")), GBC.std().insets(25, 5, 0, 5));
381        projPanel.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
382        projPanel.add(bounds, GBC.eop().fill(GBC.HORIZONTAL).insets(0, 5, 5, 5));
383        projPanel.add(projSubPrefPanelWrapper, GBC.eol().fill(GBC.HORIZONTAL).insets(20, 5, 5, 5));
384
385        projectionCodeLabel.setLabelFor(projectionCode);
386        projectionNameLabel.setLabelFor(projectionName);
387
388        JButton btnSetAsDefault = new JButton(tr("Set as default"));
389        projPanel.add(btnSetAsDefault, GBC.eol().insets(5, 10, 5, 5));
390        btnSetAsDefault.addActionListener(e -> {
391            ProjectionChoice pc2 = (ProjectionChoice) projectionCombo.getSelectedItem();
392            String id = pc2.getId();
393            Collection<String> prefs = pc2.getPreferences(projSubPrefPanel);
394            setProjection(id, prefs, true);
395            pc2.setPreferences(prefs);
396            Projection proj = pc2.getProjection();
397            new ExtendedDialog(gui, tr("Default projection"), tr("OK"))
398                    .setButtonIcons("ok")
399                    .setIcon(JOptionPane.INFORMATION_MESSAGE)
400                    .setContent(tr("Default projection has been set to ''{0}''", proj.toCode()))
401                    .showDialog();
402        });
403        ExpertToggleAction.addVisibilitySwitcher(btnSetAsDefault);
404
405        projPanel.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(0, 5, 0, 10));
406        projPanel.add(new JLabel(tr("Display coordinates as")), GBC.std().insets(5, 5, 0, 5));
407        projPanel.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
408        projPanel.add(coordinatesCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0, 5, 5, 5));
409        projPanel.add(new JLabel(tr("System of measurement")), GBC.std().insets(5, 5, 0, 5));
410        projPanel.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
411        projPanel.add(unitsCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0, 5, 5, 5));
412        projPanel.add(GBC.glue(1, 1), GBC.std().fill(GBC.HORIZONTAL).weight(1.0, 1.0));
413
414        gui.getMapPreference().addSubTab(this, tr("Map Projection"), projPanel.getVerticalScrollPane());
415
416        selectedProjectionChanged(pc);
417    }
418
419    private void updateMeta(ProjectionChoice pc) {
420        pc.setPreferences(pc.getPreferences(projSubPrefPanel));
421        Projection proj = pc.getProjection();
422        projectionCode.setText(proj.toCode());
423        projectionName.setText(proj.toString());
424        Bounds b = proj.getWorldBoundsLatLon();
425        ICoordinateFormat cf = CoordinateFormatManager.getDefaultFormat();
426        bounds.setText(cf.lonToString(b.getMin()) + ", " + cf.latToString(b.getMin()) + " : " +
427                cf.lonToString(b.getMax()) + ", " + cf.latToString(b.getMax()));
428        boolean showCode = true;
429        boolean showName = false;
430        if (pc instanceof SubPrefsOptions) {
431            showCode = ((SubPrefsOptions) pc).showProjectionCode();
432            showName = ((SubPrefsOptions) pc).showProjectionName();
433        }
434        projectionCodeLabel.setVisible(showCode);
435        projectionCodeGlue.setVisible(showCode);
436        projectionCode.setVisible(showCode);
437        projectionNameLabel.setVisible(showName);
438        projectionNameGlue.setVisible(showName);
439        projectionName.setVisible(showName);
440    }
441
442    @Override
443    public boolean ok() {
444        ProjectionChoice pc = (ProjectionChoice) projectionCombo.getSelectedItem();
445
446        String id = pc.getId();
447        Collection<String> prefs = pc.getPreferences(projSubPrefPanel);
448
449        setProjection(id, prefs, false);
450
451        if (PROP_COORDINATES.put(((ICoordinateFormat) coordinatesCombo.getSelectedItem()).getId())) {
452            CoordinateFormatManager.setCoordinateFormat((ICoordinateFormat) coordinatesCombo.getSelectedItem());
453        }
454
455        int i = unitsCombo.getSelectedIndex();
456        SystemOfMeasurement.setSystemOfMeasurement(unitsValues[i]);
457
458        return false;
459    }
460
461    public static void setProjection() {
462        setProjection(PROP_PROJECTION_DEFAULT.get(), PROP_SUB_PROJECTION_DEFAULT.get(), false);
463    }
464
465    /**
466     * Set projection.
467     * @param id id of the selected projection choice
468     * @param pref the configuration for the selected projection choice
469     * @param makeDefault true, if it is to be set as permanent default
470     * false, if it is to be set for the current session
471     * @since 12306
472     */
473    public static void setProjection(String id, Collection<String> pref, boolean makeDefault) {
474        ProjectionChoice pc = projectionChoicesById.get(id);
475
476        if (pc == null) {
477            JOptionPane.showMessageDialog(
478                    MainApplication.getMainFrame(),
479                    tr("The projection {0} could not be activated. Using Mercator", id),
480                    tr("Error"),
481                    JOptionPane.ERROR_MESSAGE
482            );
483            pref = null;
484            pc = mercator;
485        }
486        id = pc.getId();
487        Config.getPref().putList("projection.sub."+id, pref == null ? null : new ArrayList<>(pref));
488        if (makeDefault) {
489            PROP_PROJECTION_DEFAULT.put(id);
490            PROP_SUB_PROJECTION_DEFAULT.put(pref == null ? null : new ArrayList<>(pref));
491        } else {
492            projectionChoice = id;
493        }
494        pc.setPreferences(pref);
495        Projection proj = pc.getProjection();
496        ProjectionRegistry.setProjection(proj);
497    }
498
499    /**
500     * Handles all the work related to update the projection-specific
501     * preferences
502     * @param pc the choice class representing user selection
503     */
504    private void selectedProjectionChanged(final ProjectionChoice pc) {
505        // Don't try to update if we're still starting up
506        int size = projPanel.getComponentCount();
507        if (size < 1)
508            return;
509
510        final ActionListener listener = e -> updateMeta(pc);
511
512        // Replace old panel with new one
513        projSubPrefPanelWrapper.removeAll();
514        projSubPrefPanel = pc.getPreferencePanel(listener);
515        projSubPrefPanelWrapper.add(projSubPrefPanel, projSubPrefPanelGBC);
516        projPanel.revalidate();
517        projSubPrefPanel.repaint();
518        updateMeta(pc);
519    }
520
521    /**
522     * Sets up projection combobox with default values and action listener
523     * @return the choice class for user selection
524     */
525    private ProjectionChoice setupProjectionCombo() {
526        String pcId = getCurrentProjectionChoiceId();
527        ProjectionChoice pc = null;
528        for (int i = 0; i < projectionCombo.getItemCount(); ++i) {
529            ProjectionChoice pc1 = projectionCombo.getItemAt(i);
530            pc1.setPreferences(getSubprojectionPreference(pc1.getId()));
531            if (pc1.getId().equals(pcId)) {
532                projectionCombo.setSelectedIndex(i);
533                selectedProjectionChanged(pc1);
534                pc = pc1;
535            }
536        }
537        // If the ProjectionChoice from the preferences is not available, it
538        // should have been set to Mercator at JOSM start.
539        if (pc == null)
540            throw new JosmRuntimeException("Couldn't find the current projection in the list of available projections!");
541
542        projectionCombo.addActionListener(e -> {
543            ProjectionChoice pc1 = (ProjectionChoice) projectionCombo.getSelectedItem();
544            selectedProjectionChanged(pc1);
545        });
546        return pc;
547    }
548
549    /**
550     * Get the id of the projection choice that is currently set.
551     * @return id of the projection choice that is currently set
552     */
553    public static String getCurrentProjectionChoiceId() {
554        return projectionChoice != null ? projectionChoice : PROP_PROJECTION_DEFAULT.get();
555    }
556
557    /**
558     * Get the preferences that have been selected the last time for the given
559     * projection choice.
560     * @param pcId id of the projection choice
561     * @return projection choice parameters that have been selected by the user
562     * the last time; null if user has never selected the given projection choice
563     */
564    public static Collection<String> getSubprojectionPreference(String pcId) {
565        return Config.getPref().getList("projection.sub."+pcId, null);
566    }
567
568    @Override
569    public boolean isExpert() {
570        return false;
571    }
572
573    @Override
574    public TabPreferenceSetting getTabPreferenceSetting(final PreferenceTabbedPane gui) {
575        return gui.getMapPreference();
576    }
577
578    /**
579     * Selects the given projection.
580     * @param projection The projection to select.
581     * @since 5604
582     */
583    public void selectProjection(ProjectionChoice projection) {
584        if (projectionCombo != null && projection != null) {
585            projectionCombo.setSelectedItem(projection);
586        }
587    }
588}