- Timestamp:
- 2009-10-25T23:09:53+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r2305 r2322 20 20 import java.util.concurrent.ExecutorService; 21 21 import java.util.concurrent.Executors; 22 import java.util.concurrent.Future; 22 23 import java.util.regex.Matcher; 23 24 import java.util.regex.Pattern; … … 32 33 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; 33 34 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 35 import org.openstreetmap.josm.actions.downloadtasks.DownloadTask; 36 import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler; 34 37 import org.openstreetmap.josm.actions.mapmode.MapMode; 35 38 import org.openstreetmap.josm.actions.search.SearchAction; … … 46 49 import org.openstreetmap.josm.gui.SplashScreen; 47 50 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 48 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask;49 51 import org.openstreetmap.josm.gui.help.HelpBrowserProxy; 50 52 import org.openstreetmap.josm.gui.io.SaveLayersDialog; … … 421 423 //DownloadTask osmTask = main.menu.download.downloadTasks.get(0); 422 424 DownloadTask osmTask = new DownloadOsmTask(); 423 osmTask.download(main.menu.download, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon(), null); 425 Future<?> future = osmTask.download(main.menu.download, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon(), null); 426 Main.worker.submit(new PostDownloadHandler(osmTask, future)); 424 427 } 425 428 return; … … 466 469 try { 467 470 DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask(); 468 task.download(main.menu.download, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), null); 471 // asynchronously launch the download task ... 472 Future<?> future = task.download(main.menu.download, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), null); 473 // ... and the continuation when the download is finished (this will wait for the download to finish) 474 Main.worker.execute(new PostDownloadHandler(task, future)); 469 475 return; 470 476 } catch (final NumberFormatException e) { -
trunk/src/org/openstreetmap/josm/actions/DownloadAction.java
r2138 r2322 8 8 import java.awt.event.ActionEvent; 9 9 import java.awt.event.KeyEvent; 10 import java.util.List; 11 import java.util.concurrent.Future; 10 12 11 13 import javax.swing.JOptionPane; … … 13 15 14 16 import org.openstreetmap.josm.Main; 17 import org.openstreetmap.josm.actions.downloadtasks.DownloadTask; 18 import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler; 19 import org.openstreetmap.josm.gui.ExceptionDialogUtil; 15 20 import org.openstreetmap.josm.gui.ExtendedDialog; 16 21 import org.openstreetmap.josm.gui.download.DownloadDialog; 17 import org.openstreetmap.josm. gui.download.DownloadDialog.DownloadTask;22 import org.openstreetmap.josm.tools.ExceptionUtil; 18 23 import org.openstreetmap.josm.tools.Shortcut; 19 24 import org.openstreetmap.josm.tools.WindowGeometry; … … 69 74 Main.pref.put("download."+task.getPreferencesSuffix(), task.getCheckBox().isSelected()); 70 75 if (task.getCheckBox().isSelected()) { 71 task.download(this, dialog.minlat, dialog.minlon, dialog.maxlat, dialog.maxlon, null); 76 // asynchronously launch the download task ... 77 Future<?> future = task.download(this, dialog.minlat, dialog.minlon, dialog.maxlat, dialog.maxlon, null); 78 // ... and the continuation when the download task is finished 79 Main.worker.submit(new PostDownloadHandler(task, future)); 72 80 finish = true; 73 81 } -
trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java
r2308 r2322 11 11 import java.util.LinkedList; 12 12 import java.util.List; 13 import java.util.concurrent.Future; 13 14 14 15 import javax.swing.JCheckBox; … … 18 19 import org.openstreetmap.josm.Main; 19 20 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 21 import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler; 20 22 import org.openstreetmap.josm.gui.ExtendedDialog; 23 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 21 24 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 22 25 import org.openstreetmap.josm.tools.GBC; … … 102 105 */ 103 106 public void openUrl(boolean new_layer, String url) { 104 new DownloadOsmTask().loadUrl(new_layer, url, null); 107 DownloadOsmTask task = new DownloadOsmTask(); 108 PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Download Data")); 109 Future<?> future = task.loadUrl(new_layer, url, monitor); 110 Main.worker.submit(new PostDownloadHandler(task, future)); 105 111 } 106 112 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r2215 r2322 12 12 import org.openstreetmap.josm.actions.DownloadAction; 13 13 import org.openstreetmap.josm.data.gpx.GpxData; 14 import org.openstreetmap.josm.gui.ExceptionDialogUtil;15 14 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 16 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask;17 15 import org.openstreetmap.josm.gui.layer.GpxLayer; 18 16 import org.openstreetmap.josm.gui.layer.Layer; … … 22 20 import org.xml.sax.SAXException; 23 21 24 public class DownloadGpsTask implements DownloadTask { 25 private Future<Task> task = null; 22 public class DownloadGpsTask extends AbstractDownloadTask { 26 23 27 private static class Task extends PleaseWaitRunnable { 24 private JCheckBox checkBox = new JCheckBox(tr("Raw GPS data")); 25 private DownloadTask downloadTask; 26 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); 31 // We need submit instead of execute so we can wait for it to finish and get the error 32 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. 33 return Main.worker.submit(downloadTask); 34 } 35 36 public JCheckBox getCheckBox() { 37 return checkBox; 38 } 39 40 public String getPreferencesSuffix() { 41 return "gps"; 42 } 43 44 public Future<?> loadUrl(boolean a,java.lang.String b, ProgressMonitor progressMonitor) { 45 return null; 46 // FIXME this is not currently used 47 } 48 49 public void cancel() { 50 if (downloadTask != null) { 51 downloadTask.cancel(); 52 } 53 } 54 55 56 class DownloadTask extends PleaseWaitRunnable { 28 57 private BoundingBoxDownloader reader; 29 58 private GpxData rawData; 30 59 private final boolean newLayer; 31 private OsmTransferException lastException;32 60 33 public Task(boolean newLayer, BoundingBoxDownloader reader, ProgressMonitor progressMonitor) {61 public DownloadTask(boolean newLayer, BoundingBoxDownloader reader, ProgressMonitor progressMonitor) { 34 62 super(tr("Downloading GPS data")); 35 63 this.reader = reader; … … 39 67 @Override public void realRun() throws IOException, SAXException, OsmTransferException { 40 68 try { 69 if (isCanceled()) 70 return; 41 71 rawData = reader.parseRawGps(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 42 } catch(OsmTransferException e) {43 lastException = e;44 72 } catch(Exception e) { 45 lastException = new OsmTransferException(e); 73 if (isCanceled()) 74 return; 75 if (e instanceof OsmTransferException) { 76 rememberException(e); 77 } else { 78 rememberException(new OsmTransferException(e)); 79 } 46 80 } 47 81 } 48 82 49 83 @Override protected void finish() { 50 if (lastException != null) { 51 ExceptionDialogUtil.explainException(lastException); 84 if (isCanceled() || isFailed()) 52 85 return; 53 }54 86 if (rawData == null) 55 87 return; … … 79 111 80 112 @Override protected void cancel() { 113 setCanceled(true); 81 114 if (reader != null) { 82 115 reader.cancel(); … … 84 117 } 85 118 } 86 87 private JCheckBox checkBox = new JCheckBox(tr("Raw GPS data"));88 89 public void download(DownloadAction action, double minlat, double minlon,90 double maxlat, double maxlon, ProgressMonitor progressMonitor) {91 Task t = new Task(action.dialog.newLayer.isSelected(),92 new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon), progressMonitor);93 // We need submit instead of execute so we can wait for it to finish and get the error94 // message if necessary. If no one calls getErrorMessage() it just behaves like execute.95 task = Main.worker.submit(t, t);96 }97 98 public JCheckBox getCheckBox() {99 return checkBox;100 }101 102 public String getPreferencesSuffix() {103 return "gps";104 }105 106 public void loadUrl(boolean a,java.lang.String b, ProgressMonitor progressMonitor) {107 // FIXME this is not currently used108 }109 110 /*111 * (non-Javadoc)112 * @see org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask#getErrorMessage()113 */114 public String getErrorMessage() {115 if(task == null)116 return "";117 118 try {119 Task t = task.get();120 return t.getProgressMonitor().getErrorMessage() == null121 ? ""122 : t.getProgressMonitor().getErrorMessage();123 } catch (Exception e) {124 return "";125 }126 }127 119 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r2253 r2322 18 18 import org.openstreetmap.josm.data.osm.DataSource; 19 19 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 20 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask;21 20 import org.openstreetmap.josm.gui.layer.Layer; 22 21 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 26 25 import org.openstreetmap.josm.io.OsmServerReader; 27 26 import org.openstreetmap.josm.io.OsmTransferException; 28 import org.openstreetmap.josm.tools.ExceptionUtil;29 27 import org.xml.sax.SAXException; 30 28 … … 33 31 * Run in the worker thread. 34 32 */ 35 public class DownloadOsmTask implementsDownloadTask {33 public class DownloadOsmTask extends AbstractDownloadTask { 36 34 private static final Logger logger = Logger.getLogger(DownloadOsmTask.class.getName()); 37 35 38 36 private static Bounds currentBounds; 39 private Future<Task> task = null;40 37 private DataSet downloadedData; 41 private boolean canceled = false; 42 private boolean failed = false; 38 private DownloadTask downloadTask; 43 39 44 private class Task extends PleaseWaitRunnable { 40 private JCheckBox checkBox = new JCheckBox(tr("OpenStreetMap data"), true); 41 42 private void rememberDownloadedData(DataSet ds) { 43 this.downloadedData = ds; 44 } 45 46 public DataSet getDownloadedData() { 47 return downloadedData; 48 } 49 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 62 boolean newLayer = action != null 63 && (action.dialog == null || action.dialog.newLayer.isSelected()); 64 65 downloadTask = new DownloadTask(newLayer, 66 new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon), progressMonitor); 67 currentBounds = new Bounds(new LatLon(minlat, minlon), new LatLon(maxlat, maxlon)); 68 // We need submit instead of execute so we can wait for it to finish and get the error 69 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. 70 return Main.worker.submit(downloadTask); 71 } 72 73 /** 74 * Loads a given URL from the OSM Server 75 * @param True if the data should be saved to a new layer 76 * @param The URL as String 77 */ 78 public Future<?> loadUrl(boolean new_layer, String url, ProgressMonitor progressMonitor) { 79 downloadTask = new DownloadTask(new_layer, 80 new OsmServerLocationReader(url), 81 progressMonitor); 82 currentBounds = new Bounds(new LatLon(0,0), new LatLon(0,0)); 83 return Main.worker.submit(downloadTask); 84 } 85 86 public JCheckBox getCheckBox() { 87 return checkBox; 88 } 89 90 public String getPreferencesSuffix() { 91 return "osm"; 92 } 93 94 public void cancel() { 95 if (downloadTask != null) { 96 downloadTask.cancel(); 97 } 98 } 99 100 private class DownloadTask extends PleaseWaitRunnable { 45 101 private OsmServerReader reader; 46 102 private DataSet dataSet; 47 103 private boolean newLayer; 48 private boolean canceled;49 private Exception lastException;50 104 51 public Task(boolean newLayer, OsmServerReader reader, ProgressMonitor progressMonitor) {105 public DownloadTask(boolean newLayer, OsmServerReader reader, ProgressMonitor progressMonitor) { 52 106 super(tr("Downloading data"), progressMonitor, false); 53 107 this.reader = reader; … … 57 111 @Override public void realRun() throws IOException, SAXException, OsmTransferException { 58 112 try { 113 if (isCanceled()) 114 return; 59 115 dataSet = reader.parseOsm(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 60 116 } catch(Exception e) { 61 if ( canceled) {117 if (isCanceled()) { 62 118 logger.warning(tr("Ignoring exception because download has been cancelled. Exception was: {0}" + e.toString())); 63 119 return; 64 120 } 65 121 if (e instanceof OsmTransferException) { 66 lastException = e;122 rememberException(e); 67 123 } else { 68 lastException = new OsmTransferException(e);124 rememberException(new OsmTransferException(e)); 69 125 } 126 DownloadOsmTask.this.setFailed(true); 70 127 } 71 128 } … … 102 159 103 160 @Override protected void finish() { 104 if ( canceled)161 if (isFailed() || isCanceled()) 105 162 return; 106 if (lastException != null) {107 getProgressMonitor().setErrorMessage(ExceptionUtil.explainException(lastException));108 DownloadOsmTask.this.setFailed(true);109 return;110 }111 163 if (dataSet == null) 112 164 return; // user canceled download or error occurred … … 114 166 return; // no data retrieved 115 167 if (dataSet.allPrimitives().isEmpty()) { 116 progressMonitor.setErrorMessage(tr("No data found in this area."));168 rememberErrorMessage(tr("No data found in this area.")); 117 169 // need to synthesize a download bounds lest the visual indication of downloaded 118 170 // area doesn't work … … 138 190 139 191 @Override protected void cancel() { 140 this.canceled = true;192 setCanceled(true); 141 193 if (reader != null) { 142 194 reader.cancel(); 143 195 } 144 DownloadOsmTask.this.setCanceled(true);145 }146 }147 private JCheckBox checkBox = new JCheckBox(tr("OpenStreetMap data"), true);148 149 private void rememberDownloadedData(DataSet ds) {150 this.downloadedData = ds;151 }152 153 public boolean isCanceled() {154 return canceled;155 }156 157 public void setCanceled(boolean canceled) {158 this.canceled = canceled;159 }160 161 public boolean isFailed() {162 return failed;163 }164 165 public void setFailed(boolean failed) {166 this.failed = failed;167 }168 169 public DataSet getDownloadedData() {170 return downloadedData;171 }172 173 public void download(DownloadAction action, double minlat, double minlon,174 double maxlat, double maxlon, ProgressMonitor progressMonitor) {175 // Swap min and max if user has specified them the wrong way round176 // (easy to do if you are crossing 0, for example)177 // FIXME should perhaps be done in download dialog?178 if (minlat > maxlat) {179 double t = minlat; minlat = maxlat; maxlat = t;180 }181 if (minlon > maxlon) {182 double t = minlon; minlon = maxlon; maxlon = t;183 }184 185 boolean newLayer = action != null186 && (action.dialog == null || action.dialog.newLayer.isSelected());187 188 Task t = new Task(newLayer,189 new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon), progressMonitor);190 currentBounds = new Bounds(new LatLon(minlat, minlon), new LatLon(maxlat, maxlon));191 // We need submit instead of execute so we can wait for it to finish and get the error192 // message if necessary. If no one calls getErrorMessage() it just behaves like execute.193 task = Main.worker.submit(t, t);194 }195 196 /**197 * Loads a given URL from the OSM Server198 * @param True if the data should be saved to a new layer199 * @param The URL as String200 */201 public void loadUrl(boolean new_layer, String url, ProgressMonitor progressMonitor) {202 Task t = new Task(new_layer,203 new OsmServerLocationReader(url),204 progressMonitor);205 currentBounds = new Bounds(new LatLon(0,0), new LatLon(0,0));206 task = Main.worker.submit(t, t);207 }208 209 public JCheckBox getCheckBox() {210 return checkBox;211 }212 213 public String getPreferencesSuffix() {214 return "osm";215 }216 217 /*218 * (non-Javadoc)219 * @see org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask#getErrorMessage()220 */221 public String getErrorMessage() {222 if(task == null)223 return "";224 225 try {226 Task t = task.get();227 return t.getProgressMonitor().getErrorMessage() == null228 ? ""229 : t.getProgressMonitor().getErrorMessage();230 } catch (Exception e) {231 return "";232 196 } 233 197 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskList.java
r2273 r2322 5 5 6 6 import java.awt.EventQueue; 7 import java.awt.event.ActionEvent; 8 import java.awt.event.ActionListener; 7 9 import java.awt.geom.Area; 8 10 import java.awt.geom.Rectangle2D; … … 10 12 import java.util.Collection; 11 13 import java.util.HashSet; 14 import java.util.LinkedHashSet; 12 15 import java.util.LinkedList; 13 16 import java.util.List; 14 17 import java.util.Set; 18 import java.util.concurrent.Future; 15 19 16 20 import javax.swing.JOptionPane; … … 20 24 import org.openstreetmap.josm.data.osm.DataSet; 21 25 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask;23 26 import org.openstreetmap.josm.gui.layer.Layer; 24 27 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 25 28 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 29 import org.openstreetmap.josm.gui.progress.ProgressMonitor.CancelListener; 30 import org.openstreetmap.josm.tools.ExceptionUtil; 26 31 27 32 /** … … 34 39 public class DownloadOsmTaskList implements Runnable { 35 40 private List<DownloadTask> osmTasks = new LinkedList<DownloadTask>(); 41 private List<Future<?>> osmTaskFutures = new LinkedList<Future<?>>(); 36 42 private ProgressMonitor progressMonitor; 37 43 … … 41 47 * @param The List of Rectangle2D to download 42 48 */ 43 public voiddownload(boolean newLayer, List<Rectangle2D> rects, ProgressMonitor progressMonitor) {49 public Future<?> download(boolean newLayer, List<Rectangle2D> rects, ProgressMonitor progressMonitor) { 44 50 this.progressMonitor = progressMonitor; 45 51 if(newLayer) { … … 50 56 51 57 progressMonitor.beginTask(null, rects.size()); 52 try { 53 int i = 0; 54 for(Rectangle2D td : rects) { 55 i++; 56 DownloadTask dt = new DownloadOsmTask(); 57 ProgressMonitor childProgress = progressMonitor.createSubTaskMonitor(1, false); 58 childProgress.setSilent(true); 59 childProgress.setCustomText(tr("Download {0} of {1} ({2} left)", i, rects.size(), rects.size()-i)); 60 dt.download(null, td.getMinY(), td.getMinX(), td.getMaxY(), td.getMaxX(), childProgress); 61 osmTasks.add(dt); 62 } 63 } finally { 64 // If we try to get the error message now the download task will never have been started 65 // and we'd be stuck in a classical dead lock. Instead attach this to the worker and once 66 // run() gets called all downloadTasks have finished and we can grab the error messages. 67 Main.worker.execute(this); 68 } 58 int i = 0; 59 for(Rectangle2D td : rects) { 60 i++; 61 DownloadTask dt = new DownloadOsmTask(); 62 ProgressMonitor childProgress = progressMonitor.createSubTaskMonitor(1, false); 63 childProgress.setSilent(true); 64 childProgress.setCustomText(tr("Download {0} of {1} ({2} left)", i, rects.size(), rects.size()-i)); 65 Future<?> future = dt.download(null, td.getMinY(), td.getMinX(), td.getMaxY(), td.getMaxX(), childProgress); 66 osmTaskFutures.add(future); 67 osmTasks.add(dt); 68 } 69 progressMonitor.addCancelListener( 70 new CancelListener() { 71 public void operationCanceled() { 72 for (DownloadTask dt: osmTasks) { 73 dt.cancel(); 74 } 75 } 76 } 77 ); 78 return Main.worker.submit(this); 69 79 } 70 80 … … 93 103 public void run() { 94 104 progressMonitor.finishTask(); 95 String errors = ""; 96 97 LinkedList<Integer> shown = new LinkedList<Integer>(); 105 106 // wait for all tasks to finish 107 // 108 for (Future<?> future: osmTaskFutures) { 109 try { 110 future.get(); 111 } catch(Exception e) { 112 e.printStackTrace(); 113 return; 114 } 115 } 116 LinkedHashSet<Object> errors = new LinkedHashSet<Object>(); 98 117 for(DownloadTask dt : osmTasks) { 99 String err = dt.getErrorMessage(); 100 // avoid display of identical messages 101 if (err.equals("") || shown.contains(err.hashCode())) { 102 continue; 103 } 104 shown.add(err.hashCode()); 105 errors += "<br>* " + err; 106 } 107 108 if(! errors.equals("")) { 118 errors.addAll(dt.getErrorObjects()); 119 } 120 if (!errors.isEmpty()) { 121 StringBuffer sb = new StringBuffer(); 122 for (Object error:errors) { 123 if (error instanceof String) { 124 sb.append("<li>").append(error).append("</li>").append("<br>"); 125 } else if (error instanceof Exception) { 126 sb.append("<li>").append(ExceptionUtil.explainException((Exception)error)).append("</li>").append("<br>"); 127 } 128 } 129 sb.insert(0, "<ul>"); 130 sb.append("</ul>"); 131 109 132 JOptionPane.showMessageDialog( 110 133 Main.parent, 111 "<html>"+tr("The following errors occurred during mass download: {0}", errors)134 "<html>"+tr("The following errors occurred during mass download: {0}", sb.toString()) 112 135 +"</html>", 113 136 tr("Errors during Download"), -
trunk/src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java
r2319 r2322 73 73 } 74 74 } 75 } catch (SAXException x) {76 x.printStackTrace();77 progressMonitor.setErrorMessage(tr("Error while parsing")+": "+x.getMessage());78 } catch (FileNotFoundException x) {79 x.printStackTrace();80 progressMonitor.setErrorMessage(tr("File not found")+": "+x.getMessage());81 } catch (IOException x) {82 x.printStackTrace();83 progressMonitor.setErrorMessage(x.getMessage());84 } catch(OsmTransferException x) {85 x.printStackTrace();86 if (x.getCause() != null) {87 progressMonitor.setErrorMessage(x.getCause().getMessage());88 } else {89 progressMonitor.setErrorMessage(x.getMessage());90 }91 75 } finally { 92 76 progressMonitor.finishTask(); … … 96 80 } 97 81 } 98 } catch (final Throwablee) {82 } catch (final Exception e) { 99 83 if (!ignoreException) { 100 84 // Exception has to thrown in EDT to be shown to user 101 85 SwingUtilities.invokeLater(new Runnable() { 102 86 public void run() { 103 throw new RuntimeException(e);87 ExceptionDialogUtil.explainException(e); 104 88 } 105 89 }); -
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r2215 r2322 27 27 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; 28 28 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 29 import org.openstreetmap.josm.actions.downloadtasks.DownloadTask; 29 30 import org.openstreetmap.josm.data.Bounds; 30 31 import org.openstreetmap.josm.gui.MapView; … … 46 47 public class DownloadDialog extends JPanel { 47 48 48 public interface DownloadTask {49 /**50 * Execute the download using the given bounding box. Set silent on progressMonitor51 * if no error messages should be popped up.52 */53 void download(DownloadAction action, double minlat, double minlon,54 double maxlat, double maxlon, ProgressMonitor progressMonitor);55 56 /**57 * Execute the download using the given URL58 * @param newLayer59 * @param url60 */61 void loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor);62 63 /**64 * @return The checkbox presented to the user65 */66 JCheckBox getCheckBox();67 68 /**69 * @return The name of the preferences suffix to use for storing the70 * selection state.71 */72 String getPreferencesSuffix();73 74 /**75 * Gets the error message of the task once it executed. If there is no error message, an empty76 * string is returned.77 *78 * WARNING: Never call this in the same thread you requested the download() or it will cause a79 * dead lock. See actions/downloadTasks/DownloadOsmTaskList.java for a proper implementation.80 *81 * @return Error message or empty String82 */83 String getErrorMessage();84 }85 86 49 /** 87 50 * The list of download tasks. First entry should be the osm data entry -
trunk/src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java
r2186 r2322 278 278 private final Collection<File> files; 279 279 private final GpxLayer gpxLayer; 280 private LinkedList<TimedPoint> gps; 281 280 282 public Loader(Collection<File> files, GpxLayer gpxLayer) { 281 283 super(tr("Images for {0}", gpxLayer.getName())); … … 286 288 progressMonitor.subTask(tr("Read GPX...")); 287 289 progressMonitor.setTicksCount(10 + files.size()); 288 LinkedList<TimedPoint>gps = new LinkedList<TimedPoint>();290 gps = new LinkedList<TimedPoint>(); 289 291 290 292 // Extract dates and locations from GPX input … … 322 324 323 325 324 if (gps.isEmpty()) { 325 progressMonitor.setErrorMessage(tr("No images with readable timestamps found.")); 326 if (gps.isEmpty()) 326 327 return; 327 }328 328 329 329 // read the image files … … 352 352 } 353 353 @Override protected void finish() { 354 if (gps.isEmpty()) { 355 JOptionPane.showMessageDialog( 356 Main.parent, 357 tr("No images with readable timestamps found."), 358 tr("Warning"), 359 JOptionPane.WARNING_MESSAGE 360 ); 361 return; 362 } 354 363 if (layer != null) { 355 364 Main.main.addLayer(layer); 356 365 } 357 366 } 367 358 368 @Override 359 369 protected void cancel() { -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r2151 r2322 29 29 import java.util.LinkedList; 30 30 import java.util.List; 31 import java.util.concurrent.Future; 31 32 32 33 import javax.swing.AbstractAction; … … 346 347 347 348 if (data.tracks.size() > 0) { 348 349 350 351 352 353 349 info.append("<table><thead align=\"center\"><tr><td colspan=\"5\">" 350 + trn("{0} track", "{0} tracks", data.tracks.size(), data.tracks.size()) 351 + "</td></tr><tr><td>" + tr("Name") + "</td><td>" 352 + tr("Description") + "</td><td>" + tr("Timespan") 353 + "</td><td>" + tr("Length") + "</td><td>" + tr("URL") 354 + "</td></tr></thead>"); 354 355 355 356 for (GpxTrack trk : data.tracks) { 356 WayPoint earliest = null, latest = null; 357 358 info.append("<tr><td>"); 359 if (trk.attr.containsKey("name")) 360 info.append(trk.attr.get("name")); 361 info.append("</td><td>"); 362 if (trk.attr.containsKey("desc")) 363 info.append(" ").append(trk.attr.get("desc")); 364 info.append("</td><td>"); 357 WayPoint earliest = null, latest = null; 358 359 info.append("<tr><td>"); 360 if (trk.attr.containsKey("name")) { 361 info.append(trk.attr.get("name")); 362 } 363 info.append("</td><td>"); 364 if (trk.attr.containsKey("desc")) { 365 info.append(" ").append(trk.attr.get("desc")); 366 } 367 info.append("</td><td>"); 365 368 366 369 for (Collection<WayPoint> seg : trk.trackSegs) { … … 378 381 } 379 382 380 if (earliest != null && latest != null) { 381 DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT); 382 info.append(df.format(new Date((long) (earliest.time * 1000))) + " - " 383 + df.format(new Date((long) (latest.time * 1000)))); 384 int diff = (int) (latest.time - earliest.time); 385 info.append(" (" + (diff / 3600) + ":" + ((diff % 3600) / 60) + ")"); 386 } 387 388 info.append("</td><td>"); 389 info.append(new DecimalFormat("#0.00").format(trk.length() / 1000) + "km"); 390 info.append("</td><td>"); 391 if (trk.attr.containsKey("url")) 392 info.append(trk.attr.get("url")); 393 info.append("</td></tr>"); 394 } 395 396 info.append("</table><br><br>"); 383 if (earliest != null && latest != null) { 384 DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT); 385 info.append(df.format(new Date((long) (earliest.time * 1000))) + " - " 386 + df.format(new Date((long) (latest.time * 1000)))); 387 int diff = (int) (latest.time - earliest.time); 388 info.append(" (" + (diff / 3600) + ":" + ((diff % 3600) / 60) + ")"); 389 } 390 391 info.append("</td><td>"); 392 info.append(new DecimalFormat("#0.00").format(trk.length() / 1000) + "km"); 393 info.append("</td><td>"); 394 if (trk.attr.containsKey("url")) { 395 info.append(trk.attr.get("url")); 396 } 397 info.append("</td></tr>"); 398 } 399 400 info.append("</table><br><br>"); 397 401 398 402 } … … 401 405 info.append("<br>"); 402 406 403 404 407 info.append(trn("{0} route, ", "{0} routes, ", data.routes.size(), data.routes.size())).append( 408 trn("{0} waypoint", "{0} waypoints", data.waypoints.size(), data.waypoints.size())).append("<br>"); 405 409 406 410 return info.append("</html>").toString(); … … 694 698 } // end for segment 695 699 } // end for trk 696 } // end if large || hdopcircle 700 } // end if large || hdopcircle 697 701 698 702 /**************************************************************** … … 939 943 } 940 944 } 941 new DownloadOsmTaskList().download(false, toDownload, new PleaseWaitProgressMonitor(tr("Download data"))); 945 final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Download data")); 946 final Future<?> future = new DownloadOsmTaskList().download(false, toDownload, monitor); 947 Main.worker.submit( 948 new Runnable() { 949 public void run() { 950 try { 951 future.get(); 952 } catch(Exception e) { 953 e.printStackTrace(); 954 return; 955 } 956 monitor.close(); 957 } 958 } 959 ); 942 960 } 943 961 } -
trunk/src/org/openstreetmap/josm/gui/progress/PleaseWaitProgressMonitor.java
r2319 r2322 16 16 import org.openstreetmap.josm.Main; 17 17 import org.openstreetmap.josm.gui.PleaseWaitDialog; 18 import static org.openstreetmap.josm.tools.I18n.tr; 18 19 19 20 -
trunk/src/org/openstreetmap/josm/gui/progress/ProgressMonitor.java
r2319 r2322 121 121 122 122 void setSilent(boolean value); 123 void setErrorMessage(String message);124 String getErrorMessage();125 123 126 124 /** -
trunk/src/org/openstreetmap/josm/io/OsmConnection.java
r2124 r2322 97 97 public void cancel() { 98 98 cancel = true; 99 if (activeConnection != null) { 100 activeConnection.setConnectTimeout(100); 101 activeConnection.setReadTimeout(100); 102 try { 103 Thread.sleep(100); 104 } catch (InterruptedException ex) {} 105 activeConnection.disconnect(); 99 synchronized (this) { 100 if (activeConnection != null) { 101 activeConnection.setConnectTimeout(100); 102 activeConnection.setReadTimeout(100); 103 } 104 } 105 try { 106 Thread.sleep(100); 107 } catch (InterruptedException ex) { 108 } 109 110 synchronized (this) { 111 if (activeConnection != null) { 112 activeConnection.disconnect(); 113 } 106 114 } 107 115 }
Note:
See TracChangeset
for help on using the changeset viewer.