org.openstreetmap.josm.gui.mappaint
Class ElemStyles

java.lang.Object
  extended by org.openstreetmap.josm.gui.mappaint.ElemStyles

public class ElemStyles
extends java.lang.Object


Field Summary
private  int cacheIdx
           
private  boolean defaultLines
           
private  int defaultLinesIdx
           
private  boolean defaultNodes
           
private  int defaultNodesIdx
           
private  boolean drawMultipolygon
           
private  java.util.List<StyleSource> styleSources
           
 
Constructor Summary
ElemStyles()
           
 
Method Summary
(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()
           
private
<T> T
fromCanvas(java.lang.String key, T def, java.lang.Class<T> c)
           
 Pair<StyleCache.StyleList,Range> generateStyles(OsmPrimitive osm, double scale, OsmPrimitive multipolyOuterWay, boolean pretendWayIsClosed)
          Create the list of styles and its valid scale range for one primitive.
 StyleCache.StyleList get(OsmPrimitive osm, double scale, NavigatableComponent nc)
          Create the list of styles for one primitive.
static AreaElemStyle getAreaElemStyle(OsmPrimitive p, boolean pretendWayIsClosed)
          Returns the first AreaElemStyle for a given primitive.
private  Pair<StyleCache.StyleList,Range> getImpl(OsmPrimitive osm, double scale, NavigatableComponent nc)
          Create the list of styles and its valid scale range for one primitive.
 Pair<StyleCache.StyleList,Range> getStyleCacheWithRange(OsmPrimitive osm, double scale, NavigatableComponent nc)
          Create the list of styles and its valid scale range for one primitive.
 java.util.List<StyleSource> getStyleSources()
           
static boolean hasAreaElemStyle(OsmPrimitive p, boolean pretendWayIsClosed)
          Determines whether primitive has an AreaElemStyle.
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()
           
 void setDrawMultipolygon(boolean drawMultipolygon)
           
(package private)  void setStyleSources(java.util.Collection<StyleSource> sources)
          set the style sources; only accessed from MapPaintStyles
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

styleSources

private java.util.List<StyleSource> styleSources

drawMultipolygon

private boolean drawMultipolygon

cacheIdx

private int cacheIdx

defaultNodes

private boolean defaultNodes

defaultLines

private boolean defaultLines

defaultNodesIdx

private int defaultNodesIdx

defaultLinesIdx

private int defaultLinesIdx
Constructor Detail

ElemStyles

public ElemStyles()
Method Detail

clearCached

public void clearCached()

getStyleSources

public java.util.List<StyleSource> getStyleSources()

get

public StyleCache.StyleList get(OsmPrimitive osm,
                                double scale,
                                NavigatableComponent nc)
Create the list of styles for one primitive.

Parameters:
osm - the primitive
scale - the scale (in meters per 100 pixel)
nc -
Returns:

getStyleCacheWithRange

public Pair<StyleCache.StyleList,Range> getStyleCacheWithRange(OsmPrimitive osm,
                                                               double scale,
                                                               NavigatableComponent nc)
Create the list of styles and its valid scale range for one primitive. Automatically adds default styles in case no proper style was found. Uses the cache, if possible, and saves the results to the cache.


getImpl

private Pair<StyleCache.StyleList,Range> getImpl(OsmPrimitive osm,
                                                 double scale,
                                                 NavigatableComponent nc)
Create the list of styles and its valid scale range for one primitive. This method does multipolygon handling. There are different tagging styles for multipolygons, that have to be respected: - tags on the relation - tags on the outer way - tags on both, the outer and the inner way (very old style) If the primitive is a way, look for multipolygon parents. In case it is indeed member of some multipolygon as role "outer", all area styles are removed. (They apply to the multipolygon area.) Outer ways can have their own independent line styles, e.g. a road as boundary of a forest. Otherwise, in case, the way does not have an independent line style, take a line style from the multipolygon. If the multipolygon does not have a line style either, at least create a default line style from the color of the area. Now consider the case that the way is not an outer way of any multipolygon, but is member of a multipolygon as "inner". First, the style list is regenerated, considering only tags of this way minus the tags of outer way of the multipolygon (to care for the "very old style"). Then check, if the way describes something in its own right. (linear feature or area) If not, add a default line style from the area color of the multipolygon.


generateStyles

public Pair<StyleCache.StyleList,Range> generateStyles(OsmPrimitive osm,
                                                       double scale,
                                                       OsmPrimitive multipolyOuterWay,
                                                       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 for
scale - the scale (in meters per 100 px), must be > 0
multipolyOuterWay - support for a very old multipolygon tagging style where you add the tags both to the outer and the inner way. However, independent inner way style is also possible.
pretendWayIsClosed - 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

addIfNotNull

private static <T> void addIfNotNull(java.util.List<T> list,
                                     T obj)

isDefaultNodes

private boolean isDefaultNodes()
Draw a default node symbol for nodes that have no style?


isDefaultLines

private boolean isDefaultLines()
Draw a default line for ways that do not have an own line style?


fromCanvas

private <T> T fromCanvas(java.lang.String key,
                         T def,
                         java.lang.Class<T> c)

isDrawMultipolygon

public boolean isDrawMultipolygon()

setDrawMultipolygon

public void setDrawMultipolygon(boolean drawMultipolygon)

clear

void clear()
remove all style sources; only accessed from MapPaintStyles


add

void add(StyleSource style)
add a style source; only accessed from MapPaintStyles


setStyleSources

void setStyleSources(java.util.Collection<StyleSource> sources)
set the style sources; only accessed from MapPaintStyles


getAreaElemStyle

public static AreaElemStyle getAreaElemStyle(OsmPrimitive p,
                                             boolean pretendWayIsClosed)
Returns the first AreaElemStyle for a given primitive.

Parameters:
p - the OSM primitive
pretendWayIsClosed - 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 AreaElemStyle found or null.

hasAreaElemStyle

public static boolean hasAreaElemStyle(OsmPrimitive p,
                                       boolean pretendWayIsClosed)
Determines whether primitive has an AreaElemStyle.

Parameters:
p - the OSM primitive
pretendWayIsClosed - 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:
true iff primitive has an AreaElemStyle


JOSM