Ignore:
Timestamp:
10.03.2010 10:00:20 (2 years ago)
Author:
Gubaer
Message:

fixed #4651: Ability to download incomplete relation from selection
fixed #4098: Popup Menu entry "download relation members" in relation dialog should be "download incomplete relation members"
fixed two NPEs in RelationListDialog and SelectionListDialog
refactored SelectionListDialog to support better user feedback (enabled/disabled buttons and menu items)
Finally removed the sort() method on DataSet, marked as FIXME since a long time.

CAVEAT: DataSet.getSelected() now returns an unmodifiable list instead of a copy of the selection list. This may lead to UnsupportedOperationExceptions in the next few days. I tried to make sure the JOSM core uses getSelected() only for reading, but I didn't check the plugins.

File:
1 edited

Legend:

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

    r3008 r3102  
    99import java.util.Collection; 
    1010import java.util.Collections; 
    11 import java.util.Comparator; 
    1211import java.util.HashMap; 
    1312import java.util.HashSet; 
     
    313312 
    314313    /** 
    315      * Return a list of all selected objects. Even keys are returned. 
    316      * @return List of all selected objects. 
     314     * Replies an unmodifiable collection of primitives currently selected 
     315     * in this dataset 
     316     *  
     317     * @return unmodifiable collection of primitives 
    317318     */ 
    318319    public Collection<OsmPrimitive> getSelected() { 
    319         // It would be nice to have this be a copy-on-write list 
    320         // or an Collections.unmodifiableList().  It would be 
    321         // much faster for large selections.  May users just 
    322         // call this, and only check the .size(). 
    323         return new ArrayList<OsmPrimitive>(selectedPrimitives); 
     320        return Collections.unmodifiableSet(selectedPrimitives); 
    324321    } 
    325322 
     
    610607        } 
    611608        return a; 
    612     } 
    613  
    614     // Provide well-defined sorting for collections of OsmPrimitives. 
    615     // FIXME: probably not a good place to put this code. 
    616     public static OsmPrimitive[] sort(Collection<? extends OsmPrimitive> list) { 
    617         OsmPrimitive[] selArr = new OsmPrimitive[list.size()]; 
    618         final HashMap<Object, String> h = new HashMap<Object, String>(); 
    619         selArr = list.toArray(selArr); 
    620         Arrays.sort(selArr, new Comparator<OsmPrimitive>() { 
    621             public int compare(OsmPrimitive a, OsmPrimitive b) { 
    622                 if (a.getClass() == b.getClass()) { 
    623                     String as = h.get(a); 
    624                     if (as == null) { 
    625                         as = a.getName() != null ? a.getName() : Long.toString(a.getId()); 
    626                         h.put(a, as); 
    627                     } 
    628                     String bs = h.get(b); 
    629                     if (bs == null) { 
    630                         bs = b.getName() != null ? b.getName() : Long.toString(b.getId()); 
    631                         h.put(b, bs); 
    632                     } 
    633                     int res = as.compareTo(bs); 
    634                     if (res != 0) 
    635                         return res; 
    636                 } 
    637                 return a.compareTo(b); 
    638             } 
    639         }); 
    640         return selArr; 
    641609    } 
    642610 
Note: See TracChangeset for help on using the changeset viewer.