Changeset 7536 in josm for trunk/src/org


Ignore:
Timestamp:
2014-09-14T21:43:59+02:00 (10 years ago)
Author:
Don-vip
Message:

fix #8430 - Download along: rework selection panel to allow smaller areas

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

Legend:

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

    r7315 r7536  
    7878 *
    7979 * @author imi
     80 * @since 74
    8081 */
    8182public class Preferences {
     
    16601661
    16611662        String[] obsolete = {
    1662                 "downloadAlong.downloadAlongTrack.distance",   // 07/2013 - can be removed mid-2014. Replaced by downloadAlongWay.distance
    1663                 "downloadAlong.downloadAlongTrack.area",       // 07/2013 - can be removed mid-2014. Replaced by downloadAlongWay.area
    1664                 "gpxLayer.downloadAlongTrack.distance",        // 07/2013 - can be removed mid-2014. Replaced by downloadAlongTrack.distance
    1665                 "gpxLayer.downloadAlongTrack.area",            // 07/2013 - can be removed mid-2014. Replaced by downloadAlongTrack.area
    1666                 "gpxLayer.downloadAlongTrack.near",            // 07/2013 - can be removed mid-2014. Replaced by downloadAlongTrack.near
    16671663                "validator.tests",                             // 01/2014 - can be removed end-2014. Replaced by validator.skip
    16681664                "validator.testsBeforeUpload",                 // 01/2014 - can be removed end-2014. Replaced by validator.skipBeforeUpload
     
    16811677    }
    16821678
    1683     public static boolean isEqual(Setting<?> a, Setting<?> b) {
    1684         if (a == null) return b == null;
    1685         return a.equals(b);
    1686     }
    1687 
    16881679    /**
    16891680     * Enables or not the preferences file auto-save mechanism (save each time a setting is changed).
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongPanel.java

    r7005 r7536  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.Dimension;
    67import java.awt.GridBagLayout;
    78
     
    1112import javax.swing.JOptionPane;
    1213import javax.swing.JPanel;
     14import javax.swing.JSpinner;
     15import javax.swing.SpinnerNumberModel;
    1316import javax.swing.event.ChangeEvent;
    1417import javax.swing.event.ChangeListener;
     
    2528 */
    2629public class DownloadAlongPanel extends JPanel {
    27    
     30
    2831    // Preferences keys
    2932    private final String prefOsm;
     
    3740    private final JCheckBox cbDownloadGpxData;
    3841
    39     // Legacy list of values
    40     private static final Integer[] dist = { 5000, 500, 50 };
    41     private static final Integer[] area = { 20, 10, 5, 1 };
    42    
    43     private final JList<String> buffer;
    44     private final JList<String> maxRect;
     42    private final JSpinner buffer;
     43    private final JSpinner maxRect;
    4544    private final JList<String> downloadNear;
    46    
     45
    4746    /**
    4847     * Constructs a new {@code DownloadPanel}.
     
    5554    public DownloadAlongPanel(String prefOsm, String prefGps, String prefDist, String prefArea, String prefNear) {
    5655        super(new GridBagLayout());
    57        
     56
    5857        this.prefOsm = prefOsm;
    5958        this.prefGps = prefGps;
     
    6463        cbDownloadOsmData = new JCheckBox(tr("OpenStreetMap data"), Main.pref.getBoolean(prefOsm, true));
    6564        cbDownloadOsmData.setToolTipText(tr("Select to download OSM data."));
    66         add(cbDownloadOsmData,  GBC.std().insets(1,5,1,5));
     65        add(cbDownloadOsmData, GBC.std().insets(1,5,1,5));
    6766        cbDownloadGpxData = new JCheckBox(tr("Raw GPS data"), Main.pref.getBoolean(prefGps, false));
    6867        cbDownloadGpxData.setToolTipText(tr("Select to download GPS traces."));
    69         add(cbDownloadGpxData,  GBC.eol().insets(5,5,1,5));
    70        
    71         add(new JLabel(tr("Download everything within:")), GBC.eol());
    72         String[] s = new String[dist.length];
    73         for (int i = 0; i < dist.length; ++i) {
    74             s[i] = tr("{0} meters", dist[i]);
    75         }
    76         buffer = new JList<>(s);
    77        
    78         double distanceValue = Main.pref.getDouble(prefDist, dist[0]);
    79         int distanceLegacyIndex = 0;
    80         for (int i = 0; i < dist.length; i++) {
    81             if (dist[i] == (int)distanceValue) {
    82                 distanceLegacyIndex = i;
    83                 break;
     68        add(cbDownloadGpxData, GBC.eol().insets(5,5,1,5));
     69
     70        add(new JLabel(tr("Download everything within:")), GBC.std());
     71        buffer = new JSpinner(new SpinnerNumberModel(50.0, 10.0, 5000.0, 1.0));
     72        add(buffer, GBC.std().insets(5,5,5,5));
     73        add(new JLabel(tr("meters")), GBC.eol());
     74
     75        add(new JLabel(tr("Maximum area per request:")), GBC.std());
     76        maxRect = new JSpinner(new SpinnerNumberModel(20.0, 1.0, 25.0, 1.0)) {
     77            @Override
     78            public Dimension getPreferredSize() {
     79                return buffer.getPreferredSize();
    8480            }
    85         }
    86        
    87         buffer.setSelectedIndex(distanceLegacyIndex);
    88         add(buffer, GBC.eol());
     81        };
     82        add(maxRect, GBC.std().insets(5,5,5,5));
     83        add(new JLabel(tr("sq km")), GBC.eol());
    8984
    90         add(new JLabel(tr("Maximum area per request:")), GBC.eol());
    91         s = new String[area.length];
    92         for (int i = 0; i < area.length; ++i) {
    93             s[i] = tr("{0} sq km", area[i]);
    94         }
    95         maxRect = new JList<>(s);
    96 
    97         double areaValue = Main.pref.getDouble(prefArea, area[0]);
    98         int areaLegacyIndex = 0;
    99         for (int i = 0; i < area.length; i++) {
    100             if (area[i] == (int)areaValue) {
    101                 areaLegacyIndex = i;
    102                 break;
    103             }
    104         }
    105        
    106         maxRect.setSelectedIndex(areaLegacyIndex);
    107         add(maxRect, GBC.eol());
    108        
    10985        if (prefNear != null) {
    11086            add(new JLabel(tr("Download near:")), GBC.eol());
     
    11692        }
    11793    }
    118    
     94
    11995    /**
    12096     * Gets the maximum distance in meters
     
    12298     */
    12399    public final double getDistance() {
    124         return dist[buffer.getSelectedIndex()];
     100        return (double) buffer.getValue();
    125101    }
    126102
     
    130106     */
    131107    public final double getArea() {
    132         return area[maxRect.getSelectedIndex()];
     108        return (double) maxRect.getValue();
    133109    }
    134    
     110
    135111    /**
    136112     * Gets the "download near" choosen value
     
    140116        return downloadNear.getSelectedIndex();
    141117    }
    142    
     118
    143119    /**
    144120     * Replies true if the user selected to download OSM data
     
    158134        return cbDownloadGpxData.isSelected();
    159135    }
    160    
     136
    161137    /**
    162138     * Remembers the current settings in the download panel
     
    171147        }
    172148    }
    173    
     149
    174150    /**
    175151     * Adds a change listener to comboboxes
     
    202178                )
    203179        };
    204        
     180
    205181        addChangeListener(new ChangeListener() {
    206182            @Override public void stateChanged(ChangeEvent e) {
  • trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java

    r7027 r7536  
    1717import java.util.Map;
    1818import java.util.Map.Entry;
     19import java.util.Objects;
    1920
    2021import javax.swing.AbstractAction;
     
    287288            PrefEntry en = new PrefEntry(e.getKey(), value, def, false);
    288289            // after changes we have nondefault value. Value is changed if is not equal to old value
    289             if ( !Preferences.isEqual(old, value) ) {
     290            if (!Objects.equals(old, value)) {
    290291                en.markAsChanged();
    291292            }
Note: See TracChangeset for help on using the changeset viewer.