Changeset 2348 in josm for trunk/src/org


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
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java

    r2323 r2348  
    8181        Main.main.undoRedo.add(new SequenceCommand(tr("Reverse ways"), c));
    8282        if (propertiesUpdated) {
    83             DataSet.fireSelectionChanged(getCurrentDataSet().getSelected());
     83            getCurrentDataSet().fireSelectionChanged();
    8484        }
    8585        Main.map.repaint();
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r2323 r2348  
    688688            //
    689689            layer.cleanupAfterUpload(processedPrimitives);
    690             DataSet.fireSelectionChanged(layer.data.getSelected());
     690            layer.data.fireSelectionChanged();
    691691            layer.fireDataChange();
    692692            if (lastException != null) {
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r2339 r2348  
    245245        // primitives
    246246        //
    247         DataSet.fireSelectionChanged(getCurrentDataSet().getSelected());
     247        getCurrentDataSet().fireSelectionChanged();
    248248    }
    249249
     
    272272    private void tryAgain(MouseEvent e) {
    273273        getCurrentDataSet().setSelected();
    274         DataSet.fireSelectionChanged(getCurrentDataSet().getSelected());
     274        Main.main.getCurrentDataSet().fireSelectionChanged();
    275275        mouseClicked(e);
    276276    }
     
    284284        // let everybody else know about the current selection
    285285        //
    286         DataSet.fireSelectionChanged(getCurrentDataSet().getSelected());
     286        Main.main.getCurrentDataSet().fireSelectionChanged();
    287287        lastUsedNode = null;
    288288        wayIsFinished = true;
     
    345345                // (this is just a convenience option so that people don't
    346346                // have to switch modes)
    347                 newSelection.clear();
    348                 newSelection.add(n);
     347                getCurrentDataSet().setSelected(n);
     348                selection = getCurrentDataSet().getSelected();
    349349                // The user explicitly selected a node, so let him continue drawing
    350350                wayIsFinished = false;
     
    523523
    524524                extendedWay = true;
    525                 newSelection.clear();
    526                 newSelection.add(wayToSelect);
     525                ds.setSelected(way);
     526                ds.fireSelectionChanged();
    527527            }
    528528        }
     
    540540                }
    541541            }
    542             newSelection.add(n);
     542
     543            ds.setSelected(n);
     544            ds.fireSelectionChanged();
    543545        } else if (!newNode) {
    544546            title = tr("Connect existing way to node");
     
    585587                    (posn0 < selectedWay.getNodesCount()-1) && targetNode.equals(selectedWay.getNode(posn0+1))) {  // next node
    586588                getCurrentDataSet().setSelected(targetNode);
    587                 DataSet.fireSelectionChanged(getCurrentDataSet().getSelected());
     589                getCurrentDataSet().fireSelectionChanged();
    588590                lastUsedNode = targetNode;
    589591                return true;
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r2310 r2348  
    499499                    }
    500500                }
    501                 DataSet.fireSelectionChanged(selection);
     501                getCurrentDataSet().fireSelectionChanged();
    502502            }
    503503        }
     
    515515    public void selectPrims(Collection<OsmPrimitive> selectionList, boolean shift,
    516516            boolean ctrl, boolean released, boolean area) {
     517        DataSet ds = getCurrentDataSet();
    517518        if ((shift && ctrl) || (ctrl && !released))
    518519            return; // not allowed together
    519520
    520         Collection<OsmPrimitive> curSel;
    521         if (!ctrl && !shift) {
    522             curSel = new LinkedList<OsmPrimitive>(); // new selection will replace the old.
     521        // plain clicks with no modifiers clear the selection
     522        if (!ctrl && !shift)
     523            ds.clearSelection();
     524
     525        if (ctrl) {
     526            // Ctrl on an item toggles its selection status,
     527            // but Ctrl on an *area* just clears those items
     528            // out of the selection.
     529            if (area)
     530                ds.clearSelection(selectionList);
     531            else
     532                ds.toggleSelected(selectionList);
    523533        } else {
    524             curSel = getCurrentDataSet().getSelected();
    525         }
    526 
    527         for (OsmPrimitive osm : selectionList)
    528         {
    529             if (ctrl)
    530             {
    531                 if(curSel.contains(osm)) {
    532                     curSel.remove(osm);
    533                 } else if(!area) {
    534                     curSel.add(osm);
    535                 }
    536             } else {
    537                 curSel.add(osm);
    538             }
    539         }
    540         getCurrentDataSet().setSelected(curSel);
     534            // This is either a plain click (which means we
     535            // previously cleared the selection), or a
     536            // shift-click where we are adding things to an
     537            // existing selection.
     538            ds.addSelected(selectionList);
     539        }
     540        ds.fireSelectionChanged();
    541541        Main.map.mapView.repaint();
    542542    }
  • 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() {
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r2291 r2348  
    333333                }
    334334            }
    335             DataSet.fireSelectionChanged(ds.getSelected());
     335            ds.fireSelectionChanged();
    336336        }
    337337
     
    463463                    // Let the user toggle the selection
    464464                    ds.toggleSelected(osm);
    465                     DataSet.fireSelectionChanged(ds.getSelected());
    466465                    l.validate();
    467466                }
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r2327 r2348  
    503503            if (getCurrentDataSet() != null) {
    504504                getCurrentDataSet().setSelected();
    505                 DataSet.fireSelectionChanged(getCurrentDataSet().getSelected());
     505                getCurrentDataSet().fireSelectionChanged();
    506506            }
    507507        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r2224 r2348  
    267267        }
    268268
    269         DataSet.fireSelectionChanged(sel);
     269        Main.main.getCurrentDataSet().fireSelectionChanged();
    270270        selectionChanged(sel); // update whole table
    271271        Main.parent.repaint(); // repaint all - drawing could have been changed
     
    355355            return;
    356356        Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, value));
    357         DataSet.fireSelectionChanged(sel);
     357        Main.main.getCurrentDataSet().fireSelectionChanged();
    358358        selectionChanged(sel); // update table
    359359        Main.parent.repaint(); // repaint all - drawing could have been changed
     
    826826            Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
    827827            Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, null));
    828             DataSet.fireSelectionChanged(sel);
     828            Main.main.getCurrentDataSet().fireSelectionChanged();
    829829            selectionChanged(sel); // update table
    830830
     
    852852            }
    853853            Main.main.undoRedo.add(new ChangeCommand(cur, rel));
    854             DataSet.fireSelectionChanged(sel);
     854            Main.main.getCurrentDataSet().fireSelectionChanged();
    855855            selectionChanged(sel); // update whole table
    856856        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r2317 r2348  
    517517            }
    518518            Main.map.mapView.getEditLayer().data.setSelected(selection);
    519             DataSet.fireSelectionChanged(selection);
     519            Main.map.mapView.getEditLayer().data.fireSelectionChanged();
    520520        }
    521521
     
    545545            }
    546546            Main.map.mapView.getEditLayer().data.setSelected(members);
    547             DataSet.fireSelectionChanged(members);
    548547        }
    549548
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r2317 r2348  
    883883        public void actionPerformed(ActionEvent e) {
    884884            getLayer().data.setSelected(memberTableModel.getSelectedChildPrimitives());
    885             DataSet.fireSelectionChanged(getLayer().data.getSelected());
    886885        }
    887886
     
    10061005            // make sure everybody is notified about the changes
    10071006            //
    1008             DataSet.fireSelectionChanged(getLayer().data.getSelected());
     1007            getLayer().data.fireSelectionChanged();
    10091008            getLayer().fireDataChange();
    10101009            GenericRelationEditor.this.setRelation(newRelation);
     
    10391038            memberTableModel.applyToRelation(editedRelation);
    10401039            Main.main.undoRedo.add(new ChangeCommand(getRelation(), editedRelation));
    1041             DataSet.fireSelectionChanged(getLayer().data.getSelected());
     1040            getLayer().data.fireSelectionChanged();
    10421041            getLayer().fireDataChange();
    10431042            // this will refresh the snapshot and update the dialog title
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java

    r2043 r2348  
    204204            OsmPrimitive primitive = getMemberTableModel().getReferredPrimitive(row);
    205205            layer.data.setSelected(primitive);
    206             DataSet.fireSelectionChanged(layer.data.getSelected());
    207206            AutoScaleAction action = new AutoScaleAction("selection");
    208207            action.autoScale();
  • trunk/src/org/openstreetmap/josm/gui/io/UploadLayerTask.java

    r2198 r2348  
    144144            return;
    145145        layer.cleanupAfterUpload(processedPrimitives);
    146         DataSet.fireSelectionChanged(layer.data.getSelected());
     146        layer.data.fireSelectionChanged();;
    147147        layer.fireDataChange();
    148148        layer.onPostUploadToServer();
Note: See TracChangeset for help on using the changeset viewer.