|
2 | 2 | package org.openstreetmap.josm.plugins.mapillary.data.mapillary; |
3 | 3 |
|
4 | 4 | import java.util.Map; |
| 5 | +import java.util.HashMap; |
5 | 6 |
|
6 | 7 | import org.openstreetmap.josm.data.osm.AbstractPrimitive; |
7 | 8 | import org.openstreetmap.josm.data.osm.INode; |
|
11 | 12 | import org.openstreetmap.josm.data.osm.NameFormatter; |
12 | 13 | import org.openstreetmap.josm.data.osm.OsmData; |
13 | 14 | import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; |
| 15 | +import org.openstreetmap.josm.gui.mappaint.ElemStyles; |
14 | 16 | import org.openstreetmap.josm.gui.mappaint.StyleCache; |
15 | 17 |
|
16 | 18 | abstract class MapillaryPrimitive extends AbstractPrimitive { |
17 | 19 |
|
18 | 20 | private boolean highlighted; |
19 | | - private StyleCache styleCache; |
20 | | - private boolean styleCacheIsUpToDate; |
| 21 | + private final Map<ElemStyles, StyleCache> styleCaches = new HashMap<>(); |
21 | 22 |
|
22 | 23 | @Override |
23 | 24 | protected void keysChangedImpl(Map<String, String> originalKeys) { |
@@ -83,23 +84,31 @@ public int compareTo(IPrimitive o) { |
83 | 84 | throw new UnsupportedOperationException("Not yet implemented"); |
84 | 85 | } |
85 | 86 |
|
| 87 | + // Methods required for the JOSM mappaint style engine. |
86 | 88 | @Override |
87 | | - public StyleCache getCachedStyle() { |
88 | | - return this.styleCache; |
| 89 | + public StyleCache getCachedStyle(ElemStyles elemStyles) { |
| 90 | + return styleCaches.get(elemStyles); |
89 | 91 | } |
90 | 92 |
|
91 | 93 | @Override |
92 | | - public void setCachedStyle(StyleCache mappaintStyle) { |
93 | | - this.styleCache = mappaintStyle; |
| 94 | + public void setCachedStyle(ElemStyles elemStyles, StyleCache mappaintStyle) { |
| 95 | + this.styleCaches.put(elemStyles, mappaintStyle); |
94 | 96 | } |
95 | 97 |
|
96 | 98 | @Override |
97 | | - public boolean isCachedStyleUpToDate() { |
98 | | - return this.styleCacheIsUpToDate; |
| 99 | + public boolean isCachedStyleUpToDate(ElemStyles elemStyles) { |
| 100 | + // This primitive type does not have a dataSet to sync with, so we can't use a cache index. |
| 101 | + // Invalidation is handled manually by calling clearCachedStyle(). |
| 102 | + return styleCaches.get(elemStyles) != null; |
99 | 103 | } |
100 | 104 |
|
101 | 105 | @Override |
102 | | - public void declareCachedStyleUpToDate() { |
103 | | - this.styleCacheIsUpToDate = true; |
| 106 | + public void declareCachedStyleUpToDate(ElemStyles elemStyles) { |
| 107 | + // This primitive type does not have a dataSet to sync with, so there is nothing to do here. |
104 | 108 | } |
| 109 | + |
| 110 | + @Override |
| 111 | + public void clearCachedStyle(){ |
| 112 | + this.styleCaches.clear(); |
| 113 | + }; |
105 | 114 | } |
0 commit comments