Changeset 6652 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2014-01-06T20:42:32+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r6643 r6652 24 24 import java.util.EnumSet; 25 25 import java.util.HashMap; 26 import java.util.HashSet; 26 27 import java.util.LinkedList; 27 28 import java.util.List; … … 95 96 import org.openstreetmap.josm.tools.LanguageInfo; 96 97 import org.openstreetmap.josm.tools.OpenBrowser; 98 import org.openstreetmap.josm.tools.Predicates; 97 99 import org.openstreetmap.josm.tools.Shortcut; 98 100 import org.openstreetmap.josm.tools.Utils; … … 321 323 boolean isDisabledAndHidden = (((Relation)table.getValueAt(row, 0))).isDisabledAndHidden(); 322 324 if (c instanceof JLabel) { 323 JLabel label = (JLabel)c; 324 MemberInfo col = (MemberInfo) value; 325 326 String text = null; 327 for (RelationMember r : col.role) { 328 if (text == null) { 329 text = r.getRole(); 330 } 331 else if (!text.equals(r.getRole())) { 332 text = tr("<different>"); 333 break; 334 } 335 } 336 337 label.setText(text); 325 JLabel label = (JLabel) c; 326 label.setText(((MemberInfo) value).getRoleString()); 338 327 if (isDisabledAndHidden) { 339 328 label.setFont(label.getFont().deriveFont(Font.ITALIC)); … … 623 612 MemberInfo mi = roles.get(r); 624 613 if(mi == null) { 625 mi = new MemberInfo( );614 mi = new MemberInfo(newSel); 626 615 } 627 616 roles.put(r, mi); … … 792 781 793 782 static class MemberInfo { 794 List<RelationMember> role = new ArrayList<RelationMember>(); 795 List<Integer> position = new ArrayList<Integer>(); 783 private List<RelationMember> role = new ArrayList<RelationMember>(); 784 private Set<OsmPrimitive> members = new HashSet<OsmPrimitive>(); 785 private List<Integer> position = new ArrayList<Integer>(); 786 private Iterable<OsmPrimitive> selection; 796 787 private String positionString = null; 788 private String roleString = null; 789 790 MemberInfo(Iterable<OsmPrimitive> selection) { 791 this.selection = selection; 792 } 793 797 794 void add(RelationMember r, Integer p) { 798 795 role.add(r); 796 members.add(r.getMember()); 799 797 position.add(p); 800 798 } 799 801 800 String getPositionString() { 802 801 if (positionString == null) { 803 Collections.sort(position); 804 positionString = String.valueOf(position.get(0)); 805 int cnt = 0; 806 int last = position.get(0); 807 for (int i = 1; i < position.size(); ++i) { 808 int cur = position.get(i); 809 if (cur == last + 1) { 810 ++cnt; 811 } else if (cnt == 0) { 812 positionString += "," + cur; 813 } else { 814 positionString += "-" + last; 815 positionString += "," + cur; 816 cnt = 0; 817 } 818 last = cur; 819 } 820 if (cnt >= 1) { 821 positionString += "-" + last; 822 } 802 positionString = Utils.getPositionListString(position); 803 // if not all objects from the selection are member of this relation 804 if (Utils.exists(selection, Predicates.not(Predicates.inCollection(members)))) { 805 positionString += ",\u2717"; 806 } 807 members = null; 808 position = null; 809 selection = null; 823 810 } 824 811 if (positionString.length() > 20) { … … 826 813 } 827 814 return positionString; 815 } 816 817 String getRoleString() { 818 if (roleString == null) { 819 for (RelationMember r : role) { 820 if (roleString == null) { 821 roleString = r.getRole(); 822 } else if (!roleString.equals(r.getRole())) { 823 roleString = tr("<different>"); 824 break; 825 } 826 } 827 role = null; 828 } 829 return roleString; 830 } 831 832 @Override 833 public String toString() { 834 return "MemberInfo{" + 835 "roles='" + roleString + '\'' + 836 ", positions='" + positionString + '\'' + 837 '}'; 828 838 } 829 839 } -
trunk/src/org/openstreetmap/josm/tools/Predicates.java
r6592 r6652 3 3 import org.openstreetmap.josm.data.osm.OsmPrimitive; 4 4 5 import java.util.Collection; 5 6 import java.util.regex.Pattern; 6 7 … … 84 85 }; 85 86 } 87 88 /** 89 * Returns a {@link Predicate} executing {@link Collection#contains(Object)}. 90 */ 91 public static <T> Predicate<T> inCollection(final Collection<? extends T> target) { 92 return new Predicate<T>() { 93 @Override 94 public boolean evaluate(T object) { 95 return target.contains(object); 96 } 97 }; 98 } 86 99 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r6642 r6652 37 37 import java.util.Arrays; 38 38 import java.util.Collection; 39 import java.util.Collections; 39 40 import java.util.Iterator; 40 41 import java.util.List; … … 861 862 862 863 /** 864 * Returns a human readable representation of a list of positions. 865 * <p/> 866 * For instance, {@code [1,5,2,6,7} yields "1-2,5-7 867 * @param positionList a list of positions 868 * @return a human readable representation 869 */ 870 public static String getPositionListString(List<Integer> positionList) { 871 Collections.sort(positionList); 872 final StringBuilder sb = new StringBuilder(32); 873 sb.append(positionList.get(0)); 874 int cnt = 0; 875 int last = positionList.get(0); 876 for (int i = 1; i < positionList.size(); ++i) { 877 int cur = positionList.get(i); 878 if (cur == last + 1) { 879 ++cnt; 880 } else if (cnt == 0) { 881 sb.append(",").append(cur); 882 } else { 883 sb.append("-").append(last); 884 sb.append(",").append(cur); 885 cnt = 0; 886 } 887 last = cur; 888 } 889 if (cnt >= 1) { 890 sb.append("-").append(last); 891 } 892 return sb.toString(); 893 } 894 895 896 /** 863 897 * Returns a list of capture groups if {@link Matcher#matches()}, or {@code null}. 864 898 * The first element (index 0) is the complete match.
Note:
See TracChangeset
for help on using the changeset viewer.