Ignore:
Timestamp:
2017-10-09T17:14:50+02:00 (7 years ago)
Author:
bastiK
Message:

use RenderingHelper in MapCSSRendererTest; move getBackgroundColor() from PaintColors to ElemStyles (no longer global) (see #15273)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r12881 r12966  
    1010import java.util.Map;
    1111import java.util.Map.Entry;
     12import java.util.Optional;
    1213
    1314import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
     
    1718import org.openstreetmap.josm.data.osm.Relation;
    1819import org.openstreetmap.josm.data.osm.Way;
     20import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
    1921import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon;
    2022import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache;
     
    6971    private final Map<String, String> preferenceCache = new HashMap<>();
    7072
     73    private static volatile Color backgroundColorCache;
     74
    7175    /**
    7276     * Constructs a new {@code ElemStyles}.
     
    7579        styleSources = new ArrayList<>();
    7680        Config.getPref().addPreferenceChangeListener(this);
     81        MapPaintStyles.addMapPaintSylesUpdateListener(new MapPaintStyles.MapPaintSylesUpdateListener() {
     82            //TODO: Listen to wireframe map mode changes.
     83            @Override
     84            public void mapPaintStylesUpdated() {
     85                backgroundColorCache = null;
     86            }
     87
     88            @Override
     89            public void mapPaintStyleEntryUpdated(int idx) {
     90                mapPaintStylesUpdated();
     91            }
     92        });
    7793    }
    7894
     
    94110    public List<StyleSource> getStyleSources() {
    95111        return Collections.<StyleSource>unmodifiableList(styleSources);
     112    }
     113
     114    public Color getBackgroundColor() {
     115        if (backgroundColorCache != null)
     116            return backgroundColorCache;
     117        for (StyleSource s : styleSources) {
     118            if (!s.active) {
     119                continue;
     120            }
     121            Color backgroundColorOverride = s.getBackgroundColorOverride();
     122            if (backgroundColorOverride != null) {
     123                backgroundColorCache = backgroundColorOverride;
     124            }
     125        }
     126        return Optional.ofNullable(backgroundColorCache).orElseGet(PaintColors.BACKGROUND::get);
    96127    }
    97128
Note: See TracChangeset for help on using the changeset viewer.