Changeset 12758 in josm


Ignore:
Timestamp:
2017-09-06T15:29:05+02:00 (3 months ago)
Author:
Don-vip
Message:

see #15229 - see #15182 - deprecate DataSet.getAutoCompletionManager() - replacement: AutoCompletionManager.of(DataSet)

Location:
trunk/src/org/openstreetmap/josm
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r12726 r12758  
    334334
    335335    /**
    336      * Maintains a list of used tags for autocompletion.
    337      */
    338     private AutoCompletionManager autocomplete;
    339 
    340     /**
    341336     * Returns the autocompletion manager, which maintains a list of used tags for autocompletion.
    342337     * @return the autocompletion manager
    343      */
     338     * @deprecated to be removed end of 2017. Use {@link AutoCompletionManager#of(DataSet)} instead.
     339     */
     340    @Deprecated
    344341    public AutoCompletionManager getAutoCompletionManager() {
    345         if (autocomplete == null) {
    346             autocomplete = new AutoCompletionManager(this);
    347             addDataSetListener(autocomplete);
    348         }
    349         return autocomplete;
     342        return AutoCompletionManager.of(this);
    350343    }
    351344
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolver.java

    r12660 r12758  
    3636import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    3737import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
     38import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
    3839import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
    3940import org.openstreetmap.josm.tools.ImageProvider;
     
    203204        OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    204205        if (editLayer != null) {
    205             editLayer.data.getAutoCompletionManager().populateWithMemberRoles(acList);
     206            AutoCompletionManager.of(editLayer.data).populateWithMemberRoles(acList);
    206207        }
    207208        tfRole.setAutoCompletionList(acList);
     
    212213        AutoCompletionList acList2 = new AutoCompletionList();
    213214        if (editLayer != null) {
    214             editLayer.data.getAutoCompletionManager().populateWithKeys(acList2);
     215            AutoCompletionManager.of(editLayer.data).populateWithKeys(acList2);
    215216        }
    216217        tfKey.setAutoCompletionList(acList2);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r12748 r12758  
    446446            mainPanel.add(p, BorderLayout.CENTER);
    447447
    448             AutoCompletionManager autocomplete = MainApplication.getLayerManager().getEditLayer().data.getAutoCompletionManager();
     448            AutoCompletionManager autocomplete = AutoCompletionManager.of(MainApplication.getLayerManager().getEditLayer().data);
    449449            List<AutoCompletionListItem> keyList = autocomplete.getKeys();
    450450            keyList.sort(DEFAULT_AC_ITEM_COMPARATOR);
     
    692692
    693693            cacheRecentTags();
    694             AutoCompletionManager autocomplete = MainApplication.getLayerManager().getEditLayer().data.getAutoCompletionManager();
     694            AutoCompletionManager autocomplete = AutoCompletionManager.of(MainApplication.getLayerManager().getEditLayer().data);
    695695            List<AutoCompletionListItem> keyList = autocomplete.getKeys();
    696696
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r12678 r12758  
    9494import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    9595import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
     96import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
    9697import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
    9798import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetHandler;
     
    423424                        if (list != null) {
    424425                            list.clear();
    425                             re.getLayer().data.getAutoCompletionManager().populateWithMemberRoles(list, re.getRelation());
     426                            AutoCompletionManager.of(re.getLayer().data).populateWithMemberRoles(list, re.getRelation());
    426427                        }
    427428                    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberRoleCellEditor.java

    r12657 r12758  
    1414import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    1515import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
     16import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
    1617
    1718/**
     
    4748        editor.setText(role);
    4849        autoCompletionList.clear();
    49         ds.getAutoCompletionManager().populateWithMemberRoles(autoCompletionList, relation);
     50        AutoCompletionManager.of(ds).populateWithMemberRoles(autoCompletionList, relation);
    5051        return editor;
    5152    }
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java

    r10611 r12758  
    181181        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    182182
    183         AutoCompletionManager autocomplete = layer.data.getAutoCompletionManager();
     183        AutoCompletionManager autocomplete = AutoCompletionManager.of(layer.data);
    184184        AutoCompletionList acList = new AutoCompletionList();
    185185
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionManager.java

    r12042 r12758  
    66import java.util.Collection;
    77import java.util.Collections;
     8import java.util.HashMap;
    89import java.util.HashSet;
    910import java.util.LinkedHashSet;
     
    2829import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
    2930import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
     31import org.openstreetmap.josm.gui.MainApplication;
     32import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     33import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     34import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     35import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
     36import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3037import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
    3138import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
     
    129136    static final Set<String> PRESET_ROLE_CACHE = new HashSet<>();
    130137
     138    private static final Map<DataSet, AutoCompletionManager> INSTANCES = new HashMap<>();
     139
    131140    /**
    132141     * Constructs a new {@code AutoCompletionManager}.
     
    422431        dirty = true;
    423432    }
     433
     434    private static void registerListeners(AutoCompletionManager autoCompletionManager) {
     435        autoCompletionManager.ds.addDataSetListener(autoCompletionManager);
     436        MainApplication.getLayerManager().addLayerChangeListener(new LayerChangeListener() {
     437            @Override
     438            public void layerRemoving(LayerRemoveEvent e) {
     439                if (e.getRemovedLayer() instanceof OsmDataLayer
     440                        && ((OsmDataLayer) e.getRemovedLayer()).data == autoCompletionManager.ds) {
     441                    INSTANCES.remove(autoCompletionManager.ds);
     442                    autoCompletionManager.ds.removeDataSetListener(autoCompletionManager);
     443                    MainApplication.getLayerManager().removeLayerChangeListener(this);
     444                }
     445            }
     446
     447            @Override
     448            public void layerOrderChanged(LayerOrderChangeEvent e) {
     449                // Do nothing
     450            }
     451
     452            @Override
     453            public void layerAdded(LayerAddEvent e) {
     454                // Do nothing
     455            }
     456        });
     457    }
     458
     459    /**
     460     * Returns the {@code AutoCompletionManager} for the given data set.
     461     * @param dataSet the data set
     462     * @return the {@code AutoCompletionManager} for the given data set
     463     * @since 12758
     464     */
     465    public static AutoCompletionManager of(DataSet dataSet) {
     466        AutoCompletionManager result = INSTANCES.get(dataSet);
     467        if (result == null) {
     468            result = new AutoCompletionManager(dataSet);
     469            INSTANCES.put(dataSet, result);
     470            registerListeners(result);
     471        }
     472        return result;
     473    }
    424474}
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItem.java

    r12636 r12758  
    2424import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    2525import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
     26import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
    2627import org.openstreetmap.josm.tools.ImageProvider;
    2728import org.openstreetmap.josm.tools.Logging;
     
    4849        }
    4950        AutoCompletionList list = new AutoCompletionList();
    50         layer.data.getAutoCompletionManager().populateWithTagValues(list, keys);
     51        AutoCompletionManager.of(layer.data).populateWithTagValues(list, keys);
    5152        field.setAutoCompletionList(list);
    5253    }
Note: See TracChangeset for help on using the changeset viewer.