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