Class ElemStyles
java.lang.Object
org.openstreetmap.josm.gui.mappaint.ElemStyles
- All Implemented Interfaces:
PreferenceChangedListener
Generates a list of
StyleElements for a primitive, to
be drawn on the map.
There are several steps to derive the list of elements for display:
generateStyles(IPrimitive, double, boolean)applies theStyleSources one after another to get a key-value map of MapCSS properties. Then a preliminary set of StyleElements is derived from the properties map.getImpl(IPrimitive, double, NavigatableComponent)handles the different forms of multipolygon tagging.getStyleCacheWithRange(IPrimitive, double, NavigatableComponent)adds a default StyleElement for primitives that would be invisible otherwise. (For example untagged nodes and ways.)
setStyleSources(Collection) to select the StyleSources that are applied.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Colorprivate shortprivate booleanprivate shortprivate booleanprivate shortprivate booleanprivate final List<StyleSource> -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newElemStyles.ElemStyles(Collection<StyleSource> sources) Constructs a newElemStyleswith specific style sources. -
Method Summary
Modifier and TypeMethodDescription(package private) voidadd(StyleSource style) add a style source; only accessed from MapPaintStylesprivate static <T> voidaddIfNotNull(List<T> list, T obj) (package private) voidclear()remove all style sources; only accessed from MapPaintStylesvoidClear the style cache for all primitives of all DataSets.private <T> TfromCanvas(String key, T def, Class<T> c) generateStyles(IPrimitive osm, double scale, boolean pretendWayIsClosed) Create the list of styles and its valid scale range for one primitive.get(IPrimitive osm, double scale, NavigatableComponent nc) Create the list of styles for one primitive.static AreaElementgetAreaElemStyle(IPrimitive p, boolean pretendWayIsClosed) Returns the first AreaElement for a given primitive.Returns the background color.private Pair<StyleElementList,Range> getImpl(IPrimitive osm, double scale, NavigatableComponent nc) Create the list of styles and its valid scale range for one primitive.getPreferenceCached(StyleSource source, String key, String def) Looks up a preference value and ensures the style cache is invalidated as soon as this preference value is changed by the user.getStyleCacheWithRange(IPrimitive osm, double scale, NavigatableComponent nc) Create the list of styles and its valid scale range for one primitive.Returns the list of style sources.static booleanhasAreaElemStyle(IPrimitive p, boolean pretendWayIsClosed) Determines whether primitive has an AreaElement.static booleanDetermines whether primitive has area-typeStyleElements, but no line-type StyleElements.private booleanDraw a default line for ways that do not have an own line style?private booleanDraw a default node symbol for nodes that have no style?booleanDetermines whether multipolygons must be drawn.voidTriggered when a preference entry value changes.(package private) booleanremove(StyleSource style) remove a style source; only accessed from MapPaintStylesvoidsetDrawMultipolygon(boolean drawMultipolygon) Sets whether multipolygons must be drawn.(package private) voidsetStyleSources(Collection<StyleSource> sources) set the style sources; only accessed from MapPaintStyles
-
Field Details
-
styleSources
-
drawMultipolygon
-
cacheIdx
-
defaultNodes
-
defaultLines
-
defaultNodesIdx
-
defaultLinesIdx
-
preferenceCache
-
backgroundColorCache
-
-
Constructor Details
-
ElemStyles
public ElemStyles()Constructs a newElemStyles. -
ElemStyles
Constructs a newElemStyleswith specific style sources. This does not listen to preference changes, and therefore should only be used with layers that have specific drawing requirements.- Parameters:
sources- The style sources (these cannot be added to, or removed from)- Since:
- 17862
-
-
Method Details
-
clearCached
Clear the style cache for all primitives of all DataSets. -
getStyleSources
Returns the list of style sources.- Returns:
- the list of style sources
-
getBackgroundColor
Returns the background color.- Returns:
- the background color
-
generateStyles
public Pair<StyleElementList,Range> generateStyles(IPrimitive osm, double scale, boolean pretendWayIsClosed) Create the list of styles and its valid scale range for one primitive. Loops over the list of style sources, to generate the map of properties. From these properties, it generates the different types of styles.- Parameters:
osm- the primitive to create styles forscale- the scale (in meters per 100 px), must be > 0pretendWayIsClosed- For styles that require the way to be closed, we pretend it is. This is useful for generating area styles from the (segmented) outer ways of a multipolygon.- Returns:
- the generated styles and the valid range as a pair
- Since:
- 13810 (signature)
-
addIfNotNull
-
isDefaultNodes
Draw a default node symbol for nodes that have no style?- Returns:
trueif default node symbol must be drawn
-
isDefaultLines
Draw a default line for ways that do not have an own line style?- Returns:
trueif default line must be drawn
-
fromCanvas
-
isDrawMultipolygon
Determines whether multipolygons must be drawn.- Returns:
- whether multipolygons must be drawn.
-
setDrawMultipolygon
Sets whether multipolygons must be drawn.- Parameters:
drawMultipolygon- whether multipolygons must be drawn
-
clear
void clear()remove all style sources; only accessed from MapPaintStyles -
add
add a style source; only accessed from MapPaintStyles- Parameters:
style- style source to add
-
remove
remove a style source; only accessed from MapPaintStyles- Parameters:
style- style source to remove- Returns:
trueif this list contained the specified element
-
setStyleSources
set the style sources; only accessed from MapPaintStyles- Parameters:
sources- new style sources
-
getAreaElemStyle
Returns the first AreaElement for a given primitive.- Parameters:
p- the OSM primitivepretendWayIsClosed- For styles that require the way to be closed, we pretend it is. This is useful for generating area styles from the (segmented) outer ways of a multipolygon.- Returns:
- first AreaElement found or
null. - Since:
- 13810 (signature)
-
hasAreaElemStyle
Determines whether primitive has an AreaElement.- Parameters:
p- the OSM primitivepretendWayIsClosed- For styles that require the way to be closed, we pretend it is. This is useful for generating area styles from the (segmented) outer ways of a multipolygon.- Returns:
trueif primitive has an AreaElement- Since:
- 13810 (signature)
-
hasOnlyAreaElements
Determines whether primitive has area-typeStyleElements, but no line-type StyleElements.TextElementis ignored, as it can be both line and area-type.- Parameters:
p- the OSM primitive- Returns:
trueif primitive has area elements, but no line elements- Since:
- 12700, 13810 (signature)
-
getPreferenceCached
Looks up a preference value and ensures the style cache is invalidated as soon as this preference value is changed by the user. In addition, it adds an intermediate cache for the preference values, as frequent preference lookup (usingConfig.getPref().get()) for each primitive can be slow during rendering. If the default value can be converted to aColor, theNamedColorPropertyis retrieved as string.- Parameters:
source- style sourcekey- preference keydef- default value- Returns:
- the corresponding preference value
- See Also:
-
preferenceChanged
Description copied from interface:PreferenceChangedListenerTriggered when a preference entry value changes.- Specified by:
preferenceChangedin interfacePreferenceChangedListener- Parameters:
e- the preference change event
-