Ticket #12350: ZoomPreferences.patch

File ZoomPreferences.patch, 4.7 KB (added by kolesar, 5 years ago)
  • src/org/openstreetmap/josm/gui/preferences/display/LafPreference.java

    diff --git a/src/org/openstreetmap/josm/gui/preferences/display/LafPreference.java b/src/org/openstreetmap/josm/gui/preferences/display/LafPreference.java
    index 3d80963..47ce2f0 100644
    a b import javax.swing.BorderFactory; 
    1212import javax.swing.Box;
    1313import javax.swing.DefaultListCellRenderer;
    1414import javax.swing.JCheckBox;
     15import javax.swing.JFormattedTextField;
    1516import javax.swing.JLabel;
    1617import javax.swing.JList;
    1718import javax.swing.JScrollPane;
     19import javax.swing.JSpinner;
    1820import javax.swing.ListCellRenderer;
    1921import javax.swing.LookAndFeel;
     22import javax.swing.SpinnerNumberModel;
    2023import javax.swing.UIManager;
    2124import javax.swing.UIManager.LookAndFeelInfo;
    2225
    2326import org.openstreetmap.josm.Main;
    2427import org.openstreetmap.josm.actions.ExpertToggleAction;
    2528import org.openstreetmap.josm.gui.MapMover;
     29import org.openstreetmap.josm.gui.NavigatableComponent;
    2630import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
    2731import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    2832import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
    public class LafPreference implements SubPreferenceSetting { 
    6367    private final JCheckBox isoDates = new JCheckBox(tr("Display ISO dates"));
    6468    private final JCheckBox nativeFileChoosers = new JCheckBox(tr("Use native file choosers (nicer, but do not support file filters)"));
    6569    private final JCheckBox zoomReverseWheel = new JCheckBox(tr("Reverse zoom with mouse wheel"));
     70    private final JCheckBox zoomIntermediateSteps = new JCheckBox(tr("Intermediate steps between native resolutions"));
     71    private JSpinner spinZoomRatio;
    6672
    6773    @Override
    6874    public void addGui(PreferenceTabbedPane gui) {
    public class LafPreference implements SubPreferenceSetting { 
    147153        zoomReverseWheel.setSelected(MapMover.PROP_ZOOM_REVERSE_WHEEL.get());
    148154        panel.add(zoomReverseWheel, GBC.eop().insets(20, 0, 0, 0));
    149155
    150         panel.add(Box.createVerticalGlue(), GBC.eol().insets(0, 20, 0, 0));
     156        zoomIntermediateSteps.setToolTipText(
     157                tr("Divide intervals between native resolution levels to smaller steps if they are much larger than zoom ratio"));
     158        zoomIntermediateSteps.setSelected(NavigatableComponent.PROP_ZOOM_INTERMEDIATE_STEPS.get());
     159        ExpertToggleAction.addVisibilitySwitcher(zoomIntermediateSteps);
     160        panel.add(zoomIntermediateSteps, GBC.eop().insets(20, 0, 0, 0));
     161
     162        panel.add(Box.createVerticalGlue(), GBC.eol().insets(0, 10, 0, 0));
     163
     164        double logZoomLevel = Math.log(2) / Math.log(NavigatableComponent.PROP_ZOOM_RATIO.get());
     165        logZoomLevel = Math.max(1, logZoomLevel);
     166        logZoomLevel = Math.min(5, logZoomLevel);
     167        JLabel labelZoomRatio = new JLabel(tr("Zoom steps to get double scale"));
     168        spinZoomRatio = new JSpinner(new SpinnerNumberModel(logZoomLevel, 1, 5, 1));
     169        Component spinZoomRatioEditor = spinZoomRatio.getEditor();
     170        JFormattedTextField jftf = ((JSpinner.DefaultEditor) spinZoomRatioEditor).getTextField();
     171        jftf.setColumns(2);
     172        String zoomRatioToolTipText = tr("Higher value means more steps needed, therefore zoom steps will be smaller");
     173        spinZoomRatio.setToolTipText(zoomRatioToolTipText);
     174        labelZoomRatio.setToolTipText(zoomRatioToolTipText);
     175        labelZoomRatio.setLabelFor(spinZoomRatio);
     176        panel.add(labelZoomRatio, GBC.std().insets(20, 0, 0, 0));
     177        panel.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
     178        panel.add(spinZoomRatio, GBC.eol());
    151179
    152180        panel.add(new JLabel(tr("Look and Feel")), GBC.std().insets(20, 0, 0, 0));
    153181        panel.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
    public class LafPreference implements SubPreferenceSetting { 
    168196        Main.pref.put(ToggleDialog.PROP_DYNAMIC_BUTTONS.getKey(), dynamicButtons.isSelected());
    169197        Main.pref.put(DateUtils.PROP_ISO_DATES.getKey(), isoDates.isSelected());
    170198        Main.pref.put(FileChooserManager.PROP_USE_NATIVE_FILE_DIALOG.getKey(), nativeFileChoosers.isSelected());
    171         Main.pref.put(MapMover.PROP_ZOOM_REVERSE_WHEEL.getKey(), zoomReverseWheel.isSelected());
     199        MapMover.PROP_ZOOM_REVERSE_WHEEL.put(zoomReverseWheel.isSelected());
     200        NavigatableComponent.PROP_ZOOM_INTERMEDIATE_STEPS.put(zoomIntermediateSteps.isSelected());
     201        NavigatableComponent.PROP_ZOOM_RATIO.put(Math.pow(2, 1/(double) spinZoomRatio.getModel().getValue()));
    172202        mod |= Main.pref.put("laf", ((LookAndFeelInfo) lafCombo.getSelectedItem()).getClassName());
    173203        return mod;
    174204    }