Changeset 6473 in josm for trunk/src/org


Ignore:
Timestamp:
2013-12-14T16:13:55+01:00 (11 years ago)
Author:
Don-vip
Message:

fix #9428 - highlight: handle recursive relations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/util/HighlightHelper.java

    r6038 r6473  
    77import java.util.Iterator;
    88import java.util.Set;
     9
    910import org.openstreetmap.josm.Main;
    1011import org.openstreetmap.josm.data.osm.DataSet;
     
    1819public class HighlightHelper {
    1920    Set<OsmPrimitive> highlightedPrimitives = new HashSet<OsmPrimitive>();
    20    
     21
    2122    /**
    2223     * Highlight and remember given primitives
     
    2627        return highlight(prims, false);
    2728    }
    28    
     29
    2930    /**
    3031     * Highlight and remember given primitives
     
    5152        return needsRepaint;
    5253    }
    53    
     54
    5455    /**
    5556     * Highlight and remember given primitives, forgetting previously highlighted by this instance
     
    5960        return highlight(prims, true);
    6061    }
    61    
     62
    6263    /**
    6364     * Highlight and remember given primitive, forgetting previously highlighted by this instance
     
    6768        return highlight(Collections.singleton(p), true);
    6869    }
    69    
     70
    7071    /**
    7172     * Highlight and remember given primitive
     
    7475     */
    7576    public boolean setHighlight(OsmPrimitive p, boolean flag) {
     77        return setHighlight(p, flag, new HashSet<Relation>());
     78    }
     79
     80    private boolean setHighlight(OsmPrimitive p, boolean flag, Set<Relation> seenRelations) {
    7681        if (p instanceof Relation) {
     82            Relation r = (Relation) p;
     83            seenRelations.add(r);
    7784            boolean needRepaint = false;
    78             for (OsmPrimitive m: ((Relation) p).getMemberPrimitives()) {
    79                 needRepaint |= setHighlight(m, flag);
     85            for (OsmPrimitive m : r.getMemberPrimitives()) {
     86                if (!(m instanceof Relation) || !seenRelations.contains(m)) {
     87                    needRepaint |= setHighlight(m, flag, seenRelations);
     88                }
    8089            }
    8190            return needRepaint;
    82         } else
    83         if (flag) {
     91        } else if (flag) {
    8492            if (highlightedPrimitives.add(p)) {
    8593                p.setHighlighted(true);
     
    94102        return false;
    95103    }
    96    
     104
    97105    /**
    98106     * Clear highlighting of all remembered primitives
     
    104112        highlightedPrimitives.clear();
    105113    }
    106    
     114
    107115    /**
    108116     * Slow method to import all currently highlighted primitives into this instance
     
    114122        }
    115123    }
    116    
     124
    117125    /**
    118126     * Slow method to remove highlights from all primitives
Note: See TracChangeset for help on using the changeset viewer.