Changeset 13636 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2018-04-15T18:58:21+02:00 (6 years ago)
Author:
Don-vip
Message:

extract style methods to a new Stylable interface

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
5 edited

Legend:

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

    r13564 r13636  
    1111 * @since 4098
    1212 */
    13 public interface IPrimitive extends Tagged, PrimitiveId {
     13public interface IPrimitive extends Tagged, PrimitiveId, Stylable {
    1414
    1515    /**
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r13564 r13636  
    193193     * MAPPAINT
    194194     *--------*/
    195     public StyleCache mappaintStyle;
     195    private StyleCache mappaintStyle;
    196196    private short mappaintCacheIdx;
    197197
    198     /* This should not be called from outside. Fixing the UI to add relevant
    199        get/set functions calling this implicitely is preferred, so we can have
    200        transparent cache handling in the future. */
    201     public void clearCachedStyle() {
    202         mappaintStyle = null;
    203     }
    204 
    205     /**
    206      * Check if the cached style for this primitive is up to date.
    207      * @return true if the cached style for this primitive is up to date
    208      * @since 13420
    209      */
     198    @Override
     199    public final StyleCache getCachedStyle() {
     200        return mappaintStyle;
     201    }
     202
     203    @Override
     204    public final void setCachedStyle(StyleCache mappaintStyle) {
     205        this.mappaintStyle = mappaintStyle;
     206    }
     207
     208    @Override
    210209    public final boolean isCachedStyleUpToDate() {
    211210        return mappaintStyle != null && mappaintCacheIdx == dataSet.getMappaintCacheIndex();
    212211    }
    213212
    214     /**
    215      * Declare that the cached style for this primitive is up to date.
    216      * @since 13420
    217      */
     213    @Override
    218214    public final void declareCachedStyleUpToDate() {
    219215        this.mappaintCacheIdx = dataSet.getMappaintCacheIndex();
    220     }
    221 
    222     /**
    223      * Returns mappaint cache index.
    224      * @return mappaint cache index
    225      * @deprecated no longer supported (see also {@link #isCachedStyleUpToDate()})
    226      */
    227     @Deprecated
    228     public final short getMappaintCacheIdx() {
    229         return mappaintCacheIdx;
    230     }
    231 
    232     /**
    233      * Sets the mappaint cache index.
    234      * @param mappaintCacheIdx mappaint cache index
    235      * @deprecated no longer supported (see also {@link #declareCachedStyleUpToDate()})
    236      */
    237     @Deprecated
    238     public final void setMappaintCacheIdx(short mappaintCacheIdx) {
    239         this.mappaintCacheIdx = mappaintCacheIdx;
    240216    }
    241217
  • trunk/src/org/openstreetmap/josm/data/osm/PrimitiveData.java

    r12017 r13636  
    1111import java.util.List;
    1212import java.util.Map;
     13
     14import org.openstreetmap.josm.gui.mappaint.StyleCache;
    1315
    1416/**
     
    130132        ois.defaultReadObject();
    131133    }
     134
     135    @Override
     136    public StyleCache getCachedStyle() {
     137        return null;
     138    }
     139
     140    @Override
     141    public void setCachedStyle(StyleCache mappaintStyle) {
     142        // Override if needed
     143    }
     144
     145    @Override
     146    public boolean isCachedStyleUpToDate() {
     147        return false;
     148    }
     149
     150    @Override
     151    public void declareCachedStyleUpToDate() {
     152        // Override if needed
     153    }
    132154}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java

    r13434 r13636  
    151151        if (sel.size() == 2) {
    152152            List<OsmPrimitive> selList = new ArrayList<>(sel);
    153             StyleCache sc1 = selList.get(0).mappaintStyle;
    154             StyleCache sc2 = selList.get(1).mappaintStyle;
     153            StyleCache sc1 = selList.get(0).getCachedStyle();
     154            StyleCache sc2 = selList.get(1).getCachedStyle();
    155155            if (sc1 == sc2) {
    156156                txtMappaint.append(tr("The 2 selected objects have identical style caches."));
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r13420 r13636  
    105105    }
    106106
     107    /**
     108     * Returns the background color.
     109     * @return the background color
     110     */
    107111    public Color getBackgroundColor() {
    108112        if (backgroundColorCache != null)
     
    144148    public Pair<StyleElementList, Range> getStyleCacheWithRange(OsmPrimitive osm, double scale, NavigatableComponent nc) {
    145149        if (!osm.isCachedStyleUpToDate() || scale <= 0) {
    146             osm.mappaintStyle = StyleCache.EMPTY_STYLECACHE;
     150            osm.setCachedStyle(StyleCache.EMPTY_STYLECACHE);
    147151        } else {
    148             Pair<StyleElementList, Range> lst = osm.mappaintStyle.getWithRange(scale, osm.isSelected());
     152            Pair<StyleElementList, Range> lst = osm.getCachedStyle().getWithRange(scale, osm.isSelected());
    149153            if (lst.a != null)
    150154                return lst;
     
    191195            }
    192196        }
    193         StyleCache style = osm.mappaintStyle != null ? osm.mappaintStyle : StyleCache.EMPTY_STYLECACHE;
     197        StyleCache style = osm.getCachedStyle() != null ? osm.getCachedStyle() : StyleCache.EMPTY_STYLECACHE;
    194198        try {
    195             osm.mappaintStyle = style.put(p.a, p.b, osm.isSelected());
     199            osm.setCachedStyle(style.put(p.a, p.b, osm.isSelected()));
    196200        } catch (RangeViolatedError e) {
    197201            throw new AssertionError("Range violated: " + e.getMessage()
    198                     + " (object: " + osm.getPrimitiveId() + ", current style: "+osm.mappaintStyle
     202                    + " (object: " + osm.getPrimitiveId() + ", current style: "+osm.getCachedStyle()
    199203                    + ", scale: " + scale + ", new stylelist: " + p.a + ", new range: " + p.b + ')', e);
    200204        }
     
    462466    }
    463467
     468    /**
     469     * Determines whether multipolygons must be drawn.
     470     * @return whether multipolygons must be drawn.
     471     */
    464472    public boolean isDrawMultipolygon() {
    465473        return drawMultipolygon;
    466474    }
    467475
     476    /**
     477     * Sets whether multipolygons must be drawn.
     478     * @param drawMultipolygon whether multipolygons must be drawn
     479     */
    468480    public void setDrawMultipolygon(boolean drawMultipolygon) {
    469481        this.drawMultipolygon = drawMultipolygon;
Note: See TracChangeset for help on using the changeset viewer.