[3836] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.gui.mappaint;
|
---|
| 3 |
|
---|
[3893] | 4 | import java.util.Collection;
|
---|
[3836] | 5 | import java.util.HashMap;
|
---|
[3893] | 6 | import java.util.Map;
|
---|
| 7 | import java.util.Map.Entry;
|
---|
[3836] | 8 |
|
---|
[3987] | 9 | import org.openstreetmap.josm.tools.CheckParameterUtil;
|
---|
| 10 |
|
---|
[3836] | 11 | /**
|
---|
[3893] | 12 | * Several layers / cascades, e.g. one for the main Line and one for each overlay.
|
---|
| 13 | * The range is (0,Infinity) at first and it shrinks in the process when
|
---|
[3836] | 14 | * StyleSources apply zoom level dependent properties.
|
---|
| 15 | */
|
---|
[5342] | 16 | public class MultiCascade implements StyleKeys {
|
---|
[3987] | 17 |
|
---|
[9078] | 18 | private final Map<String, Cascade> layers;
|
---|
[12378] | 19 | /**
|
---|
| 20 | * The scale range this cascade is valid for
|
---|
| 21 | */
|
---|
[3836] | 22 | public Range range;
|
---|
| 23 |
|
---|
[6990] | 24 | /**
|
---|
| 25 | * Constructs a new {@code MultiCascade}.
|
---|
| 26 | */
|
---|
[3836] | 27 | public MultiCascade() {
|
---|
[7005] | 28 | layers = new HashMap<>();
|
---|
[6561] | 29 | range = Range.ZERO_TO_INFINITY;
|
---|
[3836] | 30 | }
|
---|
| 31 |
|
---|
[3882] | 32 | /**
|
---|
[3893] | 33 | * Return the cascade with the given name. If it doesn't exist, create
|
---|
| 34 | * a new layer with that name and return it. The new layer will be
|
---|
| 35 | * a clone of the "*" layer, if it exists.
|
---|
[9239] | 36 | * @param layer layer
|
---|
| 37 | * @return cascade
|
---|
[3882] | 38 | */
|
---|
[3893] | 39 | public Cascade getOrCreateCascade(String layer) {
|
---|
[3987] | 40 | CheckParameterUtil.ensureParameterNotNull(layer);
|
---|
[3893] | 41 | Cascade c = layers.get(layer);
|
---|
[3865] | 42 | if (c == null) {
|
---|
[3893] | 43 | if (layers.containsKey("*")) {
|
---|
[11388] | 44 | c = new Cascade(layers.get("*"));
|
---|
[3893] | 45 | } else {
|
---|
| 46 | c = new Cascade();
|
---|
| 47 | // Everything that is not on the default layer is assumed to
|
---|
| 48 | // be a modifier. Can be overridden in style definition.
|
---|
[6990] | 49 | if (!"default".equals(layer) && !"*".equals(layer)) {
|
---|
[8846] | 50 | c.put(MODIFIER, Boolean.TRUE);
|
---|
[3893] | 51 | }
|
---|
| 52 | }
|
---|
| 53 | layers.put(layer, c);
|
---|
[3836] | 54 | }
|
---|
[3865] | 55 | return c;
|
---|
[3836] | 56 | }
|
---|
| 57 |
|
---|
[3893] | 58 | /**
|
---|
[9239] | 59 | * Read-only version of {@link #getOrCreateCascade}. For convenience, it returns an
|
---|
[3893] | 60 | * empty cascade for non-existing layers. However this empty (read-only) cascade
|
---|
| 61 | * is not added to this MultiCascade object.
|
---|
[9239] | 62 | * @param layer layer
|
---|
| 63 | * @return cascade
|
---|
[3893] | 64 | */
|
---|
| 65 | public Cascade getCascade(String layer) {
|
---|
| 66 | if (layer == null) {
|
---|
| 67 | layer = "default";
|
---|
| 68 | }
|
---|
| 69 | Cascade c = layers.get(layer);
|
---|
| 70 | if (c == null) {
|
---|
| 71 | c = new Cascade();
|
---|
[6990] | 72 | if (!"default".equals(layer) && !"*".equals(layer)) {
|
---|
[8377] | 73 | c.put(MODIFIER, Boolean.TRUE);
|
---|
[3893] | 74 | }
|
---|
| 75 | }
|
---|
| 76 | return c;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[12378] | 79 | /**
|
---|
| 80 | * Gets all cascades for the known layers
|
---|
| 81 | * @return The cascades for the layers
|
---|
| 82 | */
|
---|
[3893] | 83 | public Collection<Entry<String, Cascade>> getLayers() {
|
---|
| 84 | return layers.entrySet();
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[12378] | 87 | /**
|
---|
| 88 | * Check whether this cascade has a given layer
|
---|
| 89 | * @param layer The layer to check for
|
---|
| 90 | * @return <code>true</code> if it has that layer
|
---|
| 91 | */
|
---|
[3893] | 92 | public boolean hasLayer(String layer) {
|
---|
| 93 | return layers.containsKey(layer);
|
---|
| 94 | }
|
---|
[3836] | 95 | }
|
---|