Changeset 28108 in osm for applications/editors/josm
- Timestamp:
- 2012-03-18T00:20:41+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/mirrored_download
- Files:
-
- 2 deleted
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mirrored_download/build.xml
r28106 r28108 86 86 <attribute name="Plugin-Description" value="Simplifies download from different read-only APIs."/> 87 87 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/mirrored_download"/> 88 <attribute name="Plugin-Mainversion" value="50 89"/>88 <attribute name="Plugin-Mainversion" value="5097"/> 89 89 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 90 90 </manifest> -
applications/editors/josm/plugins/mirrored_download/src/mirrored_download/MirroredDownloadAction.java
r28106 r28108 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others1 // License: GPL. For details, see LICENSE file. 2 2 package mirrored_download; 3 3 … … 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 7 import java.awt.Component; 8 import java.awt.GridBagConstraints; 9 7 10 import java.awt.event.ActionEvent; 8 11 import java.awt.event.KeyEvent; 12 import java.util.LinkedList; 9 13 import java.util.concurrent.Future; 14 import java.util.regex.Pattern; 15 import javax.swing.JComboBox; 16 import javax.swing.JLabel; 17 import javax.swing.JPanel; 18 import javax.swing.text.JTextComponent; 10 19 11 20 import org.openstreetmap.josm.actions.JosmAction; 12 21 13 22 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.actions.downloadtasks.Download GpsTask;23 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 15 24 import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler; 16 25 import org.openstreetmap.josm.data.Bounds; 26 import org.openstreetmap.josm.data.osm.DataSet; 27 import org.openstreetmap.josm.data.osm.DataSource; 17 28 import org.openstreetmap.josm.gui.download.DownloadDialog; 29 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 30 import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator; 31 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 32 import org.openstreetmap.josm.io.BoundingBoxDownloader; 33 import org.openstreetmap.josm.io.OsmTransferException; 34 import org.openstreetmap.josm.tools.GBC; 18 35 import org.openstreetmap.josm.tools.Shortcut; 19 36 20 /** 21 * Action that opens a connection to the osm server and downloads map data. 22 * 23 * An dialog is displayed asking the user to specify a rectangle to grab. 24 * The url and account settings from the preferences are used. 25 * 26 * @author imi 27 */ 28 public class DownloadAction2 extends JosmAction { 29 public DownloadAction2() { 37 public class MirroredDownloadAction extends JosmAction { 38 39 static final String XAPI_QUERY_HISTORY_KEY = "plugin.mirrored_download.query-history"; 40 static final String XAPI_QUERY_TOOLTIP = tr("XAPI query, e.g., '''' (to download all data), ''[highway=*]'', or ''[[network=VRR][ref=603|613]''"); 41 42 public MirroredDownloadAction() { 30 43 super(tr("Download from OSM mirror..."), null, tr("Download map data from the OSM server."), 31 Shortcut.registerShortcut("mirror:download", tr("File: {0}", tr("Download from OSM mirror...")), KeyEvent.VK_DOWN, Shortcut.ALT_SHIFT), 32 true, "mirroreddownload/download", true); 44 Shortcut.registerShortcut("mirror:download", tr("File: {0}", tr("Download from OSM mirror...")), KeyEvent.VK_DOWN, Shortcut.ALT_SHIFT), 45 true, "mirroreddownload/download", true); 33 46 putValue("help", ht("/Action/MirroredDownload")); 34 47 } 35 48 49 @Override 36 50 public void actionPerformed(ActionEvent e) { 37 DownloadDialog dialog = DownloadDialog.getInstance(); 51 MirroredDownloadDialog dialog = MirroredDownloadDialog.getInstance(); 38 52 dialog.restoreSettings(); 39 53 dialog.setVisible(true); 40 if (! 54 if (!dialog.isCanceled()) { 41 55 dialog.rememberSettings(); 42 56 Bounds area = dialog.getSelectedDownloadArea(); 43 if (dialog.isDownloadOsmData()) { 44 DownloadOsmTask2 task = new DownloadOsmTask2(); 45 Future<?> future = task.download(dialog.isNewLayerRequired(), area, null); 46 Main.worker.submit(new PostDownloadHandler(task, future)); 57 DownloadOsmTask task = new DownloadOsmTask(); 58 Future<?> future = task.download( 59 new MirroredDownloadReader(area, dialog.getOverpassType(), dialog.getOverpassQuery()), 60 dialog.isNewLayerRequired(), area, null); 61 Main.worker.submit(new PostDownloadHandler(task, future)); 62 } 63 } 64 65 static class XAPIQueryValidator extends AbstractTextComponentValidator { 66 67 static final Pattern pattern = Pattern.compile("^(\\[([^=]+=[^=]*)\\])*$"); 68 69 public XAPIQueryValidator(JTextComponent tc) throws IllegalArgumentException { 70 super(tc); 71 } 72 73 @Override 74 public void validate() { 75 if (pattern.matcher(getComponent().getText().trim()).matches()) { 76 feedbackValid(XAPI_QUERY_TOOLTIP); 77 } else { 78 feedbackInvalid(tr("This XAPI query seems to be invalid, please doublecheck")); 47 79 } 48 if (dialog.isDownloadGpxData()) { 49 DownloadGpsTask task = new DownloadGpsTask(); 50 Future<?> future = task.download(dialog.isNewLayerRequired(),area, null); 51 Main.worker.submit(new PostDownloadHandler(task, future)); 80 } 81 82 @Override 83 public boolean isValid() { 84 return pattern.matcher(getComponent().getText().trim()).matches(); 85 } 86 } 87 88 static class MirroredDownloadDialog extends DownloadDialog { 89 90 protected JComboBox<String> overpassType; 91 protected HistoryComboBox overpassQuery; 92 private static MirroredDownloadDialog instance; 93 94 private MirroredDownloadDialog(Component parent) { 95 super(parent); 96 cbDownloadOsmData.setEnabled(false); 97 cbDownloadGpxData.setEnabled(false); 98 cbStartup.setEnabled(false); 99 } 100 101 static public MirroredDownloadDialog getInstance() { 102 if (instance == null) { 103 instance = new MirroredDownloadDialog(Main.parent); 52 104 } 105 return instance; 106 } 107 108 @Override 109 protected void buildMainPanelAboveDownloadSelections(JPanel pnl) { 110 overpassType = new JComboBox<String>(new String[]{"*", "node", "way", "relation"}); 111 pnl.add(new JLabel(tr("Object type: ")), GBC.std().insets(5, 5, 5, 5)); 112 pnl.add(overpassType, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 113 overpassType.setToolTipText(tr("OSM object type to download (''*'' stands for any)")); 114 overpassQuery = new HistoryComboBox(); 115 pnl.add(new JLabel(tr("XAPI query: ")), GBC.std().insets(5, 5, 5, 5)); 116 new XAPIQueryValidator((JTextComponent) overpassQuery.getEditor().getEditorComponent()); 117 pnl.add(overpassQuery, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 118 overpassQuery.setToolTipText(XAPI_QUERY_TOOLTIP); 119 } 120 121 public String getOverpassQuery() { 122 return overpassQuery.getText(); 123 } 124 125 public String getOverpassType() { 126 return overpassType.getItemAt(overpassType.getSelectedIndex()); 127 } 128 129 @Override 130 public void restoreSettings() { 131 super.restoreSettings(); 132 overpassQuery.setPossibleItems( 133 Main.pref.getCollection(XAPI_QUERY_HISTORY_KEY, new LinkedList<String>())); 134 } 135 136 @Override 137 public void rememberSettings() { 138 super.rememberSettings(); 139 overpassQuery.addCurrentItemToHistory(); 140 Main.pref.putCollection(XAPI_QUERY_HISTORY_KEY, overpassQuery.getHistory()); 141 } 142 } 143 144 static class MirroredDownloadReader extends BoundingBoxDownloader { 145 146 final String overpassType; 147 final String overpassQuery; 148 149 public MirroredDownloadReader(Bounds downloadArea, String overpassType, String overpassQuery) { 150 super(downloadArea); 151 this.overpassType = overpassType; 152 this.overpassQuery = overpassQuery.trim(); 153 } 154 155 @Override 156 protected String getBaseUrl() { 157 return MirroredDownloadPlugin.getDownloadUrl(); 158 } 159 160 @Override 161 protected String getRequestForBbox(double lon1, double lat1, double lon2, double lat2) { 162 return overpassQuery.isEmpty() && "*".equals(overpassType) 163 ? super.getRequestForBbox(lon1, lat1, lon2, lat2) 164 : overpassType + "[bbox=" + lon1 + "," + lat1 + "," + lon2 + "," + lat2 + "][@meta]" + overpassQuery; 165 } 166 167 @Override 168 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 169 170 DataSet ds = super.parseOsm(progressMonitor); 171 172 // add bounds if necessary (note that Overpass API does not return bounds in the response XML) 173 if (ds != null && ds.dataSources.isEmpty()) { 174 if (crosses180th) { 175 Bounds bounds = new Bounds(lat1, lon1, lat2, 180.0); 176 DataSource src = new DataSource(bounds, MirroredDownloadPlugin.getDownloadUrl()); 177 ds.dataSources.add(src); 178 179 bounds = new Bounds(lat1, -180.0, lat2, lon2); 180 src = new DataSource(bounds, MirroredDownloadPlugin.getDownloadUrl()); 181 ds.dataSources.add(src); 182 } else { 183 Bounds bounds = new Bounds(lat1, lon1, lat2, lon2); 184 DataSource src = new DataSource(bounds, MirroredDownloadPlugin.getDownloadUrl()); 185 ds.dataSources.add(src); 186 } 187 } 188 189 return ds; 53 190 } 54 191 } -
applications/editors/josm/plugins/mirrored_download/src/mirrored_download/MirroredDownloadPlugin.java
r28106 r28108 1 // License: GPL. For details, see LICENSE file. 1 2 package mirrored_download; 2 3 import javax.swing.JMenu;4 3 5 4 import org.openstreetmap.josm.Main; … … 10 9 public class MirroredDownloadPlugin extends Plugin { 11 10 12 static JMenu jMenu;13 14 11 public MirroredDownloadPlugin(PluginInformation info) { 15 12 super(info); 16 MainMenu.addAfter(Main.main.menu.fileMenu, new DownloadAction 2(), false, Main.main.menu.download);13 MainMenu.addAfter(Main.main.menu.fileMenu, new MirroredDownloadAction(), false, Main.main.menu.download); 17 14 MainMenu.add(Main.main.menu.editMenu, new UrlSelectionAction()); 18 15 } -
applications/editors/josm/plugins/mirrored_download/src/mirrored_download/UrlSelectionAction.java
r28106 r28108 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others1 // License: GPL. For details, see LICENSE file. 2 2 package mirrored_download; 3 3 -
applications/editors/josm/plugins/mirrored_download/src/mirrored_download/UrlSelectionDialog.java
r27729 r28108 1 // License: GPL. For details, see LICENSE file. 1 2 package mirrored_download; 2 3
Note:
See TracChangeset
for help on using the changeset viewer.