Changeset 2330 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-10-27T13:04:39+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/DownloadAction.java
r2328 r2330 10 10 import java.awt.event.KeyEvent; 11 11 import java.util.concurrent.Future; 12 import java.util.logging.Logger; 12 13 13 14 import javax.swing.JOptionPane; … … 18 19 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 19 20 import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler; 21 import org.openstreetmap.josm.data.Bounds; 20 22 import org.openstreetmap.josm.gui.ExtendedDialog; 21 23 import org.openstreetmap.josm.gui.download.DownloadDialog; … … 32 34 */ 33 35 public class DownloadAction extends JosmAction { 36 private static final Logger logger = Logger.getLogger(DownloadAction.class.getName()); 34 37 35 36 38 private DownloadDialog dialog; 37 39 private ExtendedDialog downloadDialog; … … 45 47 /** 46 48 * Creates the download dialog 49 * 47 50 * @return the downlaod dialog 48 51 */ 49 protected ExtendedDialog create UploadDialog() {50 if (dialog == null) 52 protected ExtendedDialog createDownloadDialog() { 53 if (dialog == null) 51 54 dialog = new DownloadDialog(); 52 55 dialog.restoreSettings(); 53 JPanel downPanel = new JPanel(new BorderLayout());54 downPanel.add(dialog, BorderLayout.CENTER);55 56 56 57 final String prefName = dialog.getClass().getName()+ ".geometry"; … … 59 60 60 61 if (downloadDialog == null) { 62 JPanel downPanel = new JPanel(new BorderLayout()); 63 downPanel.add(dialog, BorderLayout.CENTER); 61 64 downloadDialog= new ExtendedDialog(Main.parent, 62 65 tr("Download"), … … 70 73 71 74 public void actionPerformed(ActionEvent e) { 72 ExtendedDialog dlg = create UploadDialog();75 ExtendedDialog dlg = createDownloadDialog(); 73 76 boolean finish = false; 74 77 while (!finish) { … … 76 79 if (dlg.getValue() == 1 /* OK */) { 77 80 dialog.rememberSettings(); 81 Bounds area = dialog.getSelectedDownloadArea(); 78 82 if (dialog.isDownloadOsmData()) { 79 83 DownloadOsmTask task = new DownloadOsmTask(); 80 Future<?> future = task.download(dialog.isNewLayerRequired(), dialog.getSelectedDownloadArea(), null);84 Future<?> future = task.download(dialog.isNewLayerRequired(), area, null); 81 85 Main.worker.submit(new PostDownloadHandler(task, future)); 82 86 finish = true; … … 84 88 if (dialog.isDownloadGpxData()) { 85 89 DownloadGpsTask task = new DownloadGpsTask(); 86 Future<?> future = task.download(dialog.isNewLayerRequired(), dialog.getSelectedDownloadArea(), null);90 Future<?> future = task.download(dialog.isNewLayerRequired(),area, null); 87 91 Main.worker.submit(new PostDownloadHandler(task, future)); 88 92 finish = true; … … 100 104 } 101 105 } 102 103 dialog = null;104 dlg.dispose();105 106 } 106 107 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTask.java
r2328 r2330 11 11 public interface DownloadTask { 12 12 /** 13 * Execute the download using the given bounding box. Set silent on progressMonitor 14 * if no error messages should be popped up. 13 * Asynchronously launches the download task for a given bounding box. 14 * 15 * Set <code>progressMonitor</code> to null, if the task should create, open, and close a progress monitor. 16 * Set progressMonitor to {@see NullProgressMonitor#INSTANCE} if progress information is to 17 * be discarded. 18 * 19 * You can wait for the asynchronous download task to finish by synchronizing on the returned 20 * {@see Future}, but make sure not to freeze up JOSM. Example: 21 * <pre> 22 * Future<?> future = task.download(...); 23 * // DON'T run this on the Swing EDT or JOSM will freeze 24 * future.get(); // waits for the dowload task to complete 25 * </pre> 26 * 27 * The following example uses a pattern which is better suited if a task is launched from 28 * the Swing EDT: 29 * <pre> 30 * final Future<?> future = task.download(...); 31 * Runnable runAfterTask = new Runnable() { 32 * public void run() { 33 * // this is not strictly necessary because of the type of executor service 34 * // Main.worker is initialized with, but it doesn't harm either 35 * // 36 * future.get(); // wait for the download task to complete 37 * doSomethingAfterTheTaskCompleted(); 38 * } 39 * } 40 * Main.worker.submit(runAfterTask); 41 * </pre> 42 * 43 * @param newLayer true, if the data is to be downloaded into a new layer. If false, the task 44 * selects one of the existing layers as download layer, preferably the active layer. 45 * 46 * @param downloadArea the area to download 47 * @param progressMonitor the progressMonitor 48 * @return the future representing the asynchronous task 15 49 */ 16 50 Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor); 17 51 18 52 /** 19 * Execute the download using the given URL 20 * @param newLayer 21 * @param url 53 * Asynchronously launches the download task for a given bounding URL. 54 * 55 * Set progressMonitor to null, if the task should create, open, and close a progress monitor. 56 * Set progressMonitor to {@see NullProgressMonitor#INSTANCE} if progress information is to 57 * be discarded. 58 59 * @param newLayer newLayer true, if the data is to be downloaded into a new layer. If false, the task 60 * selects one of the existing layers as download layer, preferably the active layer. 61 * @param url the url to download from 62 * @param progressMonitor the progressMonitor 63 * @return the future representing the asynchronous task 64 * 65 * @see #download(boolean, Bounds, ProgressMonitor) 22 66 */ 23 67 Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor); … … 28 72 * Error objects are either {@see String}s with error messages or {@see Exception}s. 29 73 * 30 * WARNING: Never call this in the same thread you requested the download() or it will cause a31 * dead lock. See actions/downloadTasks/DownloadOsmTaskList.java for a proper implementation.32 *33 74 * @return the list of error objects 34 75 */ 35 76 List<Object> getErrorObjects(); 36 77 78 /** 79 * Cancels the asynchronous download task. 80 * 81 */ 37 82 public void cancel(); 38 83 } -
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r2327 r2330 148 148 * @param eventSource - the DownloadSelection object that fired this notification. 149 149 */ 150 public void boundingBoxChanged(Bounds b, DownloadSelection eventSource) { 150 public void boundingBoxChanged(Bounds b, DownloadSelection eventSource) { 151 151 this.currentBounds = b; 152 152 for (DownloadSelection s : downloadSelections) {
Note:
See TracChangeset
for help on using the changeset viewer.