1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.tagging.presets.items;
|
---|
3 |
|
---|
4 | import java.util.Collection;
|
---|
5 |
|
---|
6 | import javax.swing.Icon;
|
---|
7 | import javax.swing.ImageIcon;
|
---|
8 | import javax.swing.JLabel;
|
---|
9 | import javax.swing.JPanel;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
12 | import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader;
|
---|
13 | import org.openstreetmap.josm.tools.GBC;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Label type.
|
---|
17 | */
|
---|
18 | public class Label extends TextItem {
|
---|
19 |
|
---|
20 | /** The location of icon file to display (optional) */
|
---|
21 | public String icon; // NOSONAR
|
---|
22 | /** The size of displayed icon. If not set, default is 16px */
|
---|
23 | public String icon_size; // NOSONAR
|
---|
24 |
|
---|
25 | @Override
|
---|
26 | public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
|
---|
27 | initializeLocaleText(null);
|
---|
28 | addLabel(p, getIcon(), locale_text);
|
---|
29 | return true;
|
---|
30 | }
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Adds a new {@code JLabel} to the given panel.
|
---|
34 | * @param p The panel
|
---|
35 | * @param icon the icon (optional, can be null)
|
---|
36 | * @param label The text label
|
---|
37 | */
|
---|
38 | public static void addLabel(JPanel p, Icon icon, String label) {
|
---|
39 | p.add(new JLabel(label, icon, JLabel.LEADING), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Returns the label icon, if any.
|
---|
44 | * @return the label icon, or {@code null}
|
---|
45 | */
|
---|
46 | public ImageIcon getIcon() {
|
---|
47 | Integer size = parseInteger(icon_size);
|
---|
48 | return icon == null ? null : loadImageIcon(icon, TaggingPresetReader.getZipIcons(), size != null ? size : 16);
|
---|
49 | }
|
---|
50 | }
|
---|