- Timestamp:
- 2010-09-14T18:21:43+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r3525 r3529 20 20 import java.net.HttpURLConnection; 21 21 import java.net.URI; 22 import java.net.URLEncoder; 22 23 import java.util.ArrayList; 23 24 import java.util.Collection; … … 28 29 import java.util.List; 29 30 import java.util.Map; 31 import java.util.Map.Entry; 32 import java.util.TreeMap; 30 33 import java.util.Vector; 31 import java.util.TreeMap;32 import java.util.Map.Entry;33 34 34 35 import javax.swing.AbstractAction; … … 70 71 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter; 71 72 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 73 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 72 74 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 73 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;74 75 import org.openstreetmap.josm.gui.DefaultNameFormatter; 75 76 import org.openstreetmap.josm.gui.ExtendedDialog; … … 164 165 165 166 private DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this); 167 private HelpAction helpAction = new HelpAction(); 166 168 private AddAction addAction = new AddAction(); 167 169 private Shortcut addActionShortcut = Shortcut.registerShortcut("properties:add", tr("Add Properties"), KeyEvent.VK_B, … … 543 545 propertyData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")}); 544 546 propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 547 propertyTable.addMouseListener(new PopupMenuLauncher() { 548 @Override 549 public void launch(MouseEvent evt) { 550 Point p = evt.getPoint(); 551 int row = propertyTable.rowAtPoint(p); 552 if (row > -1) { 553 propertyTable.changeSelection(row, 0, false, false); 554 JPopupMenu menu = new JPopupMenu(); 555 menu.add(helpAction); 556 menu.show(propertyTable, p.x, p.y-3); 557 } 558 } 559 }); 545 560 546 561 propertyTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer(){ … … 578 593 int row = membershipTable.rowAtPoint(p); 579 594 if (row > -1) { 595 membershipTable.changeSelection(row, 0, false, false); 580 596 JPopupMenu menu = new JPopupMenu(); 581 597 Relation relation = (Relation)membershipData.getValueAt(row, 0); 582 598 menu.add(new SelectRelationAction(relation, true)); 583 599 menu.add(new SelectRelationAction(relation, false)); 600 menu.addSeparator(); 601 menu.add(helpAction); 584 602 menu.show(membershipTable, p.x, p.y-3); 585 603 } … … 712 730 // -- help action 713 731 // 714 HelpAction helpAction = new HelpAction();715 propertyTable.getSelectionModel().addListSelectionListener(helpAction);716 732 getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( 717 733 KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), "onHelp"); … … 1034 1050 } 1035 1051 1036 class HelpAction extends AbstractAction implements ListSelectionListener{1052 class HelpAction extends AbstractAction { 1037 1053 public HelpAction() { 1038 putValue(NAME, tr(" Help"));1054 putValue(NAME, tr("Go to OSM wiki for tag help (F1)")); 1039 1055 putValue(SHORT_DESCRIPTION, tr("Launch browser with wiki help to selected object")); 1040 updateEnabledState();1056 putValue(SMALL_ICON, ImageProvider.get("dialogs", "search")); 1041 1057 } 1042 1058 1043 1059 public void actionPerformed(ActionEvent e) { 1044 if (!isEnabled())1045 return;1046 1047 1060 try { 1048 1061 String base = new String(Main.pref.get("url.openstreetmap-wiki", "http://wiki.openstreetmap.org/wiki/")); 1049 1062 String l = LanguageInfo.getWikiLanguagePrefix(); 1050 1063 List<URI> uris = new ArrayList<URI>(); 1051 1052 1064 int row; 1053 1065 if (propertyTable.getSelectedRowCount() == 1) { 1054 1066 row = propertyTable.getSelectedRow(); 1055 String key = propertyData.getValueAt(row, 0).toString();1067 String key = URLEncoder.encode(propertyData.getValueAt(row, 0).toString(), "UTF-8"); 1056 1068 @SuppressWarnings("unchecked") 1057 String val = ((Map<String,Integer>)propertyData.getValueAt(row, 1)).entrySet().iterator().next().getKey(); 1069 String val = URLEncoder.encode( 1070 ((Map<String,Integer>)propertyData.getValueAt(row, 1)) 1071 .entrySet().iterator().next().getKey(), "UTF-8" 1072 ); 1058 1073 1059 1074 uris.add(new URI(String.format("%s%sTag:%s=%s", base, l, key, val))); … … 1065 1080 } else if (membershipTable.getSelectedRowCount() == 1) { 1066 1081 row = membershipTable.getSelectedRow(); 1067 String type = ((Relation)membershipData.getValueAt(row, 0)).get("type"); 1068 1082 String type = URLEncoder.encode( 1083 ((Relation)membershipData.getValueAt(row, 0)).get("type"), "UTF-8" 1084 ); 1085 1069 1086 if (type != null && !type.equals("")) { 1070 1087 uris.add(new URI(String.format("%s%sRelation:%s", base, l, type))); 1071 1088 uris.add(new URI(String.format("%sRelation:%s", base, type))); 1072 1089 } 1090 1073 1091 uris.add(new URI(String.format("%s%sRelations", base, l))); 1074 1092 uris.add(new URI(String.format("%sRelations", base))); 1093 } else { 1094 // give the generic help page, if more than one element is selected 1095 uris.add(new URI(String.format("%s%sMap_Features", base, l))); 1096 uris.add(new URI(String.format("%sMap_Features", base))); 1075 1097 } 1076 1098 1077 1099 // find a page that actually exists in the wiki 1078 URI uri = null; 1079 for (URI u : uris) { 1080 System.out.println("INFO: looking for " + u); 1081 if (((HttpURLConnection) u.toURL().openConnection()).getResponseCode() == 200) { 1082 uri = u; 1083 break; 1100 HttpURLConnection conn; 1101 for(URI u : uris) { 1102 conn = (HttpURLConnection) u.toURL().openConnection(); 1103 1104 if (conn.getResponseCode() != 200) { 1105 System.out.println("INFO: " + u + " does not exist"); 1106 conn.disconnect(); 1107 } else { 1108 int osize = conn.getContentLength(); 1109 conn.disconnect(); 1110 1111 conn = (HttpURLConnection) new URI(u.toString() 1112 .replace("=", "%3D") /* do not URLencode whole string! */ 1113 .replaceFirst("/wiki/", "/w/index.php?redirect=no&title=") 1114 ).toURL().openConnection(); 1115 1116 /* redirect pages have different content length, but retrieving a "nonredirect" 1117 * page using index.php and the direct-link method gives slightly different 1118 * content lengths, so we have to be fuzzy.. (this is UGLY, recode if u know better) 1119 */ 1120 if (Math.abs(conn.getContentLength()-osize) > 200) { 1121 System.out.println("INFO: " + u + " is a mediawiki redirect"); 1122 conn.disconnect(); 1123 } else { 1124 System.out.println("INFO: browsing to " + u); 1125 conn.disconnect(); 1126 1127 OpenBrowser.displayUrl(u.toString()); 1128 break; 1129 } 1084 1130 } 1085 }1086 1087 // browse the help page1088 if (uri != null) {1089 System.out.println("INFO: browsing to url " + uri);1090 OpenBrowser.displayUrl(uri);1091 1131 } 1092 1132 } catch (Exception e1) { 1093 1133 e1.printStackTrace(); 1094 1134 } 1095 }1096 1097 protected void updateEnabledState() {1098 setEnabled(1099 propertyTable.getSelectedRowCount() == 11100 ^ membershipTable.getSelectedRowCount() == 11101 );1102 }1103 1104 public void valueChanged(ListSelectionEvent e) {1105 updateEnabledState();1106 1135 } 1107 1136 }
Note:
See TracChangeset
for help on using the changeset viewer.