source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/MultiCascade.java@ 9239

Last change on this file since 9239 was 9239, checked in by Don-vip, 8 years ago

javadoc update

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint;
3
4import java.util.Collection;
5import java.util.HashMap;
6import java.util.Map;
7import java.util.Map.Entry;
8
9import 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 */
16public class MultiCascade implements StyleKeys {
17
18 private final 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 * @param layer layer
34 * @return cascade
35 */
36 public Cascade getOrCreateCascade(String layer) {
37 CheckParameterUtil.ensureParameterNotNull(layer);
38 Cascade c = layers.get(layer);
39 if (c == null) {
40 if (layers.containsKey("*")) {
41 c = layers.get("*").clone();
42 } else {
43 c = new Cascade();
44 // Everything that is not on the default layer is assumed to
45 // be a modifier. Can be overridden in style definition.
46 if (!"default".equals(layer) && !"*".equals(layer)) {
47 c.put(MODIFIER, Boolean.TRUE);
48 }
49 }
50 layers.put(layer, c);
51 }
52 return c;
53 }
54
55 /**
56 * Read-only version of {@link #getOrCreateCascade}. For convenience, it returns an
57 * empty cascade for non-existing layers. However this empty (read-only) cascade
58 * is not added to this MultiCascade object.
59 * @param layer layer
60 * @return cascade
61 */
62 public Cascade getCascade(String layer) {
63 if (layer == null) {
64 layer = "default";
65 }
66 Cascade c = layers.get(layer);
67 if (c == null) {
68 c = new Cascade();
69 if (!"default".equals(layer) && !"*".equals(layer)) {
70 c.put(MODIFIER, Boolean.TRUE);
71 }
72 }
73 return c;
74 }
75
76 public Collection<Entry<String, Cascade>> getLayers() {
77 return layers.entrySet();
78 }
79
80 public boolean hasLayer(String layer) {
81 return layers.containsKey(layer);
82 }
83}
Note: See TracBrowser for help on using the repository browser.