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 | public MultiCascade() {
|
---|
22 | layers = new HashMap<String, Cascade>();
|
---|
23 | range = Range.ZERO_TO_INFINITY;
|
---|
24 | }
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Return the cascade with the given name. If it doesn't exist, create
|
---|
28 | * a new layer with that name and return it. The new layer will be
|
---|
29 | * a clone of the "*" layer, if it exists.
|
---|
30 | */
|
---|
31 | public Cascade getOrCreateCascade(String layer) {
|
---|
32 | CheckParameterUtil.ensureParameterNotNull(layer);
|
---|
33 | Cascade c = layers.get(layer);
|
---|
34 | if (c == null) {
|
---|
35 | if (layers.containsKey("*")) {
|
---|
36 | c = layers.get("*").clone();
|
---|
37 | } else {
|
---|
38 | c = new Cascade();
|
---|
39 | // Everything that is not on the default layer is assumed to
|
---|
40 | // be a modifier. Can be overridden in style definition.
|
---|
41 | if (!layer.equals("default") && !layer.equals("*")) {
|
---|
42 | c.put(MODIFIER, true);
|
---|
43 | }
|
---|
44 | }
|
---|
45 | layers.put(layer, c);
|
---|
46 | }
|
---|
47 | return c;
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Read-only version of getOrCreateCascade. For convenience, it returns an
|
---|
52 | * empty cascade for non-existing layers. However this empty (read-only) cascade
|
---|
53 | * is not added to this MultiCascade object.
|
---|
54 | */
|
---|
55 | public Cascade getCascade(String layer) {
|
---|
56 | if (layer == null) {
|
---|
57 | layer = "default";
|
---|
58 | }
|
---|
59 | Cascade c = layers.get(layer);
|
---|
60 | if (c == null) {
|
---|
61 | c = new Cascade();
|
---|
62 | if (!layer.equals("default") && !layer.equals("*")) {
|
---|
63 | c.put(MODIFIER, true);
|
---|
64 | }
|
---|
65 | }
|
---|
66 | return c;
|
---|
67 | }
|
---|
68 |
|
---|
69 | public Collection<Entry<String, Cascade>> getLayers() {
|
---|
70 | return layers.entrySet();
|
---|
71 | }
|
---|
72 |
|
---|
73 | public boolean hasLayer(String layer) {
|
---|
74 | return layers.containsKey(layer);
|
---|
75 | }
|
---|
76 | }
|
---|