Changeset 949 in josm for trunk/src/org
- Timestamp:
- 2008-09-13T14:36:19+02:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r916 r949 67 67 public static class Usage { 68 68 Set<String> values; 69 Boolean hadKeys = false; 70 Boolean hadEmpty = false; 71 public Boolean allSimilar() 72 { 73 return values.size() == 1 && !hadEmpty; 74 } 75 public Boolean unused() 76 { 77 return values.size() == 0; 78 } 79 public String getFirst() 80 { 81 return (String)(values.toArray()[0]); 82 } 83 public Boolean hadKeys() 84 { 85 return hadKeys; 86 } 69 87 } 70 88 … … 76 94 for (OsmPrimitive s : sel) { 77 95 String v = s.get(key); 78 /* if (v != null) */ returnValue.values.add(v); 96 if (v != null) 97 returnValue.values.add(v); 98 else 99 returnValue.hadEmpty = true; 100 if(s.keys != null && s.keys.size() > 0) 101 returnValue.hadKeys = true; 79 102 } 80 103 return returnValue; … … 107 130 // find out if our key is already used in the selection. 108 131 Usage usage = determineTextUsage(sel, key); 109 if (usage.values.size() == 1 && usage.values.toArray()[0] == null) { 132 if (usage.unused()) 133 { 110 134 value = new JTextField(); 111 135 if (use_last_as_default && lastValue.containsKey(key)) { … … 114 138 ((JTextField)value).setText(default_); 115 139 } 116 } else if (usage. values.size() == 1) {140 } else if (usage.allSimilar()) { 117 141 // all objects use the same value 118 142 value = new JTextField(); … … 123 147 value = new JComboBox(usage.values.toArray()); 124 148 ((JComboBox)value).setEditable(true); 125 126 149 ((JComboBox)value).getEditor().setItem(DIFFERENT); 150 originalValue = DIFFERENT; 127 151 } 128 152 if(locale_text == null) … … 244 268 245 269 lhm = new LinkedHashMap<String,String>(); 246 if (usage.values.size() > 1) { 270 if (!usage.allSimilar() && !usage.unused()) 271 { 247 272 lhm.put(DIFFERENT, DIFFERENT); 248 273 } … … 252 277 tr(display_array[i]) : display_array[i]); 253 278 } 254 for (String s : usage.values) { 255 if (!lhm.containsKey(s)) lhm.put(s, s); 256 } 257 if ((default_ != null) && (!lhm.containsKey(default_))) lhm.put(default_, default_); 258 279 if(!usage.unused()) 280 { 281 for (String s : usage.values) { 282 if (!lhm.containsKey(s)) lhm.put(s, s); 283 } 284 } 285 if (default_ != null && !lhm.containsKey(default_)) lhm.put(default_, default_); 286 if(!lhm.containsKey("")) lhm.put("", ""); 287 259 288 combo = new JComboBox(lhm.values().toArray()); 260 289 combo.setEditable(editable); 261 if (usage.values.size() == 1) { 262 for (String s : usage.values) { combo.setSelectedItem(lhm.get(s)); originalValue=s; } 263 } else { 264 combo.setSelectedItem(DIFFERENT); originalValue=DIFFERENT; 265 } 290 if (usage.allSimilar() && !usage.unused()) 291 { 292 originalValue=usage.getFirst(); 293 combo.setSelectedItem(lhm.get(originalValue)); 294 } 295 // use default only in case it is a totally new entry 296 else if(default_ != null && !usage.hadKeys()) 297 { 298 combo.setSelectedItem(default_); 299 originalValue=DIFFERENT; 300 } 301 else if(usage.unused()) 302 { 303 combo.setSelectedItem(""); 304 originalValue=""; 305 } 306 else 307 { 308 combo.setSelectedItem(DIFFERENT); 309 originalValue=DIFFERENT; 310 } 311 266 312 if(locale_text == null) 267 313 locale_text = tr(text);
Note:
See TracChangeset
for help on using the changeset viewer.