Ignore:
Timestamp:
2009-10-25T23:09:53+01:00 (16 years ago)
Author:
Gubaer
Message:

Added canceling of DownloadOsmTaskLists
Removed error remembering in the progress dialog

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java

    r2319 r2322  
    7373                    }
    7474                }
    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                 }
    9175            } finally {
    9276                progressMonitor.finishTask();
     
    9680                }
    9781            }
    98         } catch (final Throwable e) {
     82        } catch (final Exception e) {
    9983            if (!ignoreException) {
    10084                // Exception has to thrown in EDT to be shown to user
    10185                SwingUtilities.invokeLater(new Runnable() {
    10286                    public void run() {
    103                         throw new RuntimeException(e);
     87                        ExceptionDialogUtil.explainException(e);
    10488                    }
    10589                });
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java

    r2215 r2322  
    2727import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;
    2828import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
     29import org.openstreetmap.josm.actions.downloadtasks.DownloadTask;
    2930import org.openstreetmap.josm.data.Bounds;
    3031import org.openstreetmap.josm.gui.MapView;
     
    4647public class DownloadDialog extends JPanel {
    4748
    48     public interface DownloadTask {
    49         /**
    50          * Execute the download using the given bounding box. Set silent on progressMonitor
    51          * 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 URL
    58          * @param newLayer
    59          * @param url
    60          */
    61         void loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor);
    62 
    63         /**
    64          * @return The checkbox presented to the user
    65          */
    66         JCheckBox getCheckBox();
    67 
    68         /**
    69          * @return The name of the preferences suffix to use for storing the
    70          * 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 empty
    76          * string is returned.
    77          *
    78          * WARNING: Never call this in the same thread you requested the download() or it will cause a
    79          * dead lock. See actions/downloadTasks/DownloadOsmTaskList.java for a proper implementation.
    80          *
    81          * @return Error message or empty String
    82          */
    83         String getErrorMessage();
    84     }
    85 
    8649    /**
    8750     * The list of download tasks. First entry should be the osm data entry
  • trunk/src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java

    r2186 r2322  
    278278        private final Collection<File> files;
    279279        private final GpxLayer gpxLayer;
     280        private LinkedList<TimedPoint> gps;
     281
    280282        public Loader(Collection<File> files, GpxLayer gpxLayer) {
    281283            super(tr("Images for {0}", gpxLayer.getName()));
     
    286288            progressMonitor.subTask(tr("Read GPX..."));
    287289            progressMonitor.setTicksCount(10 + files.size());
    288             LinkedList<TimedPoint> gps = new LinkedList<TimedPoint>();
     290            gps = new LinkedList<TimedPoint>();
    289291
    290292            // Extract dates and locations from GPX input
     
    322324
    323325
    324             if (gps.isEmpty()) {
    325                 progressMonitor.setErrorMessage(tr("No images with readable timestamps found."));
     326            if (gps.isEmpty())
    326327                return;
    327             }
    328328
    329329            // read the image files
     
    352352        }
    353353        @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            }
    354363            if (layer != null) {
    355364                Main.main.addLayer(layer);
    356365            }
    357366        }
     367
    358368        @Override
    359369        protected void cancel() {
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r2151 r2322  
    2929import java.util.LinkedList;
    3030import java.util.List;
     31import java.util.concurrent.Future;
    3132
    3233import javax.swing.AbstractAction;
     
    346347
    347348        if (data.tracks.size() > 0) {
    348             info.append("<table><thead align=\"center\"><tr><td colspan=\"5\">"
    349                 + trn("{0} track", "{0} tracks", data.tracks.size(), data.tracks.size())
    350                 + "</td></tr><tr><td>" + tr("Name") + "</td><td>"
    351                 + tr("Description") + "</td><td>" + tr("Timespan")
    352                 + "</td><td>" + tr("Length") + "</td><td>" + tr("URL")
    353                 + "</td></tr></thead>");
     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>");
    354355
    355356            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>");
    365368
    366369                for (Collection<WayPoint> seg : trk.trackSegs) {
     
    378381                }
    379382
    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>");
    397401
    398402        }
     
    401405        info.append("<br>");
    402406
    403         info.append(trn("{0} route, ", "{0} routes, ", data.routes.size(), data.routes.size())).append(
    404                         trn("{0} waypoint", "{0} waypoints", data.waypoints.size(), data.waypoints.size())).append("<br>");
     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>");
    405409
    406410        return info.append("</html>").toString();
     
    694698                } // end for segment
    695699            } // end for trk
    696         } // end if large || hdopcircle 
     700        } // end if large || hdopcircle
    697701
    698702        /****************************************************************
     
    939943                }
    940944            }
    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            );
    942960        }
    943961    }
  • trunk/src/org/openstreetmap/josm/gui/progress/PleaseWaitProgressMonitor.java

    r2319 r2322  
    1616import org.openstreetmap.josm.Main;
    1717import org.openstreetmap.josm.gui.PleaseWaitDialog;
     18import static org.openstreetmap.josm.tools.I18n.tr;
    1819
    1920
  • trunk/src/org/openstreetmap/josm/gui/progress/ProgressMonitor.java

    r2319 r2322  
    121121
    122122    void setSilent(boolean value);
    123     void setErrorMessage(String message);
    124     String getErrorMessage();
    125123
    126124    /**
Note: See TracChangeset for help on using the changeset viewer.