Changeset 3124 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-03-12T19:36:17+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r3123 r3124 18 18 import java.util.Collection; 19 19 import java.util.Collections; 20 import java.util.Comparator; 21 import java.util.HashMap; 20 22 import java.util.HashSet; 21 23 import java.util.LinkedList; … … 49 51 import org.openstreetmap.josm.data.osm.Node; 50 52 import org.openstreetmap.josm.data.osm.OsmPrimitive; 53 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 51 54 import org.openstreetmap.josm.data.osm.Relation; 52 55 import org.openstreetmap.josm.data.osm.Way; … … 64 67 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 65 68 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 69 import org.openstreetmap.josm.gui.DefaultNameFormatter; 66 70 import org.openstreetmap.josm.gui.MapView; 67 71 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; … … 517 521 } 518 522 this.selection.addAll(selection); 523 sort(); 519 524 fireContentsChanged(this, 0, getSize()); 520 525 remember(selection); … … 566 571 } 567 572 573 /** 574 * Sorts the current elements in the selection 575 */ 576 public void sort() { 577 Collections.sort(this.selection, new OsmPrimitiveComparator()); 578 } 579 568 580 /* ------------------------------------------------------------------------ */ 569 581 /* interface EditLayerChangeListener */ … … 764 776 } 765 777 } 778 779 static private class OsmPrimitiveComparator implements Comparator<OsmPrimitive> { 780 final private HashMap<Object, String> cache= new HashMap<Object, String>(); 781 final private DefaultNameFormatter df = DefaultNameFormatter.getInstance(); 782 783 private String cachedName(OsmPrimitive p) { 784 String name = cache.get(p); 785 if (name == null) { 786 name = p.getDisplayName(df); 787 cache.put(p, name); 788 } 789 return name; 790 } 791 792 private int compareName(OsmPrimitive a, OsmPrimitive b) { 793 String an = cachedName(a); 794 String bn = cachedName(b); 795 // make sure display names starting with digits are the end of the 796 // list 797 if (Character.isDigit(an.charAt(0)) && Character.isDigit(bn.charAt(0))) 798 return an.compareTo(bn); 799 else if (Character.isDigit(an.charAt(0)) && !Character.isDigit(bn.charAt(0))) 800 return 1; 801 else if (!Character.isDigit(an.charAt(0)) && Character.isDigit(bn.charAt(0))) 802 return -1; 803 return an.compareTo(bn); 804 } 805 806 private int compareType(OsmPrimitive a, OsmPrimitive b) { 807 // show ways before relations, then nodes 808 // 809 if (a.getType().equals(b.getType())) return 0; 810 if (a.getType().equals(OsmPrimitiveType.WAY)) return -1; 811 if (a.getType().equals(OsmPrimitiveType.NODE)) return 1; 812 // a is a relation 813 if (b.getType().equals(OsmPrimitiveType.WAY)) return 1; 814 // b is a node 815 return -1; 816 } 817 public int compare(OsmPrimitive a, OsmPrimitive b) { 818 if (a.getType().equals(b.getType())) 819 return compareName(a, b); 820 return compareType(a, b); 821 } 822 } 766 823 }
Note:
See TracChangeset
for help on using the changeset viewer.