Changeset 11033 in josm for trunk/src


Ignore:
Timestamp:
2016-09-20T12:28:48+02:00 (3 years ago)
Author:
simon04
Message:

fix #13663 - Two data layers with the same name

Counting starts from 1 again in an saved session file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r10972 r11033  
    3131import java.util.Set;
    3232import java.util.concurrent.CopyOnWriteArrayList;
     33import java.util.concurrent.atomic.AtomicInteger;
    3334import java.util.regex.Pattern;
    3435
     
    9899import org.openstreetmap.josm.gui.widgets.JosmTextArea;
    99100import org.openstreetmap.josm.io.OsmImporter;
     101import org.openstreetmap.josm.tools.AlphanumComparator;
    100102import org.openstreetmap.josm.tools.CheckParameterUtil;
    101103import org.openstreetmap.josm.tools.GBC;
     
    198200
    199201    /** the global counter for created data layers */
    200     private static int dataLayerCounter;
     202    private static final AtomicInteger dataLayerCounter = new AtomicInteger();
    201203
    202204    /**
     
    206208     */
    207209    public static String createNewName() {
    208         dataLayerCounter++;
    209         return tr("Data Layer {0}", dataLayerCounter);
     210        return createLayerName(dataLayerCounter.incrementAndGet());
     211    }
     212
     213    static String createLayerName(Object arg) {
     214        return tr("Data Layer {0}", arg);
    210215    }
    211216
     
    352357        data.addDataSetListener(MultipolygonCache.getInstance());
    353358        DataSet.addSelectionListener(this);
     359        if (name != null && name.startsWith(createLayerName(""))) {
     360            while (AlphanumComparator.getInstance().compare(createLayerName(dataLayerCounter), name) < 0) {
     361                dataLayerCounter.incrementAndGet();
     362            }
     363        }
    354364    }
    355365
Note: See TracChangeset for help on using the changeset viewer.