Changeset 16274 in josm for trunk


Ignore:
Timestamp:
2020-04-12T16:21:14+02:00 (4 years ago)
Author:
simon04
Message:

see #19075 - Generify HelpTagAction

File:
1 edited

Legend:

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

    r15581 r16274  
    88import java.util.Objects;
    99import java.util.function.IntFunction;
     10import java.util.function.Supplier;
    1011
    1112import javax.swing.JTable;
    1213
     14import org.openstreetmap.josm.data.osm.Tag;
    1315import org.openstreetmap.josm.gui.MainApplication;
    1416
     
    1820 */
    1921public class HelpTagAction extends HelpAction {
    20     private final JTable tagTable;
    21     private final IntFunction<String> tagKeySupplier;
    22     private final IntFunction<Map<String, Integer>> tagValuesSupplier;
     22    private final Supplier<Tag> tagSupplier;
     23
     24    /**
     25     * Constructs a new {@code HelpAction}.
     26     * @param tagSupplier Supplies the tag for which the help should be shown
     27     * @since 16274
     28     */
     29    public HelpTagAction(Supplier<Tag> tagSupplier) {
     30        this.tagSupplier = Objects.requireNonNull(tagSupplier);
     31        putValue(NAME, tr("Go to OSM wiki for tag help"));
     32    }
    2333
    2434    /**
     
    2939     */
    3040    public HelpTagAction(JTable tagTable, IntFunction<String> tagKeySupplier, IntFunction<Map<String, Integer>> tagValuesSupplier) {
    31         this.tagTable = Objects.requireNonNull(tagTable);
    32         this.tagKeySupplier = Objects.requireNonNull(tagKeySupplier);
    33         this.tagValuesSupplier = Objects.requireNonNull(tagValuesSupplier);
     41        this.tagSupplier = () -> {
     42            if (tagTable.getSelectedRowCount() == 1) {
     43                int row = tagTable.getSelectedRow();
     44                String key = tagKeySupplier.apply(row);
     45                Map<String, Integer> m = tagValuesSupplier.apply(row);
     46                if (!m.isEmpty()) {
     47                    String val = m.entrySet().iterator().next().getKey();
     48                    return new Tag(key, val);
     49                }
     50            }
     51            return null;
     52        };
    3453        putValue(NAME, tr("Go to OSM wiki for tag help"));
    3554    }
     
    3756    @Override
    3857    public void actionPerformed(ActionEvent e) {
    39         if (tagTable.getSelectedRowCount() == 1) {
    40             int row = tagTable.getSelectedRow();
    41             String key = tagKeySupplier.apply(row);
    42             Map<String, Integer> m = tagValuesSupplier.apply(row);
    43             if (!m.isEmpty()) {
    44                 String val = m.entrySet().iterator().next().getKey();
    45                 MainApplication.worker.execute(() -> displayTagHelp(key, val));
    46             }
     58        Tag tag = tagSupplier.get();
     59        if (tag != null) {
     60            MainApplication.worker.execute(() -> displayTagHelp(tag.getKey(), tag.getValue()));
    4761        } else {
    4862            super.actionPerformed(e);
Note: See TracChangeset for help on using the changeset viewer.