Changeset 29745 in osm for applications


Ignore:
Timestamp:
2013-07-06T18:27:54+02:00 (11 years ago)
Author:
donvip
Message:

[josm_download_along] fix #josm2283 - Download GPX data along a way

Location:
applications/editors/josm/plugins/download_along
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/download_along/build.xml

    r29744 r29745  
    44    <property name="commit.message" value="Changed the constructor signature of the plugin main class"/>
    55    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    6     <property name="plugin.main.version" value="4980"/>
     6    <property name="plugin.main.version" value="6053"/>
    77
    88        <!-- Configure these properties (replace "..." accordingly).
  • applications/editors/josm/plugins/download_along/src/org/openstreetmap/josm/plugin/download_along/DownloadAlong.java

    r29744 r29745  
    77
    88public class DownloadAlong extends Plugin {
    9         static final String PREF_DOWNLOAD_ALONG_TRACK_DISTANCE = "downloadAlong.downloadAlongTrack.distance";
    10         static final String PREF_DOWNLOAD_ALONG_TRACK_AREA = "downloadAlong.downloadAlongTrack.area";
     9        public static final String PREF_DOWNLOAD_ALONG_TRACK_DISTANCE = "downloadAlong.downloadAlongTrack.distance";
     10        public static final String PREF_DOWNLOAD_ALONG_TRACK_AREA = "downloadAlong.downloadAlongTrack.area";
     11
     12        public static final String PREF_DOWNLOAD_ALONG_OSM = "downloadAlong.download.osm";
     13        public static final String PREF_DOWNLOAD_ALONG_GPS = "downloadAlong.download.gps";
    1114
    1215        public DownloadAlong(PluginInformation info) {
  • applications/editors/josm/plugins/download_along/src/org/openstreetmap/josm/plugin/download_along/DownloadAlongAction.java

    r29744 r29745  
    1616import javax.swing.JOptionPane;
    1717import javax.swing.JPanel;
     18import javax.swing.event.ChangeEvent;
     19import javax.swing.event.ChangeListener;
    1820
    1921import org.openstreetmap.josm.Main;
    2022import org.openstreetmap.josm.actions.JosmAction;
    21 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTaskList;
     23import org.openstreetmap.josm.actions.downloadtasks.DownloadTaskList;
    2224import org.openstreetmap.josm.data.coor.LatLon;
    2325import org.openstreetmap.josm.data.osm.Node;
     
    5557                }
    5658
    57                 DownloadPanel panel = new DownloadPanel();
     59                final DownloadPanel panel = new DownloadPanel();
    5860               
    59         ButtonSpec[] options = new ButtonSpec[] {
     61        final ButtonSpec[] options = new ButtonSpec[] {
    6062                new ButtonSpec(
    6163                        tr("Download"),
     
    7173                )
    7274        };
     75       
     76        panel.addChangeListener(new ChangeListener() {
     77                        @Override public void stateChanged(ChangeEvent e) {
     78                                options[0].setEnabled(panel.isDownloadOsmData() || panel.isDownloadGpxData());
     79                        }
     80                });
    7381
    7482                if (0 != HelpAwareOptionPane.showOptionDialog(Main.parent, panel, tr("Download from OSM along this track"),
     
    7684                        return;
    7785                }
    78 
    79                 Main.pref.putDouble(DownloadAlong.PREF_DOWNLOAD_ALONG_TRACK_DISTANCE, panel.getDistance());
    80                 Main.pref.putDouble(DownloadAlong.PREF_DOWNLOAD_ALONG_TRACK_AREA, panel.getArea());
     86               
     87                panel.rememberSettings();
    8188
    8289                /*
     
    191198                }
    192199                final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Download data"));
    193                 final Future<?> future = new DownloadOsmTaskList().download(false, toDownload, monitor);
     200                final Future<?> future = new DownloadTaskList().download(false, toDownload, panel.isDownloadOsmData(), panel.isDownloadGpxData(), monitor);
    194201                Main.worker.submit(new Runnable() {
    195202                        public void run() {
  • applications/editors/josm/plugins/download_along/src/org/openstreetmap/josm/plugin/download_along/DownloadPanel.java

    r29744 r29745  
    55import java.awt.GridBagLayout;
    66
     7import javax.swing.JCheckBox;
    78import javax.swing.JLabel;
    89import javax.swing.JList;
    910import javax.swing.JPanel;
     11import javax.swing.event.ChangeListener;
    1012
    1113import org.openstreetmap.josm.Main;
     
    1416public class DownloadPanel extends JPanel {
    1517
     18        // Data types to download
     19    private final JCheckBox cbDownloadOsmData;
     20    private final JCheckBox cbDownloadGpxData;
     21
     22    // Legacy list of values
    1623        private static final Integer dist[] = { 5000, 500, 50 };
    1724        private static final Integer area[] = { 20, 10, 5, 1 };
     
    2027        private final JList maxRect;
    2128       
     29        // Get value from preferences, taking into account legacy plugin stored only index from list of values instead of real value
    2230        private static final double getPreferenceValue(String prefKey, Integer array[]) {
    23                 int legacyIndex = Main.pref.getInteger(prefKey, -1);
     31                int legacyIndex = Main.pref.getInteger(prefKey, array[0]);
    2432                return (0 <= legacyIndex && legacyIndex < array.length)
    2533                                ? array[legacyIndex]
     
    2735        }
    2836       
     37        /**
     38         * Constructs a new {@code DownloadPanel}.
     39         */
    2940        public DownloadPanel() {
    3041                super(new GridBagLayout());
    3142
     43                cbDownloadOsmData = new JCheckBox(tr("OpenStreetMap data"), Main.pref.getBoolean(DownloadAlong.PREF_DOWNLOAD_ALONG_OSM, true));
     44        cbDownloadOsmData.setToolTipText(tr("Select to download OSM data."));
     45        add(cbDownloadOsmData,  GBC.std().insets(1,5,1,5));
     46        cbDownloadGpxData = new JCheckBox(tr("Raw GPS data"), Main.pref.getBoolean(DownloadAlong.PREF_DOWNLOAD_ALONG_GPS, false));
     47        cbDownloadGpxData.setToolTipText(tr("Select to download GPS traces."));
     48        add(cbDownloadGpxData,  GBC.eol().insets(5,5,1,5));
     49       
    3250                add(new JLabel(tr("Download everything within:")), GBC.eol());
    3351                String s[] = new String[dist.length];
     
    3856               
    3957                double distanceValue = getPreferenceValue(DownloadAlong.PREF_DOWNLOAD_ALONG_TRACK_DISTANCE, dist);
    40                 int distanceLegacyIndex = Main.pref.getInteger(DownloadAlong.PREF_DOWNLOAD_ALONG_TRACK_DISTANCE, -1);
    41                 if (distanceLegacyIndex == -1) {
     58                int distanceLegacyIndex = Main.pref.getInteger(DownloadAlong.PREF_DOWNLOAD_ALONG_TRACK_DISTANCE, dist[0]);
     59                if (distanceLegacyIndex == dist[0]) {
    4260                        for (int i = 0; i < dist.length; i++) {
    4361                                if (dist[i] == (int)distanceValue) {
     
    5977
    6078                double areaValue = getPreferenceValue(DownloadAlong.PREF_DOWNLOAD_ALONG_TRACK_AREA, area);
    61                 int areaLegacyIndex = Main.pref.getInteger(DownloadAlong.PREF_DOWNLOAD_ALONG_TRACK_AREA, -1);
    62                 if (areaLegacyIndex == -1) {
     79                int areaLegacyIndex = Main.pref.getInteger(DownloadAlong.PREF_DOWNLOAD_ALONG_TRACK_AREA, area[0]);
     80                if (areaLegacyIndex == area[0]) {
    6381                        for (int i = 0; i < area.length; i++) {
    6482                                if (area[i] == (int)areaValue) {
     
    7391        }
    7492       
     93        /**
     94         * Gets the maximum distance in meters
     95         * @return The maximum distance, in meters
     96         */
    7597        public final double getDistance() {
    7698                return dist[buffer.getSelectedIndex()];
    7799        }
    78100
     101        /**
     102         * Gets the maximum area in squared kilometers
     103         * @return The maximum distance, in squared kilometers
     104         */
    79105        public final double getArea() {
    80106                return area[maxRect.getSelectedIndex()];
    81107        }
     108       
     109    /**
     110     * Replies true if the user selected to download OSM data
     111     *
     112     * @return true if the user selected to download OSM data
     113     */
     114    public boolean isDownloadOsmData() {
     115        return cbDownloadOsmData.isSelected();
     116    }
     117
     118    /**
     119     * Replies true if the user selected to download GPX data
     120     *
     121     * @return true if the user selected to download GPX data
     122     */
     123    public boolean isDownloadGpxData() {
     124        return cbDownloadGpxData.isSelected();
     125    }
     126       
     127    /**
     128     * Remembers the current settings in the download panel
     129     */
     130    public final void rememberSettings() {
     131                Main.pref.putDouble(DownloadAlong.PREF_DOWNLOAD_ALONG_TRACK_DISTANCE, getDistance());
     132                Main.pref.putDouble(DownloadAlong.PREF_DOWNLOAD_ALONG_TRACK_AREA, getArea());
     133                Main.pref.put(DownloadAlong.PREF_DOWNLOAD_ALONG_OSM, isDownloadOsmData());
     134                Main.pref.put(DownloadAlong.PREF_DOWNLOAD_ALONG_GPS, isDownloadGpxData());
     135    }
     136   
     137    /**
     138     * Adds a change listener to comboboxes
     139     * @param listener The listener that will be notified of each combobox change
     140     */
     141    public final void addChangeListener(ChangeListener listener) {
     142        cbDownloadGpxData.addChangeListener(listener);
     143        cbDownloadOsmData.addChangeListener(listener);
     144    }
    82145}
Note: See TracChangeset for help on using the changeset viewer.