source: josm/trunk/src/org/openstreetmap/josm/gui/tagging/TagModel.java@ 2040

Last change on this file since 2040 was 2040, checked in by Gubaer, 15 years ago

improved upload dialog
new: tags for changesets
new: multiple uploads to the same changeset
fixed #3381: simple imput of a changeset source
fixed #2491: Allow arbitrary key-value pairs in changesets
fixed #2436: Allow multiple uploads to one changeset

File size: 2.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging;
3
4import java.util.ArrayList;
5import java.util.List;
6
7public class TagModel {
8
9 /** the name of the tag */
10 private String name = null;
11
12 /** the list of values */
13 private ArrayList<String> values = null;
14
15 /**
16 * constructor
17 */
18 public TagModel() {
19 values = new ArrayList<String>();
20 setName("");
21 setValue("");
22 }
23
24 /**
25 * constructor
26 * @param name the tag name
27 */
28 public TagModel(String name) {
29 this();
30 setName(name);
31 }
32
33 /**
34 * constructor
35 *
36 * @param name the tag name
37 * @param value the tag value
38 */
39 public TagModel(String name, String value) {
40 this();
41 setName(name);
42 setValue(value);
43 }
44
45 /**
46 * sets the name. Converts name to "" if null.
47 * @param name the tag name
48 */
49 public void setName(String name) {
50 name = (name == null) ? "" : name;
51 this.name = name;
52 }
53
54 /**
55 * @return the tag name
56 */
57 public String getName(){
58 return name;
59 }
60
61 /**
62 * removes all values from the list of values
63 */
64 public void clearValues() {
65 this.values.clear();
66 }
67
68 /**
69 * sets a unique value for this tag. Converts value to "", if null.
70 * @param value the value.
71 */
72 public void setValue(String value) {
73 value = (value == null) ? "" : value;
74 clearValues();
75 this.values.add(value);
76 }
77
78 /**
79 *
80 * @param value the value to be checked; converted to "" if null
81 * @return true, if the values of this tag include <code>value</code>; false otherwise
82 */
83 public boolean hasValue(String value) {
84 value = (value == null) ? "" : value;
85 return values.contains(value);
86 }
87
88 public void addValue(String value) {
89 value = (value == null) ? "" : value;
90 if (hasValue(value)) {
91 return;
92 }
93 values.add(value);
94 }
95
96
97 /**
98 * removes a value from the list of values. Converts value to "" if null
99 * @param value the value
100 */
101 public void removeValue(String value){
102 value = (value == null) ? "" : value;
103 values.remove(value);
104 }
105
106 public List<String> getValues() {
107 return values;
108 }
109
110 public String getValue() {
111 if (getValueCount() == 0) {
112 return "";
113 } else if (getValueCount() == 1) {
114 return values.get(0);
115 } else {
116 StringBuilder sb = new StringBuilder();
117 for (int i =0; i < values.size(); i++) {
118 sb.append(values.get(i));
119 if (i + 1 < values.size()) {
120 sb.append(";");
121 }
122 }
123 return sb.toString();
124 }
125 }
126
127 public int getValueCount() {
128 return values.size();
129 }
130}
Note: See TracBrowser for help on using the repository browser.