Changeset 31915 in osm for applications/editors/josm/plugins/wikipedia/src
- Timestamp:
- 2016-01-02T21:28:53+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikidataTagCellRenderer.java
r31866 r31915 2 2 3 3 import java.awt.Component; 4 import java.util.ArrayList; 5 import java.util.Arrays; 6 import java.util.Collection; 7 import java.util.Collections; 8 import java.util.List; 4 9 import java.util.Map; 5 10 import java.util.concurrent.Callable; … … 14 19 import org.openstreetmap.josm.Main; 15 20 import org.openstreetmap.josm.tools.LanguageInfo; 21 import org.openstreetmap.josm.tools.Predicates; 16 22 import org.openstreetmap.josm.tools.Utils; 17 23 … … 50 56 51 57 final String id = ((Map<?, ?>) value).keySet().iterator().next().toString(); 52 if (!WikipediaApp.WIKIDATA_PATTERN.matcher(id).matches()) { 53 return null; 58 final JLabel component = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 59 if (WikipediaApp.WIKIDATA_PATTERN.matcher(id).matches()) { 60 return renderValues(Collections.singleton(id), table, component); 61 } else if (id.contains(";")) { 62 final List<String> ids = Arrays.asList(id.split("\\s*;\\s*")); 63 if (Utils.forAll(ids, Predicates.stringMatchesPattern(WikipediaApp.WIKIDATA_PATTERN))) { 64 return renderValues(ids, table, component); 65 } 66 } 67 return null; 68 } 69 70 protected JLabel renderValues(Collection<String> ids, JTable table, JLabel component) { 71 72 for (String id : ids) { 73 if (!labelCache.containsKey(id)) { 74 labelCache.put(id, Main.worker.submit(new LabelLoader(id, table))); 75 } 54 76 } 55 77 56 if (!labelCache.containsKey(id)) { 57 labelCache.put(id, Main.worker.submit(new LabelLoader(id, table))); 78 final Collection<String> texts = new ArrayList<>(ids.size()); 79 for (String id : ids) { 80 if (!labelCache.get(id).isDone()) { 81 return null; 82 } 83 final String label; 84 try { 85 label = labelCache.get(id).get(); 86 } catch (InterruptedException | ExecutionException e) { 87 Main.warn("Could not fetch Wikidata label for " + id); 88 Main.warn(e); 89 return null; 90 } 91 if (label == null) { 92 return null; 93 } 94 texts.add(Utils.escapeReservedCharactersHTML(id) 95 + " <span color='gray'>" + Utils.escapeReservedCharactersHTML(label) + "</span>"); 58 96 } 59 try { 60 final String label = labelCache.get(id).isDone() ? labelCache.get(id).get() : null; 61 final JLabel component = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 62 component.setText("<html>" + Utils.escapeReservedCharactersHTML(id) + (label != null 63 ? " <span color='gray'>" + Utils.escapeReservedCharactersHTML(label) + "</span>" 64 : "")); 65 component.setToolTipText(label); 66 return component; 67 } catch (InterruptedException | ExecutionException e) { 68 Main.warn("Could not fetch Wikidata label for " + id); 69 Main.warn(e); 70 return null; 71 } 97 component.setText("<html>" + Utils.join("; ", texts)); 98 component.setToolTipText("<html>" + Utils.joinAsHtmlUnorderedList(texts)); 99 return component; 72 100 } 73 101 }
Note:
See TracChangeset
for help on using the changeset viewer.