Ignore:
Timestamp:
2019-10-05T19:23:20+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #17240 - Presets: verify that wiki links are no redirect

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Link.java

    r14649 r15423  
    77import java.util.Arrays;
    88import java.util.Collection;
    9 import java.util.List;
    109import java.util.Optional;
    1110
     
    2221/**
    2322 * Hyperlink type.
     23 * @since 8863
    2424 */
    2525public class Link extends TextItem {
     
    3737    public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
    3838        initializeLocaleText(tr("More information about this feature"));
     39        Optional.ofNullable(buildUrlLabel()).ifPresent(label -> p.add(label, GBC.eol().insets(0, 10, 0, 0).fill(GBC.HORIZONTAL)));
     40        return false;
     41    }
     42
     43    protected UrlLabel buildUrlLabel() {
     44        final String url = getUrl();
    3945        if (wiki != null) {
    40             final String url = Config.getUrls().getOSMWiki() + "/wiki/" + wiki;
    41             final UrlLabel label = new UrlLabel(url, locale_text, 2) {
     46            return new UrlLabel(url, locale_text, 2) {
    4247                @Override
    4348                public void mouseClicked(MouseEvent e) {
    4449                    if (SwingUtilities.isLeftMouseButton(e)) {
    4550                        // Open localized page if exists
    46                         final List<String> pages = Arrays.asList(
     51                        HelpAction.displayHelp(Arrays.asList(
    4752                                LanguageInfo.getWikiLanguagePrefix(LanguageInfo.LocaleType.OSM_WIKI) + wiki,
    48                                 wiki);
    49                         HelpAction.displayHelp(pages);
     53                                wiki));
    5054                    } else {
    5155                        super.mouseClicked(e);
     
    5357                }
    5458            };
    55             p.add(label, GBC.eol().insets(0, 10, 0, 0).fill(GBC.HORIZONTAL));
    5659        } else if (href != null || locale_href != null) {
    57             final String url = Optional.ofNullable(locale_href).orElse(href);
    58             final UrlLabel label = new UrlLabel(url, locale_text, 2);
    59             p.add(label, GBC.eol().insets(0, 10, 0, 0).fill(GBC.HORIZONTAL));
     60            return new UrlLabel(url, locale_text, 2);
    6061        }
    61         return false;
     62        return null;
     63    }
     64
     65    /**
     66     * Returns the link URL.
     67     * @return the link URL
     68     * @since 15423
     69     */
     70    public String getUrl() {
     71        if (wiki != null) {
     72            return Config.getUrls().getOSMWiki() + "/wiki/" + wiki;
     73        } else if (href != null || locale_href != null) {
     74            return Optional.ofNullable(locale_href).orElse(href);
     75        }
     76        return null;
    6277    }
    6378
Note: See TracChangeset for help on using the changeset viewer.