- Timestamp:
- 2020-02-18T23:13:44+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
r15835 r15885 938 938 @Override 939 939 public void actionPerformed(ActionEvent e) { 940 keys.setSelectedItem(t.getKey() );940 keys.setSelectedItem(t.getKey(), true); 941 941 // fix #7951, #8298 - update list of values before setting value (?) 942 942 focus.focusGained(null); 943 values.setSelectedItem(t.getValue() );943 values.setSelectedItem(t.getValue(), true); 944 944 selectValuesCombobox(); 945 945 } -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java
r15837 r15885 12 12 import java.util.LinkedList; 13 13 import java.util.Locale; 14 import java.util.stream.IntStream; 14 15 15 16 import javax.swing.ComboBoxEditor; … … 257 258 /** 258 259 * Selects a given item in the ComboBox model 259 * @param item excepts AutoCompletionItem, String andnull260 * @param item the item of type AutoCompletionItem, String or null 260 261 */ 261 262 @Override 262 263 public void setSelectedItem(Object item) { 264 setSelectedItem(item, false); 265 } 266 267 /** 268 * Selects a given item in the ComboBox model 269 * @param item the item of type AutoCompletionItem, String or null 270 * @param disableAutoComplete if true, autocomplete {@linkplain #setAutocompleteEnabled is disabled} during the operation 271 * @since 15885 272 */ 273 public void setSelectedItem(Object item, final boolean disableAutoComplete) { 274 final boolean previousState = isAutocompleteEnabled(); 275 if (disableAutoComplete) { 276 // disable autocomplete to prevent unnecessary actions in AutoCompletingComboBoxDocument#insertString 277 setAutocompleteEnabled(false); 278 } 263 279 if (item == null) { 264 280 super.setSelectedItem(null); … … 268 284 String s = (String) item; 269 285 // find the string in the model or create a new item 270 for (int i = 0; i < getModel().getSize(); i++) { 271 AutoCompletionItem acItem = getModel().getElementAt(i); 272 if (s.equals(acItem.getValue())) { 273 super.setSelectedItem(acItem); 274 return; 275 } 276 } 277 super.setSelectedItem(new AutoCompletionItem(s, AutoCompletionPriority.UNKNOWN)); 286 AutoCompletionItem acItem = IntStream.range(0, getModel().getSize()) 287 .mapToObj(i -> getModel().getElementAt(i)) 288 .filter(i -> s.equals(i.getValue())) 289 .findFirst() 290 .orElseGet(() -> new AutoCompletionItem(s, AutoCompletionPriority.UNKNOWN)); 291 super.setSelectedItem(acItem); 278 292 } else { 293 setAutocompleteEnabled(previousState); 279 294 throw new IllegalArgumentException("Unsupported item: "+item); 280 295 } 296 setAutocompleteEnabled(previousState); 281 297 } 282 298 … … 293 309 } 294 310 this.setSelectedItem(null); 295 // disable autocomplete to prevent unnecessary actions in AutoCompletingComboBoxDocument#insertString 296 autocompleteEnabled = false; 297 this.setSelectedItem(oldValue); 298 autocompleteEnabled = true; 311 this.setSelectedItem(oldValue, true); 299 312 } 300 313
Note:
See TracChangeset
for help on using the changeset viewer.