Changeset 16598 in josm


Ignore:
Timestamp:
2020-06-11T11:32:23+02:00 (8 weeks ago)
Author:
simon04
Message:

see #19369 - PropertiesDialog: avoid re-creating national TaginfoActions on every selection change

File:
1 edited

Legend:

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

    r16597 r16598  
    116116import org.openstreetmap.josm.tools.Logging;
    117117import org.openstreetmap.josm.tools.Shortcut;
     118import org.openstreetmap.josm.tools.TaginfoRegionalInstance;
    118119import org.openstreetmap.josm.tools.Territories;
    119120import org.openstreetmap.josm.tools.Utils;
     
    197198    private final TaginfoAction tagHistoryAction = taginfoAction.toTagHistoryAction();
    198199    private final Collection<TaginfoAction> taginfoNationalActions = new ArrayList<>();
     200    private transient int taginfoNationalHash;
    199201    private final PasteValueAction pasteValueAction = new PasteValueAction();
    200202    private final CopyValueAction copyValueAction = new CopyValueAction(
     
    371373
    372374    private void setupTaginfoNationalActions(Collection<? extends IPrimitive> newSel) {
     375        if (newSel.isEmpty()) {
     376            return;
     377        }
     378        final LatLon center = newSel.iterator().next().getBBox().getCenter();
     379        List<TaginfoRegionalInstance> regionalInstances = Territories.getRegionalTaginfoUrls(center);
     380        int newHashCode = regionalInstances.hashCode();
     381        if (newHashCode == taginfoNationalHash) {
     382            // taginfoNationalActions are still valid
     383            return;
     384        }
     385        taginfoNationalHash = newHashCode;
    373386        destroyTaginfoNationalActions();
    374         if (!newSel.isEmpty()) {
    375             final LatLon center = newSel.iterator().next().getBBox().getCenter();
    376             Territories.getRegionalTaginfoUrls(center).stream()
    377                     .map(taginfo -> taginfoAction.withTaginfoUrl(tr("Go to Taginfo ({0})", taginfo.toString()), taginfo.getUrl())
    378                     ).forEach(taginfoNationalActions::add);
    379             taginfoNationalActions.stream().map(membershipMenu::add).forEach(membershipMenuTagInfoNatItems::add);
    380             taginfoNationalActions.stream().map(tagMenu::add).forEach(tagMenuTagInfoNatItems::add);
    381         }
     387        regionalInstances.stream()
     388                .map(taginfo -> taginfoAction.withTaginfoUrl(tr("Go to Taginfo ({0})", taginfo.toString()), taginfo.getUrl()))
     389                .forEach(taginfoNationalActions::add);
     390        taginfoNationalActions.stream().map(membershipMenu::add).forEach(membershipMenuTagInfoNatItems::add);
     391        taginfoNationalActions.stream().map(tagMenu::add).forEach(tagMenuTagInfoNatItems::add);
    382392    }
    383393
Note: See TracChangeset for help on using the changeset viewer.