Changeset 2088 in josm for trunk/src/org
- Timestamp:
- 2009-09-09T19:38:48+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/tagging
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/AutoCompletingTextField.java
r2070 r2088 7 7 import java.awt.event.KeyAdapter; 8 8 import java.awt.event.KeyEvent; 9 import java.util.ArrayList;10 9 import java.util.EventObject; 11 import java.util.LinkedList;12 import java.util.List;13 10 import java.util.logging.Logger; 14 11 … … 17 14 import javax.swing.JTextField; 18 15 import javax.swing.event.CellEditorListener; 19 import javax.swing.event.ChangeEvent;20 16 import javax.swing.table.TableCellEditor; 21 17 import javax.swing.text.AttributeSet; … … 194 190 setText(anObject.toString()); 195 191 } 196 197 192 } 198 193 -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r2055 r2088 68 68 public String locale_name; 69 69 70 private static AutoCompletionList autoCompletionList;71 72 public static AutoCompletionList getPresetAutocompletionList() {73 if (autoCompletionList == null) {74 autoCompletionList = new AutoCompletionList();75 }76 return autoCompletionList;77 }78 79 70 public static abstract class Item { 80 71 protected void initAutoCompletionField(AutoCompletingTextField field, String key) { 81 72 OsmDataLayer layer = Main.main.getEditLayer(); 82 73 if (layer == null) return; 83 field.setAutoCompletionList(getPresetAutocompletionList()); 74 AutoCompletionList list = new AutoCompletionList(); 75 List<String> values = AutoCompletionCache.getCacheForLayer(Main.main.getEditLayer()).getValues(key); 76 list.add(values,AutoCompletionItemPritority.IS_IN_DATASET); 77 field.setAutoCompletionList(list); 84 78 } 85 79 … … 154 148 // find out if our key is already used in the selection. 155 149 Usage usage = determineTextUsage(sel, key); 150 AutoCompletingTextField textField = new AutoCompletingTextField(); 151 initAutoCompletionField(textField, key); 156 152 if (usage.unused()){ 157 AutoCompletingTextField textField = new AutoCompletingTextField();158 initAutoCompletionField(textField, key);159 153 if (use_last_as_default && lastValue.containsKey(key)) { 160 154 textField.setText(lastValue.get(key)); … … 166 160 } else if (usage.hasUniqueValue()) { 167 161 // all objects use the same value 168 AutoCompletingTextField textField = new AutoCompletingTextField();169 initAutoCompletionField(textField, key);170 162 textField.setText(usage.getFirst()); 171 163 value = textField; … … 173 165 } else { 174 166 // the objects have different values 175 AutoCompletingTextField textField = new AutoCompletingTextField();176 initAutoCompletionField(textField, key);177 167 JComboBox comboBox = new JComboBox(usage.values.toArray()); 178 168 comboBox.setEditable(true); … … 646 636 } 647 637 648 protected void refreshAutocompletionList(final OsmDataLayer layer) {649 Runnable task = new Runnable() {650 public void run() {651 System.out.print("refreshing preset auto completion list ...");652 AutoCompletionCache.getCacheForLayer(layer).initFromDataSet();653 AutoCompletionCache.getCacheForLayer(layer).populateWithValues( getPresetAutocompletionList(), false /* don't append */);654 System.out.println("DONE");655 }656 };657 new Thread(task).run();658 659 }660 638 public PresetPanel createPanel(Collection<OsmPrimitive> selected) { 661 639 if (data == null) … … 663 641 OsmDataLayer layer = Main.main.getEditLayer(); 664 642 if (layer != null) { 665 refreshAutocompletionList(layer);643 AutoCompletionCache.getCacheForLayer(layer).initFromDataSet(); 666 644 } 667 645 PresetPanel p = new PresetPanel(); -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionCache.java
r2048 r2088 3 3 import java.util.ArrayList; 4 4 import java.util.Collection; 5 import java.util.Collections;6 5 import java.util.HashMap; 7 6 import java.util.HashSet; 8 import java.util.LinkedList;9 7 import java.util.List; 10 8 import java.util.Set; … … 74 72 /** the cached list of member roles */ 75 73 private Set<String> roleCache; 76 /** the cache of all tag values */77 private Set<String> allTagValues;78 74 /** the layer this cache is built for */ 79 75 private OsmDataLayer layer; … … 86 82 tagCache = new HashMap<String, Set<String>>(); 87 83 roleCache = new HashSet<String>(); 88 allTagValues = new HashSet<String>();89 84 this.layer = layer; 90 85 } … … 114 109 cacheKey(key); 115 110 tagCache.get(key).add(value); 116 allTagValues.add(value);117 111 } 118 112 … … 236 230 list.add(tagCache.keySet(), AutoCompletionItemPritority.IS_IN_DATASET); 237 231 } 238 239 240 /**241 * Populates the an {@see AutoCompletionList} with the currently cached242 * tag values243 *244 * @param list the list to populate245 * @param append true to add the keys to the list; false, to replace the keys246 * in the list by the keys in the cache247 */248 public void populateWithValues(AutoCompletionList list, boolean append) {249 if (!append) {250 list.clear();251 }252 list.add(this.allTagValues, AutoCompletionItemPritority.IS_IN_DATASET);253 }254 232 } -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionList.java
r2048 r2088 4 4 import java.util.Collection; 5 5 import java.util.Collections; 6 import java.util.HashMap; 6 7 import java.util.List; 8 import java.util.Map; 7 9 8 10 import javax.swing.JTable; … … 33 35 /** the filter expression */ 34 36 private String filter = null; 37 /** map from value to priority */ 38 private Map<String,AutoCompletionListItem> valutToItemMap; 35 39 36 40 /** … … 40 44 list = new ArrayList<AutoCompletionListItem>(); 41 45 filtered = new ArrayList<AutoCompletionListItem>(); 46 valutToItemMap = new HashMap<String, AutoCompletionListItem>(); 42 47 } 43 48 … … 148 153 149 154 protected void appendOrUpdatePriority(AutoCompletionListItem toadd) { 150 AutoCompletionListItem item = lookup(toadd.getValue());155 AutoCompletionListItem item = valutToItemMap.get(toadd.getValue()); 151 156 if (item == null) { 152 157 // new item does not exist yet. Add it to the list 153 158 // 154 159 list.add(toadd); 160 valutToItemMap.put(toadd.getValue(), toadd); 155 161 } else { 156 162 // new item already exists. Update priority if necessary … … 191 197 return false; 192 198 } 193 194 /**195 *196 * @param value a specific value197 * @return the auto completion item for this value; null, if there is no198 * such auto completion item199 */200 public AutoCompletionListItem lookup(String value) {201 if (value == null)202 return null;203 for (AutoCompletionListItem item : list) {204 if (item.getValue().equals(value))205 return item;206 }207 return null;208 }209 210 199 211 200 /**
Note:
See TracChangeset
for help on using the changeset viewer.