- Timestamp:
- 2009-09-04T10:49:53+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 11 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r2044 r2048 66 66 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 67 67 import org.openstreetmap.josm.gui.SideButton; 68 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionCache;69 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionList;70 68 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 71 69 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; … … 75 73 import org.openstreetmap.josm.gui.tagging.TagEditorModel; 76 74 import org.openstreetmap.josm.gui.tagging.TagTable; 75 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 76 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 77 77 import org.openstreetmap.josm.io.OsmApi; 78 78 import org.openstreetmap.josm.io.OsmServerObjectReader; … … 125 125 // 126 126 acCache = AutoCompletionCache.getCacheForLayer(getLayer()); 127 acCache.initFrom JOSMDataset();127 acCache.initFromDataSet(); 128 128 acList = new AutoCompletionList(); 129 129 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberRoleCellEditor.java
r2040 r2048 9 9 import javax.swing.table.TableCellEditor; 10 10 11 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionCache;12 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionItemPritority;13 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionList;14 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionListItem;15 11 import org.openstreetmap.josm.gui.tagging.AutoCompletingTextField; 12 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 13 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPritority; 14 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 15 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem; 16 16 17 17 public class MemberRoleCellEditor extends AbstractCellEditor implements TableCellEditor { -
trunk/src/org/openstreetmap/josm/gui/tagging/AutoCompletingTextField.java
r2040 r2048 2 2 package org.openstreetmap.josm.gui.tagging; 3 3 4 import java.awt.Component; 4 5 import java.awt.event.FocusAdapter; 5 6 import java.awt.event.FocusEvent; … … 8 9 import java.util.logging.Logger; 9 10 11 import javax.swing.ComboBoxEditor; 10 12 import javax.swing.JTextField; 11 13 import javax.swing.text.AttributeSet; … … 14 16 import javax.swing.text.PlainDocument; 15 17 16 import org.openstreetmap.josm.gui. dialogs.relation.ac.AutoCompletionList;18 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 17 19 18 20 /** … … 25 27 * 26 28 */ 27 public class AutoCompletingTextField extends JTextField { 29 public class AutoCompletingTextField extends JTextField implements ComboBoxEditor { 28 30 29 31 static private Logger logger = Logger.getLogger(AutoCompletingTextField.class.getName()); … … 54 56 return; 55 57 } 58 56 59 String currentText = getText(0, getLength()); 60 // if the text starts with a number we don't autocomplete 61 // 62 try { 63 Long.parseLong(str); 64 if (currentText.length() == 0) { 65 // we don't autocomplete on numbers 66 super.insertString(offs, str, a); 67 return; 68 } 69 Long.parseLong(currentText); 70 super.insertString(offs, str, a); 71 return; 72 } catch(NumberFormatException e) { 73 // either the new text or the current text isn't a number. We continue with 74 // autocompletion 75 } 57 76 String prefix = currentText.substring(0, offs); 58 77 autoCompletionList.applyFilter(prefix+str); … … 150 169 this.autoCompletionList = autoCompletionList; 151 170 } 171 172 public Component getEditorComponent() { 173 return this; 174 } 175 176 public Object getItem() { 177 return getText(); 178 } 179 180 public void setItem(Object anObject) { 181 if (anObject == null) { 182 setText(""); 183 } else { 184 setText(anObject.toString()); 185 } 186 187 } 188 189 152 190 } -
trunk/src/org/openstreetmap/josm/gui/tagging/TagCellEditor.java
r2040 r2048 9 9 import javax.swing.table.TableCellEditor; 10 10 11 import org.openstreetmap.josm.gui. dialogs.relation.ac.AutoCompletionCache;12 import org.openstreetmap.josm.gui. dialogs.relation.ac.AutoCompletionItemPritority;13 import org.openstreetmap.josm.gui. dialogs.relation.ac.AutoCompletionList;14 import org.openstreetmap.josm.gui. dialogs.relation.ac.AutoCompletionListItem;11 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 12 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPritority; 13 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 14 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem; 15 15 16 16 /** -
trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java
r2046 r2048 20 20 import javax.swing.event.ListSelectionListener; 21 21 22 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionCache;23 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionList;24 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 23 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 24 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 25 25 import org.openstreetmap.josm.tools.ImageProvider; 26 26 … … 228 228 // 229 229 acCache = AutoCompletionCache.getCacheForLayer(layer); 230 acCache.initFrom JOSMDataset();230 acCache.initFromDataSet(); 231 231 acList = new AutoCompletionList(); 232 232 -
trunk/src/org/openstreetmap/josm/gui/tagging/TagTable.java
r2040 r2048 34 34 35 35 import org.openstreetmap.josm.gui.dialogs.relation.RunnableAction; 36 import org.openstreetmap.josm.gui. dialogs.relation.ac.AutoCompletionCache;37 import org.openstreetmap.josm.gui. dialogs.relation.ac.AutoCompletionList;36 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 37 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 38 38 39 39 /** -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r2017 r2048 18 18 import java.util.Collection; 19 19 import java.util.HashMap; 20 import java.util.HashSet;21 20 import java.util.LinkedHashMap; 22 21 import java.util.LinkedList; 23 22 import java.util.List; 24 import java.util.Set; 23 import java.util.TreeSet; 25 24 26 25 import javax.swing.AbstractAction; … … 45 44 import org.openstreetmap.josm.gui.ExtendedDialog; 46 45 import org.openstreetmap.josm.gui.QuadStateCheckBox; 46 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 47 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 48 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPritority; 49 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 47 50 import org.openstreetmap.josm.io.MirroredInputStream; 48 51 import org.openstreetmap.josm.tools.GBC; … … 66 69 67 70 public static abstract class Item { 71 protected void initAutoCompletionField(AutoCompletingTextField field, String key) { 72 OsmDataLayer layer = Main.main.getEditLayer(); 73 if (layer == null) return; 74 AutoCompletionCache cache = AutoCompletionCache.getCacheForLayer(layer); 75 AutoCompletionList list = new AutoCompletionList(); 76 cache.populateWithValues(list, false /* don't append */); 77 field.setAutoCompletionList(list); 78 } 79 68 80 public boolean focus = false; 69 81 abstract boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel); … … 73 85 74 86 public static class Usage { 75 Set<String> values; 76 Boolean hadKeys = false; 77 Boolean hadEmpty = false; 78 public Boolean allSimilar() 79 { 87 TreeSet<String> values; 88 boolean hadKeys = false; 89 boolean hadEmpty = false; 90 public boolean hasUniqueValue() { 80 91 return values.size() == 1 && !hadEmpty; 81 92 } 82 public Boolean unused() 83 { 93 94 public boolean unused() { 84 95 return values.size() == 0; 85 96 } 86 public String getFirst() 87 { 88 return (String)(values.toArray()[0]); 89 } 90 public Boolean hadKeys() 91 { 97 public String getFirst() { 98 return values.first(); 99 } 100 101 public boolean hadKeys() { 92 102 return hadKeys; 93 103 } … … 98 108 static Usage determineTextUsage(Collection<OsmPrimitive> sel, String key) { 99 109 Usage returnValue = new Usage(); 100 returnValue.values = new HashSet<String>();110 returnValue.values = new TreeSet<String>(); 101 111 for (OsmPrimitive s : sel) { 102 112 String v = s.get(key); … … 106 116 returnValue.hadEmpty = true; 107 117 } 108 returnValue.hadKeys = returnValue.had Keys | s.hasKeys();118 returnValue.hadKeys = ! returnValue.values.isEmpty() | returnValue.hadEmpty; 109 119 } 110 120 return returnValue; … … 114 124 115 125 Usage returnValue = new Usage(); 116 returnValue.values = new HashSet<String>();126 returnValue.values = new TreeSet<String>(); 117 127 for (OsmPrimitive s : sel) { 118 128 returnValue.values.add(OsmUtils.getNamedOsmBoolean(s.get(key))); … … 133 143 private JComponent value; 134 144 145 135 146 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 136 147 137 148 // find out if our key is already used in the selection. 138 149 Usage usage = determineTextUsage(sel, key); 139 if (usage.unused()) 140 {141 value = new JTextField();150 if (usage.unused()){ 151 AutoCompletingTextField textField = new AutoCompletingTextField(); 152 initAutoCompletionField(textField, key); 142 153 if (use_last_as_default && lastValue.containsKey(key)) { 143 ((JTextField)value).setText(lastValue.get(key));154 textField.setText(lastValue.get(key)); 144 155 } else { 145 ((JTextField)value).setText(default_); 146 } 156 textField.setText(default_); 157 } 158 value = textField; 147 159 originalValue = null; 148 } else if (usage. allSimilar()) {160 } else if (usage.hasUniqueValue()) { 149 161 // all objects use the same value 150 value= newJTextField();151 for (String s : usage.values) {152 ((JTextField) value).setText(s);153 }154 originalValue = ((JTextField)value).getText();162 AutoCompletingTextField textField = new AutoCompletingTextField(); 163 initAutoCompletionField(textField, key); 164 textField.setText(usage.getFirst()); 165 value = textField; 166 originalValue = usage.getFirst(); 155 167 } else { 156 168 // the objects have different values 157 value = new JComboBox(usage.values.toArray()); 158 ((JComboBox)value).setEditable(true); 159 ((JComboBox)value).getEditor().setItem(DIFFERENT); 169 AutoCompletingTextField textField = new AutoCompletingTextField(); 170 initAutoCompletionField(textField, key); 171 JComboBox comboBox = new JComboBox(usage.values.toArray()); 172 comboBox.setEditable(true); 173 comboBox.setEditor(textField); 174 comboBox.getEditor().setItem(DIFFERENT); 175 value=comboBox; 160 176 originalValue = DIFFERENT; 161 177 } … … 300 316 301 317 lhm = new LinkedHashMap<String,String>(); 302 if (!usage.allSimilar() && !usage.unused()) 303 { 318 if (!usage.hasUniqueValue() && !usage.unused()){ 304 319 lhm.put(DIFFERENT, DIFFERENT); 305 320 } … … 309 324 tr(display_array[i]) : display_array[i]); 310 325 } 311 if(!usage.unused()) 312 { 326 if(!usage.unused()){ 313 327 for (String s : usage.values) { 314 328 if (!lhm.containsKey(s)) { … … 326 340 combo = new JComboBox(lhm.values().toArray()); 327 341 combo.setEditable(editable); 328 if (usage.allSimilar() && !usage.unused()) 329 { 342 AutoCompletingTextField tf = new AutoCompletingTextField(); 343 initAutoCompletionField(tf, key); 344 tf.getAutoCompletionList().add(Arrays.asList(display_array), AutoCompletionItemPritority.IS_IN_STANDARD); 345 combo.setEditor(tf); 346 347 if (usage.hasUniqueValue() && !usage.unused()){ 330 348 originalValue=usage.getFirst(); 331 349 combo.setSelectedItem(lhm.get(originalValue)); 332 350 } 333 351 // use default only in case it is a totally new entry 334 else if(default_ != null && !usage.hadKeys()) 335 { 352 else if(default_ != null && !usage.hadKeys()) { 336 353 combo.setSelectedItem(default_); 337 354 originalValue=DIFFERENT; 338 355 } 339 else if(usage.unused()) 340 { 356 else if(usage.unused()){ 341 357 combo.setSelectedItem(""); 342 358 originalValue=""; 343 359 } 344 else 345 { 360 else{ 346 361 combo.setSelectedItem(DIFFERENT); 347 362 originalValue=DIFFERENT; … … 628 643 if (data == null) 629 644 return null; 645 OsmDataLayer layer = Main.main.getEditLayer(); 646 if (layer != null) { 647 AutoCompletionCache.getCacheForLayer(layer).initFromDataSet(); 648 } 630 649 PresetPanel p = new PresetPanel(); 631 650 LinkedList<Item> l = new LinkedList<Item>(); 632 if(types != null) 633 { 651 if(types != null){ 634 652 JPanel pp = new JPanel(); 635 for(String t : types) 636 { 653 for(String t : types){ 637 654 JLabel la = new JLabel(ImageProvider.get("Mf_" + t)); 638 655 la.setToolTipText(tr("Elements of type {0} are supported.", tr(t))); … … 642 659 } 643 660 644 for (Item i : data) 645 { 661 for (Item i : data){ 646 662 if(i instanceof Link) { 647 663 l.add(i); 648 } else 649 { 664 } else { 650 665 if(i.addToPanel(p, selected)) { 651 666 p.hasElements = true; … … 683 698 true); 684 699 contentConstraints = GBC.eol().fill().insets(5,10,5,0); 685 setupDialog(content, new String[] {"ok.png", "cancel.png" }); 700 setButtonIcons(new String[] {"ok.png", "cancel.png" }); 701 setContent(content); 702 setupDialog(); 686 703 buttons.get(0).setEnabled(!disableApply); 687 704 buttons.get(0).setToolTipText(title); -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionCache.java
r1930 r2048 1 package org.openstreetmap.josm.gui. dialogs.relation.ac;1 package org.openstreetmap.josm.gui.tagging.ac; 2 2 3 3 import java.util.ArrayList; … … 5 5 import java.util.Collections; 6 6 import java.util.HashMap; 7 import java.util.HashSet; 8 import java.util.LinkedList; 7 9 import java.util.List; 10 import java.util.Set; 8 11 import java.util.logging.Logger; 9 12 … … 67 70 68 71 69 /** the cache */ 70 private HashMap<String, ArrayList<String>> cache; 71 private ArrayList<String> roleCache; 72 /** the cached tags give by a tag key and a list of values for this tag*/ 73 private HashMap<String, Set<String>> tagCache; 74 /** the cached list of member roles */ 75 private Set<String> roleCache; 76 /** the cache of all tag values */ 77 private Set<String> allTagValues; 78 /** the layer this cache is built for */ 72 79 private OsmDataLayer layer; 73 80 81 74 82 /** 75 83 * constructor 76 84 */ 77 85 public AutoCompletionCache(OsmDataLayer layer) { 78 cache = new HashMap<String, ArrayList<String>>(); 79 roleCache = new ArrayList<String>(); 86 tagCache = new HashMap<String, Set<String>>(); 87 roleCache = new HashSet<String>(); 88 allTagValues = new HashSet<String>(); 80 89 this.layer = layer; 81 90 } … … 91 100 */ 92 101 protected void cacheKey(String key) { 93 if ( cache.containsKey(key))102 if (tagCache.containsKey(key)) 94 103 return; 95 else { 96 cache.put(key, new ArrayList<String>()); 97 } 104 tagCache.put(key, new HashSet<String>()); 98 105 } 99 106 … … 106 113 protected void cacheValue(String key, String value) { 107 114 cacheKey(key); 108 ArrayList<String> values = cache.get(key); 109 if (!values.contains(value)) { 110 values.add(value); 111 } 115 tagCache.get(key).add(value); 116 allTagValues.add(value); 112 117 } 113 118 … … 143 148 * 144 149 */ 145 public void initFrom JOSMDataset() {146 cache = new HashMap<String,ArrayList<String>>();150 public void initFromDataSet() { 151 tagCache = new HashMap<String, Set<String>>(); 147 152 if (layer == null) 148 153 return; … … 152 157 } 153 158 for (Relation relation : layer.data.relations) { 154 if (relation.incomplete || relation. deleted) {159 if (relation.incomplete || relation.isDeleted()) { 155 160 continue; 156 161 } 157 162 cacheRelationMemberRoles(relation); 158 Collections.sort(roleCache);159 163 } 160 164 } … … 166 170 */ 167 171 public List<String> getKeys() { 168 return new ArrayList<String>( cache.keySet());172 return new ArrayList<String>(tagCache.keySet()); 169 173 } 170 174 … … 177 181 */ 178 182 public List<String> getValues(String key) { 179 if (! cache.containsKey(key))183 if (!tagCache.containsKey(key)) 180 184 return new ArrayList<String>(); 181 return cache.get(key);185 return new ArrayList<String>(tagCache.get(key)); 182 186 } 183 187 … … 188 192 */ 189 193 public List<String> getMemberRoles() { 190 return roleCache; 194 return new ArrayList<String>(roleCache); 191 195 } 192 196 … … 199 203 public void populateWithMemberRoles(AutoCompletionList list) { 200 204 list.clear(); 201 for (String role: roleCache) { 202 list.add(new AutoCompletionListItem(role, AutoCompletionItemPritority.IS_IN_DATASET)); 203 } 205 list.add(roleCache, AutoCompletionItemPritority.IS_IN_DATASET); 206 } 207 208 /** 209 * Populates the an {@see AutoCompletionList} with the currently cached 210 * values for a tag 211 * 212 * @param list the list to populate 213 * @param key the tag key 214 * @param append true to add the values to the list; false, to replace the values 215 * in the list by the tag values 216 */ 217 public void populateWithTagValues(AutoCompletionList list, String key, boolean append) { 218 if (!append) { 219 list.clear(); 220 } 221 list.add(getValues(key), AutoCompletionItemPritority.IS_IN_DATASET); 222 } 223 224 /** 225 * Populates the an {@see AutoCompletionList} with the currently cached 226 * tag keys 227 * 228 * @param list the list to populate 229 * @param append true to add the keys to the list; false, to replace the keys 230 * in the list by the keys in the cache 231 */ 232 public void populateWithKeys(AutoCompletionList list, boolean append) { 233 if (!append) { 234 list.clear(); 235 } 236 list.add(tagCache.keySet(), AutoCompletionItemPritority.IS_IN_DATASET); 237 } 238 239 240 /** 241 * Populates the an {@see AutoCompletionList} with the currently cached 242 * tag values 243 * 244 * @param list the list to populate 245 * @param append true to add the keys to the list; false, to replace the keys 246 * in the list by the keys in the cache 247 */ 248 public void populateWithValues(AutoCompletionList list, boolean append) { 249 if (!append) { 250 list.clear(); 251 } 252 list.add(this.allTagValues, AutoCompletionItemPritority.IS_IN_DATASET); 204 253 } 205 254 } -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionItemPritority.java
r1762 r2048 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui. dialogs.relation.ac;2 package org.openstreetmap.josm.gui.tagging.ac; 3 3 4 4 public enum AutoCompletionItemPritority implements Comparable<AutoCompletionItemPritority> { -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionList.java
r1762 r2048 1 package org.openstreetmap.josm.gui. dialogs.relation.ac;1 package org.openstreetmap.josm.gui.tagging.ac; 2 2 3 3 import java.util.ArrayList; 4 import java.util.Collection; 4 5 import java.util.Collections; 5 6 import java.util.List; … … 125 126 } 126 127 128 /** 129 * adds a list of strings to this list. Only strings which 130 * are not null and which do not exist yet in the list are added. 131 * 132 * @param value a list of strings to add 133 * @param priority the priority to use 134 */ 135 public void add(Collection<String> values, AutoCompletionItemPritority priority) { 136 if (values == null) return; 137 for (String value: values) { 138 if (value == null) { 139 continue; 140 } 141 AutoCompletionListItem item = new AutoCompletionListItem(value,priority); 142 appendOrUpdatePriority(item); 143 144 } 145 sort(); 146 filter(); 147 } 148 127 149 protected void appendOrUpdatePriority(AutoCompletionListItem toadd) { 128 150 AutoCompletionListItem item = lookup(toadd.getValue()); -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionListItem.java
r1762 r2048 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui. dialogs.relation.ac;2 package org.openstreetmap.josm.gui.tagging.ac; 3 3 4 4 /**
Note:
See TracChangeset
for help on using the changeset viewer.