Changeset 29776 in osm for applications/editors/josm/plugins
- Timestamp:
- 2013-07-25T03:26:37+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/DirectDownload
- Files:
-
- 4 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/DirectDownload/README
r23585 r29776 7 7 track using the "Open file ..." dialog. 8 8 9 The plugin provides a new entry "Download track ..." in the file9 The plugin provides a new entry "Download track ..." in the GPS 10 10 menu (no keyboard shortcut yet). This opens a dialog that will 11 11 present a list of your uploaded tracks, showing the tracks timestamp -
applications/editors/josm/plugins/DirectDownload/build.xml
r29435 r29776 1 1 <?xml version="1.0" encoding="utf-8"?> 2 <!--3 ** This is a template build file for a JOSM plugin.4 **5 ** Maintaining versions6 ** ====================7 ** see README.template8 **9 ** Usage10 ** =====11 ** To build it run12 **13 ** > ant dist14 **15 ** To install the generated plugin locally (in you default plugin directory) run16 **17 ** > ant install18 **19 ** The generated plugin jar is not automatically available in JOSMs plugin configuration20 ** dialog. You have to check it in first.21 **22 ** Use the ant target 'publish' to check in the plugin and make it available to other23 ** JOSM users:24 ** set the properties commit.message and plugin.main.version25 ** and run26 ** > ant publish27 **28 **29 -->30 2 <project name="DirectDownload" default="dist" basedir="."> 31 3 <!-- enter the SVN commit message --> 32 4 <property name="commit.message" value="Commit message"/> 33 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 34 <property name="plugin.main.version" value="5679"/> 35 <!-- 36 ************************************************ 37 ** should not be necessary to change the following properties 38 --> 39 <property name="josm" location="../../core/dist/josm-custom.jar"/> 40 <property name="plugin.build.dir" value="build"/> 41 <property name="plugin.src.dir" value="src"/> 42 <!-- this is the directory where the plugin jar is copied to --> 43 <property name="plugin.dist.dir" value="../../dist"/> 44 <property name="ant.build.javac.target" value="1.5"/> 45 <property name="plugin.dist.dir" value="../../dist"/> 46 <property name="plugin.jar" value="${plugin.dist.dir}/${ant.project.name}.jar"/> 47 <!-- 48 ********************************************************** 49 ** init - initializes the build 50 ********************************************************** 6 <property name="plugin.main.version" value="6082"/> 7 8 <!-- Configure these properties (replace "..." accordingly). 9 See http://josm.openstreetmap.de/wiki/DevelopersGuide/DevelopingPlugins 51 10 --> 52 <target name="init"> 53 <mkdir dir="${plugin.build.dir}"/> 54 </target> 55 <!-- 56 ********************************************************** 57 ** compile - complies the source tree 58 ********************************************************** 59 --> 60 <target name="compile" depends="init"> 61 <echo message="compiling sources for ${plugin.jar} ... "/> 62 <javac srcdir="src" classpath="${josm}" debug="true" destdir="${plugin.build.dir}"> 63 <compilerarg value="-Xlint:deprecation"/> 64 <compilerarg value="-Xlint:unchecked"/> 65 </javac> 66 </target> 67 <!-- 68 ********************************************************** 69 ** dist - creates the plugin jar 70 ********************************************************** 71 --> 72 <target name="dist" depends="compile,revision"> 73 <echo message="creating ${ant.project.name}.jar ... "/> 74 <copy todir="${plugin.build.dir}/resources"> 75 <fileset dir="resources"/> 76 </copy> 77 <copy todir="${plugin.build.dir}/images"> 78 <fileset dir="images"/> 79 </copy> 80 <copy todir="${plugin.build.dir}/data"> 81 <fileset dir="data"/> 82 </copy> 83 <copy todir="${plugin.build.dir}"> 84 <fileset dir="."> 85 <include name="README"/> 86 <include name="LICENSE"/> 87 </fileset> 88 </copy> 89 <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}"> 90 <!-- 91 ************************************************ 92 ** configure these properties. Most of them will be copied to the plugins 93 ** manifest file. Property values will also show up in the list available 94 ** plugins: http://josm.openstreetmap.de/wiki/Plugins. 95 ** 96 ************************************************ 97 --> 98 <manifest> 99 <attribute name="Author" value="Hartmut Holzgraefe"/> 100 <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.directdownload.DirectDownload"/> 101 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> 102 <attribute name="Plugin-Description" value="Download your GPX tracks from openstreetmap.org"/> 103 <attribute name="Plugin-Icon" value="images/DownloadAction.png"/> 104 <!-- <attribute name="Plugin-Link" value="..."/> --> 105 <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/> 106 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 107 </manifest> 108 </jar> 109 </target> 110 <!-- 111 ********************************************************** 112 ** revision - extracts the current revision number for the 113 ** file build.number and stores it in the XML property 114 ** version.* 115 ********************************************************** 116 --> 117 <target name="revision"> 118 <exec append="false" output="REVISION" executable="svn" failifexecutionfails="false"> 119 <env key="LANG" value="C"/> 120 <arg value="info"/> 121 <arg value="--xml"/> 122 <arg value="."/> 123 </exec> 124 <xmlproperty file="REVISION" prefix="version" keepRoot="false" collapseAttributes="true"/> 125 <delete file="REVISION"/> 126 </target> 127 <!-- 128 ********************************************************** 129 ** clean - clean up the build environment 130 ********************************************************** 131 --> 132 <target name="clean"> 133 <delete dir="${plugin.build.dir}"/> 134 <delete file="${plugin.jar}"/> 135 </target> 136 <!-- 137 ********************************************************** 138 ** install - install the plugin in your local JOSM installation 139 ********************************************************** 140 --> 141 <target name="install" depends="dist"> 142 <property environment="env"/> 143 <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins"> 144 <and> 145 <os family="windows"/> 146 </and> 147 </condition> 148 <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/> 149 </target> 150 <!-- 151 ************************** Publishing the plugin *********************************** 152 --> 153 <!-- 154 ** extracts the JOSM release for the JOSM version in ../core and saves it in the 155 ** property ${coreversion.info.entry.revision} 156 ** 157 --> 158 <target name="core-info"> 159 <exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false"> 160 <env key="LANG" value="C"/> 161 <arg value="info"/> 162 <arg value="--xml"/> 163 <arg value="../../core"/> 164 </exec> 165 <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true"/> 166 <echo>Building against core revision ${coreversion.info.entry.revision}.</echo> 167 <echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo> 168 <delete file="core.info.xml"/> 169 </target> 170 <!-- 171 ** commits the source tree for this plugin 172 --> 173 <target name="commit-current"> 174 <echo>Commiting the plugin source with message '${commit.message}' ...</echo> 175 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 176 <env key="LANG" value="C"/> 177 <arg value="commit"/> 178 <arg value="-m '${commit.message}'"/> 179 <arg value="."/> 180 </exec> 181 </target> 182 <!-- 183 ** updates (svn up) the source tree for this plugin 184 --> 185 <target name="update-current"> 186 <echo>Updating plugin source ...</echo> 187 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 188 <env key="LANG" value="C"/> 189 <arg value="up"/> 190 <arg value="."/> 191 </exec> 192 <echo>Updating ${plugin.jar} ...</echo> 193 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 194 <env key="LANG" value="C"/> 195 <arg value="up"/> 196 <arg value="../dist/${plugin.jar}"/> 197 </exec> 198 </target> 199 <!-- 200 ** commits the plugin.jar 201 --> 202 <target name="commit-dist"> 203 <echo> 204 ***** Properties of published ${plugin.jar} ***** 205 Commit message : '${commit.message}' 206 Plugin-Mainversion: ${plugin.main.version} 207 JOSM build version: ${coreversion.info.entry.revision} 208 Plugin-Version : ${version.entry.commit.revision} 209 ***** / Properties of published ${plugin.jar} ***** 210 211 Now commiting ${plugin.jar} ... 212 </echo> 213 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 214 <env key="LANG" value="C"/> 215 <arg value="-m '${commit.message}'"/> 216 <arg value="commit"/> 217 <arg value="${plugin.jar}"/> 218 </exec> 219 </target> 220 <!-- ** make sure svn is present as a command line tool ** --> 221 <target name="ensure-svn-present"> 222 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false" failonerror="false" resultproperty="svn.exit.code"> 223 <env key="LANG" value="C"/> 224 <arg value="--version"/> 225 </exec> 226 <fail message="Fatal: command 'svn --version' failed. Please make sure svn is installed on your system."> 227 <!-- return code not set at all? Most likely svn isn't installed --> 228 <condition> 229 <not> 230 <isset property="svn.exit.code"/> 231 </not> 232 </condition> 233 </fail> 234 <fail message="Fatal: command 'svn --version' failed. Please make sure a working copy of svn is installed on your system."> 235 <!-- error code from SVN? Most likely svn is not what we are looking on this system --> 236 <condition> 237 <isfailure code="${svn.exit.code}"/> 238 </condition> 239 </fail> 240 </target> 241 <target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist"> 242 </target> 11 <property name="plugin.author" value="Hartmut Holzgraefe"/> 12 <property name="plugin.class" value="org.openstreetmap.josm.plugins.directdownload.DirectDownload"/> 13 <property name="plugin.description" value="Download your GPX tracks from openstreetmap.org"/> 14 <property name="plugin.icon" value="images/DownloadAction.png"/> 15 <!-- <property name="plugin.link" value="..."/>--> 16 <!--<property name="plugin.early" value="..."/>--> 17 <!--<property name="plugin.requires" value="..."/>--> 18 <!--<property name="plugin.stage" value="..."/>--> 19 20 <!-- ** include targets that all plugins have in common ** --> 21 <import file="../build-common.xml"/> 243 22 </project> -
applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload/DirectDownload.java
r29222 r29776 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.event.ActionEvent; 5 6 import java.io.InputStream; 6 import java.io.IOException;7 8 7 import java.net.URL; 9 8 10 import java.util.List; 11 12 import java.awt.event.ActionEvent; 9 import javax.swing.JOptionPane; 13 10 14 11 import org.openstreetmap.josm.Main; 15 12 import org.openstreetmap.josm.actions.JosmAction; 16 13 import org.openstreetmap.josm.gui.MainMenu; 14 import org.openstreetmap.josm.gui.layer.GpxLayer; 15 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 16 import org.openstreetmap.josm.io.GpxReader; 17 import org.openstreetmap.josm.io.OsmApi; 17 18 import org.openstreetmap.josm.plugins.Plugin; 18 19 import org.openstreetmap.josm.plugins.PluginInformation; 19 20 import org.openstreetmap.josm.gui.download.DownloadSelection;21 22 import org.openstreetmap.josm.gui.layer.GpxLayer;23 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;24 25 import org.openstreetmap.josm.io.GpxReader;26 27 import javax.swing.JOptionPane;28 29 20 import org.xml.sax.SAXException; 30 21 31 22 public class DirectDownload extends Plugin { 32 DownloadAction openaction;23 private DownloadAction openaction; 33 24 34 35 36 37 38 39 40 25 /** 26 * Will be invoked by JOSM to bootstrap the plugin 27 * 28 * @param info information about the plugin and its local installation 29 */ 30 public DirectDownload(PluginInformation info) { 31 super(info); 41 32 42 43 Main.main.menu.fileMenu.add(openaction);44 33 openaction = new DownloadAction(); 34 MainMenu.add(Main.main.menu.gpsMenu, openaction); 35 } 45 36 46 class DownloadAction extends JosmAction {47 public DownloadAction() {48 super(tr("Download Track ..."), "DownloadAction", tr("Download GPX track from openstreetmap.org"),49 null, false);37 class DownloadAction extends JosmAction { 38 public DownloadAction() { 39 super(tr("Download Track ..."), "DownloadAction", 40 tr("Download GPX track from openstreetmap.org"), null, false); 50 41 } 42 51 43 public void actionPerformed(ActionEvent event) { 52 44 DownloadDataGui go = new DownloadDataGui(); 53 45 go.setVisible(true); 54 46 55 47 UserTrack track = go.getSelectedUserTrack(); 56 48 57 if ((go.getValue() == 1) && (track != null)) { 58 String apiBaseUrl = "http://api.openstreetmap.org/api/0.6/"; 59 String urlString = apiBaseUrl + "gpx/" + track.id + "/data"; 49 if ((go.getValue() == 1) && (track != null)) { 50 String urlString = OsmApi.getOsmApi().getBaseUrl() + "gpx/" + track.id + "/data"; 60 51 61 62 63 52 try { 53 URL trackDataUrl = new URL(urlString); 54 InputStream is = trackDataUrl.openStream(); 64 55 65 66 67 56 GpxReader r = new GpxReader(is); 57 boolean parsedProperly = r.parse(true); 58 GpxLayer gpxLayer = new GpxLayer(r.getGpxData(), track.filename, true); 68 59 69 60 if (r.getGpxData().hasRoutePoints() || r.getGpxData().hasTrackPoints()) { … … 78 69 } 79 70 if (!parsedProperly) { 80 JOptionPane.showMessageDialog(null, tr("Error occurred while parsing gpx file {0}. Only a part of the file will be available.", urlString)); 71 JOptionPane.showMessageDialog(Main.parent, 72 tr("Error occurred while parsing gpx file {0}. Only a part of the file will be available.", urlString)); 81 73 } 82 74 83 } catch (java.net.MalformedURLException e) { 84 JOptionPane.showMessageDialog(null, tr("Invalid URL {0}", urlString)); 85 } catch (java.io.IOException e) { 86 JOptionPane.showMessageDialog(null, tr("Error fetching URL {0}", urlString)); 87 } catch (SAXException e) { 88 JOptionPane.showMessageDialog(null, tr("Error parsing data from URL {0}", urlString)); 89 } 90 } 75 } catch (java.net.MalformedURLException e) { 76 JOptionPane.showMessageDialog(Main.parent, 77 tr("Invalid URL {0}", urlString)); 78 } catch (java.io.IOException e) { 79 JOptionPane.showMessageDialog(Main.parent, 80 tr("Error fetching URL {0}", urlString)); 81 } catch (SAXException e) { 82 JOptionPane.showMessageDialog(Main.parent, 83 tr("Error parsing data from URL {0}", urlString)); 84 } 85 } 91 86 } 92 87 } 93 94 88 } 95 -
applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload/DownloadDataGui.java
r23585 r29776 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java. io.InputStream;6 import java. io.IOException;7 5 import java.awt.BorderLayout; 6 import java.awt.Component; 7 import java.awt.Dimension; 8 8 import java.net.URL; 9 10 9 import java.util.ArrayList; 11 10 import java.util.LinkedList; 12 11 import java.util.List; 13 import java.util.StringTokenizer;14 15 import org.openstreetmap.josm.Main;16 import org.openstreetmap.josm.gui.ExtendedDialog;17 18 import java.awt.BorderLayout;19 import java.awt.Component;20 import java.awt.Dimension;21 12 22 13 import javax.swing.BorderFactory; 23 import javax.swing.DefaultListModel;24 14 import javax.swing.DefaultListSelectionModel; 25 15 import javax.swing.JLabel; 26 import javax.swing.JList;27 16 import javax.swing.JOptionPane; 28 17 import javax.swing.JPanel; … … 31 20 import javax.swing.ListSelectionModel; 32 21 import javax.swing.UIManager; 33 34 22 import javax.swing.event.ListSelectionEvent; 35 23 import javax.swing.event.ListSelectionListener; 36 37 24 import javax.swing.table.DefaultTableColumnModel; 38 25 import javax.swing.table.DefaultTableModel; 39 26 import javax.swing.table.TableCellRenderer; 40 27 import javax.swing.table.TableColumn; 41 42 import org.xml.sax.*;43 import org.xml.sax.helpers.*;44 45 import javax.xml.parsers.SAXParserFactory;46 28 import javax.xml.parsers.ParserConfigurationException; 47 29 import javax.xml.parsers.SAXParser; 48 30 import javax.xml.parsers.SAXParserFactory; 31 32 import org.openstreetmap.josm.Main; 33 import org.openstreetmap.josm.gui.ExtendedDialog; 34 import org.openstreetmap.josm.io.OsmApi; 35 import org.xml.sax.Attributes; 36 import org.xml.sax.SAXException; 37 import org.xml.sax.helpers.DefaultHandler; 49 38 50 39 public class DownloadDataGui extends ExtendedDialog { 51 private String apiBaseUrl = "http://api.openstreetmap.org/api/0.6/";52 53 // User for log in when downloading trace54 private String username = Main.pref.get("osm-server.username");55 private String password = Main.pref.get("osm-server.password");56 40 57 41 private NamedResultTableModel model; … … 62 46 // Initalizes ExtendedDialog 63 47 super(Main.parent, 64 65 66 67 68 69 70 71 48 tr("Download Track"), 49 new String[] {tr("Download Track"), tr("Cancel")}, 50 true 51 ); 52 53 JPanel panel = new JPanel(); 54 panel.setLayout(new BorderLayout()); 55 72 56 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); 73 57 model = new NamedResultTableModel(selectionModel); … … 80 64 panel.add(scrollPane, BorderLayout.CENTER); 81 65 82 83 84 85 66 model.setData(getTrackList()); 67 68 setContent(panel); 69 setupDialog(); 86 70 } 87 71 88 72 private static class TrackListHandler extends DefaultHandler { 89 73 private LinkedList<UserTrack> data = new LinkedList<UserTrack>(); 90 private String cdata = new String(); 91 92 @Override 93 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) 94 throws SAXException { 95 if (qName.equals("gpx_file")) { 96 UserTrack track = new UserTrack(); 97 98 track.id = atts.getValue("id"); 99 track.filename = atts.getValue("name"); 100 track.datetime = atts.getValue("timestamp").replaceAll("[TZ]", " "); // TODO: do real parsing and time zone conversion 101 102 data.addFirst(track); 103 } 104 cdata = new String(); 105 } 106 107 public void characters(char ch[], int start, int length) 108 throws SAXException { 109 cdata += new String(ch, start, length); 110 } 111 112 public void endElement(String uri, String localName, 113 String qName) 114 throws SAXException { 115 if (qName.equals("description")) { 116 data.getFirst().description = cdata; 117 } 118 /* 119 else if (qName.equals("tag")) { 120 data.getFirst().tags = cdata; 121 cdata = new String(); 122 } 123 */ 124 } 125 74 75 private String cdata = new String(); 76 77 @Override 78 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 79 if (qName.equals("gpx_file")) { 80 UserTrack track = new UserTrack(); 81 82 track.id = atts.getValue("id"); 83 track.filename = atts.getValue("name"); 84 track.datetime = atts.getValue("timestamp").replaceAll("[TZ]", " "); // TODO: do real parsing and time zone conversion 85 86 data.addFirst(track); 87 } 88 cdata = new String(); 89 } 90 91 public void characters(char ch[], int start, int length) 92 throws SAXException { 93 cdata += new String(ch, start, length); 94 } 95 96 public void endElement(String uri, String localName, String qName) throws SAXException { 97 if (qName.equals("description")) { 98 data.getFirst().description = cdata; 99 } 100 /* 101 else if (qName.equals("tag")) { 102 data.getFirst().tags = cdata; 103 cdata = new String(); 104 } 105 */ 106 } 126 107 127 108 public List<UserTrack> getResult() { … … 131 112 132 113 private List<UserTrack> getTrackList() { 133 String urlString = apiBaseUrl+ "user/gpx_files";134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 114 String urlString = OsmApi.getOsmApi().getBaseUrl() + "user/gpx_files"; 115 116 try { 117 URL userTracksUrl = new URL(urlString); 118 119 SAXParserFactory spf = SAXParserFactory.newInstance(); 120 TrackListHandler handler = new TrackListHandler(); 121 122 //get a new instance of parser 123 SAXParser sp = spf.newSAXParser(); 124 125 //parse the file and also register this class for call backs 126 sp.parse(userTracksUrl.openStream(), handler); 127 128 return handler.getResult(); 129 } catch (java.net.MalformedURLException e) { 130 JOptionPane.showMessageDialog(null, tr("Invalid URL {0}", urlString)); 131 } catch (java.io.IOException e) { 132 JOptionPane.showMessageDialog(null, tr("Error fetching URL {0}", urlString)); 133 } catch (SAXException e) { 134 JOptionPane.showMessageDialog(null, tr("Error parsing data from URL {0}", urlString)); 135 } catch(ParserConfigurationException pce) { 136 JOptionPane.showMessageDialog(null, tr("Error parsing data from URL {0}", urlString)); 137 } 138 139 return new LinkedList<UserTrack>(); 159 140 } 160 141 … … 167 148 this.selectionModel = selectionModel; 168 149 } 150 169 151 @Override 170 152 public int getRowCount() { … … 187 169 fireTableDataChanged(); 188 170 } 171 189 172 @Override 190 173 public boolean isCellEditable(int row, int column) { … … 200 183 201 184 public UserTrack getSelectedUserTrack() { 202 return model.getSelectedUserTrack(); 203 } 204 185 return model.getSelectedUserTrack(); 186 } 205 187 206 188 static class NamedResultTableColumnModel extends DefaultTableColumnModel { … … 234 216 235 217 // column 3 - tags 236 218 /* 237 219 col = new TableColumn(3); 238 220 col.setHeaderValue(tr("Tags")); … … 241 223 col.setCellRenderer(renderer); 242 224 addColumn(col); 243 225 */ 244 226 } 245 227 … … 286 268 switch(column) { 287 269 case 0: 288 270 setText(sr.datetime); 289 271 break; 290 272 case 1: 291 273 setText(sr.filename); 292 break; 293 274 break; 275 case 2: 294 276 setText(sr.description); 295 277 break; 296 278 /* 297 279 case 3: 298 280 setText(sr.tags); 299 281 break; 300 282 */ 301 283 } 302 284 return this; 303 285 } 304 286 } 305 306 287 }
Note:
See TracChangeset
for help on using the changeset viewer.