Changeset 5097 in josm for trunk


Ignore:
Timestamp:
2012-03-17T23:51:40+01:00 (8 years ago)
Author:
simon04
Message:

see #7511 - make DownloadDialog, Osm download related classes more adaptable

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r5044 r5097  
    4848    }
    4949
     50    @Override
    5051    public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) {
    51 
    52         downloadTask = new DownloadTask(newLayer,
    53                 new BoundingBoxDownloader(downloadArea), progressMonitor);
    54         currentBounds = new Bounds(downloadArea);
     52        return download(new BoundingBoxDownloader(downloadArea), newLayer, downloadArea, progressMonitor);
     53    }
     54
     55    public Future<?> download(OsmServerReader reader, boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) {
     56        return download(new DownloadTask(newLayer, reader, progressMonitor), downloadArea);
     57    }
     58
     59    protected Future<?> download(DownloadTask downloadTask, Bounds downloadArea) {
     60        this.downloadTask = downloadTask;
     61        this.currentBounds = new Bounds(downloadArea);
    5562        // We need submit instead of execute so we can wait for it to finish and get the error
    5663        // message if necessary. If no one calls getErrorMessage() it just behaves like execute.
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java

    r4984 r5097  
    6666    }
    6767
    68     private final List<DownloadSelection> downloadSelections = new ArrayList<DownloadSelection>();
    69     private final JTabbedPane tpDownloadAreaSelectors = new JTabbedPane();
    70     private JCheckBox cbNewLayer;
    71     private JCheckBox cbStartup;
    72     private final JLabel sizeCheck = new JLabel();
    73     private Bounds currentBounds = null;
    74     private boolean canceled;
    75 
    76     private JCheckBox cbDownloadOsmData;
    77     private JCheckBox cbDownloadGpxData;
     68    protected final List<DownloadSelection> downloadSelections = new ArrayList<DownloadSelection>();
     69    protected final JTabbedPane tpDownloadAreaSelectors = new JTabbedPane();
     70    protected JCheckBox cbNewLayer;
     71    protected JCheckBox cbStartup;
     72    protected final JLabel sizeCheck = new JLabel();
     73    protected Bounds currentBounds = null;
     74    protected boolean canceled;
     75
     76    protected JCheckBox cbDownloadOsmData;
     77    protected JCheckBox cbDownloadGpxData;
    7878    /** the download action and button */
    7979    private DownloadAction actDownload;
    80     private SideButton btnDownload;
     80    protected SideButton btnDownload;
    8181
    8282    private void makeCheckBoxRespondToEnter(JCheckBox cb) {
     
    8585    }
    8686
    87     public JPanel buildMainPanel() {
    88         // generic constraints used by different components
    89         GridBagConstraints gridBagConstraints;
    90 
     87    protected JPanel buildMainPanel() {
    9188        JPanel pnl = new JPanel();
    9289        pnl.setLayout(new GridBagLayout());
     
    10097        cbDownloadGpxData.setToolTipText(tr("Select to download GPS traces in the selected download area."));
    10198        pnl.add(cbDownloadGpxData,  GBC.eol().insets(5,5,1,5));
     99
     100        buildMainPanelAboveDownloadSelections(pnl);
    102101
    103102        // predefined download selections
     
    390389    }
    391390
     391    protected void buildMainPanelAboveDownloadSelections(JPanel pnl) {
     392    }
     393
    392394    class CancelAction extends AbstractAction {
    393395        public CancelAction() {
  • trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

    r4580 r5097  
    1818     * The boundings of the desired map data.
    1919     */
    20     private final double lat1;
    21     private final double lon1;
    22     private final double lat2;
    23     private final double lon2;
    24     private final boolean crosses180th;
     20    protected final double lat1;
     21    protected final double lon1;
     22    protected final double lat2;
     23    protected final double lon2;
     24    protected final boolean crosses180th;
    2525
    2626    public BoundingBoxDownloader(Bounds downloadArea) {
     
    101101    }
    102102
     103    protected String getRequestForBbox(double lon1, double lat1, double lon2, double lat2) {
     104        return "map?bbox=" + lon1 + "," + lat1 + "," + lon2 + "," + lat2;
     105    }
     106
    103107    /**
    104108     * Read the data from the osm server address.
     
    114118            if (crosses180th) {
    115119                // API 0.6 does not support requests crossing the 180th meridian, so make two requests
    116                 in = getInputStream("map?bbox="+lon1+","+lat1+",180.0,"+lat2, progressMonitor.createSubTaskMonitor(9, false));
     120                in = getInputStream(getRequestForBbox(lon1, lat1, 180.0, lat2), progressMonitor.createSubTaskMonitor(9, false));
    117121                if (in == null)
    118122                    return null;
    119123                ds = OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false));
    120124
    121                 in = getInputStream("map?bbox=-180.0,"+lat1+","+lon2+","+lat2, progressMonitor.createSubTaskMonitor(9, false));
     125                in = getInputStream(getRequestForBbox(-180.0, lat1, lon2, lat2), progressMonitor.createSubTaskMonitor(9, false));
    122126                if (in == null)
    123127                    return null;
     
    129133            } else {
    130134                // Simple request
    131                 in = getInputStream("map?bbox="+lon1+","+lat1+","+lon2+","+lat2, progressMonitor.createSubTaskMonitor(9, false));
     135                in = getInputStream(getRequestForBbox(lon1, lat1, lon2, lat2), progressMonitor.createSubTaskMonitor(9, false));
    132136                if (in == null)
    133137                    return null;
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r4530 r5097  
    4343        try {
    4444            api.initialize(progressMonitor);
    45             urlStr = api.getBaseUrl() + urlStr;
     45            urlStr = urlStr.startsWith("http") ? urlStr : (getBaseUrl() + urlStr);
    4646            return getInputStreamRaw(urlStr, progressMonitor);
    4747        } finally {
    4848            progressMonitor.invalidate();
    4949        }
     50    }
     51
     52    protected String getBaseUrl() {
     53        return api.getBaseUrl();
    5054    }
    5155
Note: See TracChangeset for help on using the changeset viewer.