Changeset 3893 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint/MultiCascade.java
- Timestamp:
- 2011-02-12T20:30:01+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/MultiCascade.java
r3882 r3893 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import java.util.Collection; 4 5 import java.util.HashMap; 6 import java.util.Map; 7 import java.util.Map.Entry; 5 8 6 9 /** 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 when10 * 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 9 12 * StyleSources apply zoom level dependent properties. 10 13 */ 11 public class MultiCascade extends HashMap<String, Cascade> { 14 public class MultiCascade { 15 16 private Map<String, Cascade> layers; 12 17 public Range range; 13 18 14 19 public MultiCascade() { 15 super();20 layers = new HashMap<String, Cascade>(); 16 21 range = new Range(); 17 22 } 18 23 19 24 /** 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. 22 28 */ 23 public Cascade get Cascade(String layer) {29 public Cascade getOrCreateCascade(String layer) { 24 30 if (layer == null) 25 31 throw new IllegalArgumentException(); 26 Cascade c = get(layer);32 Cascade c = layers.get(layer); 27 33 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); 29 45 } 30 46 return c; 31 47 } 32 48 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 } 33 75 }
Note:
See TracChangeset
for help on using the changeset viewer.