Changeset 29523 in osm for applications
- Timestamp:
- 2013-04-21T12:37:12+02:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/wikipedia/src/org/wikipedia
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaApp.java
r29521 r29523 9 9 import java.net.URLDecoder; 10 10 import java.net.URLEncoder; 11 import java.util.AbstractList; 11 12 import java.util.ArrayList; 12 13 import java.util.Arrays; … … 107 108 final String url = "http://toolserver.org/~master/osmjson/getGeoJSON.php?action=check" 108 109 + "&lang=" + wikipediaLang; 109 System.out.println("Wikipedia: POST " + url );110 System.out.println("Wikipedia: POST " + url + " " + articleNames); 110 111 111 112 try { … … 329 330 } 330 331 } 332 333 public static <T> List<List<T>> partitionList(final List<T> list, final int size) { 334 return new AbstractList<List<T>>() { 335 @Override 336 public List<T> get(int index) { 337 final int fromIndex = index * size; 338 final int toIndex = Math.min(fromIndex + size, list.size()); 339 return list.subList(fromIndex, toIndex); 340 } 341 342 @Override 343 public int size() { 344 return (int) Math.ceil(((float) list.size()) / size); 345 } 346 }; 347 } 331 348 } -
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaToggleDialog.java
r29334 r29523 18 18 import javax.swing.JList; 19 19 import javax.swing.JOptionPane; 20 import javax.swing.SwingWorker; 20 21 import org.openstreetmap.josm.Main; 21 22 import org.openstreetmap.josm.actions.search.SearchAction; 22 23 import org.openstreetmap.josm.command.ChangePropertyCommand; 23 import org.openstreetmap.josm.data.Preferences;24 24 import org.openstreetmap.josm.data.coor.LatLon; 25 25 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 30 30 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 31 31 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 32 import org.openstreetmap.josm.data.preferences.IntegerProperty; 32 33 import org.openstreetmap.josm.data.preferences.StringProperty; 33 34 import org.openstreetmap.josm.gui.MapView; … … 102 103 }; 103 104 104 private void setWikipediaEntries(List<WikipediaEntry> entries) {105 Collections.sort(entries);106 WikipediaApp.updateWIWOSMStatus(wikipediaLang.get(), entries);107 model.clear();108 for (WikipediaEntry i : entries) {109 model.addElement(i);110 }111 }112 113 105 private void updateTitle() { 114 106 if (titleContext == null) { … … 130 122 try { 131 123 // determine bbox 132 LatLon min = Main.map.mapView.getLatLon(0, Main.map.mapView.getHeight()); 133 LatLon max = Main.map.mapView.getLatLon(Main.map.mapView.getWidth(), 0); 134 List<WikipediaEntry> entries = WikipediaApp.getEntriesFromCoordinates( 135 wikipediaLang.get(), min, max); 124 final LatLon min = Main.map.mapView.getLatLon(0, Main.map.mapView.getHeight()); 125 final LatLon max = Main.map.mapView.getLatLon(Main.map.mapView.getWidth(), 0); 136 126 // add entries to list model 137 setWikipediaEntries(entries);138 127 titleContext = tr("coordinates"); 139 128 updateTitle(); 129 new UpdateWikipediaArticlesSwingWorker() { 130 131 @Override 132 List<WikipediaEntry> getEntries() { 133 return WikipediaApp.getEntriesFromCoordinates( 134 wikipediaLang.get(), min, max); 135 } 136 }.execute(); 140 137 } catch (Exception ex) { 141 138 throw new RuntimeException(ex); 142 139 } 143 140 } 141 } 142 143 abstract class UpdateWikipediaArticlesSwingWorker extends SwingWorker<Void, WikipediaEntry> { 144 145 private final IntegerProperty wikipediaStatusUpdateChunkSize = new IntegerProperty("wikipedia.statusupdate.chunk-size", 20); 146 147 abstract List<WikipediaEntry> getEntries(); 148 149 @Override 150 protected Void doInBackground() throws Exception { 151 final List<WikipediaEntry> entries = getEntries(); 152 Collections.sort(entries); 153 publish(entries.toArray(new WikipediaEntry[entries.size()])); 154 for (List<WikipediaEntry> chunk : WikipediaApp.partitionList(entries, wikipediaStatusUpdateChunkSize.get())) { 155 WikipediaApp.updateWIWOSMStatus(wikipediaLang.get(), chunk); 156 } 157 return null; 158 } 159 160 @Override 161 protected void process(List<WikipediaEntry> chunks) { 162 model.clear(); 163 for (WikipediaEntry i : chunks) { 164 model.addElement(i); 165 } 166 } 167 144 168 } 145 169 … … 159 183 return; 160 184 } 161 List<WikipediaEntry> entries = WikipediaApp.getEntriesFromCategory( 162 wikipediaLang.get(), category, Main.pref.getInteger("wikipedia.depth", 3)); 163 setWikipediaEntries(entries); 185 164 186 titleContext = category; 165 187 updateTitle(); 188 189 new UpdateWikipediaArticlesSwingWorker() { 190 @Override 191 List<WikipediaEntry> getEntries() { 192 return WikipediaApp.getEntriesFromCategory( 193 wikipediaLang.get(), category, Main.pref.getInteger("wikipedia.depth", 3)); 194 } 195 }.execute(); 166 196 } 167 197 } … … 176 206 @Override 177 207 public void actionPerformed(ActionEvent e) { 178 setWikipediaEntries(WikipediaApp.getEntriesFromClipboard(wikipediaLang.get()));179 208 titleContext = tr("clipboard"); 180 209 updateTitle(); 210 new UpdateWikipediaArticlesSwingWorker() { 211 212 @Override 213 List<WikipediaEntry> getEntries() { 214 return WikipediaApp.getEntriesFromClipboard(wikipediaLang.get()); 215 } 216 }.execute(); 181 217 } 182 218 }
Note:
See TracChangeset
for help on using the changeset viewer.