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


Ignore:
Timestamp:
2011-01-22T00:04:51+01:00 (13 years ago)
Author:
bastiK
Message:

move inner class to separate file

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java

    r3653 r3799  
    5252    private boolean drawRestriction;
    5353    private boolean leftHandTraffic;
    54     private ElemStyles.StyleSet styles;
     54    private StyleSet styles;
    5555    private double circum;
    5656    private double dist;
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java

    r3673 r3799  
    2424import org.openstreetmap.josm.gui.mappaint.AreaElemStyle;
    2525import org.openstreetmap.josm.gui.mappaint.ElemStyle;
    26 import org.openstreetmap.josm.gui.mappaint.ElemStyles;
    2726import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
     27import org.openstreetmap.josm.gui.mappaint.StyleSource;
    2828
    2929public class MultipolygonTest extends Test {
     
    4141    protected static final int NO_STYLE_POLYGON = 1611;
    4242
    43     private static ElemStyles.StyleSet styles;
     43    private static StyleSource styles;
    4444
    4545    private final List<List<Node>> nonClosedWays = new ArrayList<List<Node>>();
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r3719 r3799  
    1717public class ElemStyles
    1818{
    19     public static class StyleSet {
    20         private HashMap<String, IconElemStyle> icons;
    21         private HashMap<String, LineElemStyle> lines;
    22         private HashMap<String, AreaElemStyle> areas;
    23         private HashMap<String, LineElemStyle> modifiers;
    24         private LinkedList<IconElemStyle> iconsList;
    25         private LinkedList<LineElemStyle> linesList;
    26         private LinkedList<AreaElemStyle> areasList;
    27         private LinkedList<LineElemStyle> modifiersList;
    28         public StyleSet()
    29         {
    30             icons = new HashMap<String, IconElemStyle>();
    31             lines = new HashMap<String, LineElemStyle>();
    32             modifiers = new HashMap<String, LineElemStyle>();
    33             areas = new HashMap<String, AreaElemStyle>();
    34             iconsList = new LinkedList<IconElemStyle>();
    35             linesList = new LinkedList<LineElemStyle>();
    36             modifiersList = new LinkedList<LineElemStyle>();
    37             areasList = new LinkedList<AreaElemStyle>();
    38         }
    39         private IconElemStyle getNode(OsmPrimitive primitive)
    40         {
    41             IconElemStyle ret = null;
    42             for (String key: primitive.keySet()) {
    43                 String val = primitive.get(key);
    44                 IconElemStyle style;
    45                 if((style = icons.get("n" + key + "=" + val)) != null)
    46                 {
    47                     if(ret == null || style.priority > ret.priority) {
    48                         ret = style;
    49                     }
    50                 }
    51                 if((style = icons.get("b" + key + "=" + OsmUtils.getNamedOsmBoolean(val))) != null)
    52                 {
    53                     if(ret == null || style.priority > ret.priority) {
    54                         ret = style;
    55                     }
    56                 }
    57                 if((style = icons.get("x" + key)) != null)
    58                 {
    59                     if(ret == null || style.priority > ret.priority) {
    60                         ret = style;
    61                     }
    62                 }
    63             }
    64             for(IconElemStyle s : iconsList)
    65             {
    66                 if((ret == null || s.priority > ret.priority) && s.check(primitive)) {
    67                     ret = s;
    68                 }
    69             }
    70             return ret;
    71         }
    72         private ElemStyle get(OsmPrimitive primitive, boolean noclosed)
    73         {
    74             AreaElemStyle retArea = null;
    75             LineElemStyle retLine = null;
    76             String linestring = null;
    77             HashMap<String, LineElemStyle> over = new HashMap<String, LineElemStyle>();
    78             for (String key: primitive.keySet()) {
    79                 String val = primitive.get(key);
    80                 AreaElemStyle styleArea;
    81                 LineElemStyle styleLine;
    82                 String idx = "n" + key + "=" + val;
    83                 if((styleArea = areas.get(idx)) != null && (retArea == null
    84                         || styleArea.priority > retArea.priority) && (!noclosed
    85                                 || !styleArea.closed)) {
    86                     retArea = styleArea;
    87                 }
    88                 if((styleLine = lines.get(idx)) != null && (retLine == null
    89                         || styleLine.priority > retLine.priority))
    90                 {
    91                     retLine = styleLine;
    92                     linestring = idx;
    93                 }
    94                 if((styleLine = modifiers.get(idx)) != null) {
    95                     over.put(idx, styleLine);
    96                 }
    97                 idx = "b" + key + "=" + OsmUtils.getNamedOsmBoolean(val);
    98                 if((styleArea = areas.get(idx)) != null && (retArea == null
    99                         || styleArea.priority > retArea.priority) && (!noclosed
    100                                 || !styleArea.closed)) {
    101                     retArea = styleArea;
    102                 }
    103                 if((styleLine = lines.get(idx)) != null && (retLine == null
    104                         || styleLine.priority > retLine.priority))
    105                 {
    106                     retLine = styleLine;
    107                     linestring = idx;
    108                 }
    109                 if((styleLine = modifiers.get(idx)) != null) {
    110                     over.put(idx, styleLine);
    111                 }
    112                 idx = "x" + key;
    113                 if((styleArea = areas.get(idx)) != null && (retArea == null
    114                         || styleArea.priority > retArea.priority) && (!noclosed
    115                                 || !styleArea.closed)) {
    116                     retArea = styleArea;
    117                 }
    118                 if((styleLine = lines.get(idx)) != null && (retLine == null
    119                         || styleLine.priority > retLine.priority))
    120                 {
    121                     retLine = styleLine;
    122                     linestring = idx;
    123                 }
    124                 if((styleLine = modifiers.get(idx)) != null) {
    125                     over.put(idx, styleLine);
    126                 }
    127             }
    128             for(AreaElemStyle s : areasList)
    129             {
    130                 if((retArea == null || s.priority > retArea.priority)
    131                         && (!noclosed || !s.closed) && s.check(primitive)) {
    132                     retArea = s;
    133                 }
    134             }
    135             for(LineElemStyle s : linesList)
    136             {
    137                 if((retLine == null || s.priority > retLine.priority)
    138                         && s.check(primitive)) {
    139                     retLine = s;
    140                 }
    141             }
    142             for(LineElemStyle s : modifiersList)
    143             {
    144                 if(s.check(primitive)) {
    145                     over.put(s.getCode(), s);
    146                 }
    147             }
    148             over.remove(linestring);
    149             if(over.size() != 0 && retLine != null)
    150             {
    151                 List<LineElemStyle> s = new LinkedList<LineElemStyle>(over.values());
    152                 Collections.sort(s);
    153                 retLine = new LineElemStyle(retLine, s);
    154             }
    155             if(retArea != null)
    156             {
    157                 if(retLine != null)
    158                     return new AreaElemStyle(retArea, retLine);
    159                 else
    160                     return retArea;
    161             }
    162             return retLine;
    163         }
    164 
    165         public ElemStyle get(OsmPrimitive osm)
    166         {
    167             return (!osm.hasKeys()) ? null :
    168                 ((osm instanceof Node) ? getNode(osm) : get(osm,
    169                         osm instanceof Way && !((Way)osm).isClosed()));
    170         }
    171 
    172         public ElemStyle getArea(Way osm)
    173         {
    174             if(osm.hasKeys())
    175             {
    176                 /* force area mode also for unclosed ways */
    177                 ElemStyle style = get(osm, false);
    178                 if(style != null && style instanceof AreaElemStyle)
    179                     return style;
    180             }
    181             return null;
    182         }
    183 
    184         public IconElemStyle getIcon(OsmPrimitive osm)
    185         {
    186             return osm.hasKeys() ? getNode(osm): null;
    187         }
    188 
    189         public boolean isArea(OsmPrimitive o)
    190         {
    191             if(o.hasKeys() && !(o instanceof Node))
    192             {
    193                 boolean noclosed = o instanceof Way && !((Way)o).isClosed();
    194                 Iterator<String> iterator = o.keySet().iterator();
    195                 while(iterator.hasNext())
    196                 {
    197                     String key = iterator.next();
    198                     String val = o.get(key);
    199                     AreaElemStyle s = areas.get("n" + key + "=" + val);
    200                     if(s == null || (s.closed && noclosed)) {
    201                         s = areas.get("b" + key + "=" + OsmUtils.getNamedOsmBoolean(val));
    202                     }
    203                     if(s == null || (s.closed && noclosed)) {
    204                         s = areas.get("x" + key);
    205                     }
    206                     if(s != null && !(s.closed && noclosed))
    207                         return true;
    208                 }
    209                 for(AreaElemStyle s : areasList)
    210                 {
    211                     if(!(s.closed && noclosed) && s.check(o))
    212                         return true;
    213                 }
    214             }
    215             return false;
    216         }
    217 
    218         public boolean hasAreas()
    219         {
    220             return areas.size() > 0;
    221         }
    222     }
    223 
    224     HashMap<String, StyleSet> styleSet;
     19    HashMap<String, StyleSource> styleSet;
    22520    public ElemStyles()
    22621    {
    227         styleSet = new HashMap<String, StyleSet>();
     22        styleSet = new HashMap<String, StyleSource>();
    22823    }
    22924
     
    28883    }
    28984
    290     private StyleSet getStyleSet(String name, boolean create)
     85    private StyleSource getStyleSet(String name, boolean create)
    29186    {
    29287        if(name == null) {
     
    29489        }
    29590
    296         StyleSet s = styleSet.get(name);
     91        StyleSource s = styleSet.get(name);
    29792        if(create && s == null)
    29893        {
    299             s = new StyleSet();
     94            s = new StyleSource();
    30095            styleSet.put(name, s);
    30196        }
     
    30499
    305100    /* called from class users, never return null */
    306     public StyleSet getStyleSet()
     101    public StyleSource getStyleSet()
    307102    {
    308103        return getStyleSet(null, true);
Note: See TracChangeset for help on using the changeset viewer.