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