Changeset 6031 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2013-06-26T21:04:53+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java
r5772 r6031 33 33 import org.openstreetmap.josm.gui.ExtendedDialog; 34 34 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 35 import org.openstreetmap.josm.gui.util.GuiHelper; 35 36 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 36 37 import org.openstreetmap.josm.tools.Shortcut; … … 148 149 149 150 /** 151 * Summarizes acceptable urls for error message purposes. 152 * @since 6030 153 */ 154 public String findSummaryDocumentation() { 155 String result = ""; 156 for (int i = 0; i < downloadTasks.size(); i++) { 157 Class<? extends DownloadTask> taskClass = downloadTasks.get(i); 158 if (taskClass != null) { 159 try { 160 DownloadTask task = taskClass.getConstructor().newInstance(); 161 result += "<br/>" + task.acceptsDocumentationSummary(); 162 } catch (Exception e) { 163 e.printStackTrace(); 164 } 165 } 166 } 167 return result; 168 } 169 170 /** 150 171 * Open the given URL. 151 172 * @param new_layer true if the URL needs to be opened in a new layer, false otherwise … … 164 185 Main.worker.submit(new PostDownloadHandler(task, future)); 165 186 } else { 187 final String details = findSummaryDocumentation(); // Explain what patterns are supported 166 188 SwingUtilities.invokeLater(new Runnable() { 189 @Override 167 190 public void run() { 168 191 JOptionPane.showMessageDialog(Main.parent, tr( 169 "<html> Cannot open URL ''{0}'' because no suitable download task is available.</html>",170 url ), tr("Download Location"), JOptionPane.ERROR_MESSAGE);192 "<html><p>Cannot open URL ''{0}''<br/>The following load tasks accept the URL patterns shown:<br/>{1}</p></html>", 193 url, details), tr("Download Location"), JOptionPane.ERROR_MESSAGE); 171 194 } 172 195 }); -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/AbstractDownloadTask.java
r3083 r6031 4 4 import java.util.ArrayList; 5 5 import java.util.List; 6 import org.openstreetmap.josm.io.XmlWriter; 6 7 7 8 public abstract class AbstractDownloadTask implements DownloadTask { … … 38 39 } 39 40 41 @Override 40 42 public List<Object> getErrorObjects() { 41 43 return errorMessages; 42 44 } 45 46 @Override 47 public String acceptsDocumentationSummary() { 48 StringBuilder buf = new StringBuilder(); 49 buf.append(getTitle()); 50 String patterns[] = getPatterns(); 51 if (patterns.length>0) { 52 buf.append(":<br/><ul>"); 53 for (String pattern: patterns) { 54 buf.append("<li>"); 55 buf.append(XmlWriter.encode(pattern)); 56 } 57 buf.append("</ul>"); 58 } 59 return buf.toString(); 60 } 61 62 // Can be overridden for more complex checking logic 63 @Override 64 public boolean acceptsUrl(String url) { 65 if (url==null) return false; 66 for (String p: getPatterns()) { 67 if (url.matches(p)) { 68 return true; 69 } 70 } 71 return false; 72 } 73 74 // Default name to keep old plugins compatible 75 @Override 76 public String getTitle() { 77 return getClass().getName(); 78 } 79 80 // Default pattern to keep old plugins compatible 81 @Override 82 public String[] getPatterns() { 83 return new String[]{}; 84 } 85 43 86 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r5745 r6031 45 45 protected String newLayerName = null; 46 46 47 @Override 48 public String[] getPatterns() { 49 return new String[] {PATTERN_EXTERNAL_GPX_FILE, PATTERN_EXTERNAL_GPX_SCRIPT, PATTERN_TRACE_ID, PATTERN_TRACKPOINTS_BBOX}; 50 } 51 52 @Override 53 public String getTitle() { 54 return tr("Download GPS"); 55 } 56 57 @Override 47 58 public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) { 48 59 downloadTask = new DownloadTask(newLayer, … … 53 64 } 54 65 66 @Override 55 67 public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) { 56 68 if (url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_EXTERNAL_GPX_SCRIPT) || url.matches(PATTERN_EXTERNAL_GPX_FILE))) { … … 74 86 } 75 87 76 /* (non-Javadoc) 77 * @see org.openstreetmap.josm.actions.downloadtasks.DownloadTask#acceptsUrl(java.lang.String) 78 */ 79 @Override 80 public boolean acceptsUrl(String url) { 81 return url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_TRACKPOINTS_BBOX) 82 || url.matches(PATTERN_EXTERNAL_GPX_SCRIPT) || url.matches(PATTERN_EXTERNAL_GPX_FILE)); 83 } 84 88 @Override 85 89 public void cancel() { 86 90 if (downloadTask != null) { -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeCompressedTask.java
r5909 r6031 3 3 4 4 import java.util.concurrent.Future; 5 6 import static org.openstreetmap.josm.tools.I18n.tr; 5 7 6 8 import org.openstreetmap.josm.Main; … … 11 13 12 14 public class DownloadOsmChangeCompressedTask extends DownloadOsmChangeTask { 15 16 @Override 17 public String[] getPatterns() { 18 return new String[]{"https?://.*/.*\\.osc.(gz|bz2?)"}; 19 } 20 21 @Override 22 public String getTitle() { 23 return tr("Download Compressed OSM Change"); 24 } 13 25 14 /* (non-Javadoc)15 * @see org.openstreetmap.josm.actions.downloadtasks.DownloadTask#acceptsUrl(java.lang.String)16 */17 @Override18 public boolean acceptsUrl(String url) {19 return url != null && url.matches("https?://.*/.*\\.osc.(gz|bz2?)"); // Remote .osc.gz / .osc.bz / .osc.bz2 files20 }21 22 26 /** 23 27 * Loads a given URL … … 26 30 * @param progressMonitor progress monitor for user interaction 27 31 */ 32 @Override 28 33 public Future<?> loadUrl(boolean new_layer, final String url, ProgressMonitor progressMonitor) { 29 34 downloadTask = new DownloadTask(new_layer, new OsmServerLocationReader(url), progressMonitor) { -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java
r5927 r6031 8 8 import java.util.Map; 9 9 import java.util.concurrent.Future; 10 11 import static org.openstreetmap.josm.tools.I18n.tr; 10 12 11 13 import org.openstreetmap.josm.Main; … … 41 43 42 44 @Override 43 public boolean acceptsUrl(String url) { 44 return url != null && ( 45 url.matches("http://.*/api/0.6/changeset/\\p{Digit}+/download") // OSM API 0.6 changesets 46 || url.matches("https?://.*/.*\\.osc") // Remote .osc files 47 ); 48 } 49 45 public String[] getPatterns() { 46 return new String[]{"http://.*/api/0.6/changeset/\\p{Digit}+/download", // OSM API 0.6 changesets 47 "https?://.*/.*\\.osc" // Remote .osc files 48 }; 49 } 50 51 @Override 52 public String getTitle() { 53 return tr("Download OSM Change"); 54 } 55 50 56 /* (non-Javadoc) 51 57 * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask#download(boolean, org.openstreetmap.josm.data.Bounds, org.openstreetmap.josm.gui.progress.ProgressMonitor) -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmCompressedTask.java
r5909 r6031 3 3 4 4 import java.util.concurrent.Future; 5 6 import static org.openstreetmap.josm.tools.I18n.tr; 5 7 6 8 import org.openstreetmap.josm.Main; … … 12 14 13 15 public class DownloadOsmCompressedTask extends DownloadOsmTask { 14 15 /* (non-Javadoc) 16 * @see org.openstreetmap.josm.actions.downloadtasks.DownloadTask#acceptsUrl(java.lang.String) 17 */ 16 17 String PATTERN_GZ = "https?://.*/.*\\.osm.(gz|bz2?)"; 18 18 19 @Override 19 public boolean acceptsUrl(String url) { 20 return url != null && url.matches("https?://.*/.*\\.osm.(gz|bz2?)"); // Remote .osm.gz / .osm.bz / .osm.bz2 files 20 public String[] getPatterns() { 21 return new String[]{PATTERN_GZ}; 22 } 23 24 @Override 25 public String getTitle() { 26 return tr("Download Compressed OSM"); 21 27 } 22 28 … … 36 42 * @param progressMonitor progress monitor for user interaction 37 43 */ 44 @Override 38 45 public Future<?> loadUrl(boolean new_layer, final String url, ProgressMonitor progressMonitor) { 39 46 downloadTask = new DownloadTask(new_layer, new OsmServerLocationReader(url), progressMonitor) { -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r5782 r6031 49 49 50 50 protected String newLayerName = null; 51 52 @Override 53 public String[] getPatterns() { 54 if (this.getClass() == DownloadOsmTask.class) { 55 return new String[]{PATTERN_OSM_API_URL, PATTERN_OVERPASS_API_URL, 56 PATTERN_OVERPASS_API_XAPI_URL, PATTERN_EXTERNAL_OSM_FILE}; 57 } else { 58 return super.getPatterns(); 59 } 60 } 61 62 @Override 63 public String getTitle() { 64 if (this.getClass() == DownloadOsmTask.class) { 65 return tr("Download OSM"); 66 } else { 67 return super.getTitle(); 68 } 69 } 51 70 52 71 protected void rememberDownloadedData(DataSet ds) { … … 136 155 * @param url The URL as String 137 156 */ 157 @Override 138 158 public Future<?> loadUrl(boolean new_layer, String url, ProgressMonitor progressMonitor) { 139 159 if (url.matches(PATTERN_OVERPASS_API_URL)) { … … 156 176 newLayerName = matcher.matches() ? matcher.group(1) : null; 157 177 } 158 159 /* (non-Javadoc) 160 * @see org.openstreetmap.josm.actions.downloadtasks.DownloadTask#acceptsUrl(java.lang.String) 161 */ 162 @Override 163 public boolean acceptsUrl(String url) { 164 return url != null && ( 165 url.matches(PATTERN_OSM_API_URL) // OSM API 0.6 and XAPI 166 || url.matches(PATTERN_OVERPASS_API_URL) // Overpass API 167 || url.matches(PATTERN_OVERPASS_API_XAPI_URL) // Overpass API XAPI compatibility layer 168 || url.matches(PATTERN_EXTERNAL_OSM_FILE) // Remote .osm files 169 ); 170 } 171 178 179 @Override 172 180 public void cancel() { 173 181 if (downloadTask != null) { -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmUrlTask.java
r5011 r6031 3 3 4 4 import java.util.concurrent.Future; 5 6 import static org.openstreetmap.josm.tools.I18n.tr; 5 7 6 8 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 13 15 return download(newLayer, OsmUrlToBounds.parse(url), null); 14 16 } 17 18 @Override 19 public String[] getPatterns() { 20 return new String[]{"http://www\\.openstreetmap\\.org/\\?lat=.*&lon=.*"}; 21 } 15 22 16 23 @Override 17 public boolean acceptsUrl(String url) { 18 return url != null && ( 19 url.matches("http://www\\.openstreetmap\\.org/\\?lat=.*&lon=.*") 20 ); 24 public String getTitle() { 25 return tr("Download OSM URL"); 21 26 } 22 27 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTask.java
r5691 r6031 80 80 81 81 /** 82 * Returns a short html documentation string, describing acceptable URLs. 83 */ 84 String acceptsDocumentationSummary(); 85 86 /** 87 * Returns human-readable description of the task 88 */ 89 String getTitle(); 90 91 /** 92 * Returns regular expression that match the URLs 93 */ 94 String[] getPatterns(); 95 96 /** 82 97 * Replies the error objects of the task. Empty list, if no error messages are available. 83 98 *
Note:
See TracChangeset
for help on using the changeset viewer.