public class ElemStyles extends java.lang.Object implements PreferenceChangedListener
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 the
StyleSources 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.| Modifier and Type | Field and Description |
|---|---|
private java.awt.Color |
backgroundColorCache |
private short |
cacheIdx |
private boolean |
defaultLines |
private short |
defaultLinesIdx |
private boolean |
defaultNodes |
private short |
defaultNodesIdx |
private boolean |
drawMultipolygon |
private java.util.Map<java.lang.String,java.lang.String> |
preferenceCache |
private java.util.List<StyleSource> |
styleSources |
| Constructor and Description |
|---|
ElemStyles()
Constructs a new
ElemStyles. |
| Modifier and Type | Method and Description |
|---|---|
(package private) void |
add(StyleSource style)
add a style source; only accessed from MapPaintStyles
|
private static <T> void |
addIfNotNull(java.util.List<T> list,
T obj) |
(package private) void |
clear()
remove all style sources; only accessed from MapPaintStyles
|
void |
clearCached()
Clear the style cache for all primitives of all DataSets.
|
private <T> T |
fromCanvas(java.lang.String key,
T def,
java.lang.Class<T> c) |
Pair<StyleElementList,Range> |
generateStyles(IPrimitive osm,
double scale,
boolean pretendWayIsClosed)
Create the list of styles and its valid scale range for one primitive.
|
StyleElementList |
get(IPrimitive osm,
double scale,
NavigatableComponent nc)
Create the list of styles for one primitive.
|
static AreaElement |
getAreaElemStyle(IPrimitive p,
boolean pretendWayIsClosed)
Returns the first AreaElement for a given primitive.
|
java.awt.Color |
getBackgroundColor()
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.
|
java.lang.String |
getPreferenceCached(java.lang.String key,
java.lang.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.
|
Pair<StyleElementList,Range> |
getStyleCacheWithRange(IPrimitive osm,
double scale,
NavigatableComponent nc)
Create the list of styles and its valid scale range for one primitive.
|
java.util.List<StyleSource> |
getStyleSources()
Returns the list of style sources.
|
static boolean |
hasAreaElemStyle(IPrimitive p,
boolean pretendWayIsClosed)
Determines whether primitive has an AreaElement.
|
static boolean |
hasOnlyAreaElements(IPrimitive p)
Determines whether primitive has area-type
StyleElements, but
no line-type StyleElements. |
private boolean |
isDefaultLines()
Draw a default line for ways that do not have an own line style?
|
private boolean |
isDefaultNodes()
Draw a default node symbol for nodes that have no style?
|
boolean |
isDrawMultipolygon()
Determines whether multipolygons must be drawn.
|
void |
preferenceChanged(PreferenceChangeEvent e)
Triggered when a preference entry value changes.
|
(package private) boolean |
remove(StyleSource style)
remove a style source; only accessed from MapPaintStyles
|
void |
setDrawMultipolygon(boolean drawMultipolygon)
Sets whether multipolygons must be drawn.
|
(package private) void |
setStyleSources(java.util.Collection<StyleSource> sources)
set the style sources; only accessed from MapPaintStyles
|
private final java.util.List<StyleSource> styleSources
private boolean drawMultipolygon
private short cacheIdx
private boolean defaultNodes
private boolean defaultLines
private short defaultNodesIdx
private short defaultLinesIdx
private final java.util.Map<java.lang.String,java.lang.String> preferenceCache
private volatile java.awt.Color backgroundColorCache
public ElemStyles()
ElemStyles.public void clearCached()
public java.util.List<StyleSource> getStyleSources()
public java.awt.Color getBackgroundColor()
public StyleElementList get(IPrimitive osm, double scale, NavigatableComponent nc)
osm - the primitivescale - the scale (in meters per 100 pixel)nc - display componentpublic Pair<StyleElementList,Range> getStyleCacheWithRange(IPrimitive osm, double scale, NavigatableComponent nc)
osm - OSM primitivescale - scalenc - navigatable componentprivate Pair<StyleElementList,Range> getImpl(IPrimitive osm, double scale, NavigatableComponent nc)
osm - OSM primitivescale - scalenc - navigatable componentpublic Pair<StyleElementList,Range> generateStyles(IPrimitive osm, double scale, boolean pretendWayIsClosed)
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.private static <T> void addIfNotNull(java.util.List<T> list, T obj)
private boolean isDefaultNodes()
true if default node symbol must be drawnprivate boolean isDefaultLines()
true if default line must be drawnprivate <T> T fromCanvas(java.lang.String key, T def, java.lang.Class<T> c)
public boolean isDrawMultipolygon()
public void setDrawMultipolygon(boolean drawMultipolygon)
drawMultipolygon - whether multipolygons must be drawnvoid clear()
void add(StyleSource style)
style - style source to addboolean remove(StyleSource style)
style - style source to removetrue if this list contained the specified elementvoid setStyleSources(java.util.Collection<StyleSource> sources)
sources - new style sourcespublic static AreaElement getAreaElemStyle(IPrimitive p, boolean pretendWayIsClosed)
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.null.public static boolean hasAreaElemStyle(IPrimitive p, boolean pretendWayIsClosed)
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.true if primitive has an AreaElementpublic static boolean hasOnlyAreaElements(IPrimitive p)
StyleElements, but
no line-type StyleElements.
TextElement is ignored, as it can be both line and area-type.p - the OSM primitivetrue if primitive has area elements, but no line elementspublic java.lang.String getPreferenceCached(java.lang.String key, java.lang.String def)
Config.getPref().get()) for
each primitive can be slow during rendering.key - preference keydef - default valueAbstractPreferences.get(String, String)public void preferenceChanged(PreferenceChangeEvent e)
PreferenceChangedListenerpreferenceChanged in interface PreferenceChangedListenere - the preference change event