source: josm/trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItem.java@ 6572

Last change on this file since 6572 was 6336, checked in by Don-vip, 11 years ago

code cleanup / robustness in edit layer handling

File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging;
3
4import java.util.Collection;
5import java.util.List;
6import java.util.Map;
7
8import javax.swing.JPanel;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.data.osm.OsmPrimitive;
12import org.openstreetmap.josm.data.osm.Tag;
13import org.openstreetmap.josm.gui.layer.OsmDataLayer;
14import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
15import 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 */
21public 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}
Note: See TracBrowser for help on using the repository browser.