Changeset 11680 in josm for trunk


Ignore:
Timestamp:
2017-03-05T01:10:20+01:00 (8 years ago)
Author:
Don-vip
Message:

fix #14458 - sort by default in order [relations, ways, nodes] in selection dialog

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

Legend:

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

    r11177 r11680  
    6969    }
    7070
     71    /**
     72     * Returns a comparator ordering the primitives by type in the order RELATION, WAY, NODE
     73     *
     74     * @return a comparator ordering the primitives by type in the order RELATION, WAY, NODE
     75     * @since 11679
     76     */
     77    public static Comparator<OsmPrimitive> orderingRelationsWaysNodes() {
     78        return comparingInt(osm -> {
     79            switch (osm.getType()) {
     80                case RELATION:
     81                    return 1;
     82                case WAY:
     83                    return 2;
     84                case NODE:
     85                    return 3;
     86                default:
     87                    throw new IllegalStateException();
     88            }
     89        });
     90    }
     91
    7192    private static <T, R> Function<T, R> memoize(Function<T, R> base) {
    7293        final Map<T, R> cache = new HashMap<>();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r11386 r11680  
    1717import java.util.Collection;
    1818import java.util.Collections;
     19import java.util.Comparator;
    1920import java.util.HashSet;
    2021import java.util.Iterator;
     
    660661            if (selection.size() <= Main.pref.getInteger("selection.no_sort_above", 100_000)) {
    661662                boolean quick = selection.size() > Main.pref.getInteger("selection.fast_sort_above", 10_000);
    662                 selection.sort(OsmPrimitiveComparator.orderingWaysRelationsNodes().thenComparing(quick
     663                Comparator<OsmPrimitive> c = Main.pref.getBoolean("selection.sort_relations_before_ways", true)
     664                        ? OsmPrimitiveComparator.orderingRelationsWaysNodes()
     665                        : OsmPrimitiveComparator.orderingWaysRelationsNodes();
     666                selection.sort(c.thenComparing(quick
    663667                        ? OsmPrimitiveComparator.comparingUniqueId()
    664668                        : OsmPrimitiveComparator.comparingNames()));
Note: See TracChangeset for help on using the changeset viewer.