- Timestamp:
- 2016-01-03T18:13:45+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r9278 r9284 61 61 import org.openstreetmap.josm.gui.mappaint.ElemStyles; 62 62 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 63 import org.openstreetmap.josm.gui.mappaint.Style Cache.StyleList;63 import org.openstreetmap.josm.gui.mappaint.StyleElementList; 64 64 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 65 65 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector; … … 1825 1825 1826 1826 public void add(Node osm, int flags) { 1827 Style List sl = styles.get(osm, circum, nc);1827 StyleElementList sl = styles.get(osm, circum, nc); 1828 1828 for (StyleElement s : sl) { 1829 1829 output.add(new StyleRecord(s, osm, flags)); … … 1832 1832 1833 1833 public void add(Relation osm, int flags) { 1834 Style List sl = styles.get(osm, circum, nc);1834 StyleElementList sl = styles.get(osm, circum, nc); 1835 1835 for (StyleElement s : sl) { 1836 1836 if (drawMultipolygon && drawArea && s instanceof AreaElement && (flags & FLAG_DISABLED) == 0) { … … 1843 1843 1844 1844 public void add(Way osm, int flags) { 1845 Style List sl = styles.get(osm, circum, nc);1845 StyleElementList sl = styles.get(osm, circum, nc); 1846 1846 for (StyleElement s : sl) { 1847 1847 if (!(drawArea && (flags & FLAG_DISABLED) == 0) && s instanceof AreaElement) { -
trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java
r9278 r9284 44 44 import org.openstreetmap.josm.gui.mappaint.MultiCascade; 45 45 import org.openstreetmap.josm.gui.mappaint.StyleCache; 46 import org.openstreetmap.josm.gui.mappaint.Style Cache.StyleList;46 import org.openstreetmap.josm.gui.mappaint.StyleElementList; 47 47 import org.openstreetmap.josm.gui.mappaint.StyleSource; 48 48 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; … … 362 362 } 363 363 txtMappaint.append(tr("\n\nList of generated Styles:\n")); 364 Style List sl = elemstyles.get(osm, scale, nc);364 StyleElementList sl = elemstyles.get(osm, scale, nc); 365 365 for (StyleElement s : sl) { 366 366 txtMappaint.append(" * ").append(s).append('\n'); -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r9278 r9284 21 21 import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; 22 22 import org.openstreetmap.josm.gui.NavigatableComponent; 23 import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList;24 23 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 25 24 import org.openstreetmap.josm.gui.mappaint.styleelement.AreaElement; … … 80 79 * @return list of styles 81 80 */ 82 public Style List get(OsmPrimitive osm, double scale, NavigatableComponent nc) {81 public StyleElementList get(OsmPrimitive osm, double scale, NavigatableComponent nc) { 83 82 return getStyleCacheWithRange(osm, scale, nc).a; 84 83 } … … 94 93 * @return pair containing style list and range 95 94 */ 96 public Pair<Style List, Range> getStyleCacheWithRange(OsmPrimitive osm, double scale, NavigatableComponent nc) {95 public Pair<StyleElementList, Range> getStyleCacheWithRange(OsmPrimitive osm, double scale, NavigatableComponent nc) { 97 96 if (osm.mappaintStyle == null || osm.mappaintCacheIdx != cacheIdx || scale <= 0) { 98 97 osm.mappaintStyle = StyleCache.EMPTY_STYLECACHE; 99 98 } else { 100 Pair<Style List, Range> lst = osm.mappaintStyle.getWithRange(scale);99 Pair<StyleElementList, Range> lst = osm.mappaintStyle.getWithRange(scale); 101 100 if (lst.a != null) 102 101 return lst; 103 102 } 104 Pair<Style List, Range> p = getImpl(osm, scale, nc);103 Pair<StyleElementList, Range> p = getImpl(osm, scale, nc); 105 104 if (osm instanceof Node && isDefaultNodes()) { 106 105 if (p.a.isEmpty()) { … … 123 122 } 124 123 if (!hasNonModifier) { 125 p.a = new Style List(p.a, NodeElement.SIMPLE_NODE_ELEMSTYLE);124 p.a = new StyleElementList(p.a, NodeElement.SIMPLE_NODE_ELEMSTYLE); 126 125 if (!hasText) { 127 126 if (TextLabel.AUTO_LABEL_COMPOSITION_STRATEGY.compose(osm) != null) { 128 p.a = new Style List(p.a, BoxTextElement.SIMPLE_NODE_TEXT_ELEMSTYLE);127 p.a = new StyleElementList(p.a, BoxTextElement.SIMPLE_NODE_TEXT_ELEMSTYLE); 129 128 } 130 129 } … … 142 141 AreaElement area = Utils.find(p.a, AreaElement.class); 143 142 LineElement line = area == null ? LineElement.UNTAGGED_WAY : LineElement.createSimpleLineStyle(area.color, true); 144 p.a = new Style List(p.a, line);143 p.a = new StyleElementList(p.a, line); 145 144 } 146 145 } … … 186 185 * @return pair containing style list and range 187 186 */ 188 private Pair<Style List, Range> getImpl(OsmPrimitive osm, double scale, NavigatableComponent nc) {187 private Pair<StyleElementList, Range> getImpl(OsmPrimitive osm, double scale, NavigatableComponent nc) { 189 188 if (osm instanceof Node) 190 189 return generateStyles(osm, scale, false); 191 190 else if (osm instanceof Way) { 192 Pair<Style List, Range> p = generateStyles(osm, scale, false);191 Pair<StyleElementList, Range> p = generateStyles(osm, scale, false); 193 192 194 193 boolean isOuterWayOfSomeMP = false; … … 216 215 } 217 216 } 218 p.a = new Style List(tmp);217 p.a = new StyleElementList(tmp); 219 218 isOuterWayOfSomeMP = true; 220 219 } 221 220 222 221 if (!hasIndependentLineStyle) { 223 Pair<Style List, Range> mpElemStyles;222 Pair<StyleElementList, Range> mpElemStyles; 224 223 synchronized (r) { 225 224 mpElemStyles = getStyleCacheWithRange(r, scale, nc); … … 234 233 p.b = Range.cut(p.b, mpElemStyles.b); 235 234 if (mpLine != null) { 236 p.a = new Style List(p.a, mpLine);235 p.a = new StyleElementList(p.a, mpLine); 237 236 break; 238 237 } else if (wayColor == null && isDefaultLines()) { … … 255 254 } 256 255 if (!hasLineStyle) { 257 p.a = new Style List(p.a, LineElement.createSimpleLineStyle(wayColor, true));256 p.a = new StyleElementList(p.a, LineElement.createSimpleLineStyle(wayColor, true)); 258 257 } 259 258 } … … 281 280 if (!hasIndependentElemStyle && !multipolygon.getOuterWays().isEmpty()) { 282 281 Color mpColor = null; 283 Style List mpElemStyles = null;282 StyleElementList mpElemStyles = null; 284 283 synchronized (ref) { 285 284 mpElemStyles = get(ref, scale, nc); … … 291 290 } 292 291 } 293 p.a = new Style List(p.a, LineElement.createSimpleLineStyle(mpColor, true));292 p.a = new StyleElementList(p.a, LineElement.createSimpleLineStyle(mpColor, true)); 294 293 } 295 294 return p; … … 298 297 return p; 299 298 } else if (osm instanceof Relation) { 300 Pair<Style List, Range> p = generateStyles(osm, scale, true);299 Pair<StyleElementList, Range> p = generateStyles(osm, scale, true); 301 300 if (drawMultipolygon && ((Relation) osm).isMultipolygon()) { 302 301 if (!Utils.exists(p.a, AreaElement.class) && Main.pref.getBoolean("multipolygon.deprecated.outerstyle", true)) { … … 304 303 Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, (Relation) osm); 305 304 for (Way w : multipolygon.getOuterWays()) { 306 Pair<Style List, Range> wayStyles = generateStyles(w, scale, false);305 Pair<StyleElementList, Range> wayStyles = generateStyles(w, scale, false); 307 306 p.b = Range.cut(p.b, wayStyles.b); 308 307 StyleElement area = Utils.find(wayStyles.a, AreaElement.class); 309 308 if (area != null) { 310 p.a = new Style List(p.a, area);309 p.a = new StyleElementList(p.a, area); 311 310 break; 312 311 } … … 332 331 * @return the generated styles and the valid range as a pair 333 332 */ 334 public Pair<Style List, Range> generateStyles(OsmPrimitive osm, double scale, boolean pretendWayIsClosed) {333 public Pair<StyleElementList, Range> generateStyles(OsmPrimitive osm, double scale, boolean pretendWayIsClosed) { 335 334 336 335 List<StyleElement> sl = new ArrayList<>(); … … 377 376 } 378 377 } 379 return new Pair<>(new Style List(sl), mc.range);378 return new Pair<>(new StyleElementList(sl), mc.range); 380 379 } 381 380 … … 501 500 if (MapPaintStyles.getStyles() == null) 502 501 return false; 503 Style List styles = MapPaintStyles.getStyles().generateStyles(p, 1.0, false).a;502 StyleElementList styles = MapPaintStyles.getStyles().generateStyles(p, 1.0, false).a; 504 503 if (styles.isEmpty()) { 505 504 return false; -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r9278 r9284 27 27 import org.openstreetmap.josm.data.osm.Tag; 28 28 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 29 import org.openstreetmap.josm.gui.mappaint.Style Cache.StyleList;29 import org.openstreetmap.josm.gui.mappaint.StyleElementList; 30 30 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 31 31 import org.openstreetmap.josm.gui.mappaint.styleelement.MapImage; … … 184 184 Node virtualNode = new Node(LatLon.ZERO); 185 185 virtualNode.put(tag.getKey(), tag.getValue()); 186 Style List styleList;186 StyleElementList styleList; 187 187 MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock(); 188 188 try { -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleCache.java
r9278 r9284 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import java.util.ArrayList;5 import java.util.Arrays;6 import java.util.Collection;7 import java.util.Iterator;8 import java.util.List;9 import java.util.Objects;10 11 4 import org.openstreetmap.josm.data.osm.Storage; 12 import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement;13 import org.openstreetmap.josm.tools.Pair;14 5 15 6 /** 16 7 * Caches styles for a single primitive. 17 * Splits the range of possible scale values (0 < scale < +Infinity) into multiple18 * subranges, for each scale range it keeps a list of styles.19 * Immutable class, equals & hashCode is required (the same for StyleList, StyleElement20 and its subclasses).21 8 */ 22 public final class StyleCache { 23 /* list of boundaries for the scale ranges */ 24 private final List<Double> bd; 25 /* styles for each scale range */ 26 private final List<StyleList> data; 9 public final class StyleCache extends DividedScale<StyleElementList> { 27 10 28 11 // TODO: clean up the intern pool from time to time (after purge or layer removal) … … 31 14 public static final StyleCache EMPTY_STYLECACHE = (new StyleCache()).intern(); 32 15 33 private StyleCache() { 34 bd = new ArrayList<>(); 35 bd.add(0.0); 36 bd.add(Double.POSITIVE_INFINITY); 37 data = new ArrayList<>(); 38 data.add(null); 16 private StyleCache(StyleCache sc) { 17 super(sc); 39 18 } 40 19 41 private StyleCache(StyleCache s) { 42 bd = new ArrayList<>(s.bd); 43 data = new ArrayList<>(s.data); 20 private StyleCache() { 21 super(); 44 22 } 45 23 46 24 /** 47 * List of Styles, immutable 25 * Add data object which is valid for the given range. 26 * 27 * This is only possible, if there is no data for the given range yet. 28 * 29 * @param o data object 30 * @param r the valid range 31 * @return a new, updated, <code>DividedScale</code> object 48 32 */ 49 public static class StyleList implements Iterable<StyleElement> { 50 private final List<StyleElement> lst; 51 52 /** 53 * Constructs a new {@code StyleList}. 54 */ 55 public StyleList() { 56 lst = new ArrayList<>(); 57 } 58 59 public StyleList(StyleElement... init) { 60 lst = new ArrayList<>(Arrays.asList(init)); 61 } 62 63 public StyleList(Collection<StyleElement> sl) { 64 lst = new ArrayList<>(sl); 65 } 66 67 public StyleList(StyleList sl, StyleElement s) { 68 lst = new ArrayList<>(sl.lst); 69 lst.add(s); 70 } 71 72 @Override 73 public Iterator<StyleElement> iterator() { 74 return lst.iterator(); 75 } 76 77 public boolean isEmpty() { 78 return lst.isEmpty(); 79 } 80 81 public int size() { 82 return lst.size(); 83 } 84 85 @Override 86 public String toString() { 87 return lst.toString(); 88 } 89 90 @Override 91 public boolean equals(Object obj) { 92 if (obj == null || getClass() != obj.getClass()) 93 return false; 94 final StyleList other = (StyleList) obj; 95 return Objects.equals(lst, other.lst); 96 } 97 98 @Override 99 public int hashCode() { 100 return lst.hashCode(); 101 } 102 } 103 104 /** 105 * looks up styles for a certain scale value 106 * @param scale scale 107 * @return style list 108 */ 109 public StyleList get(double scale) { 110 if (scale <= 0) 111 throw new IllegalArgumentException("scale must be <= 0 but is "+scale); 112 for (int i = 0; i < data.size(); ++i) { 113 if (bd.get(i) < scale && scale <= bd.get(i+1)) { 114 return data.get(i); 115 } 116 } 117 throw new AssertionError(); 118 } 119 120 /** 121 * looks up styles for a certain scale value and additionally returns 122 * the scale range for the returned styles 123 * @param scale scale 124 * @return pair containing syle list and range 125 */ 126 public Pair<StyleList, Range> getWithRange(double scale) { 127 if (scale <= 0) 128 throw new IllegalArgumentException("scale must be <= 0 but is "+scale); 129 for (int i = 0; i < data.size(); ++i) { 130 if (bd.get(i) < scale && scale <= bd.get(i+1)) { 131 return new Pair<>(data.get(i), new Range(bd.get(i), bd.get(i+1))); 132 } 133 } 134 throw new AssertionError(); 135 } 136 137 public StyleCache put(StyleList sl, Range r) { 138 return put(sl, r.getLower(), r.getUpper()); 139 } 140 141 /** 142 * add a new styles to the cache. this is only possible, if 143 * for this scale range, there is nothing in the cache yet. 144 * @param sl style list 145 * @param lower lower bound 146 * @param upper upper bound 147 * @return interned style cache 148 */ 149 public StyleCache put(StyleList sl, double lower, double upper) { 33 @Override 34 public StyleCache put(StyleElementList o, Range r) { 150 35 StyleCache s = new StyleCache(this); 151 s.putImpl( sl, lower, upper);36 s.putImpl(o, r.getLower(), r.getUpper()); 152 37 s.consistencyTest(); 153 return s.intern(); 154 } 155 156 // this exception type is for debugging #8997 and can later be replaced 157 // by AssertionError 158 public static class RangeViolatedError extends Error { 159 public RangeViolatedError() { 160 } 161 162 public RangeViolatedError(String message) { 163 super(message); 164 } 165 } 166 167 /** 168 * ASCII-art explanation: 169 * 170 * data[i] 171 * --|-------|---------|-- 172 * bd[i-1] bd[i] bd[i+1] 173 * 174 * (--------] 175 * lower upper 176 * @param sl style list 177 * @param lower lower bound 178 * @param upper upper bound 179 */ 180 private void putImpl(StyleList sl, double lower, double upper) { 181 int i = 0; 182 while (bd.get(i) < lower) { 183 ++i; 184 } 185 if (bd.get(i) == lower) { 186 if (upper > bd.get(i+1)) 187 throw new RangeViolatedError("the new range must be within a single subrange (1)"); 188 if (data.get(i) != null) 189 throw new RangeViolatedError("the new range must be within a subrange that has no data"); 190 191 if (bd.get(i+1) == upper) { 192 // --|-------|--------|-- 193 // i-1 i i+1 194 // (--------] 195 data.set(i, sl); 196 } else { 197 // --|-------|--------|-- 198 // i-1 i i+1 199 // (-----] 200 bd.add(i+1, upper); 201 data.add(i, sl); 202 } 203 return; 204 } else { 205 if (bd.get(i) < upper) 206 throw new RangeViolatedError("the new range must be within a single subrange (2)"); 207 if (data.get(i-1) != null) 208 throw new AssertionError(); 209 210 // --|-------|--------|-- 211 // i-1 i i+1 212 // (--] or 213 // (----] 214 bd.add(i, lower); 215 data.add(i, sl); 216 217 // --|--|----|--------|-- 218 // i-1 i i+1 i+2 219 // (--] 220 if (bd.get(i+1) > upper) { 221 bd.add(i+1, upper); 222 data.add(i+1, null); 223 } 224 return; 225 } 226 } 227 228 public void consistencyTest() { 229 if (bd.size() < 2) throw new AssertionError(bd); 230 if (data.isEmpty()) throw new AssertionError(data); 231 if (bd.size() != data.size() + 1) throw new AssertionError(); 232 if (bd.get(0) != 0) throw new AssertionError(); 233 if (bd.get(bd.size() - 1) != Double.POSITIVE_INFINITY) throw new AssertionError(); 234 for (int i = 0; i < data.size() - 1; ++i) { 235 if (bd.get(i) >= bd.get(i + 1)) throw new AssertionError(); 236 } 38 s.intern(); 39 return s; 237 40 } 238 41 … … 242 45 * @return style cache 243 46 */ 244 p ublicStyleCache intern() {47 private StyleCache intern() { 245 48 return internPool.putUnique(this); 246 49 } 247 248 @Override249 public boolean equals(Object obj) {250 if (obj == null || getClass() != obj.getClass())251 return false;252 final StyleCache other = (StyleCache) obj;253 return bd.equals(other.bd) && data.equals(other.data);254 }255 256 @Override257 public int hashCode() {258 int hash = 7;259 hash = 23 * hash + bd.hashCode();260 hash = 23 * hash + data.hashCode();261 return hash;262 }263 264 @Override265 public String toString() {266 return "SC{" + bd + ' ' + data + '}';267 }268 50 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java
r9278 r9284 19 19 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 20 20 import org.openstreetmap.josm.gui.mappaint.MultiCascade; 21 import org.openstreetmap.josm.gui.mappaint.Style Cache.StyleList;21 import org.openstreetmap.josm.gui.mappaint.StyleElementList; 22 22 import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.BoxProvider; 23 23 import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.SimpleBoxProvider; … … 95 95 } 96 96 97 public static final Style List DEFAULT_NODE_STYLELIST = new StyleList(NodeElement.SIMPLE_NODE_ELEMSTYLE);98 public static final Style List DEFAULT_NODE_STYLELIST_TEXT = new StyleList(NodeElement.SIMPLE_NODE_ELEMSTYLE,97 public static final StyleElementList DEFAULT_NODE_STYLELIST = new StyleElementList(NodeElement.SIMPLE_NODE_ELEMSTYLE); 98 public static final StyleElementList DEFAULT_NODE_STYLELIST_TEXT = new StyleElementList(NodeElement.SIMPLE_NODE_ELEMSTYLE, 99 99 BoxTextElement.SIMPLE_NODE_TEXT_ELEMSTYLE); 100 100 -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r9278 r9284 61 61 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 62 62 import org.openstreetmap.josm.gui.mappaint.Range; 63 import org.openstreetmap.josm.gui.mappaint.Style Cache.StyleList;63 import org.openstreetmap.josm.gui.mappaint.StyleElementList; 64 64 import org.openstreetmap.josm.gui.mappaint.styleelement.MapImage; 65 65 import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement; … … 1299 1299 // Check if the current styles have special icon for tagged nodes. 1300 1300 if (primitive instanceof org.openstreetmap.josm.data.osm.Node) { 1301 Pair<Style List, Range> nodeStyles = MapPaintStyles.getStyles().generateStyles(primitive, 100, false);1301 Pair<StyleElementList, Range> nodeStyles = MapPaintStyles.getStyles().generateStyles(primitive, 100, false); 1302 1302 for (StyleElement style : nodeStyles.a) { 1303 1303 if (style instanceof NodeElement) {
Note:
See TracChangeset
for help on using the changeset viewer.