Changeset 4628 in josm for trunk/src/org
- Timestamp:
- 2011-12-03T01:54:59+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/Multipolygon.java
r4627 r4628 9 9 import java.util.ArrayList; 10 10 import java.util.Collection; 11 import java.util.Collections; 11 12 import java.util.List; 12 13 … … 172 173 173 174 public final Path2D.Double poly; 174 public finalboolean selected;175 public boolean selected; 175 176 private Rectangle2D bounds; 176 177 public PolyData(JoinedWay joinedWay) { 178 this(joinedWay.getNodes(), joinedWay.isSelected()); 179 } 180 181 public PolyData(List<Node> nodes, boolean selected) { 177 private final Collection<Way> ways; 178 179 public PolyData(JoinedWay joinedWay, Collection<Way> refWays) { 180 this(joinedWay.getNodes(), joinedWay.isSelected(), refWays); 181 } 182 183 public PolyData(List<Node> nodes, boolean selected, Collection<Way> refWays) { 184 this.ways = Collections.unmodifiableCollection(refWays); 182 185 this.selected = selected; 183 186 boolean initial = true; … … 200 203 this.selected = copy.selected; 201 204 this.poly = (Double) copy.poly.clone(); 205 this.ways = new ArrayList<Way>(copy.ways); 202 206 } 203 207 … … 235 239 return bounds; 236 240 } 241 242 public Collection<Way> getWays() { 243 return ways; 244 } 237 245 } 238 246 … … 282 290 for (Way way: ways) { 283 291 if (way.isClosed()) { 284 result.add(new PolyData(way.getNodes(), way.isSelected() ));292 result.add(new PolyData(way.getNodes(), way.isSelected(), Collections.singleton(way))); 285 293 } else { 286 294 waysToJoin.add(way); … … 289 297 290 298 for (JoinedWay jw: joinWays(waysToJoin)) { 291 result.add(new PolyData(jw ));299 result.add(new PolyData(jw, waysToJoin)); 292 300 } 293 301 } … … 449 457 } 450 458 } 459 460 // Clear inner and outer polygons to reduce memory footprint 461 innerPolygons.clear(); 462 outerPolygons.clear(); 451 463 } 452 464 … … 458 470 return innerWays; 459 471 } 460 472 /* 461 473 public List<PolyData> getInnerPolygons() { 462 474 return innerPolygons; … … 466 478 return outerPolygons; 467 479 } 468 480 */ 469 481 public List<PolyData> getCombinedPolygons() { 470 482 return combinedPolygons; -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java
r4627 r4628 4 4 import java.util.Collection; 5 5 import java.util.HashMap; 6 import java.util.Iterator; 6 7 import java.util.List; 7 8 import java.util.Map; 8 9 9 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.data.SelectionChangedListener; 10 12 import org.openstreetmap.josm.data.osm.DataSet; 11 13 import org.openstreetmap.josm.data.osm.Node; … … 22 24 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 23 25 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 26 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData; 24 27 import org.openstreetmap.josm.data.projection.Projection; 25 28 import org.openstreetmap.josm.data.projection.ProjectionChangeListener; … … 33 36 * 34 37 */ 35 public class MultipolygonCache implements DataSetListener, LayerChangeListener, ProjectionChangeListener {38 public class MultipolygonCache implements DataSetListener, LayerChangeListener, ProjectionChangeListener, SelectionChangedListener { 36 39 37 40 private static final MultipolygonCache instance = new MultipolygonCache(); 38 41 39 42 private final Map<NavigatableComponent, Map<DataSet, Map<Relation, Multipolygon>>> cache; 43 44 private final Collection<PolyData> selectedPolyData; 40 45 41 46 private MultipolygonCache() { 42 47 this.cache = new HashMap<NavigatableComponent, Map<DataSet, Map<Relation, Multipolygon>>>(); 48 this.selectedPolyData = new ArrayList<Multipolygon.PolyData>(); 43 49 Main.addProjectionChangeListener(this); 50 DataSet.addSelectionListener(this); 44 51 } 45 52 … … 66 73 if (multipolygon == null || forceRefresh) { 67 74 map2.put(r, multipolygon = new Multipolygon(r)); 75 for (PolyData pd : multipolygon.getCombinedPolygons()) { 76 if (pd.selected) { 77 selectedPolyData.add(pd); 78 } 79 } 68 80 } 69 81 } … … 157 169 @Override 158 170 public void primitivesRemoved(PrimitivesRemovedEvent event) { 159 removeMultipolygonsReferringTo(event); 171 removeMultipolygonsReferringTo(event);// FIXME: See if it is possible to update only concerned PolyData 160 172 } 161 173 162 174 @Override 163 175 public void tagsChanged(TagsChangedEvent event) { 164 removeMultipolygonsReferringTo(event);176 //removeMultipolygonsReferringTo(event); 165 177 } 166 178 167 179 @Override 168 180 public void nodeMoved(NodeMovedEvent event) { 169 removeMultipolygonsReferringTo(event); 181 removeMultipolygonsReferringTo(event);// FIXME: See if it is possible to update only concerned PolyData 170 182 } 171 183 172 184 @Override 173 185 public void wayNodesChanged(WayNodesChangedEvent event) { 174 removeMultipolygonsReferringTo(event); 186 removeMultipolygonsReferringTo(event);// FIXME: See if it is possible to update only concerned PolyData 175 187 } 176 188 177 189 @Override 178 190 public void relationMembersChanged(RelationMembersChangedEvent event) { 179 removeMultipolygonsReferringTo(event); 191 removeMultipolygonsReferringTo(event);// FIXME: See if it is possible to update only concerned PolyData 180 192 } 181 193 182 194 @Override 183 195 public void otherDatasetChange(AbstractDatasetChangedEvent event) { 184 removeMultipolygonsReferringTo(event); 196 removeMultipolygonsReferringTo(event);// FIXME: See if it is possible to update only concerned PolyData 185 197 } 186 198 187 199 @Override 188 200 public void dataChanged(DataChangedEvent event) { 189 removeMultipolygonsReferringTo(event); 201 removeMultipolygonsReferringTo(event);// FIXME: See if it is possible to update only concerned PolyData 190 202 } 191 203 … … 211 223 clear(); 212 224 } 225 226 @Override 227 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 228 229 for (Iterator<PolyData> it = selectedPolyData.iterator(); it.hasNext();) { 230 it.next().selected = false; 231 it.remove(); 232 } 233 234 DataSet ds = null; 235 Collection<Map<Relation, Multipolygon>> maps = null; 236 for (OsmPrimitive p : newSelection) { 237 if (p instanceof Way && p.getDataSet() != null) { 238 if (ds == null) { 239 ds = p.getDataSet(); 240 } 241 for (OsmPrimitive ref : p.getReferrers()) { 242 if (isMultipolygon(ref)) { 243 if (maps == null) { 244 maps = getMapsFor(ds); 245 } 246 for (Map<Relation, Multipolygon> map : maps) { 247 Multipolygon multipolygon = map.get(ref); 248 if (multipolygon != null) { 249 for (PolyData pd : multipolygon.getCombinedPolygons()) { 250 if (pd.getWays().contains(p)) { 251 pd.selected = true; 252 selectedPolyData.add(pd); 253 } 254 } 255 } 256 } 257 } 258 } 259 } 260 } 261 } 213 262 }
Note:
See TracChangeset
for help on using the changeset viewer.