Ignore:
Timestamp:
2011-02-12T20:30:01+01:00 (13 years ago)
Author:
bastiK
Message:

mapcss: some rework of Error Handling, (Multi)Cascade and icon loading

File:
1 edited

Legend:

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

    r3882 r3893  
    22package org.openstreetmap.josm.gui.mappaint;
    33
     4import java.util.Collection;
    45import java.util.HashMap;
     6import java.util.Map;
     7import java.util.Map.Entry;
    58
    69/**
    7  * Several cascades, e.g. one for the main Line and one for each overlay.
    8  * The range is (0,Inf) at first and it shrinks in the process when
     10 * Several layers / cascades, e.g. one for the main Line and one for each overlay.
     11 * The range is (0,Infinity) at first and it shrinks in the process when
    912 * StyleSources apply zoom level dependent properties.
    1013 */
    11 public class MultiCascade extends HashMap<String, Cascade> {
     14public class MultiCascade {
     15   
     16    private Map<String, Cascade> layers;
    1217    public Range range;
    1318
    1419    public MultiCascade() {
    15         super();
     20        layers = new HashMap<String, Cascade>();
    1621        range = new Range();
    1722    }
    1823
    1924    /**
    20      * Return the cascade for the given layer key. If it does not exist,
    21      * return a new cascade, but do not keep it.
     25     * Return the cascade with the given name. If it doesn't exist, create
     26     * a new layer with that name and return it. The new layer will be
     27     * a clone of the "*" layer, if it exists.
    2228     */
    23     public Cascade getCascade(String layer) {
     29    public Cascade getOrCreateCascade(String layer) {
    2430        if (layer == null)
    2531            throw new IllegalArgumentException();
    26         Cascade c = get(layer);
     32        Cascade c = layers.get(layer);
    2733        if (c == null) {
    28             c = new Cascade(!layer.equals("default"));
     34            if (layers.containsKey("*")) {
     35                c = layers.get("*").clone();
     36            } else {
     37                c = new Cascade();
     38                // Everything that is not on the default layer is assumed to
     39                // be a modifier. Can be overridden in style definition.
     40                if (!layer.equals("default")) {
     41                    c.put("modifier", true);
     42                }
     43            }
     44            layers.put(layer, c);
    2945        }
    3046        return c;
    3147    }
    3248
     49    /**
     50     * Read-only version of getOrCreateCascade. For convenience, it returns an
     51     * empty cascade for non-existing layers. However this empty (read-only) cascade
     52     * is not added to this MultiCascade object.
     53     */
     54    public Cascade getCascade(String layer) {
     55        if (layer == null) {
     56            layer = "default";
     57        }
     58        Cascade c = layers.get(layer);
     59        if (c == null) {
     60            c = new Cascade();
     61            if (!layer.equals("default")) {
     62                c.put("modifier", true);
     63            }
     64        }
     65        return c;
     66    }
     67
     68    public Collection<Entry<String, Cascade>> getLayers() {
     69        return layers.entrySet();
     70    }
     71
     72    public boolean hasLayer(String layer) {
     73        return layers.containsKey(layer);
     74    }
    3375}
Note: See TracChangeset for help on using the changeset viewer.