Ignore:
Timestamp:
2009-10-29T19:45:49+01:00 (15 years ago)
Author:
Gubaer
Message:

applied #3780: patch by hansendc: Shift selection is broken

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

Legend:

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

    r2098 r2348  
    5050
    5151        // the command may have changed the selection so tell the listeners about the current situation
    52         DataSet.fireSelectionChanged(Main.main.getCurrentDataSet().getSelected());
     52        Main.main.getCurrentDataSet().fireSelectionChanged();
    5353    }
    5454
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r2317 r2348  
    2626 */
    2727public class DataSet implements Cloneable {
    28 
    29     /**
    30      * The API version that created this data set, if any.
    31      */
    32     public String version;
    33 
    34     /**
    35      * All nodes goes here, even when included in other data (ways etc). This enables the instant
    36      * conversion of the whole DataSet by iterating over this data structure.
    37      */
    38     public QuadBuckets<Node> nodes = new QuadBuckets<Node>();
    39 
    40     /**
    41      * All ways (Streets etc.) in the DataSet.
    42      *
    43      * The way nodes are stored only in the way list.
    44      */
    45     public QuadBuckets<Way> ways = new QuadBuckets<Way>();
    46 
    47     /**
    48      * All relations/relationships
    49      */
    50     public Collection<Relation> relations = new LinkedList<Relation>();
    51 
    52     /**
    53      * All data sources of this DataSet.
    54      */
    55     public Collection<DataSource> dataSources = new LinkedList<DataSource>();
    56 
     28   
    5729    /**
    5830     * A list of listeners to selection changed events. The list is static, as listeners register
     
    6133     */
    6234    public static Collection<SelectionChangedListener> selListeners = new LinkedList<SelectionChangedListener>();
    63 
     35   
     36    /**
     37     * notifies all registered selection change listeners about the current selection of
     38     * primitives
     39     *
     40     * @param sel the current selection
     41     */
     42    private static void notifySelectionChangeListeners(Collection<? extends OsmPrimitive> sel) {
     43        for (SelectionChangedListener l : selListeners) {
     44            l.selectionChanged(sel);
     45        }
     46    }
     47
     48    /**
     49     * The API version that created this data set, if any.
     50     */
     51    public String version;
     52
     53    /**
     54     * All nodes goes here, even when included in other data (ways etc). This enables the instant
     55     * conversion of the whole DataSet by iterating over this data structure.
     56     */
     57    public QuadBuckets<Node> nodes = new QuadBuckets<Node>();
     58
     59    /**
     60     * All ways (Streets etc.) in the DataSet.
     61     *
     62     * The way nodes are stored only in the way list.
     63     */
     64    public QuadBuckets<Way> ways = new QuadBuckets<Way>();
     65
     66    /**
     67     * All relations/relationships
     68     */
     69    public Collection<Relation> relations = new LinkedList<Relation>();
     70
     71    /**
     72     * All data sources of this DataSet.
     73     */
     74    public Collection<DataSource> dataSources = new LinkedList<DataSource>();
     75   
    6476    /**
    6577     * @return A collection containing all primitives of the dataset. The data is ordered after:
     
    242254    LinkedHashSet<OsmPrimitive> selectedPrimitives = new LinkedHashSet<OsmPrimitive>();
    243255
    244     public boolean toggleSelected(OsmPrimitive osm) {
     256    public boolean toggleSelected(Collection<OsmPrimitive> osm) {
     257        for (OsmPrimitive o : osm)
     258            this.__toggleSelected(o);
     259        fireSelectionChanged();
     260        return true;
     261    }
     262    public boolean toggleSelected(OsmPrimitive... osm) {
     263        return this.toggleSelected(Arrays.asList(osm));
     264    }
     265    private boolean __toggleSelected(OsmPrimitive osm) {
    245266        if (!selectedPrimitives.remove(osm)) {
    246267            selectedPrimitives.add(osm);
     
    276297        selectedPrimitives = new LinkedHashSet<OsmPrimitive>(selection);
    277298        if (fireSelectionChangeEvent) {
    278             fireSelectionChanged(selection);
     299            fireSelectionChanged();
    279300        }
    280301    }
     
    314335        selectedPrimitives.addAll(selection);
    315336        if (fireSelectionChangeEvent) {
    316             fireSelectionChanged(selection);
     337            fireSelectionChanged();
    317338        }
    318339    }
     
    326347        List<OsmPrimitive> list = Arrays.asList(osm);
    327348        setSelected(list);
    328         fireSelectionChanged(list);
     349        fireSelectionChanged();
    329350    }
    330351
     
    359380        clearSelection(Arrays.asList(osm));
    360381    }
    361     private void clearSelection(Collection<? extends OsmPrimitive> list) {
     382    public void clearSelection(Collection<? extends OsmPrimitive> list) {
    362383        if (list == null)
    363384            return;
    364385        selectedPrimitives.removeAll(list);
     386    }
     387    public void clearSelection() {
     388        selectedPrimitives.clear();
    365389    }
    366390
     
    381405
    382406    /**
    383      * Remember to fire an selection changed event. A call to this will not fire the event
    384      * immediately. For more,
    385      * @see SelectionChangedListener
    386      */
    387     public static void fireSelectionChanged(Collection<? extends OsmPrimitive> sel) {
    388         for (SelectionChangedListener l : selListeners) {
    389             l.selectionChanged(sel);
    390         }
    391     }
     407     * Notifies all registered {@see SelectionChangedListener} about the current selection in
     408     * this dataset.
     409     *
     410     */
     411    public void fireSelectionChanged(){
     412        notifySelectionChangeListeners(selectedPrimitives);
     413    }
     414
    392415
    393416    @Override public DataSet clone() {
Note: See TracChangeset for help on using the changeset viewer.