Changeset 2088 in josm


Ignore:
Timestamp:
2009-09-09T19:38:48+02:00 (15 years ago)
Author:
Gubaer
Message:

see #3393: loooong delay when using presets with a large osm file

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  
    77import java.awt.event.KeyAdapter;
    88import java.awt.event.KeyEvent;
    9 import java.util.ArrayList;
    109import java.util.EventObject;
    11 import java.util.LinkedList;
    12 import java.util.List;
    1310import java.util.logging.Logger;
    1411
     
    1714import javax.swing.JTextField;
    1815import javax.swing.event.CellEditorListener;
    19 import javax.swing.event.ChangeEvent;
    2016import javax.swing.table.TableCellEditor;
    2117import javax.swing.text.AttributeSet;
     
    194190            setText(anObject.toString());
    195191        }
    196 
    197192    }
    198193
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r2055 r2088  
    6868    public String locale_name;
    6969
    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 
    7970    public static abstract class Item {
    8071        protected void initAutoCompletionField(AutoCompletingTextField field, String key) {
    8172            OsmDataLayer layer = Main.main.getEditLayer();
    8273            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);
    8478        }
    8579
     
    154148            // find out if our key is already used in the selection.
    155149            Usage usage = determineTextUsage(sel, key);
     150            AutoCompletingTextField textField = new AutoCompletingTextField();
     151            initAutoCompletionField(textField, key);
    156152            if (usage.unused()){
    157                 AutoCompletingTextField textField = new AutoCompletingTextField();
    158                 initAutoCompletionField(textField, key);
    159153                if (use_last_as_default && lastValue.containsKey(key)) {
    160154                    textField.setText(lastValue.get(key));
     
    166160            } else if (usage.hasUniqueValue()) {
    167161                // all objects use the same value
    168                 AutoCompletingTextField textField = new AutoCompletingTextField();
    169                 initAutoCompletionField(textField, key);
    170162                textField.setText(usage.getFirst());
    171163                value = textField;
     
    173165            } else {
    174166                // the objects have different values
    175                 AutoCompletingTextField textField = new AutoCompletingTextField();
    176                 initAutoCompletionField(textField, key);
    177167                JComboBox comboBox = new JComboBox(usage.values.toArray());
    178168                comboBox.setEditable(true);
     
    646636    }
    647637
    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     }
    660638    public PresetPanel createPanel(Collection<OsmPrimitive> selected) {
    661639        if (data == null)
     
    663641        OsmDataLayer layer = Main.main.getEditLayer();
    664642        if (layer != null) {
    665             refreshAutocompletionList(layer);
     643            AutoCompletionCache.getCacheForLayer(layer).initFromDataSet();
    666644        }
    667645        PresetPanel p = new PresetPanel();
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionCache.java

    r2048 r2088  
    33import java.util.ArrayList;
    44import java.util.Collection;
    5 import java.util.Collections;
    65import java.util.HashMap;
    76import java.util.HashSet;
    8 import java.util.LinkedList;
    97import java.util.List;
    108import java.util.Set;
     
    7472    /** the cached list of member roles */
    7573    private  Set<String> roleCache;
    76     /** the cache of all tag values */
    77     private  Set<String> allTagValues;
    7874    /**  the layer this cache is built for */
    7975    private OsmDataLayer layer;
     
    8682        tagCache = new HashMap<String, Set<String>>();
    8783        roleCache = new HashSet<String>();
    88         allTagValues = new HashSet<String>();
    8984        this.layer = layer;
    9085    }
     
    114109        cacheKey(key);
    115110        tagCache.get(key).add(value);
    116         allTagValues.add(value);
    117111    }
    118112
     
    236230        list.add(tagCache.keySet(), AutoCompletionItemPritority.IS_IN_DATASET);
    237231    }
    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);
    253     }
    254232}
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionList.java

    r2048 r2088  
    44import java.util.Collection;
    55import java.util.Collections;
     6import java.util.HashMap;
    67import java.util.List;
     8import java.util.Map;
    79
    810import javax.swing.JTable;
     
    3335    /** the filter expression */
    3436    private String filter = null;
     37    /** map from value to priority */
     38    private Map<String,AutoCompletionListItem> valutToItemMap;
    3539
    3640    /**
     
    4044        list = new ArrayList<AutoCompletionListItem>();
    4145        filtered = new ArrayList<AutoCompletionListItem>();
     46        valutToItemMap = new HashMap<String, AutoCompletionListItem>();
    4247    }
    4348
     
    148153
    149154    protected void appendOrUpdatePriority(AutoCompletionListItem toadd) {
    150         AutoCompletionListItem item = lookup(toadd.getValue());
     155        AutoCompletionListItem item = valutToItemMap.get(toadd.getValue());
    151156        if (item == null) {
    152157            // new item does not exist yet. Add it to the list
    153158            //
    154159            list.add(toadd);
     160            valutToItemMap.put(toadd.getValue(), toadd);
    155161        } else {
    156162            // new item already exists. Update priority if necessary
     
    191197        return false;
    192198    }
    193 
    194     /**
    195      *
    196      * @param value a specific value
    197      * @return  the auto completion item for this value; null, if there is no
    198      *   such auto completion item
    199      */
    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 
    210199
    211200    /**
Note: See TracChangeset for help on using the changeset viewer.