Changeset 6026 in josm for trunk/src/org/openstreetmap/josm/gui
- Timestamp:
- 2013-06-26T11:09:17+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.