---
core-dave/src/org/openstreetmap/josm/data/osm/DataSet.java | 50 +++++--------
1 file changed, 21 insertions(+), 29 deletions(-)
diff -puN src/org/openstreetmap/josm/data/osm/DataSet.java~implement-selection-storage-in-DataSet src/org/openstreetmap/josm/data/osm/DataSet.java
|
a
|
b
|
import java.awt.geom.Area;
|
| 6 | 6 | import java.util.ArrayList; |
| 7 | 7 | import java.util.Arrays; |
| 8 | 8 | import java.util.Collection; |
| | 9 | import java.util.Collections; |
| 9 | 10 | import java.util.Comparator; |
| 10 | 11 | import java.util.HashMap; |
| | 12 | import java.util.LinkedHashSet; |
| 11 | 13 | import java.util.HashSet; |
| 12 | 14 | import java.util.Iterator; |
| 13 | 15 | import java.util.LinkedList; |
| … |
… |
import java.util.Set;
|
| 16 | 18 | |
| 17 | 19 | import org.openstreetmap.josm.data.SelectionChangedListener; |
| 18 | 20 | import org.openstreetmap.josm.data.osm.QuadBuckets; |
| | 21 | import org.openstreetmap.josm.data.osm.OsmPrimitive; |
| 19 | 22 | |
| 20 | 23 | /** |
| 21 | 24 | * DataSet is the data behind the application. It can consists of only a few points up to the whole |
| … |
… |
public class DataSet implements Cloneabl
|
| 142 | 145 | } else if (primitive instanceof Relation) { |
| 143 | 146 | relations.remove(primitive); |
| 144 | 147 | } |
| | 148 | selectedPrimitives.remove(primitive); |
| 145 | 149 | } |
| 146 | 150 | |
| 147 | 151 | public Collection<OsmPrimitive> getSelectedNodesAndWays() { |
| … |
… |
public class DataSet implements Cloneabl
|
| 156 | 160 | * @return List of all selected objects. |
| 157 | 161 | */ |
| 158 | 162 | public Collection<OsmPrimitive> getSelected() { |
| 159 | | Collection<OsmPrimitive> sel = getSelected(nodes); |
| 160 | | sel.addAll(getSelected(ways)); |
| 161 | | sel.addAll(getSelected(relations)); |
| 162 | | return sel; |
| | 163 | // It would be nice to have this be a copy-on-write list |
| | 164 | // or an Collections.unmodifiableList(). It would be |
| | 165 | // much faster for large selections. May users just |
| | 166 | // call this, and only check the .size(). |
| | 167 | return new ArrayList<OsmPrimitive>(selectedPrimitives); |
| 163 | 168 | } |
| 164 | 169 | |
| 165 | 170 | /** |
| … |
… |
public class DataSet implements Cloneabl
|
| 215 | 220 | } |
| 216 | 221 | } |
| 217 | 222 | |
| 218 | | public boolean addSelected(OsmPrimitive osm) { |
| 219 | | osm.setSelected(true); |
| 220 | | return true; |
| 221 | | } |
| | 223 | LinkedHashSet<OsmPrimitive> selectedPrimitives = new LinkedHashSet<OsmPrimitive>(); |
| 222 | 224 | |
| 223 | 225 | public boolean toggleSelected(OsmPrimitive osm) { |
| 224 | | osm.setSelected(!osm.isSelected()); |
| | 226 | if (!selectedPrimitives.remove(osm)) |
| | 227 | selectedPrimitives.add(osm); |
| 225 | 228 | return true; |
| 226 | 229 | } |
| 227 | 230 | public boolean isSelected(OsmPrimitive osm) { |
| 228 | | return osm.isSelected(); |
| | 231 | return selectedPrimitives.contains(osm); |
| 229 | 232 | } |
| 230 | 233 | |
| 231 | 234 | public void setDisabled(OsmPrimitive... osm) { |
| … |
… |
public class DataSet implements Cloneabl
|
| 253 | 256 | clearSelection(nodes); |
| 254 | 257 | clearSelection(ways); |
| 255 | 258 | clearSelection(relations); |
| 256 | | for (OsmPrimitive osm : selection) { |
| 257 | | osm.setSelected(true); |
| 258 | | } |
| | 259 | addSelected(selection); |
| 259 | 260 | if (fireSelectionChangeEvent) { |
| 260 | 261 | fireSelectionChanged(selection); |
| 261 | 262 | } |
| … |
… |
public class DataSet implements Cloneabl
|
| 292 | 293 | for (OsmPrimitive osm : selection) { |
| 293 | 294 | osm.setSelected(true); |
| 294 | 295 | } |
| | 296 | selectedPrimitives.addAll(selection); |
| 295 | 297 | if (fireSelectionChangeEvent) { |
| 296 | 298 | fireSelectionChanged(selection); |
| 297 | 299 | } |
| … |
… |
public class DataSet implements Cloneabl
|
| 303 | 305 | setSelected(); |
| 304 | 306 | return; |
| 305 | 307 | } |
| 306 | | clearSelection(nodes); |
| 307 | | clearSelection(ways); |
| 308 | | clearSelection(relations); |
| 309 | | for (OsmPrimitive o : osm) |
| 310 | | if (o != null) { |
| 311 | | o.setSelected(true); |
| 312 | | } |
| | 308 | List<OsmPrimitive> list = Arrays.asList(osm); |
| | 309 | setSelected(list); |
| 313 | 310 | fireSelectionChanged(Arrays.asList(osm)); |
| 314 | 311 | } |
| 315 | 312 | |
| … |
… |
public class DataSet implements Cloneabl
|
| 346 | 343 | private void clearSelection(Collection<? extends OsmPrimitive> list) { |
| 347 | 344 | if (list == null) |
| 348 | 345 | return; |
| 349 | | for (OsmPrimitive osm : list) { |
| 350 | | osm.setSelected(false); |
| 351 | | } |
| | 346 | selectedPrimitives.removeAll(list); |
| 352 | 347 | } |
| 353 | 348 | |
| 354 | 349 | /** |
| … |
… |
public class DataSet implements Cloneabl
|
| 356 | 351 | * @param list The collection from which the selected items are returned. |
| 357 | 352 | */ |
| 358 | 353 | private Collection<OsmPrimitive> getSelected(Collection<? extends OsmPrimitive> list) { |
| 359 | | Collection<OsmPrimitive> sel = new HashSet<OsmPrimitive>(); |
| 360 | 354 | if (list == null) |
| 361 | | return sel; |
| 362 | | for (OsmPrimitive osm : list) |
| 363 | | if (osm.isSelected() && !osm.isDeleted()) { |
| 364 | | sel.add(osm); |
| 365 | | } |
| | 355 | return new LinkedList<OsmPrimitive>(); |
| | 356 | Collection<OsmPrimitive> sel = new LinkedHashSet<OsmPrimitive>(selectedPrimitives); |
| | 357 | sel.retainAll(list); |
| 366 | 358 | return sel; |
| 367 | 359 | } |
| 368 | 360 | |