Changeset 26922 in osm
- Timestamp:
- 2011-10-22T00:05:00+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/tag2link
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/tag2link
-
Property svn:ignore
set to
build
.settings
.classpath
.project
-
Property svn:ignore
set to
-
applications/editors/josm/plugins/tag2link/build.xml
r26917 r26922 32 32 <property name="commit.message" value="Commit message"/> 33 33 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 34 <property name="plugin.main.version" value="4 487"/>34 <property name="plugin.main.version" value="4536"/> 35 35 <!-- should not be necessary to change the following properties --> 36 36 <property name="josm" location="../../core/dist/josm-custom.jar"/> … … 99 99 <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.tag2link.Tag2LinkPlugin"/> 100 100 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> 101 <attribute name="Plugin-Description" value="TODO"/> 102 <attribute name="fr_Plugin-Description" value="TODO"/> 101 <attribute name="Plugin-Description" value="Launch browser to a Web resource about a selected object having known tags, such as Wikipedia"/> 103 102 <attribute name="Plugin-Early" value="false"/> 104 103 <attribute name="Plugin-Icon" value="images/tag2linkv2_24x24.png"/> -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkPlugin.java
r26917 r26922 28 28 * Main class of tag2links plugin. 29 29 * @author Don-vip 30 * @version 1.030 * @version 0.1 31 31 * History: 32 * 1.0 ??-Oct-2011 firstversion32 * 0.1 22-Oct-2011 first working prototype 33 33 */ 34 34 public class Tag2LinkPlugin extends Plugin { -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkPreferenceSetting.java
r26917 r26922 16 16 package org.openstreetmap.josm.plugins.tag2link; 17 17 18 import static org.openstreetmap.josm.tools.I18n.tr;19 20 import javax.swing.JPanel;21 22 18 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 23 19 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; … … 27 23 @Override 28 24 public void addGui(PreferenceTabbedPane gui) { 29 JPanel p = gui.createPreferenceTab(ICON_48, tr("Tag2Link Preferences"), 30 tr("Tag2Link Preferences"), false); 25 /*JPanel p = gui.createPreferenceTab(ICON_48, tr("Tag2Link Preferences"), 26 tr("Tag2Link Preferences"), false);*/ 31 27 // TODO 32 28 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkRuleChecker.java
r26921 r26922 24 24 25 25 import org.openstreetmap.josm.data.osm.IPrimitive; 26 import org.openstreetmap.josm.data.osm.Tag; 26 27 import org.openstreetmap.josm.plugins.tag2link.data.Link; 27 28 import org.openstreetmap.josm.plugins.tag2link.data.Rule; … … 53 54 } 54 55 56 private static Collection<Link> processEval(EvalResult eval, Rule rule, Source source) { 57 Collection<Link> result = new ArrayList<Link>(); 58 if (eval.matches()) { 59 for (Link link : rule.links) { 60 Link copy = new Link(link); 61 copy.name = copy.name.replaceAll("%name%", source.name); 62 Matcher m = Pattern.compile("%([^%]*)%").matcher(copy.url); 63 while (m.find()) { 64 String arg = m.group(1); 65 String val = findValue(arg, eval.matchingTags); 66 if (val == null && arg.contains(":")) { 67 String[] vars = arg.split(":"); 68 for (int i = 0; val == null && i < vars.length-1; i++) { 69 val = findValue(vars[i], eval.matchingTags); 70 } 71 if (val == null) { 72 // Default value 73 val = vars[vars.length-1]; 74 } 75 } 76 if (val != null) { 77 try { 78 // Special hack for Wikipedia that prevents spaces being replaced by "+" characters, but by "_" 79 if (copy.url.contains("wikipedia.")) { 80 val = val.replaceAll(" ", "_"); 81 } 82 // Encode param to be included in the URL, except if it is the URL itself ! 83 if (!m.group().equals(copy.url)) { 84 val = URLEncoder.encode(val, UTF8_ENCODING); 85 } 86 // Finally replace parameter 87 copy.url = copy.url.replaceFirst(m.group(), val); 88 } catch (UnsupportedEncodingException e) { 89 e.printStackTrace(); 90 } 91 } else { 92 System.err.println("Invalid argument: "+arg); 93 } 94 } 95 result.add(copy); 96 } 97 } 98 return result; 99 } 100 55 101 public static Collection<Link> getLinks(IPrimitive p) { 56 102 Collection<Link> result = new ArrayList<Link>(); 57 103 for (Source source : sources) { 58 104 for (Rule rule : source.rules) { 59 EvalResult eval = rule.evaluates(p); 60 if (eval.matches()) { 61 for (Link link : rule.links) { 62 Link copy = new Link(link); 63 copy.name = copy.name.replaceAll("%name%", source.name); 64 Matcher m = Pattern.compile("%([^%]*)%").matcher(copy.url); 65 while (m.find()) { 66 String arg = m.group(1); 67 String val = findValue(arg, eval.matchingTags); 68 if (val == null && arg.contains(":")) { 69 String[] vars = arg.split(":"); 70 for (int i = 0; val == null && i < vars.length-1; i++) { 71 val = findValue(vars[i], eval.matchingTags); 72 } 73 if (val == null) { 74 // Default value 75 val = vars[vars.length-1]; 76 } 77 } 78 if (val != null) { 79 try { 80 // Special hack for Wikipedia that prevents spaces being replaced by "+" characters, but by "_" 81 if (copy.url.contains("wikipedia.")) { 82 val = val.replaceAll(" ", "_"); 83 } 84 // Encode param to be included in the URL, except if it is the URL itself ! 85 if (!m.group().equals(copy.url)) { 86 val = URLEncoder.encode(val, UTF8_ENCODING); 87 } 88 // Finally replace parameter 89 copy.url = copy.url.replaceFirst(m.group(), val); 90 } catch (UnsupportedEncodingException e) { 91 e.printStackTrace(); 92 } 93 } else { 94 System.err.println("Invalid argument: "+arg); 95 } 96 } 97 result.add(copy); 98 } 99 } 105 result.addAll(processEval(rule.evaluates(p), rule, source)); 100 106 } 101 107 } 102 108 return result; 103 109 } 110 111 public static Collection<Link> getLinks(Tag tag) { 112 Collection<Link> result = new ArrayList<Link>(); 113 for (Source source : sources) { 114 for (Rule rule : source.rules) { 115 result.addAll(processEval(rule.evaluates(tag), rule, source)); 116 } 117 } 118 return result; 119 } 104 120 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Rule.java
r26921 r26922 8 8 9 9 import org.openstreetmap.josm.data.osm.IPrimitive; 10 import org.openstreetmap.josm.data.osm.Tag; 10 11 11 12 public class Rule { … … 47 48 } 48 49 49 public EvalResult evaluates( IPrimitive p) {50 public EvalResult evaluates(Map<String, String> tags) { 50 51 EvalResult result = new EvalResult(); 51 Map<String, String> tags = p.getKeys();52 52 for (Condition c : conditions) { 53 53 for (String key : tags.keySet()) { … … 73 73 } 74 74 return result; 75 75 76 } 77 78 public EvalResult evaluates(IPrimitive p) { 79 return evaluates(p.getKeys()); 80 } 81 82 public EvalResult evaluates(Tag tag) { 83 Map<String, String> map = new HashMap<String, String>(); 84 map.put(tag.getKey(), tag.getValue()); 85 return evaluates(map); 86 } 76 87 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/MembershipPopupListener.java
r26921 r26922 27 27 @Override 28 28 protected IPrimitive getFirstSelectedPrimitive() { 29 return frame.propertiesDialog.getSelectedMembershipRelation s().iterator().next();29 return frame.propertiesDialog.getSelectedMembershipRelation(); 30 30 } 31 31 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/PropertyPopupListener.java
r26917 r26922 16 16 package org.openstreetmap.josm.plugins.tag2link.listeners; 17 17 18 import javax.swing.JPopupMenu; 18 19 import javax.swing.event.PopupMenuEvent; 19 20 21 import org.openstreetmap.josm.data.osm.Tag; 20 22 import org.openstreetmap.josm.gui.MapFrame; 23 import org.openstreetmap.josm.plugins.tag2link.Tag2LinkRuleChecker; 24 import org.openstreetmap.josm.plugins.tag2link.data.Link; 21 25 22 26 public class PropertyPopupListener extends AbstractPopupListener { … … 24 28 public PropertyPopupListener(MapFrame frame) { 25 29 super(frame); 26 // TODO Auto-generated constructor stub27 30 } 28 31 29 32 @Override 30 33 public void popupMenuWillBecomeVisible(PopupMenuEvent e) { 31 // TODO Auto-generated method stub 32 34 Tag tag = frame.propertiesDialog.getSelectedProperty(); 35 if (tag != null) { 36 JPopupMenu popup = (JPopupMenu) e.getSource(); 37 for (Link link : Tag2LinkRuleChecker.getLinks(tag)) { 38 addLink(popup, link); 39 } 40 } 33 41 } 34 35 42 }
Note:
See TracChangeset
for help on using the changeset viewer.