Changeset 7092 in josm
- Timestamp:
- 2014-05-10T02:51:06+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ChildRelationBrowser.java
r7005 r7092 50 50 /** 51 51 * ChildRelationBrowser is a UI component which provides a tree-like view on the hierarchical 52 * structure of relations 52 * structure of relations. 53 53 * 54 * 54 * @since 1828 55 55 */ 56 56 public class ChildRelationBrowser extends JPanel { … … 278 278 } 279 279 280 /** 281 * The asynchronous task for downloading relation members. 282 * 283 * 284 */ 285 class DownloadAllChildrenTask extends PleaseWaitRunnable { 286 private boolean canceled; 287 private int conflictsCount; 288 private Exception lastException; 289 private Relation relation; 290 private Stack<Relation> relationsToDownload; 291 private Set<Long> downloadedRelationIds; 292 293 public DownloadAllChildrenTask(Dialog parent, Relation r) { 294 super(tr("Download relation members"), new PleaseWaitProgressMonitor(parent), false /* 295 * don't 296 * ignore 297 * exception 298 */); 299 this.relation = r; 300 relationsToDownload = new Stack<>(); 301 downloadedRelationIds = new HashSet<>(); 302 relationsToDownload.push(this.relation); 280 abstract class DownloadTask extends PleaseWaitRunnable { 281 protected boolean canceled; 282 protected int conflictsCount; 283 protected Exception lastException; 284 285 public DownloadTask(String title, Dialog parent) { 286 super(title, new PleaseWaitProgressMonitor(parent), false); 303 287 } 304 288 … … 337 321 ); 338 322 } 323 } 324 } 325 326 /** 327 * The asynchronous task for downloading relation members. 328 */ 329 class DownloadAllChildrenTask extends DownloadTask { 330 private final Relation relation; 331 private final Stack<Relation> relationsToDownload; 332 private final Set<Long> downloadedRelationIds; 333 334 public DownloadAllChildrenTask(Dialog parent, Relation r) { 335 super(tr("Download relation members"), parent); 336 this.relation = r; 337 relationsToDownload = new Stack<>(); 338 downloadedRelationIds = new HashSet<>(); 339 relationsToDownload.push(this.relation); 339 340 } 340 341 … … 439 440 * The asynchronous task for downloading a set of relations 440 441 */ 441 class DownloadRelationSetTask extends PleaseWaitRunnable { 442 private boolean canceled; 443 private int conflictsCount; 444 private Exception lastException; 445 private Set<Relation> relations; 442 class DownloadRelationSetTask extends DownloadTask { 443 private final Set<Relation> relations; 446 444 447 445 public DownloadRelationSetTask(Dialog parent, Set<Relation> relations) { 448 super(tr("Download relation members"), new PleaseWaitProgressMonitor(parent), false /* 449 * don't 450 * ignore 451 * exception 452 */); 446 super(tr("Download relation members"), parent); 453 447 this.relations = relations; 454 }455 456 @Override457 protected void cancel() {458 canceled = true;459 OsmApi.getOsmApi().cancel();460 }461 462 protected void refreshView(Relation relation){463 for (int i=0; i < childTree.getRowCount(); i++) {464 Relation reference = (Relation)childTree.getPathForRow(i).getLastPathComponent();465 if (reference == relation) {466 model.refreshNode(childTree.getPathForRow(i));467 }468 }469 }470 471 @Override472 protected void finish() {473 if (canceled)474 return;475 if (lastException != null) {476 ExceptionDialogUtil.explainException(lastException);477 return;478 }479 480 if (conflictsCount > 0) {481 JOptionPane.showMessageDialog(482 Main.parent,483 trn("There was {0} conflict during import.",484 "There were {0} conflicts during import.",485 conflictsCount, conflictsCount),486 trn("Conflict in data", "Conflicts in data", conflictsCount),487 JOptionPane.WARNING_MESSAGE488 );489 }490 448 } 491 449 -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
r7083 r7092 698 698 } 699 699 700 private static void prepareFileChooser(String url, JFileChooser fc) { 701 if (url == null || url.trim().length() == 0) return; 702 URL sourceUrl = null; 703 try { 704 sourceUrl = new URL(url); 705 } catch(MalformedURLException e) { 706 File f = new File(url); 707 if (f.isFile()) { 708 f = f.getParentFile(); 709 } 710 if (f != null) { 711 fc.setCurrentDirectory(f); 712 } 713 return; 714 } 715 if (sourceUrl.getProtocol().startsWith("file")) { 716 File f = new File(sourceUrl.getPath()); 717 if (f.isFile()) { 718 f = f.getParentFile(); 719 } 720 if (f != null) { 721 fc.setCurrentDirectory(f); 722 } 723 } 724 } 725 700 726 protected class EditSourceEntryDialog extends ExtendedDialog { 701 727 … … 765 791 putValue(SMALL_ICON, ImageProvider.get("open")); 766 792 putValue(SHORT_DESCRIPTION, tr("Launch a file chooser to select a file")); 767 }768 769 protected void prepareFileChooser(String url, JFileChooser fc) {770 if (url == null || url.trim().length() == 0) return;771 URL sourceUrl = null;772 try {773 sourceUrl = new URL(url);774 } catch(MalformedURLException e) {775 File f = new File(url);776 if (f.isFile()) {777 f = f.getParentFile();778 }779 if (f != null) {780 fc.setCurrentDirectory(f);781 }782 return;783 }784 if (sourceUrl.getProtocol().startsWith("file")) {785 File f = new File(sourceUrl.getPath());786 if (f.isFile()) {787 f = f.getParentFile();788 }789 if (f != null) {790 fc.setCurrentDirectory(f);791 }792 }793 793 } 794 794 … … 1501 1501 } 1502 1502 1503 protected void prepareFileChooser(String url, JFileChooser fc) {1504 if (url == null || url.trim().length() == 0) return;1505 URL sourceUrl = null;1506 try {1507 sourceUrl = new URL(url);1508 } catch(MalformedURLException e) {1509 File f = new File(url);1510 if (f.isFile()) {1511 f = f.getParentFile();1512 }1513 if (f != null) {1514 fc.setCurrentDirectory(f);1515 }1516 return;1517 }1518 if (sourceUrl.getProtocol().startsWith("file")) {1519 File f = new File(sourceUrl.getPath());1520 if (f.isFile()) {1521 f = f.getParentFile();1522 }1523 if (f != null) {1524 fc.setCurrentDirectory(f);1525 }1526 }1527 }1528 1529 1503 @Override 1530 1504 public void actionPerformed(ActionEvent e) { -
trunk/src/org/openstreetmap/josm/io/OsmServerBackreferenceReader.java
r7050 r7092 22 22 * OsmServerBackreferenceReader fetches the primitives from the OSM server which 23 23 * refer to a specific primitive. For a {@link org.openstreetmap.josm.data.osm.Node Node}, ways and relations are retrieved 24 * which refer to the node. For a {@link Way} or a {@link Relation}, only relations are 25 * read. 24 * which refer to the node. For a {@link Way} or a {@link Relation}, only relations are read. 26 25 * 27 26 * OsmServerBackreferenceReader uses the API calls <code>[node|way|relation]/#id/relations</code> … … 32 31 * to complete incomplete primitives. 33 32 * 34 * 33 * @since 1806 35 34 */ 36 35 public class OsmServerBackreferenceReader extends OsmServerReader { … … 123 122 } 124 123 125 /** 126 * Reads referring ways from the API server and replies them in a {@link DataSet} 127 * 128 * @return the data set 129 * @throws OsmTransferException 130 */ 131 protected DataSet getReferringWays(ProgressMonitor progressMonitor) throws OsmTransferException { 124 private DataSet getReferringPrimitives(ProgressMonitor progressMonitor, String type, String message) throws OsmTransferException { 132 125 progressMonitor.beginTask(null, 2); 133 126 try { 134 progressMonitor. indeterminateSubTask(tr("Downloading fromOSM Server..."));127 progressMonitor.subTask(tr("Contacting OSM Server...")); 135 128 StringBuilder sb = new StringBuilder(); 136 sb.append(primitiveType.getAPIName()) 137 .append("/").append(id).append("/ways"); 129 sb.append(primitiveType.getAPIName()).append("/").append(id).append(type); 138 130 139 131 try (InputStream in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true))) { 140 132 if (in == null) 141 133 return null; 142 progressMonitor.subTask( tr("Downloading referring ways ..."));134 progressMonitor.subTask(message); 143 135 return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, true)); 144 136 } … … 156 148 157 149 /** 150 * Reads referring ways from the API server and replies them in a {@link DataSet} 151 * 152 * @return the data set 153 * @throws OsmTransferException 154 */ 155 protected DataSet getReferringWays(ProgressMonitor progressMonitor) throws OsmTransferException { 156 return getReferringPrimitives(progressMonitor, "/ways", tr("Downloading referring ways ...")); 157 } 158 159 /** 158 160 * Reads referring relations from the API server and replies them in a {@link DataSet} 159 161 * … … 163 165 */ 164 166 protected DataSet getReferringRelations(ProgressMonitor progressMonitor) throws OsmTransferException { 165 progressMonitor.beginTask(null, 2); 166 try { 167 progressMonitor.subTask(tr("Contacting OSM Server...")); 168 StringBuilder sb = new StringBuilder(); 169 sb.append(primitiveType.getAPIName()) 170 .append("/").append(id).append("/relations"); 171 172 try (InputStream in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true))) { 173 if (in == null) 174 return null; 175 progressMonitor.subTask(tr("Downloading referring relations ...")); 176 return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, true)); 177 } 178 } catch(OsmTransferException e) { 179 throw e; 180 } catch (Exception e) { 181 if (cancel) 182 return null; 183 throw new OsmTransferException(e); 184 } finally { 185 progressMonitor.finishTask(); 186 activeConnection = null; 187 } 167 return getReferringPrimitives(progressMonitor, "/relations", tr("Downloading referring relations ...")); 188 168 } 189 169
Note:
See TracChangeset
for help on using the changeset viewer.