Ticket #5443: PropertiesDialog.java.respcode-used.patch
| File PropertiesDialog.java.respcode-used.patch, 5.8 KB (added by , 15 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
6 6 7 7 import java.awt.BorderLayout; 8 8 import java.awt.Component; 9 import java.awt.Desktop; 10 import java.awt.Dialog.ModalityType; 9 11 import java.awt.Font; 10 12 import java.awt.GridBagLayout; 11 13 import java.awt.Point; 12 import java.awt.Dialog.ModalityType;13 14 import java.awt.event.ActionEvent; 14 15 import java.awt.event.ActionListener; 15 16 import java.awt.event.FocusAdapter; … … 17 18 import java.awt.event.KeyEvent; 18 19 import java.awt.event.MouseAdapter; 19 20 import java.awt.event.MouseEvent; 21 import java.net.URI; 20 22 import java.util.ArrayList; 21 23 import java.util.Collection; 22 24 import java.util.Collections; … … 24 26 import java.util.HashMap; 25 27 import java.util.Iterator; 26 28 import java.util.List; 29 import java.util.Locale; 27 30 import java.util.Map; 31 import java.util.Map.Entry; 28 32 import java.util.TreeMap; 29 33 import java.util.Vector; 30 import java.util.Map.Entry;31 34 32 35 import javax.swing.AbstractAction; 33 36 import javax.swing.Box; … … 67 70 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 68 71 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter; 69 72 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 70 import org.openstreetmap.josm.data.osm.event.SelectionEventManager;71 73 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 74 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 72 75 import org.openstreetmap.josm.gui.DefaultNameFormatter; 73 76 import org.openstreetmap.josm.gui.ExtendedDialog; 74 77 import org.openstreetmap.josm.gui.MapFrame; … … 87 90 import org.openstreetmap.josm.tools.ImageProvider; 88 91 import org.openstreetmap.josm.tools.Shortcut; 89 92 93 import sun.net.www.protocol.http.HttpURLConnection; 94 90 95 /** 91 96 * This dialog displays the properties of the current selected primitives. 92 97 * … … 704 709 getActionMap().put("delete", deleteAction); 705 710 buttonPanel.add(this.btnDel); 706 711 add(buttonPanel, BorderLayout.SOUTH); 712 713 // -- help action 714 // 715 HelpAction helpAction = new HelpAction(); 716 propertyTable.getSelectionModel().addListSelectionListener(helpAction); 717 getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( 718 KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), "onHelp"); 719 getActionMap().put("onHelp", helpAction); 707 720 } 708 721 709 722 @Override public void setVisible(boolean b) { … … 1021 1034 } 1022 1035 } 1023 1036 1037 class HelpAction extends AbstractAction implements ListSelectionListener { 1038 public HelpAction() { 1039 putValue(NAME, tr("Help")); 1040 putValue(SHORT_DESCRIPTION, tr("Launch browser with wiki help to selected object")); 1041 updateEnabledState(); 1042 } 1043 1044 @SuppressWarnings("unchecked") 1045 public void actionPerformed(ActionEvent e) { 1046 if (!isEnabled()) 1047 return; 1048 1049 try { 1050 String base = new String("http://wiki.openstreetmap.org/wiki/"); 1051 String l = Locale.getDefault().getCountry() + ":"; 1052 Vector<URI> v = new Vector<URI>(); 1053 1054 String uri; 1055 int row; 1056 if (propertyTable.getSelectedRowCount() == 1) { 1057 row = propertyTable.getSelectedRow(); 1058 uri = base + l + "Tag:" + 1059 propertyData.getValueAt(row, 0).toString() + "=" + 1060 ((Map<String,Integer>)propertyData.getValueAt(row, 1)).entrySet().iterator().next().getKey(); 1061 1062 v.add(new URI(uri)); 1063 v.add(new URI(uri.substring(0, uri.indexOf('=')).replace("Tag:", "Key:"))); 1064 v.add(new URI(base + l + "Map_Features")); 1065 } else if (membershipTable.getSelectedRowCount() == 1) { 1066 row = membershipTable.getSelectedRow(); 1067 uri = base + l + "Relation:" + ((Relation)membershipData.getValueAt(row, 0)).get("type"); 1068 1069 v.add(new URI(uri)); 1070 v.add(new URI(uri = base + l + "Relations")); 1071 } 1072 1073 // try all localized variants and if they are not available, try default as well 1074 for (row = 0; row < v.size(); row++) { 1075 v.insertElementAt(new URI(v.get(row).toString().replace(l, "")), ++row); 1076 } 1077 // find a page that actually exists in the wiki 1078 while ( !v.isEmpty() && 1079 ((HttpURLConnection) v.firstElement().toURL().openConnection()) 1080 .getResponseCode() != 200) { 1081 System.out.println("INFO: looking for " + v.firstElement()); 1082 v.remove(0); 1083 } 1084 1085 // browse the help page 1086 if (!v.isEmpty()) { 1087 System.out.println("INFO: browsing to url " + v.firstElement()); 1088 Desktop.getDesktop().browse(v.firstElement()); 1089 } 1090 } catch (Exception e1) { 1091 e1.printStackTrace(); 1092 } 1093 } 1094 1095 protected void updateEnabledState() { 1096 setEnabled( 1097 propertyTable.getSelectedRowCount() == 1 1098 ^ membershipTable.getSelectedRowCount() == 1 1099 ); 1100 } 1101 1102 public void valueChanged(ListSelectionEvent e) { 1103 updateEnabledState(); 1104 } 1105 } 1106 1024 1107 static class SelectRelationAction extends AbstractAction { 1025 1108 boolean selectionmode; 1026 1109 Relation relation;
