]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/function/GetWikipediaFunction.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / function / GetWikipediaFunction.java
index acef09c6a15d3ba2a396df9b6733c781f97b856b..0e6d9eb5ae432454b505cc8fb8ba4a200b2bf57c 100644 (file)
@@ -26,6 +26,8 @@ public class GetWikipediaFunction extends GenericDownloaderFunction
        private static final int MAX_RESULTS = 20;
        /** Maximum distance from point in km */
        private static final int MAX_DISTANCE = 15;
+       /** Username to use for geonames queries */
+       private static final String GEONAMES_USERNAME = "gpsprune";
 
 
        /**
@@ -77,10 +79,11 @@ public class GetWikipediaFunction extends GenericDownloaderFunction
                String descMessage = "";
                InputStream inStream = null;
 
-               // Example http://ws.geonames.org/findNearbyWikipedia?lat=47&lng=9
-               String urlString = "http://ws.geonames.org/findNearbyWikipedia?lat=" +
+               // Example http://api.geonames.org/findNearbyWikipedia?lat=47&lng=9
+               String urlString = "http://api.geonames.org/findNearbyWikipedia?lat=" +
                        lat + "&lng=" + lon + "&maxRows=" + MAX_RESULTS
-                       + "&radius=" + MAX_DISTANCE + "&lang=" + I18nManager.getText("wikipedia.lang");
+                       + "&radius=" + MAX_DISTANCE + "&lang=" + I18nManager.getText("wikipedia.lang")
+                       + "&username=" + GEONAMES_USERNAME;
                // Parse the returned XML with a special handler
                GetWikipediaXmlHandler xmlHandler = new GetWikipediaXmlHandler();
                try
@@ -106,24 +109,38 @@ public class GetWikipediaFunction extends GenericDownloaderFunction
                        descMessage = I18nManager.getText("dialog.gpsies.nonefound");
                }
                _statusLabel.setText(descMessage);
+               // Show error message if any
+               if (trackList == null || trackList.size() == 0) {
+                       String error = xmlHandler.getErrorMessage();
+                       if (error != null && !error.equals("")) {
+                               _app.showErrorMessageNoLookup(getNameKey(), error);
+                       }
+               }
        }
 
+
        /**
-        * Load the selected track or point
+        * Load the selected point(s)
         */
        protected void loadSelected()
        {
-               // Find the row selected in the table and get the corresponding track
-               int rowNum = _trackTable.getSelectedRow();
-               if (rowNum >= 0 && rowNum < _trackListModel.getRowCount())
+               // Find the rows selected in the table and get the corresponding coords
+               int numSelected = _trackTable.getSelectedRowCount();
+               if (numSelected < 1) return;
+               int[] rowNums = _trackTable.getSelectedRows();
+               for (int i=0; i<numSelected; i++)
                {
-                       String coords = _trackListModel.getTrack(rowNum).getDownloadLink();
-                       String[] latlon = coords.split(",");
-                       if (latlon.length == 2)
+                       int rowNum = rowNums[i];
+                       if (rowNum >= 0 && rowNum < _trackListModel.getRowCount())
                        {
-                               DataPoint point = new DataPoint(new Latitude(latlon[0]), new Longitude(latlon[1]), null);
-                               point.setFieldValue(Field.WAYPT_NAME, _trackListModel.getTrack(rowNum).getTrackName(), false);
-                               _app.createPoint(point);
+                               String coords = _trackListModel.getTrack(rowNum).getDownloadLink();
+                               String[] latlon = coords.split(",");
+                               if (latlon.length == 2)
+                               {
+                                       DataPoint point = new DataPoint(new Latitude(latlon[0]), new Longitude(latlon[1]), null);
+                                       point.setFieldValue(Field.WAYPT_NAME, _trackListModel.getTrack(rowNum).getTrackName(), false);
+                                       _app.createPoint(point);
+                               }
                        }
                }
                // Close the dialog