source: josm/trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Link.java@ 11747

Last change on this file since 11747 was 11553, checked in by Don-vip, 7 years ago

refactor handling of null values - use Java 8 Optional where possible

File size: 1.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging.presets.items;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Collection;
7
8import javax.swing.JPanel;
9
10import org.openstreetmap.josm.data.osm.OsmPrimitive;
11import org.openstreetmap.josm.gui.widgets.UrlLabel;
12import org.openstreetmap.josm.tools.GBC;
13
14/**
15 * Hyperlink type.
16 */
17public class Link extends TextItem {
18
19 /** The link to display. */
20 public String href; // NOSONAR
21
22 /** The localized version of {@link #href}. */
23 public String locale_href; // NOSONAR
24
25 @Override
26 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
27 initializeLocaleText(tr("More information about this feature"));
28 String url = java.util.Optional.ofNullable(locale_href).orElse(href);
29 if (url != null) {
30 p.add(new UrlLabel(url, locale_text, 2), GBC.eol().insets(0, 10, 0, 0).fill(GBC.HORIZONTAL));
31 }
32 return false;
33 }
34
35 @Override
36 protected String fieldsToString() {
37 return super.fieldsToString()
38 + (href != null ? "href=" + href + ", " : "")
39 + (locale_href != null ? "locale_href=" + locale_href + ", " : "");
40 }
41}
Note: See TracBrowser for help on using the repository browser.