Changeset 11033 in josm for trunk


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

fix #13663 - Two data layers with the same name

Counting starts from 1 again in an saved session file.

Location:
trunk
Files:
2 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
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/OsmDataLayerTest.java

    r10950 r11033  
    1010import java.io.File;
    1111
     12import org.fest.assertions.Assertions;
    1213import org.junit.BeforeClass;
    1314import org.junit.Test;
     
    254255        assertTrue(layer.checkSaveConditions());
    255256    }
     257
     258    @Test
     259    public void testLayerNameIncreases() throws Exception {
     260        final OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), OsmDataLayer.createLayerName(147), null);
     261        final OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), OsmDataLayer.createNewName(), null);
     262        assertEquals("Data Layer 147", layer1.getName());
     263        assertEquals("Data Layer 148", layer2.getName());
     264    }
    256265}
Note: See TracChangeset for help on using the changeset viewer.