- Timestamp:
- 2013-06-26T11:09:17+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r5909 r6026 28 28 import org.openstreetmap.josm.gui.layer.Layer; 29 29 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 30 import org.openstreetmap.josm.gui.util.HighlightHelper; 30 31 import org.openstreetmap.josm.tools.CheckParameterUtil; 31 32 import org.openstreetmap.josm.tools.ImageProvider; … … 57 58 * set would have to be checked. 58 59 */ 59 private Set<OsmPrimitive> oldHighlights = new HashSet<OsmPrimitive>();60 60 private WaySegment oldHighlightedWaySegment = null; 61 61 62 private static final HighlightHelper highlightHelper = new HighlightHelper(); 62 63 private boolean drawTargetHighlight; 63 64 … … 173 174 */ 174 175 private void removeHighlighting() { 175 for(OsmPrimitive prim : oldHighlights) { 176 prim.setHighlighted(false); 177 } 178 oldHighlights = new HashSet<OsmPrimitive>(); 176 highlightHelper.clear(); 179 177 DataSet ds = getCurrentDataSet(); 180 178 if(ds != null) { … … 233 231 oldHighlightedWaySegment = newHighlightedWaySegment; 234 232 } 235 236 for(OsmPrimitive x : newHighlights) { 237 if(oldHighlights.contains(x)) { 238 continue; 239 } 240 needsRepaint = true; 241 x.setHighlighted(true); 242 } 243 oldHighlights.removeAll(newHighlights); 244 for(OsmPrimitive x : oldHighlights) { 245 x.setHighlighted(false); 246 needsRepaint = true; 247 } 248 oldHighlights = newHighlights; 233 needsRepaint |= highlightHelper.highlightOnly(newHighlights); 249 234 if(needsRepaint) { 250 235 Main.map.mapView.repaint(); -
trunk/src/org/openstreetmap/josm/gui/util/HighlightHelper.java
r6025 r6026 3 3 4 4 import java.util.Collection; 5 import java.util.Collections; 5 6 import java.util.HashSet; 7 import java.util.Iterator; 6 8 import java.util.Set; 7 9 import org.openstreetmap.josm.Main; … … 20 22 * Highlight and remember given primitives 21 23 * @param prims - primitives to highlight/unhighlight 22 * @param flag - true to highlight23 24 */ 24 public void highlight(Collection <? extends OsmPrimitive> prims, boolean flag) { 25 public boolean highlight(Collection <? extends OsmPrimitive> prims) { 26 return highlight(prims, false); 27 } 28 29 /** 30 * Highlight and remember given primitives 31 * @param prims - primitives to highlight/unhighlight 32 * @param only - remove previous highlighting 33 */ 34 public boolean highlight(Collection <? extends OsmPrimitive> prims, boolean only) { 35 boolean needsRepaint = false; 36 if (only) { 37 Iterator<OsmPrimitive> it = highlightedPrimitives.iterator(); 38 while (it.hasNext()) { 39 OsmPrimitive p = it.next(); 40 if (!prims.contains(p)) { 41 p.setHighlighted(false); 42 it.remove(); 43 needsRepaint = true; 44 } 45 } 46 } 25 47 for (OsmPrimitive p: prims) { 26 highlight(p, flag);48 needsRepaint |= setHighlight(p, true); 27 49 } 50 //return true; 51 return needsRepaint; 28 52 } 29 53 … … 32 56 * @param prims - primitives to highlight/unhighlight 33 57 */ 34 public void highlightOnly(Collection <? extends OsmPrimitive> prims) { 35 clear(); 36 highlight(prims, true); 58 public boolean highlightOnly(Collection <? extends OsmPrimitive> prims) { 59 return highlight(prims, true); 37 60 } 38 61 … … 41 64 * @param p - primitives to highlight/unhighlight 42 65 */ 43 public void highlightOnly(OsmPrimitive p) { 44 clear(); 45 highlight(p, true); 66 public boolean highlightOnly(OsmPrimitive p) { 67 return highlight(Collections.singleton(p), true); 46 68 } 47 69 … … 51 73 * @param flag - true to highlight 52 74 */ 53 public void highlight(OsmPrimitive p, boolean flag) {75 public boolean setHighlight(OsmPrimitive p, boolean flag) { 54 76 if (p instanceof Relation) { 77 boolean needRepaint = false; 55 78 for (OsmPrimitive m: ((Relation) p).getMemberPrimitives()) { 56 highlight(m, flag);79 needRepaint |= setHighlight(m, flag); 57 80 } 81 return needRepaint; 58 82 } else 59 83 if (flag) { 60 84 if (highlightedPrimitives.add(p)) { 61 85 p.setHighlighted(true); 86 return true; 62 87 } 63 88 } else { 64 89 if (highlightedPrimitives.remove(p)) { 65 90 p.setHighlighted(false); 91 return true; 66 92 } 67 93 } 94 return false; 68 95 } 69 96 … … 81 108 * Slow method to import all currently highlighted primitives into this instance 82 109 */ 83 public void findAllHighlig ted() {110 public void findAllHighlighted() { 84 111 DataSet ds = Main.main.getCurrentDataSet(); 85 112 if (ds!=null) { … … 89 116 90 117 /** 91 * Slow method to import all currently highlighted primitives into this instance118 * Slow method to remove highlights from all primitives 92 119 */ 93 public static void clearAllHighlig ted() {120 public static void clearAllHighlighted() { 94 121 DataSet ds = Main.main.getCurrentDataSet(); 95 122 if (ds!=null) {
Note:
See TracChangeset
for help on using the changeset viewer.