Changeset 2327 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2009-10-27T01:21:32+01:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/DownloadAction.java
r2323 r2327 2 2 package org.openstreetmap.josm.actions; 3 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;6 6 7 7 import java.awt.BorderLayout; … … 15 15 16 16 import org.openstreetmap.josm.Main; 17 import org.openstreetmap.josm.actions.downloadtasks.DownloadTask; 17 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; 18 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 18 19 import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler; 19 20 import org.openstreetmap.josm.gui.ExtendedDialog; … … 31 32 */ 32 33 public class DownloadAction extends JosmAction { 34 33 35 34 36 public DownloadDialog dialog; 37 private ExtendedDialog downloadDialog; 35 38 36 39 public DownloadAction() { … … 45 48 */ 46 49 protected ExtendedDialog createUploadDialog() { 47 dialog = new DownloadDialog(); 50 if (dialog == null) 51 dialog = new DownloadDialog(); 52 dialog.restoreSettings(); 48 53 JPanel downPanel = new JPanel(new BorderLayout()); 49 54 downPanel.add(dialog, BorderLayout.CENTER); … … 53 58 new Dimension(1000,600)); 54 59 55 ExtendedDialog dialog = new ExtendedDialog(Main.parent, 60 if (downloadDialog == null) { 61 downloadDialog= new ExtendedDialog(Main.parent, 56 62 tr("Download"), 57 63 new String[] {tr("OK"), tr("Cancel")}); 58 dialog.setContent(downPanel, false /* don't use a scroll pane inside the dialog */); 59 dialog.setButtonIcons(new String[] {"ok", "cancel"}); 60 dialog.setRememberWindowGeometry(prefName, wg); 61 return dialog; 64 downloadDialog.setContent(downPanel, false /* don't use a scroll pane inside the dialog */); 65 downloadDialog.setButtonIcons(new String[] {"ok", "cancel"}); 66 downloadDialog.setRememberWindowGeometry(prefName, wg); 67 } 68 return downloadDialog; 62 69 } 63 70 … … 65 72 ExtendedDialog dlg = createUploadDialog(); 66 73 boolean finish = false; 67 while (!finish) { 74 while (!finish) { 68 75 dlg.showDialog(); 69 Main.pref.put("download.newlayer", dialog.newLayer.isSelected());70 76 if (dlg.getValue() == 1 /* OK */) { 71 Main.pref.put("download.tab", Integer.toString(dialog.getSelectedTab())); 72 for (DownloadTask task : dialog.downloadTasks) { 73 Main.pref.put("download."+task.getPreferencesSuffix(), task.getCheckBox().isSelected()); 74 if (task.getCheckBox().isSelected()) { 75 // asynchronously launch the download task ... 76 Future<?> future = task.download(this, dialog.minlat, dialog.minlon, dialog.maxlat, dialog.maxlon, null); 77 // ... and the continuation when the download task is finished 78 Main.worker.submit(new PostDownloadHandler(task, future)); 79 finish = true; 80 } 77 dialog.rememberSettings(); 78 if (dialog.isDownloadOsmData()) { 79 DownloadOsmTask task = new DownloadOsmTask(); 80 Future<?> future = task.download(this, dialog.getSelectedDownloadArea(), null); 81 Main.worker.submit(new PostDownloadHandler(task, future)); 82 finish = true; 83 } 84 if (dialog.isDownloadGpxData()) { 85 DownloadGpsTask task = new DownloadGpsTask(); 86 Future<?> future = task.download(this,dialog.getSelectedDownloadArea(), null); 87 Main.worker.submit(new PostDownloadHandler(task, future)); 88 finish = true; 81 89 } 82 90 } else { -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r2322 r2327 7 7 import java.util.concurrent.Future; 8 8 9 import javax.swing.JCheckBox;10 11 9 import org.openstreetmap.josm.Main; 12 10 import org.openstreetmap.josm.actions.DownloadAction; 11 import org.openstreetmap.josm.data.Bounds; 13 12 import org.openstreetmap.josm.data.gpx.GpxData; 14 13 import org.openstreetmap.josm.gui.PleaseWaitRunnable; … … 22 21 public class DownloadGpsTask extends AbstractDownloadTask { 23 22 24 private JCheckBox checkBox = new JCheckBox(tr("Raw GPS data"));25 23 private DownloadTask downloadTask; 26 24 27 public Future<?> download(DownloadAction action, double minlat, double minlon, 28 double maxlat, double maxlon, ProgressMonitor progressMonitor) { 29 downloadTask = new DownloadTask(action.dialog.newLayer.isSelected(), 30 new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon), progressMonitor); 25 public Future<?> download(DownloadAction action, Bounds downloadArea, ProgressMonitor progressMonitor) { 26 downloadTask = new DownloadTask(action.dialog.isNewLayerRequired(), 27 new BoundingBoxDownloader(downloadArea), progressMonitor); 31 28 // We need submit instead of execute so we can wait for it to finish and get the error 32 29 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. 33 30 return Main.worker.submit(downloadTask); 34 31 } 35 36 public JCheckBox getCheckBox() { 37 return checkBox; 38 } 39 40 public String getPreferencesSuffix() { 41 return "gps"; 42 } 43 32 44 33 public Future<?> loadUrl(boolean a,java.lang.String b, ProgressMonitor progressMonitor) { 45 34 return null; -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r2322 r2327 8 8 import java.util.concurrent.Future; 9 9 import java.util.logging.Logger; 10 11 import javax.swing.JCheckBox;12 10 13 11 import org.openstreetmap.josm.Main; … … 38 36 private DownloadTask downloadTask; 39 37 40 private JCheckBox checkBox = new JCheckBox(tr("OpenStreetMap data"), true);41 42 38 private void rememberDownloadedData(DataSet ds) { 43 39 this.downloadedData = ds; … … 48 44 } 49 45 50 public Future<?> download(DownloadAction action, double minlat, double minlon, 51 double maxlat, double maxlon, ProgressMonitor progressMonitor) { 52 // Swap min and max if user has specified them the wrong way round 53 // (easy to do if you are crossing 0, for example) 54 // FIXME should perhaps be done in download dialog? 55 if (minlat > maxlat) { 56 double t = minlat; minlat = maxlat; maxlat = t; 57 } 58 if (minlon > maxlon) { 59 double t = minlon; minlon = maxlon; maxlon = t; 60 } 61 46 public Future<?> download(DownloadAction action, Bounds downloadArea, ProgressMonitor progressMonitor) { 47 62 48 boolean newLayer = action != null 63 && (action.dialog == null || action.dialog. newLayer.isSelected());49 && (action.dialog == null || action.dialog.isNewLayerRequired()); 64 50 65 51 downloadTask = new DownloadTask(newLayer, 66 new BoundingBoxDownloader( minlat, minlon, maxlat, maxlon), progressMonitor);67 currentBounds = new Bounds( new LatLon(minlat, minlon), new LatLon(maxlat, maxlon));52 new BoundingBoxDownloader(downloadArea), progressMonitor); 53 currentBounds = new Bounds(downloadArea); 68 54 // We need submit instead of execute so we can wait for it to finish and get the error 69 55 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. … … 82 68 currentBounds = new Bounds(new LatLon(0,0), new LatLon(0,0)); 83 69 return Main.worker.submit(downloadTask); 84 }85 86 public JCheckBox getCheckBox() {87 return checkBox;88 }89 90 public String getPreferencesSuffix() {91 return "osm";92 70 } 93 71 -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskList.java
r2325 r2327 21 21 import org.openstreetmap.josm.Main; 22 22 import org.openstreetmap.josm.actions.UpdateSelectionAction; 23 import org.openstreetmap.josm.data.Bounds; 23 24 import org.openstreetmap.josm.data.osm.DataSet; 24 25 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 65 66 childProgress.setSilent(true); 66 67 childProgress.setCustomText(tr("Download {0} of {1} ({2} left)", i, rects.size(), rects.size() - i)); 67 Future<?> future = dt.download(null, td.getMinY(), td.getMinX(), td.getMaxY(), td.getMaxX(), childProgress);68 Future<?> future = dt.download(null, new Bounds(td), childProgress); 68 69 osmTaskFutures.add(future); 69 70 osmTasks.add(dt); -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTask.java
r2322 r2327 5 5 import java.util.concurrent.Future; 6 6 7 import javax.swing.JCheckBox;8 9 7 import org.openstreetmap.josm.actions.DownloadAction; 8 import org.openstreetmap.josm.data.Bounds; 10 9 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 11 10 … … 16 15 * if no error messages should be popped up. 17 16 */ 18 Future<?> download(DownloadAction action, double minlat, double minlon, 19 double maxlat, double maxlon, ProgressMonitor progressMonitor); 17 Future<?> download(DownloadAction action, Bounds downloadArea, ProgressMonitor progressMonitor); 20 18 21 19 /** … … 25 23 */ 26 24 Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor); 27 28 /**29 * @return The checkbox presented to the user30 */31 JCheckBox getCheckBox();32 33 /**34 * @return The name of the preferences suffix to use for storing the35 * selection state.36 */37 String getPreferencesSuffix();38 25 39 26 /** -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/PostDownloadHandler.java
r2322 r2327 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.ArrayList; 6 7 import java.util.LinkedHashSet; 8 import java.util.List; 7 9 import java.util.concurrent.Future; 8 10 … … 16 18 public class PostDownloadHandler implements Runnable { 17 19 private DownloadTask task; 18 private Future<?> future;20 private List<Future<?>> futures; 19 21 20 22 /** … … 25 27 public PostDownloadHandler(DownloadTask task, Future<?> future) { 26 28 this.task = task; 27 this.future = future; 29 this.futures = new ArrayList<Future<?>>(); 30 if (future != null) { 31 this.futures.add(future); 32 } 28 33 } 29 34 35 /** 36 * constructor 37 * @param task the asynchronous download task 38 * @param future the future on which the completion of the download task can be synchronized 39 */ 40 public PostDownloadHandler(DownloadTask task, Future<?> ... futures) { 41 this.task = task; 42 this.futures = new ArrayList<Future<?>>(); 43 if (futures == null) return; 44 for (Future<?> future: futures) { 45 this.futures.add(future); 46 } 47 } 48 49 50 /** 51 * constructor 52 * @param task the asynchronous download task 53 * @param future the future on which the completion of the download task can be synchronized 54 */ 55 public PostDownloadHandler(DownloadTask task, List<Future<?>> futures) { 56 this.task = task; 57 this.futures = new ArrayList<Future<?>>(); 58 if (futures == null) return; 59 this.futures.addAll(futures); 60 } 61 30 62 public void run() { 31 // wait for the download task to complete 63 // wait for all downloads task to finish (by waiting for the futures 64 // to return a value) 32 65 // 33 try { 34 future.get(); 35 } catch(Exception e) { 36 e.printStackTrace(); 37 return; 66 for (Future<?> future: futures) { 67 try { 68 future.get(); 69 } catch(Exception e) { 70 e.printStackTrace(); 71 return; 72 } 38 73 } 39 74
Note:
See TracChangeset
for help on using the changeset viewer.