Ticket #5443: PropertiesDialog.java.2.patch
| File PropertiesDialog.java.2.patch, 5.3 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; … … 25 27 import java.util.Iterator; 26 28 import java.util.List; 27 29 import java.util.Map; 30 import java.util.Map.Entry; 28 31 import java.util.TreeMap; 29 32 import java.util.Vector; 30 import java.util.Map.Entry;31 33 32 34 import javax.swing.AbstractAction; 33 35 import javax.swing.Box; … … 67 69 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 68 70 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter; 69 71 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 70 import org.openstreetmap.josm.data.osm.event.SelectionEventManager;71 72 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 73 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 72 74 import org.openstreetmap.josm.gui.DefaultNameFormatter; 73 75 import org.openstreetmap.josm.gui.ExtendedDialog; 74 76 import org.openstreetmap.josm.gui.MapFrame; … … 87 89 import org.openstreetmap.josm.tools.ImageProvider; 88 90 import org.openstreetmap.josm.tools.Shortcut; 89 91 92 90 93 /** 91 94 * This dialog displays the properties of the current selected primitives. 92 95 * … … 704 707 getActionMap().put("delete", deleteAction); 705 708 buttonPanel.add(this.btnDel); 706 709 add(buttonPanel, BorderLayout.SOUTH); 710 711 // -- help action 712 // 713 HelpAction helpAction = new HelpAction(); 714 propertyTable.getSelectionModel().addListSelectionListener(helpAction); 715 getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( 716 KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), "onHelp"); 717 getActionMap().put("onHelp", helpAction); 707 718 } 708 719 709 720 @Override public void setVisible(boolean b) { … … 1021 1032 } 1022 1033 } 1023 1034 1035 class HelpAction extends AbstractAction implements ListSelectionListener { 1036 public HelpAction() { 1037 putValue(NAME, tr("Help")); 1038 putValue(SHORT_DESCRIPTION, tr("Launch browser with wiki help to selected object")); 1039 updateEnabledState(); 1040 } 1041 1042 @SuppressWarnings("unchecked") 1043 public void actionPerformed(ActionEvent e) { 1044 if (!isEnabled()) 1045 return; 1046 1047 try { 1048 URI uri = new URI("http://wiki.openstreetmap.org/"); 1049 1050 if (propertyTable.getSelectedRowCount() == 1) { 1051 int row = propertyTable.getSelectedRow(); 1052 uri = new URI("http://wiki.openstreetmap.org/wiki/Tag:"+ 1053 propertyData.getValueAt(row, 0).toString()+"="+ 1054 ((Map<String,Integer>)propertyData.getValueAt(row, 1)) 1055 .entrySet().iterator().next().getKey() 1056 ); 1057 1058 byte[] b = new byte[4096]; 1059 InputStream is = uri.toURL().openStream(); 1060 is.read(b); 1061 is.close(); 1062 1063 String id = new String(b); 1064 int i1 = id.indexOf("wgArticleId="); 1065 if (i1 > -1) { 1066 id = id.substring(id.indexOf('=', i1) + 1, id.indexOf(',', i1)); 1067 } else { 1068 id = "0"; 1069 } 1070 if (id.equals("0")) { 1071 uri = new URI("http://wiki.openstreetmap.org/wiki/Key:"+ 1072 propertyData.getValueAt(row, 0).toString()); 1073 } 1074 } else if (membershipTable.getSelectedRowCount() == 1) { 1075 int row = membershipTable.getSelectedRow(); 1076 uri = new URI("http://wiki.openstreetmap.org/wiki/Relation:"+ 1077 ((Relation)membershipData.getValueAt(row, 0)).get("type")); 1078 } 1079 1080 Desktop.getDesktop().browse(uri); 1081 } catch (Exception e1) { 1082 e1.printStackTrace(); 1083 } 1084 } 1085 1086 protected void updateEnabledState() { 1087 setEnabled( 1088 propertyTable.getSelectedRowCount() == 1 1089 ^ membershipTable.getSelectedRowCount() == 1 1090 ); 1091 } 1092 1093 public void valueChanged(ListSelectionEvent e) { 1094 updateEnabledState(); 1095 } 1096 } 1097 1024 1098 static class SelectRelationAction extends AbstractAction { 1025 1099 boolean selectionmode; 1026 1100 Relation relation;
