001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.tagging.presets.items;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.util.Collection;
007
008import javax.swing.JPanel;
009
010import org.openstreetmap.josm.data.osm.OsmPrimitive;
011import org.openstreetmap.josm.gui.widgets.UrlLabel;
012import org.openstreetmap.josm.tools.GBC;
013
014/**
015 * Hyperlink type.
016 */
017public class Link extends TextItem {
018
019    /** The link to display. */
020    public String href; // NOSONAR
021
022    /** The localized version of {@link #href}. */
023    public String locale_href; // NOSONAR
024
025    @Override
026    public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
027        initializeLocaleText(tr("More information about this feature"));
028        String url = locale_href;
029        if (url == null) {
030            url = href;
031        }
032        if (url != null) {
033            p.add(new UrlLabel(url, locale_text, 2), GBC.eol().insets(0, 10, 0, 0).fill(GBC.HORIZONTAL));
034        }
035        return false;
036    }
037
038    @Override
039    protected String fieldsToString() {
040        return super.fieldsToString()
041                + (href != null ? "href=" + href + ", " : "")
042                + (locale_href != null ? "locale_href=" + locale_href + ", " : "");
043    }
044}