Changeset 32720 in osm for applications
- Timestamp:
- 2016-07-26T17:20:01+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikidataTagCellRenderer.java
r32704 r32720 9 9 import java.util.Locale; 10 10 import java.util.Map; 11 import java.util.concurrent.C allable;11 import java.util.concurrent.CompletableFuture; 12 12 import java.util.concurrent.ConcurrentHashMap; 13 13 import java.util.concurrent.ExecutionException; 14 import java.util.concurrent.Future;15 14 import java.util.stream.Collectors; 16 15 … … 20 19 21 20 import org.openstreetmap.josm.Main; 21 import org.openstreetmap.josm.gui.util.GuiHelper; 22 22 import org.openstreetmap.josm.tools.Utils; 23 23 24 24 public class WikidataTagCellRenderer extends DefaultTableCellRenderer { 25 25 26 final Map<String, Future<String>> labelCache = new ConcurrentHashMap<>(); 27 28 static class LabelLoader implements Callable<String> { 29 final String id; 30 JTable table; 31 32 public LabelLoader(String id, JTable table) { 33 this.id = id; 34 this.table = table; 35 } 36 37 @Override 38 public String call() throws Exception { 39 final String label = WikipediaApp.getLabelForWikidata(id, Locale.getDefault()); 40 table.repaint(); 41 table = null; 42 return label; 43 } 44 } 26 private final Map<String, CompletableFuture<String>> labelCache = new ConcurrentHashMap<>(); 45 27 46 28 @Override … … 70 52 protected JLabel renderValues(Collection<String> ids, JTable table, JLabel component) { 71 53 72 ids.stream() 73 .filter(id -> !labelCache.containsKey(id)) 74 .forEach(id -> { 75 labelCache.put(id, Main.worker.submit(new LabelLoader(id, table))); 76 }); 54 ids.forEach(id -> 55 labelCache.computeIfAbsent(id, x -> 56 CompletableFuture.supplyAsync(() -> WikipediaApp.getLabelForWikidata(x, Locale.getDefault()))) 57 ); 77 58 78 59 final Collection<String> texts = new ArrayList<>(ids.size()); 79 60 for (String id : ids) { 80 61 if (!labelCache.get(id).isDone()) { 62 labelCache.get(id).thenRun(() -> GuiHelper.runInEDT(table::repaint)); 81 63 return null; 82 64 }
Note:
See TracChangeset
for help on using the changeset viewer.