Changeset 19528 in josm for trunk/src


Ignore:
Timestamp:
2026-02-14T12:50:29+01:00 (4 days ago)
Author:
stoecker
Message:

see #24637 - patch by zkir (modified a bit) - allow to handle more than one style in caching

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r19331 r19528  
    1313import java.util.Objects;
    1414import java.util.Set;
     15import java.util.HashMap;
    1516import java.util.function.Consumer;
    1617import java.util.stream.Collectors;
     
    2324import org.openstreetmap.josm.data.osm.visitor.OsmPrimitiveVisitor;
    2425import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
     26import org.openstreetmap.josm.gui.mappaint.ElemStyles;
    2527import org.openstreetmap.josm.gui.mappaint.StyleCache;
    2628import org.openstreetmap.josm.spi.preferences.Config;
     
    144146     * MAPPAINT
    145147     *--------*/
    146     private StyleCache mappaintStyle;
    147 
    148     @Override
    149     public final StyleCache getCachedStyle() {
    150         return mappaintStyle;
    151     }
    152 
    153     @Override
    154     public final void setCachedStyle(StyleCache mappaintStyle) {
    155         this.mappaintStyle = mappaintStyle;
    156     }
    157 
    158     @Override
    159     public final boolean isCachedStyleUpToDate() {
    160         return mappaintStyle != null && mappaintCacheIdx == dataSet.getMappaintCacheIndex();
    161     }
    162 
    163     @Override
    164     public final void declareCachedStyleUpToDate() {
     148    private final Map<ElemStyles, StyleCache> mappaintStyle = new HashMap<>();
     149
     150    @Override
     151    public final StyleCache getCachedStyle(ElemStyles elemStyles) {
     152        return mappaintStyle.get(elemStyles);
     153    }
     154
     155    @Override
     156    public final void setCachedStyle(ElemStyles elemStyles, StyleCache mappaintStyle) {
     157        this.mappaintStyle.put(elemStyles, mappaintStyle);
     158    }
     159
     160    @Override
     161    public final boolean isCachedStyleUpToDate(ElemStyles elemStyles) {
     162        return mappaintStyle.get(elemStyles) != null && mappaintCacheIdx == dataSet.getMappaintCacheIndex();
     163    }
     164
     165    @Override
     166    public final void declareCachedStyleUpToDate(ElemStyles styles) {
    165167        this.mappaintCacheIdx = dataSet.getMappaintCacheIndex();
     168    }
     169
     170    @Override
     171    public void clearCachedStyle() {
     172        this.mappaintStyle.clear();
    166173    }
    167174
  • trunk/src/org/openstreetmap/josm/data/osm/PrimitiveData.java

    r19096 r19528  
    1212
    1313import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
     14import org.openstreetmap.josm.gui.mappaint.ElemStyles;
    1415import org.openstreetmap.josm.gui.mappaint.StyleCache;
    1516
     
    152153
    153154    @Override
    154     public StyleCache getCachedStyle() {
     155    public StyleCache getCachedStyle(ElemStyles styles) {
    155156        return null;
    156157    }
    157158
    158159    @Override
    159     public void setCachedStyle(StyleCache mappaintStyle) {
     160    public void setCachedStyle(ElemStyles styles, StyleCache mappaintStyle) {
    160161        // Override if needed
    161162    }
    162163
    163164    @Override
    164     public boolean isCachedStyleUpToDate() {
     165    public boolean isCachedStyleUpToDate(ElemStyles styles) {
    165166        return false;
    166167    }
    167168
    168169    @Override
    169     public void declareCachedStyleUpToDate() {
     170    public void declareCachedStyleUpToDate(ElemStyles styles) {
     171        // Override if needed
     172    }
     173
     174    @Override
     175    public void clearCachedStyle(){
    170176        // Override if needed
    171177    }
  • trunk/src/org/openstreetmap/josm/data/osm/Stylable.java

    r17333 r19528  
    22package org.openstreetmap.josm.data.osm;
    33
     4import org.openstreetmap.josm.gui.mappaint.ElemStyles;
    45import org.openstreetmap.josm.gui.mappaint.StyleCache;
    56
     
    1213    /**
    1314     * Returns the cached style.
     15     * @param styles styles for which the data is retrieved
    1416     * @return the cached style
     17     * @since 19528 (added param styles)
    1518     */
    16     StyleCache getCachedStyle();
     19    StyleCache getCachedStyle(ElemStyles styles);
    1720
    1821    /**
    1922     * Sets the cached style.
     23     * @param styles styles for which the data is stored
    2024     * @param mappaintStyle the cached style
     25     * @since 19528 (added param styles)
    2126     */
    22     void setCachedStyle(StyleCache mappaintStyle);
     27    void setCachedStyle(ElemStyles styles, StyleCache mappaintStyle);
    2328
    2429    /**
     
    2833     * transparent cache handling in the future.
    2934     */
    30     default void clearCachedStyle() {
    31         setCachedStyle(null);
    32     }
     35    void clearCachedStyle();
    3336
    3437    /**
    3538     * Check if the cached style for this primitive is up to date.
     39     * @param styles styles for which the data is checked
    3640     * @return true if the cached style for this primitive is up to date
    3741     * @since 13420
     42     * @since 19528 (added param styles)
    3843     */
    39     boolean isCachedStyleUpToDate();
     44    boolean isCachedStyleUpToDate(ElemStyles styles);
    4045
    4146    /**
    4247     * Declare that the cached style for this primitive is up to date.
     48     * @param styles styles for which the data is handled
    4349     * @since 13420
     50     * @since 19528 (added param styles)
    4451     */
    45     void declareCachedStyleUpToDate();
     52    void declareCachedStyleUpToDate(ElemStyles styles);
    4653}
  • trunk/src/org/openstreetmap/josm/data/vector/VectorPrimitive.java

    r19519 r19528  
    66import java.util.List;
    77import java.util.Map;
     8import java.util.HashMap;
    89import java.util.function.Consumer;
    910import java.util.stream.Collectors;
     
    1415import org.openstreetmap.josm.data.osm.IPrimitive;
    1516import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
     17import org.openstreetmap.josm.gui.mappaint.ElemStyles;
    1618import org.openstreetmap.josm.gui.mappaint.StyleCache;
    1719import org.openstreetmap.josm.tools.Utils;
     
    2527    private VectorDataSet dataSet;
    2628    private boolean highlighted;
    27     private StyleCache mappaintStyle;
     29    private final Map<ElemStyles, StyleCache> mappaintStyle = new HashMap<>();
    2830    private final String layer;
    2931
     
    7880
    7981    @Override
    80     public final StyleCache getCachedStyle() {
    81         return mappaintStyle;
    82     }
    83 
    84     @Override
    85     public final void setCachedStyle(StyleCache mappaintStyle) {
    86         this.mappaintStyle = mappaintStyle;
    87     }
    88 
    89     @Override
    90     public final boolean isCachedStyleUpToDate() {
    91         return mappaintStyle != null && mappaintCacheIdx == dataSet.getMappaintCacheIndex();
    92     }
    93 
    94     @Override
    95     public final void declareCachedStyleUpToDate() {
     82    public final StyleCache getCachedStyle(ElemStyles elemStyles) {
     83        return mappaintStyle.get(elemStyles);
     84    }
     85
     86    @Override
     87    public final void setCachedStyle(ElemStyles elemStyles, StyleCache mappaintStyle) {
     88        this.mappaintStyle.put(elemStyles, mappaintStyle);
     89    }
     90
     91    @Override
     92    public final boolean isCachedStyleUpToDate(ElemStyles elemStyles) {
     93        return mappaintStyle.get(elemStyles) != null && mappaintCacheIdx == dataSet.getMappaintCacheIndex();
     94    }
     95
     96    @Override
     97    public final void declareCachedStyleUpToDate(ElemStyles elemStyles) {
    9698        this.mappaintCacheIdx = dataSet.getMappaintCacheIndex();
     99    }
     100
     101    public void clearCachedStyle() {
     102        this.mappaintStyle.clear();
    97103    }
    98104
  • trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java

    r19120 r19528  
    164164        if (sel.size() == 2) {
    165165            List<IPrimitive> selList = new ArrayList<>(sel);
    166             StyleCache sc1 = selList.get(0).getCachedStyle();
    167             StyleCache sc2 = selList.get(1).getCachedStyle();
     166            StyleCache sc1 = selList.get(0).getCachedStyle(elemstyles);
     167            StyleCache sc2 = selList.get(1).getCachedStyle(elemstyles);
    168168            if (sc1 == sc2) {
    169169                txtMappaint.println(tr("The 2 selected objects have identical style caches."));
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r17867 r19528  
    164164    public Pair<StyleElementList, Range> getStyleCacheWithRange(IPrimitive osm, double scale, NavigatableComponent nc) {
    165165        synchronized (osm.getStyleCacheSyncObject()) {
    166             if (!osm.isCachedStyleUpToDate() || scale <= 0) {
    167                 osm.setCachedStyle(StyleCache.EMPTY_STYLECACHE);
     166            if (!osm.isCachedStyleUpToDate(this) || scale <= 0) {
     167                osm.setCachedStyle(this, StyleCache.EMPTY_STYLECACHE);
    168168            } else {
    169                 Pair<StyleElementList, Range> lst = osm.getCachedStyle().getWithRange(scale, osm.isSelected());
     169                Pair<StyleElementList, Range> lst = osm.getCachedStyle(this).getWithRange(scale, osm.isSelected());
    170170                if (lst.a != null)
    171171                    return lst;
     
    217217                }
    218218            }
    219             StyleCache style = osm.getCachedStyle() != null ? osm.getCachedStyle() : StyleCache.EMPTY_STYLECACHE;
     219            StyleCache style = osm.getCachedStyle(this) != null ? osm.getCachedStyle(this) : StyleCache.EMPTY_STYLECACHE;
    220220            try {
    221                 osm.setCachedStyle(style.put(p.a, p.b, osm.isSelected()));
     221                osm.setCachedStyle(this, style.put(p.a, p.b, osm.isSelected()));
    222222            } catch (RangeViolatedError e) {
    223223                throw new AssertionError("Range violated: " + e.getMessage()
    224                   + " (object: " + osm.getPrimitiveId() + ", current style: " + osm.getCachedStyle()
     224                  + " (object: " + osm.getPrimitiveId() + ", current style: " + osm.getCachedStyle(this)
    225225                  + ", scale: " + scale + ", new stylelist: " + p.a + ", new range: " + p.b + ')', e);
    226226            }
    227             osm.declareCachedStyleUpToDate();
     227            osm.declareCachedStyleUpToDate(this);
    228228            return p;
    229229        }
Note: See TracChangeset for help on using the changeset viewer.