Changeset 3525 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2010-09-13T21:41:49+02:00 (14 years ago)
Author:
bastiK
Message:

see #5443 (patch by Christian Müller) - integrate josm tag help with osm wiki

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r3518 r3525  
    77import java.awt.BorderLayout;
    88import java.awt.Component;
     9import java.awt.Dialog.ModalityType;
    910import java.awt.Font;
    1011import java.awt.GridBagLayout;
    1112import java.awt.Point;
    12 import java.awt.Dialog.ModalityType;
    1313import java.awt.event.ActionEvent;
    1414import java.awt.event.ActionListener;
     
    1818import java.awt.event.MouseAdapter;
    1919import java.awt.event.MouseEvent;
     20import java.net.HttpURLConnection;
     21import java.net.URI;
    2022import java.util.ArrayList;
    2123import java.util.Collection;
     
    2628import java.util.List;
    2729import java.util.Map;
     30import java.util.Vector;
    2831import java.util.TreeMap;
    29 import java.util.Vector;
    3032import java.util.Map.Entry;
    3133
     
    8688import org.openstreetmap.josm.tools.GBC;
    8789import org.openstreetmap.josm.tools.ImageProvider;
     90import org.openstreetmap.josm.tools.LanguageInfo;
     91import org.openstreetmap.josm.tools.OpenBrowser;
    8892import org.openstreetmap.josm.tools.Shortcut;
    8993
     
    705709        buttonPanel.add(this.btnDel);
    706710        add(buttonPanel, BorderLayout.SOUTH);
     711
     712        // -- help action
     713        //
     714        HelpAction helpAction = new HelpAction();
     715        propertyTable.getSelectionModel().addListSelectionListener(helpAction);
     716        getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
     717                KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), "onHelp");
     718        getActionMap().put("onHelp", helpAction);
    707719    }
    708720
     
    10221034    }
    10231035
     1036    class HelpAction extends AbstractAction implements ListSelectionListener {
     1037        public HelpAction() {
     1038            putValue(NAME, tr("Help"));
     1039            putValue(SHORT_DESCRIPTION, tr("Launch browser with wiki help to selected object"));
     1040            updateEnabledState();
     1041        }
     1042
     1043        public void actionPerformed(ActionEvent e) {
     1044            if (!isEnabled())
     1045                return;
     1046
     1047            try {
     1048                String base = new String(Main.pref.get("url.openstreetmap-wiki", "http://wiki.openstreetmap.org/wiki/"));
     1049                String l = LanguageInfo.getWikiLanguagePrefix();
     1050                List<URI> uris = new ArrayList<URI>();
     1051
     1052                int row;
     1053                if (propertyTable.getSelectedRowCount() == 1) {
     1054                    row = propertyTable.getSelectedRow();
     1055                    String key = propertyData.getValueAt(row, 0).toString();
     1056                    @SuppressWarnings("unchecked")
     1057                    String val = ((Map<String,Integer>)propertyData.getValueAt(row, 1)).entrySet().iterator().next().getKey();
     1058
     1059                    uris.add(new URI(String.format("%s%sTag:%s=%s", base, l, key, val)));
     1060                    uris.add(new URI(String.format("%sTag:%s=%s", base, key, val)));
     1061                    uris.add(new URI(String.format("%s%sKey:%s", base, l, key)));
     1062                    uris.add(new URI(String.format("%sKey:%s", base, key)));
     1063                    uris.add(new URI(String.format("%s%sMap_Features", base, l)));
     1064                    uris.add(new URI(String.format("%sMap_Features", base)));
     1065                } else if (membershipTable.getSelectedRowCount() == 1) {
     1066                    row = membershipTable.getSelectedRow();
     1067                    String type = ((Relation)membershipData.getValueAt(row, 0)).get("type");
     1068                   
     1069                    if (type != null && !type.equals("")) {
     1070                        uris.add(new URI(String.format("%s%sRelation:%s", base, l, type)));
     1071                        uris.add(new URI(String.format("%sRelation:%s", base, type)));
     1072                    }
     1073                    uris.add(new URI(String.format("%s%sRelations", base, l)));
     1074                    uris.add(new URI(String.format("%sRelations", base)));
     1075                }
     1076
     1077                // 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;
     1084                    }
     1085                }
     1086                   
     1087                // browse the help page
     1088                if (uri != null) {
     1089                    System.out.println("INFO: browsing to url " + uri);
     1090                    OpenBrowser.displayUrl(uri);
     1091                }
     1092            } catch (Exception e1) {
     1093                e1.printStackTrace();
     1094            }
     1095        }
     1096
     1097        protected void updateEnabledState() {
     1098            setEnabled(
     1099                    propertyTable.getSelectedRowCount() == 1
     1100                    ^ membershipTable.getSelectedRowCount() == 1
     1101            );
     1102        }
     1103
     1104        public void valueChanged(ListSelectionEvent e) {
     1105            updateEnabledState();
     1106        }
     1107    }
     1108
    10241109    static class SelectRelationAction extends AbstractAction {
    10251110        boolean selectionmode;
Note: See TracChangeset for help on using the changeset viewer.