Ticket #14877: projection-default.patch
File projection-default.patch, 5.9 KB (added by , 7 years ago) |
---|
-
src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java
15 15 import java.util.Map; 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; 20 21 import javax.swing.JPanel; … … 66 67 } 67 68 } 68 69 69 private static List<ProjectionChoice> projectionChoices = new ArrayList<>();70 private static Map<String, ProjectionChoice> projectionChoicesById = new HashMap<>();70 private static final List<ProjectionChoice> projectionChoices = new ArrayList<>(); 71 private static final Map<String, ProjectionChoice> projectionChoicesById = new HashMap<>(); 71 72 72 73 /** 73 74 * WGS84: Directly use latitude / longitude values as x/y. … … 268 269 return Collections.unmodifiableList(projectionChoices); 269 270 } 270 271 271 private static final StringProperty PROP_PROJECTION = new StringProperty("projection", mercator.getId()); 272 private static String projectionChoice; 273 private static final Map<String, Collection<String>> projectionChoicesSub = new HashMap<>(); 274 275 private static final StringProperty PROP_PROJECTION_DEFAULT = new StringProperty("projection.default", mercator.getId()); 272 276 private static final StringProperty PROP_COORDINATES = new StringProperty("coordinates", null); 273 private static final CollectionProperty PROP_SUB_PROJECTION = new CollectionProperty("projection.sub", null);277 private static final CollectionProperty PROP_SUB_PROJECTION_DEFAULT = new CollectionProperty("projection.default.sub", null); 274 278 public static final StringProperty PROP_SYSTEM_OF_MEASUREMENT = new StringProperty("system_of_measurement", "Metric"); 275 279 private static final String[] unitsValues = ALL_SYSTEMS.keySet().toArray(new String[ALL_SYSTEMS.size()]); 276 280 private static final String[] unitsValuesTr = new String[unitsValues.length]; … … 323 327 324 328 @Override 325 329 public void addGui(PreferenceTabbedPane gui) { 326 ProjectionChoice pc = setupProjectionCombo();330 final ProjectionChoice pc = setupProjectionCombo(); 327 331 328 332 for (int i = 0; i < coordinatesCombo.getItemCount(); ++i) { 329 333 if (coordinatesCombo.getItemAt(i).name().equals(PROP_COORDINATES.get())) { … … 357 361 projectionCodeLabel.setLabelFor(projectionCode); 358 362 projectionNameLabel.setLabelFor(projectionName); 359 363 364 JButton btnSetAsDefault = new JButton(tr("Set as default")); 365 projPanel.add(btnSetAsDefault, GBC.eol().insets(5, 10, 5, 5)); 366 btnSetAsDefault.addActionListener(e -> { 367 String id = pc.getId(); 368 Collection<String> prefs = pc.getPreferences(projSubPrefPanel); 369 setProjection(id, prefs, true); 370 }); 371 360 372 projPanel.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(0, 5, 0, 10)); 361 373 projPanel.add(new JLabel(tr("Display coordinates as")), GBC.std().insets(5, 5, 0, 5)); 362 374 projPanel.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); … … 401 413 String id = pc.getId(); 402 414 Collection<String> prefs = pc.getPreferences(projSubPrefPanel); 403 415 404 setProjection(id, prefs );416 setProjection(id, prefs, false); 405 417 406 418 if (PROP_COORDINATES.put(((CoordinateFormat) coordinatesCombo.getSelectedItem()).name())) { 407 419 CoordinateFormat.setCoordinateFormat((CoordinateFormat) coordinatesCombo.getSelectedItem()); … … 414 426 } 415 427 416 428 public static void setProjection() { 417 setProjection(PROP_PROJECTION .get(), PROP_SUB_PROJECTION.get());429 setProjection(PROP_PROJECTION_DEFAULT.get(), PROP_SUB_PROJECTION_DEFAULT.get(), false); 418 430 } 419 431 420 public static void setProjection(String id, Collection<String> pref ) {432 public static void setProjection(String id, Collection<String> pref, boolean makeDefault) { 421 433 ProjectionChoice pc = projectionChoicesById.get(id); 422 434 423 435 if (pc == null) { … … 431 443 pc = mercator; 432 444 } 433 445 id = pc.getId(); 434 PROP_PROJECTION.put(id); 435 PROP_SUB_PROJECTION.put(pref); 436 Main.pref.putCollection("projection.sub."+id, pref); 446 if (makeDefault) { 447 PROP_PROJECTION_DEFAULT.put(id); 448 PROP_SUB_PROJECTION_DEFAULT.put(pref); 449 Main.pref.putCollection("projection.default.sub."+id, pref); 450 } else { 451 projectionChoice = id; 452 projectionChoicesSub.put(id, pref); 453 } 437 454 pc.setPreferences(pref); 438 455 Projection proj = pc.getProjection(); 439 456 Main.setProjection(proj); … … 466 483 * @return the choice class for user selection 467 484 */ 468 485 private ProjectionChoice setupProjectionCombo() { 486 String pcId = projectionChoice != null ? projectionChoice : PROP_PROJECTION_DEFAULT.get(); 469 487 ProjectionChoice pc = null; 470 488 for (int i = 0; i < projectionCombo.getItemCount(); ++i) { 471 489 ProjectionChoice pc1 = projectionCombo.getItemAt(i); 472 490 pc1.setPreferences(getSubprojectionPreference(pc1)); 473 if (pc1.getId().equals( PROP_PROJECTION.get())) {491 if (pc1.getId().equals(pcId)) { 474 492 projectionCombo.setSelectedIndex(i); 475 493 selectedProjectionChanged(pc1); 476 494 pc = pc1; … … 489 507 } 490 508 491 509 private static Collection<String> getSubprojectionPreference(ProjectionChoice pc) { 492 return Main.pref.getCollection("projection.sub."+pc.getId(), null); 510 Collection<String> sessionValue = projectionChoicesSub.get(pc.getId()); 511 if (sessionValue != null) 512 return sessionValue; 513 return Main.pref.getCollection("projection.default.sub."+pc.getId(), null); 493 514 } 494 515 495 516 @Override