1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.tagging;
|
---|
3 |
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.List;
|
---|
6 | import java.util.Map;
|
---|
7 |
|
---|
8 | import javax.swing.JPanel;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
12 | import org.openstreetmap.josm.data.osm.Tag;
|
---|
13 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
14 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
|
---|
15 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Class that represents single part of a preset - one field or text label that is shown to user
|
---|
19 | * @since 6068
|
---|
20 | */
|
---|
21 | public abstract class TaggingPresetItem {
|
---|
22 |
|
---|
23 | protected void initAutoCompletionField(AutoCompletingTextField field, String key) {
|
---|
24 | if (Main.main == null) return;
|
---|
25 | OsmDataLayer layer = Main.main.getEditLayer();
|
---|
26 | if (layer == null) {
|
---|
27 | return;
|
---|
28 | }
|
---|
29 | AutoCompletionList list = new AutoCompletionList();
|
---|
30 | layer.data.getAutoCompletionManager().populateWithTagValues(list, key);
|
---|
31 | field.setAutoCompletionList(list);
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Called by {@link TaggingPreset#createPanel} during tagging preset panel creation.
|
---|
36 | * All components defining this tagging preset item must be added to given panel.
|
---|
37 | * @param p The panel where components must be added
|
---|
38 | * @param sel The related selected OSM primitives
|
---|
39 | * @return {@code true} if this item adds semantic tagging elements, {@code false} otherwise.
|
---|
40 | */
|
---|
41 | abstract boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel);
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Adds the new tags to apply to selected OSM primitives when the preset holding this item is applied.
|
---|
45 | * @param changedTags The list of changed tags to modify if needed
|
---|
46 | */
|
---|
47 | abstract void addCommands(List<Tag> changedTags);
|
---|
48 |
|
---|
49 | boolean requestFocusInWindow() {
|
---|
50 | return false;
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Tests whether the tags match this item.
|
---|
55 | * Note that for a match, at least one positive and no negative is required.
|
---|
56 | * @param tags the tags of an {@link OsmPrimitive}
|
---|
57 | * @return {@code true} if matches (positive), {@code null} if neutral, {@code false} if mismatches (negative).
|
---|
58 | */
|
---|
59 | Boolean matches(Map<String, String> tags) {
|
---|
60 | return null;
|
---|
61 | }
|
---|
62 | }
|
---|