Changeset 4623 in josm


Ignore:
Timestamp:
Dec 1, 2011 12:53:26 AM (18 months ago)
Author:
Don-vip
Message:

see #6987 - multipolygon cache aware of events requiring cache refresh (data change, zoom, layer removing)

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java

    r4388 r4623  
    3838import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon; 
    3939import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData; 
     40import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; 
    4041import org.openstreetmap.josm.gui.NavigatableComponent; 
    4142import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle; 
     
    860861 
    861862    public void drawArea(Relation r, Color color, BufferedImage fillImage, float fillImageAlpha, TextElement text) { 
    862         Multipolygon multipolygon = new Multipolygon(nc); 
    863         multipolygon.load(r); 
     863        Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, r); 
    864864        if(!r.isDisabled() && !multipolygon.getOuterWays().isEmpty()) { 
    865865            for (PolyData pd : multipolygon.getCombinedPolygons()) { 
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/Multipolygon.java

    r4191 r4623  
    134134     */ 
    135135    private static MultipolygonRoleMatcher roleMatcher; 
    136     private static MultipolygonRoleMatcher getMultipoloygonRoleMatcher() { 
     136    private static MultipolygonRoleMatcher getMultipolygonRoleMatcher() { 
    137137        if (roleMatcher == null) { 
    138138            roleMatcher = new MultipolygonRoleMatcher(); 
     
    237237    } 
    238238 
    239     private final NavigatableComponent nc; 
    240  
    241239    private final List<Way> innerWays = new ArrayList<Way>(); 
    242240    private final List<Way> outerWays = new ArrayList<Way>(); 
     
    245243    private final List<PolyData> combinedPolygons = new ArrayList<PolyData>(); 
    246244 
    247     public Multipolygon(NavigatableComponent nc) { 
    248         this.nc = nc; 
    249     } 
    250  
    251     public void load(Relation r) { 
    252         MultipolygonRoleMatcher matcher = getMultipoloygonRoleMatcher(); 
     245    public Multipolygon(NavigatableComponent nc, Relation r) { 
     246        load(r, nc); 
     247    } 
     248 
     249    private void load(Relation r, NavigatableComponent nc) { 
     250        MultipolygonRoleMatcher matcher = getMultipolygonRoleMatcher(); 
    253251 
    254252        // Fill inner and outer list with valid ways 
     
    273271        } 
    274272 
    275         createPolygons(innerWays, innerPolygons); 
    276         createPolygons(outerWays, outerPolygons); 
     273        createPolygons(nc, innerWays, innerPolygons); 
     274        createPolygons(nc, outerWays, outerPolygons); 
    277275        if (!outerPolygons.isEmpty()) { 
    278276            addInnerToOuters(); 
     
    280278    } 
    281279 
    282     private void createPolygons(List<Way> ways, List<PolyData> result) { 
     280    private void createPolygons(NavigatableComponent nc, List<Way> ways, List<PolyData> result) { 
    283281        List<Way> waysToJoin = new ArrayList<Way>(); 
    284282        for (Way way: ways) { 
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java

    r4447 r4623  
    134134            checkMembersAndRoles(r); 
    135135 
    136             Multipolygon polygon = new Multipolygon(Main.map.mapView); 
    137             polygon.load(r); 
     136            Multipolygon polygon = new Multipolygon(Main.map.mapView, r); 
    138137 
    139138            boolean hasOuterWay = false; 
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r4621 r4623  
    4545import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 
    4646import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 
     47import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; 
    4748import org.openstreetmap.josm.gui.layer.GpxLayer; 
    4849import org.openstreetmap.josm.gui.layer.Layer; 
     
    5152import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 
    5253import org.openstreetmap.josm.gui.layer.markerlayer.PlayHeadMarker; 
    53 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 
    5454import org.openstreetmap.josm.tools.AudioPlayer; 
    5555import org.openstreetmap.josm.tools.BugReportExceptionHandler; 
     
    238238            } 
    239239        }); 
     240         
     241        // Add Multipolygon cache to layer and zoom listeners 
     242        addLayerChangeListener(MultipolygonCache.getInstance()); 
     243        addZoomChangeListener(MultipolygonCache.getInstance()); 
    240244    } 
    241245 
     
    843847        Main.pref.removePreferenceChangeListener(this); 
    844848        DataSet.removeSelectionListener(repaintSelectionChangedListener); 
    845         MapPaintStyles.getStyles().clearMultipolygonsCache(this); 
     849        MultipolygonCache.getInstance().clear(this); 
    846850    } 
    847851 
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r4534 r4623  
    6363import org.openstreetmap.josm.data.osm.visitor.paint.MapRendererFactory; 
    6464import org.openstreetmap.josm.data.osm.visitor.paint.Rendering; 
     65import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; 
    6566import org.openstreetmap.josm.data.projection.Projection; 
    6667import org.openstreetmap.josm.data.validation.TestError; 
     
    207208        conflicts = new ConflictCollection(); 
    208209        data.addDataSetListener(new DataSetListenerAdapter(this)); 
     210        data.addDataSetListener(MultipolygonCache.getInstance()); 
    209211        DataSet.addSelectionListener(this); 
    210212    } 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r4621 r4623  
    66import java.util.Collection; 
    77import java.util.Collections; 
    8 import java.util.HashMap; 
    98import java.util.Iterator; 
    109import java.util.List; 
    11 import java.util.Map; 
    1210import java.util.Map.Entry; 
    1311 
     
    1715import org.openstreetmap.josm.data.osm.Way; 
    1816import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon; 
     17import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; 
    1918import org.openstreetmap.josm.gui.NavigatableComponent; 
    2019import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList; 
     
    3130    private int defaultNodesIdx, defaultLinesIdx; 
    3231     
    33     private final Map<NavigatableComponent, Map<Relation, Multipolygon>> multipolygonsCache; 
    34  
    3532    public ElemStyles() 
    3633    { 
    3734        styleSources = new ArrayList<StyleSource>(); 
    38         multipolygonsCache = new HashMap<NavigatableComponent, Map<Relation,Multipolygon>>(); 
    3935    } 
    4036 
     
    121117    } 
    122118 
    123     private final Multipolygon getCachedMultipolygon(NavigatableComponent nc, Relation r) { 
    124         Multipolygon multipolygon = null; 
    125         Map<Relation, Multipolygon> map = multipolygonsCache.get(nc); 
    126         if (map == null) { 
    127             multipolygonsCache.put(nc, map = new HashMap<Relation, Multipolygon>()); 
    128         } 
    129         multipolygon = map.get(r); 
    130         if (multipolygon == null) { 
    131             map.put(r, multipolygon = new Multipolygon(nc)); 
    132             multipolygon.load(r); 
    133         } 
    134         return multipolygon; 
    135     } 
    136      
    137119    /** 
    138120     * Create the list of styles and its valid scale range for one primitive. 
     
    179161                    continue; 
    180162                } 
    181                 Multipolygon multipolygon = getCachedMultipolygon(nc, r); 
     163                Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, r); 
    182164 
    183165                if (multipolygon.getOuterWays().contains(osm)) { 
     
    244226                    continue; 
    245227                } 
    246                 final Multipolygon multipolygon = getCachedMultipolygon(nc, ref); 
     228                final Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, ref); 
    247229 
    248230                if (multipolygon.getInnerWays().contains(osm)) { 
     
    277259                if (!Utils.exists(p.a, AreaElemStyle.class)) { 
    278260                    // look at outer ways to find area style 
    279                     Multipolygon multipolygon = new Multipolygon(nc); 
    280                     multipolygon.load((Relation) osm); 
     261                    Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, (Relation) osm); 
    281262                    for (Way w : multipolygon.getOuterWays()) { 
    282263                        Pair<StyleList, Range> wayStyles = generateStyles(w, scale, null, false); 
     
    429410        styleSources.addAll(sources); 
    430411    } 
    431  
    432     public void clearMultipolygonsCache(NavigatableComponent nc) { 
    433         multipolygonsCache.remove(nc); 
    434     } 
    435412} 
Note: See TracChangeset for help on using the changeset viewer.