Changeset 15581 in josm


Ignore:
Timestamp:
2019-12-11T01:34:19+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #18409 - distinct label for relation wiki link in Membership Context Menu

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 added
3 edited

Legend:

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

    r15490 r15581  
    1010import java.util.Arrays;
    1111import java.util.List;
    12 import java.util.Map;
    13 import java.util.Objects;
    14 import java.util.function.IntFunction;
    1512
    1613import javax.swing.AbstractAction;
    17 import javax.swing.JTable;
    1814import javax.swing.KeyStroke;
    1915import javax.xml.parsers.ParserConfigurationException;
     
    3531 * @since 13521
    3632 */
    37 public class HelpAction extends AbstractAction {
    38     private final JTable tagTable;
    39     private final IntFunction<String> tagKeySupplier;
    40     private final IntFunction<Map<String, Integer>> tagValuesSupplier;
    41 
    42     private final JTable membershipTable;
    43     private final IntFunction<IRelation<?>> memberValueSupplier;
     33public abstract class HelpAction extends AbstractAction {
    4434
    4535    /**
    4636     * Constructs a new {@code HelpAction}.
    47      * @param tagTable The tag table. Cannot be null
    48      * @param tagKeySupplier Finds the key from given row of tag table. Cannot be null
    49      * @param tagValuesSupplier Finds the values from given row of tag table (map of values and number of occurrences). Cannot be null
    50      * @param membershipTable The membership table. Can be null
    51      * @param memberValueSupplier Finds the parent relation from given row of membership table. Can be null
    52      * @since 13959 (signature)
    5337     */
    54     public HelpAction(JTable tagTable, IntFunction<String> tagKeySupplier, IntFunction<Map<String, Integer>> tagValuesSupplier,
    55             JTable membershipTable, IntFunction<IRelation<?>> memberValueSupplier) {
    56         this.tagTable = Objects.requireNonNull(tagTable);
    57         this.tagKeySupplier = Objects.requireNonNull(tagKeySupplier);
    58         this.tagValuesSupplier = Objects.requireNonNull(tagValuesSupplier);
    59         this.membershipTable = membershipTable;
    60         this.memberValueSupplier = memberValueSupplier;
    61         putValue(NAME, tr("Go to OSM wiki for tag help"));
     38    public HelpAction() {
    6239        putValue(SHORT_DESCRIPTION, tr("Launch browser with wiki help for selected object"));
    6340        new ImageProvider("dialogs", "search").getResource().attachImageIcon(this, true);
     
    6946     * @return the keystroke launching this action
    7047     */
    71     public KeyStroke getKeyStroke() {
     48    public static KeyStroke getKeyStroke() {
    7249        return KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0);
    7350    }
     
    7552    @Override
    7653    public void actionPerformed(ActionEvent e) {
    77         if (tagTable.getSelectedRowCount() == 1) {
    78             int row = tagTable.getSelectedRow();
    79             String key = tagKeySupplier.apply(row);
    80             Map<String, Integer> m = tagValuesSupplier.apply(row);
    81             if (!m.isEmpty()) {
    82                 String val = m.entrySet().iterator().next().getKey();
    83                 MainApplication.worker.execute(() -> displayTagHelp(key, val));
    84             }
    85         } else if (membershipTable != null && membershipTable.getSelectedRowCount() == 1) {
    86             int row = membershipTable.getSelectedRow();
    87             final IRelation<?> relation = memberValueSupplier.apply(row);
    88             MainApplication.worker.execute(() -> displayRelationHelp(relation));
    89         } else {
    90             // give the generic help page, if more than one element is selected
    91             MainApplication.worker.execute(HelpAction::displayGenericHelp);
    92         }
     54        // give the generic help page, if more than one element is selected
     55        MainApplication.worker.execute(HelpAction::displayGenericHelp);
    9356    }
    9457
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r15565 r15581  
    185185
    186186    private final transient DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this);
    187     private final HelpAction helpAction = new HelpAction(tagTable, editHelper::getDataKey, editHelper::getDataValues,
    188             membershipTable, x -> (IRelation<?>) membershipData.getValueAt(x, 0));
     187    private final HelpAction helpTagAction = new HelpTagAction(tagTable, editHelper::getDataKey, editHelper::getDataValues);
     188    private final HelpAction helpRelAction = new HelpMembershipAction(membershipTable, x -> (IRelation<?>) membershipData.getValueAt(x, 0));
    189189    private final TaginfoAction taginfoAction = new TaginfoAction(tagTable, editHelper::getDataKey, editHelper::getDataValues,
    190190            membershipTable, x -> (IRelation<?>) membershipData.getValueAt(x, 0));
     
    389389        RelationPopupMenus.setupHandler(membershipMenuHandler, EditRelationAction.class, DeleteRelationsAction.class);
    390390        membershipMenu.addSeparator();
    391         membershipMenu.add(helpAction);
     391        membershipMenu.add(helpRelAction);
    392392        membershipMenu.add(taginfoAction);
    393393
     
    441441        tagMenu.add(searchActionSame);
    442442        tagMenu.addSeparator();
    443         tagMenu.add(helpAction);
     443        tagMenu.add(helpTagAction);
    444444        tagMenu.add(taginfoAction);
    445445        tagTable.addMouseListener(new PopupMenuLauncher(tagMenu));
     
    486486        // F1 button = custom help action
    487487        getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
    488                 helpAction.getKeyStroke(), "onHelp");
    489         getActionMap().put("onHelp", helpAction);
     488                HelpAction.getKeyStroke(), "onHelp");
     489        getActionMap().put("onHelp", new AbstractAction() {
     490            @Override
     491            public void actionPerformed(ActionEvent e) {
     492                if (membershipTable.getSelectedRowCount() == 1) {
     493                    helpRelAction.actionPerformed(e);
     494                } else {
     495                    helpTagAction.actionPerformed(e);
     496                }
     497            }
     498        });
    490499    }
    491500
  • trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java

    r14463 r15581  
    2020import org.openstreetmap.josm.gui.dialogs.properties.CopyKeyValueAction;
    2121import org.openstreetmap.josm.gui.dialogs.properties.CopyValueAction;
    22 import org.openstreetmap.josm.gui.dialogs.properties.HelpAction;
     22import org.openstreetmap.josm.gui.dialogs.properties.HelpTagAction;
    2323import org.openstreetmap.josm.gui.dialogs.properties.TaginfoAction;
    2424import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     
    9595        tagMenu.add(trackJosmAction(new CopyAllKeyValueAction(table, tagKeyFn, objectSp)));
    9696        tagMenu.addSeparator();
    97         tagMenu.add(trackJosmAction(new HelpAction(table, tagKeyFn, tagValuesFn, null, null)));
     97        tagMenu.add(trackJosmAction(new HelpTagAction(table, tagKeyFn, tagValuesFn)));
    9898        tagMenu.add(trackJosmAction(new TaginfoAction(table, tagKeyFn, tagValuesFn, null, null)));
    9999
Note: See TracChangeset for help on using the changeset viewer.