Changeset 12306 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-06-03T00:59:16+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r12130 r12306 109 109 110 110 private static final String[] OBSOLETE_PREF_KEYS = { 111 "hdop.factor", /* remove entry after April 2017 */ 112 "imagery.layers.addedIds" /* remove entry after June 2017 */ 111 "imagery.layers.addedIds", /* remove entry after June 2017 */ 112 "projection", /* remove entry after Nov. 2017 */ 113 "projection.sub", /* remove entry after Nov. 2017 */ 113 114 }; 114 115 -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java
r11374 r12306 16 16 17 17 import javax.swing.BorderFactory; 18 import javax.swing.JButton; 18 19 import javax.swing.JLabel; 19 20 import javax.swing.JOptionPane; … … 22 23 23 24 import org.openstreetmap.josm.Main; 25 import org.openstreetmap.josm.actions.ExpertToggleAction; 24 26 import org.openstreetmap.josm.data.Bounds; 25 27 import org.openstreetmap.josm.data.SystemOfMeasurement; … … 29 31 import org.openstreetmap.josm.data.projection.CustomProjection; 30 32 import org.openstreetmap.josm.data.projection.Projection; 33 import org.openstreetmap.josm.gui.ExtendedDialog; 31 34 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 32 35 import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; … … 67 70 } 68 71 69 private static List<ProjectionChoice> projectionChoices = new ArrayList<>();70 private static Map<String, ProjectionChoice> projectionChoicesById = new HashMap<>();72 private static final List<ProjectionChoice> projectionChoices = new ArrayList<>(); 73 private static final Map<String, ProjectionChoice> projectionChoicesById = new HashMap<>(); 71 74 72 75 /** … … 269 272 } 270 273 271 private static final StringProperty PROP_PROJECTION = new StringProperty("projection", mercator.getId()); 274 private static String projectionChoice; 275 private static final Map<String, Collection<String>> projectionChoicesSub = new HashMap<>(); 276 277 private static final StringProperty PROP_PROJECTION_DEFAULT = new StringProperty("projection.default", mercator.getId()); 272 278 private static final StringProperty PROP_COORDINATES = new StringProperty("coordinates", null); 273 private static final CollectionProperty PROP_SUB_PROJECTION = new CollectionProperty("projection.sub", null);279 private static final CollectionProperty PROP_SUB_PROJECTION_DEFAULT = new CollectionProperty("projection.default.sub", null); 274 280 public static final StringProperty PROP_SYSTEM_OF_MEASUREMENT = new StringProperty("system_of_measurement", "Metric"); 275 281 private static final String[] unitsValues = ALL_SYSTEMS.keySet().toArray(new String[ALL_SYSTEMS.size()]); … … 324 330 @Override 325 331 public void addGui(PreferenceTabbedPane gui) { 326 ProjectionChoice pc = setupProjectionCombo();332 final ProjectionChoice pc = setupProjectionCombo(); 327 333 328 334 for (int i = 0; i < coordinatesCombo.getItemCount(); ++i) { … … 358 364 projectionNameLabel.setLabelFor(projectionName); 359 365 366 JButton btnSetAsDefault = new JButton(tr("Set as default")); 367 projPanel.add(btnSetAsDefault, GBC.eol().insets(5, 10, 5, 5)); 368 btnSetAsDefault.addActionListener(e -> { 369 ProjectionChoice pc2 = (ProjectionChoice) projectionCombo.getSelectedItem(); 370 String id = pc2.getId(); 371 Collection<String> prefs = pc2.getPreferences(projSubPrefPanel); 372 setProjection(id, prefs, true); 373 pc2.setPreferences(prefs); 374 Projection proj = pc2.getProjection(); 375 new ExtendedDialog(gui, tr("Default projection"), tr("OK")) 376 .setButtonIcons("ok") 377 .setIcon(JOptionPane.INFORMATION_MESSAGE) 378 .setContent(tr("Default projection has been set to ''{0}''", proj.toCode())) 379 .showDialog(); 380 }); 381 ExpertToggleAction.addVisibilitySwitcher(btnSetAsDefault); 382 360 383 projPanel.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(0, 5, 0, 10)); 361 384 projPanel.add(new JLabel(tr("Display coordinates as")), GBC.std().insets(5, 5, 0, 5)); … … 402 425 Collection<String> prefs = pc.getPreferences(projSubPrefPanel); 403 426 404 setProjection(id, prefs );427 setProjection(id, prefs, false); 405 428 406 429 if (PROP_COORDINATES.put(((CoordinateFormat) coordinatesCombo.getSelectedItem()).name())) { … … 415 438 416 439 public static void setProjection() { 417 setProjection(PROP_PROJECTION.get(), PROP_SUB_PROJECTION.get()); 418 } 419 420 public static void setProjection(String id, Collection<String> pref) { 440 setProjection(PROP_PROJECTION_DEFAULT.get(), PROP_SUB_PROJECTION_DEFAULT.get(), false); 441 } 442 443 /** 444 * Set projection. 445 * @param id id of the selected projection choice 446 * @param pref the configuration for the selected projection choice 447 * @param makeDefault true, if it is to be set as permanent default 448 * false, if it is to be set for the current session 449 * @since 12306 450 */ 451 public static void setProjection(String id, Collection<String> pref, boolean makeDefault) { 421 452 ProjectionChoice pc = projectionChoicesById.get(id); 422 453 … … 432 463 } 433 464 id = pc.getId(); 434 PROP_PROJECTION.put(id); 435 PROP_SUB_PROJECTION.put(pref); 436 Main.pref.putCollection("projection.sub."+id, pref); 465 if (makeDefault) { 466 PROP_PROJECTION_DEFAULT.put(id); 467 PROP_SUB_PROJECTION_DEFAULT.put(pref); 468 Main.pref.putCollection("projection.default.sub."+id, pref); 469 } else { 470 projectionChoice = id; 471 projectionChoicesSub.put(id, pref); 472 } 437 473 pc.setPreferences(pref); 438 474 Projection proj = pc.getProjection(); … … 467 503 */ 468 504 private ProjectionChoice setupProjectionCombo() { 505 String pcId = projectionChoice != null ? projectionChoice : PROP_PROJECTION_DEFAULT.get(); 469 506 ProjectionChoice pc = null; 470 507 for (int i = 0; i < projectionCombo.getItemCount(); ++i) { 471 508 ProjectionChoice pc1 = projectionCombo.getItemAt(i); 472 509 pc1.setPreferences(getSubprojectionPreference(pc1)); 473 if (pc1.getId().equals( PROP_PROJECTION.get())) {510 if (pc1.getId().equals(pcId)) { 474 511 projectionCombo.setSelectedIndex(i); 475 512 selectedProjectionChanged(pc1); … … 490 527 491 528 private static Collection<String> getSubprojectionPreference(ProjectionChoice pc) { 492 return Main.pref.getCollection("projection.sub."+pc.getId(), null); 529 Collection<String> sessionValue = projectionChoicesSub.get(pc.getId()); 530 if (sessionValue != null) 531 return sessionValue; 532 return Main.pref.getCollection("projection.default.sub."+pc.getId(), null); 493 533 } 494 534
Note:
See TracChangeset
for help on using the changeset viewer.