001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.tagging.presets.items; 003 004import java.util.Collection; 005 006import javax.swing.Icon; 007import javax.swing.ImageIcon; 008import javax.swing.JLabel; 009import javax.swing.JPanel; 010 011import org.openstreetmap.josm.data.osm.OsmPrimitive; 012import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader; 013import org.openstreetmap.josm.tools.GBC; 014 015/** 016 * Label type. 017 */ 018public class Label extends TextItem { 019 020 /** The location of icon file to display (optional) */ 021 public String icon; // NOSONAR 022 /** The size of displayed icon. If not set, default is 16px */ 023 public String icon_size; // NOSONAR 024 025 @Override 026 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) { 027 initializeLocaleText(null); 028 addLabel(p, getIcon(), locale_text); 029 return true; 030 } 031 032 /** 033 * Adds a new {@code JLabel} to the given panel. 034 * @param p The panel 035 * @param icon the icon (optional, can be null) 036 * @param label The text label 037 */ 038 public static void addLabel(JPanel p, Icon icon, String label) { 039 p.add(new JLabel(label, icon, JLabel.LEADING), GBC.eol().fill(GBC.HORIZONTAL)); 040 } 041 042 /** 043 * Returns the label icon, if any. 044 * @return the label icon, or {@code null} 045 */ 046 public ImageIcon getIcon() { 047 Integer size = parseInteger(icon_size); 048 return icon == null ? null : loadImageIcon(icon, TaggingPresetReader.getZipIcons(), size != null ? size : 16); 049 } 050}