source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java@ 12841

Last change on this file since 12841 was 12841, checked in by bastiK, 7 years ago

see #15229 - fix deprecations caused by [12840]

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