Changeset 14165 in josm


Ignore:
Timestamp:
2018-08-19T04:34:42+02:00 (5 weeks ago)
Author:
Don-vip
Message:

fix #16652 - validator dialog: display multiple OSM primitives like in other dialogs

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/util/MultipleNameVisitor.java

    r11553 r14165  
    55
    66import java.util.Collection;
    7 import java.util.Optional;
    87
    98import javax.swing.Icon;
    109import javax.swing.JLabel;
    1110
     11import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    1212import org.openstreetmap.josm.data.osm.OsmPrimitive;
     13import org.openstreetmap.josm.data.preferences.IntegerProperty;
    1314import org.openstreetmap.josm.tools.ImageProvider;
    1415
     
    2324     * Maximum displayed length, in characters.
    2425     */
    25     public static final int MULTIPLE_NAME_MAX_LENGTH = 80;
     26    public static final IntegerProperty MULTIPLE_NAME_MAX_LENGTH = new IntegerProperty("multiple.name.max.length", 140);
    2627
    2728    /** The class name of the combined primitives */
     
    4344        multipleClassname = null;
    4445        for (OsmPrimitive osm : data) {
    45             String name = Optional.ofNullable(osm.get("name")).orElseGet(() -> osm.get("ref"));
    46             if (name != null && !name.isEmpty() && multipleName.length() <= MULTIPLE_NAME_MAX_LENGTH) {
     46            String name = osm.getDisplayName(DefaultNameFormatter.getInstance());
     47            if (name != null && !name.isEmpty() && multipleName.length() <= MULTIPLE_NAME_MAX_LENGTH.get()) {
    4748                if (multipleName.length() > 0) {
    4849                    multipleName.append(", ");
     
    6768            if (multipleName.length() > 0) {
    6869                sb.append(": ");
    69                 if (multipleName.length() <= MULTIPLE_NAME_MAX_LENGTH) {
     70                if (multipleName.length() <= MULTIPLE_NAME_MAX_LENGTH.get()) {
    7071                    sb.append(multipleName);
    7172                } else {
    72                     sb.append(multipleName.substring(0, MULTIPLE_NAME_MAX_LENGTH)).append("...");
     73                    sb.append(multipleName.substring(0, MULTIPLE_NAME_MAX_LENGTH.get())).append("...");
    7374                }
    7475            }
  • trunk/test/unit/org/openstreetmap/josm/data/validation/util/MultipleNameVisitorTest.java

    r10962 r14165  
    88import org.junit.Rule;
    99import org.junit.Test;
     10import org.openstreetmap.josm.TestUtils;
    1011import org.openstreetmap.josm.data.osm.Way;
    1112import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    3233        MultipleNameVisitor visitor = new MultipleNameVisitor();
    3334        visitor.visit(Arrays.asList(new Way(), new Way()));
    34         assertEquals("2 ways", visitor.toString());
     35        assertEquals("2 ways: ‎0‎ (0 nodes), ‎0‎ (0 nodes)", visitor.toString());
     36    }
     37
     38    /**
     39     * Non-regression test for bug #16652.
     40     */
     41    @Test
     42    public void testTicket16652() {
     43        MultipleNameVisitor visitor = new MultipleNameVisitor();
     44        visitor.visit(Arrays.asList(
     45                TestUtils.newNode("name=foo"),
     46                TestUtils.newWay("addr:housename=Stark"),
     47                TestUtils.newRelation("type=route")));
     48        assertEquals("3 objects: foo, ‎House Stark‎ (0 nodes), route (0, 0 members)", visitor.toString());
    3549    }
    3650}
Note: See TracChangeset for help on using the changeset viewer.