Changeset 12306 in josm


Ignore:
Timestamp:
2017-06-03T00:59:16+02:00 (6 months ago)
Author:
bastiK
Message:

fixed #14877 - make projection setting transient

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r12130 r12306  
    109109
    110110    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 */
    113114    };
    114115
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java

    r11374 r12306  
    1616
    1717import javax.swing.BorderFactory;
     18import javax.swing.JButton;
    1819import javax.swing.JLabel;
    1920import javax.swing.JOptionPane;
     
    2223
    2324import org.openstreetmap.josm.Main;
     25import org.openstreetmap.josm.actions.ExpertToggleAction;
    2426import org.openstreetmap.josm.data.Bounds;
    2527import org.openstreetmap.josm.data.SystemOfMeasurement;
     
    2931import org.openstreetmap.josm.data.projection.CustomProjection;
    3032import org.openstreetmap.josm.data.projection.Projection;
     33import org.openstreetmap.josm.gui.ExtendedDialog;
    3134import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    3235import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
     
    6770    }
    6871
    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<>();
    7174
    7275    /**
     
    269272    }
    270273
    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());
    272278    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);
    274280    public static final StringProperty PROP_SYSTEM_OF_MEASUREMENT = new StringProperty("system_of_measurement", "Metric");
    275281    private static final String[] unitsValues = ALL_SYSTEMS.keySet().toArray(new String[ALL_SYSTEMS.size()]);
     
    324330    @Override
    325331    public void addGui(PreferenceTabbedPane gui) {
    326         ProjectionChoice pc = setupProjectionCombo();
     332        final ProjectionChoice pc = setupProjectionCombo();
    327333
    328334        for (int i = 0; i < coordinatesCombo.getItemCount(); ++i) {
     
    358364        projectionNameLabel.setLabelFor(projectionName);
    359365
     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
    360383        projPanel.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(0, 5, 0, 10));
    361384        projPanel.add(new JLabel(tr("Display coordinates as")), GBC.std().insets(5, 5, 0, 5));
     
    402425        Collection<String> prefs = pc.getPreferences(projSubPrefPanel);
    403426
    404         setProjection(id, prefs);
     427        setProjection(id, prefs, false);
    405428
    406429        if (PROP_COORDINATES.put(((CoordinateFormat) coordinatesCombo.getSelectedItem()).name())) {
     
    415438
    416439    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) {
    421452        ProjectionChoice pc = projectionChoicesById.get(id);
    422453
     
    432463        }
    433464        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        }
    437473        pc.setPreferences(pref);
    438474        Projection proj = pc.getProjection();
     
    467503     */
    468504    private ProjectionChoice setupProjectionCombo() {
     505        String pcId = projectionChoice != null ? projectionChoice : PROP_PROJECTION_DEFAULT.get();
    469506        ProjectionChoice pc = null;
    470507        for (int i = 0; i < projectionCombo.getItemCount(); ++i) {
    471508            ProjectionChoice pc1 = projectionCombo.getItemAt(i);
    472509            pc1.setPreferences(getSubprojectionPreference(pc1));
    473             if (pc1.getId().equals(PROP_PROJECTION.get())) {
     510            if (pc1.getId().equals(pcId)) {
    474511                projectionCombo.setSelectedIndex(i);
    475512                selectedProjectionChanged(pc1);
     
    490527
    491528    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);
    493533    }
    494534
Note: See TracChangeset for help on using the changeset viewer.