1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint;
|
---|
3 |
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.HashMap;
|
---|
6 | import java.util.Map;
|
---|
7 | import java.util.Map.Entry;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.tools.CheckParameterUtil;
|
---|
10 |
|
---|
11 | /**
|
---|
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
|
---|
14 | * StyleSources apply zoom level dependent properties.
|
---|
15 | */
|
---|
16 | public class MultiCascade implements StyleKeys {
|
---|
17 |
|
---|
18 | private Map<String, Cascade> layers;
|
---|
19 | public Range range;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Constructs a new {@code MultiCascade}.
|
---|
23 | */
|
---|
24 | public MultiCascade() {
|
---|
25 | layers = new HashMap<>();
|
---|
26 | range = Range.ZERO_TO_INFINITY;
|
---|
27 | }
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Return the cascade with the given name. If it doesn't exist, create
|
---|
31 | * a new layer with that name and return it. The new layer will be
|
---|
32 | * a clone of the "*" layer, if it exists.
|
---|
33 | */
|
---|
34 | public Cascade getOrCreateCascade(String layer) {
|
---|
35 | CheckParameterUtil.ensureParameterNotNull(layer);
|
---|
36 | Cascade c = layers.get(layer);
|
---|
37 | if (c == null) {
|
---|
38 | if (layers.containsKey("*")) {
|
---|
39 | c = layers.get("*").clone();
|
---|
40 | } else {
|
---|
41 | c = new Cascade();
|
---|
42 | // Everything that is not on the default layer is assumed to
|
---|
43 | // be a modifier. Can be overridden in style definition.
|
---|
44 | if (!"default".equals(layer) && !"*".equals(layer)) {
|
---|
45 | c.put(MODIFIER, true);
|
---|
46 | }
|
---|
47 | }
|
---|
48 | layers.put(layer, c);
|
---|
49 | }
|
---|
50 | return c;
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Read-only version of getOrCreateCascade. For convenience, it returns an
|
---|
55 | * empty cascade for non-existing layers. However this empty (read-only) cascade
|
---|
56 | * is not added to this MultiCascade object.
|
---|
57 | */
|
---|
58 | public Cascade getCascade(String layer) {
|
---|
59 | if (layer == null) {
|
---|
60 | layer = "default";
|
---|
61 | }
|
---|
62 | Cascade c = layers.get(layer);
|
---|
63 | if (c == null) {
|
---|
64 | c = new Cascade();
|
---|
65 | if (!"default".equals(layer) && !"*".equals(layer)) {
|
---|
66 | c.put(MODIFIER, true);
|
---|
67 | }
|
---|
68 | }
|
---|
69 | return c;
|
---|
70 | }
|
---|
71 |
|
---|
72 | public Collection<Entry<String, Cascade>> getLayers() {
|
---|
73 | return layers.entrySet();
|
---|
74 | }
|
---|
75 |
|
---|
76 | public boolean hasLayer(String layer) {
|
---|
77 | return layers.containsKey(layer);
|
---|
78 | }
|
---|
79 | }
|
---|