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 = java.util.Optional.ofNullable(locale_href).orElse(href); 029 if (url != null) { 030 p.add(new UrlLabel(url, locale_text, 2), GBC.eol().insets(0, 10, 0, 0).fill(GBC.HORIZONTAL)); 031 } 032 return false; 033 } 034 035 @Override 036 protected String fieldsToString() { 037 return super.fieldsToString() 038 + (href != null ? "href=" + href + ", " : "") 039 + (locale_href != null ? "locale_href=" + locale_href + ", " : ""); 040 } 041}