Index: /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java	(revision 3802)
+++ /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java	(revision 3803)
@@ -34,9 +34,9 @@
 import org.openstreetmap.josm.gui.mappaint.AreaElemStyle;
 import org.openstreetmap.josm.gui.mappaint.ElemStyle;
+import org.openstreetmap.josm.gui.mappaint.ElemStyles;
 import org.openstreetmap.josm.gui.mappaint.IconElemStyle;
 import org.openstreetmap.josm.gui.mappaint.LineElemStyle;
 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
 import org.openstreetmap.josm.gui.mappaint.SimpleNodeElemStyle;
-import org.openstreetmap.josm.gui.mappaint.StyleSource;
 
 public class MapPaintVisitor implements PaintVisitor {
@@ -49,5 +49,5 @@
     private boolean drawRestriction;
     private boolean leftHandTraffic;
-    private StyleSource styles;
+    private ElemStyles styles;
     private double circum;
     private double dist;
@@ -535,5 +535,5 @@
         zoomLevelDisplay = Main.pref.getBoolean("mappaint.zoomLevelDisplay", false);
         circum = nc.getDist100Pixel();
-        styles = MapPaintStyles.getStyles().getStyleSet();
+        styles = MapPaintStyles.getStyles();
         drawMultipolygon = Main.pref.getBoolean("mappaint.multipolygon", true);
         drawRestriction = Main.pref.getBoolean("mappaint.restriction", true);
Index: /trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java	(revision 3802)
+++ /trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java	(revision 3803)
@@ -24,6 +24,6 @@
 import org.openstreetmap.josm.gui.mappaint.AreaElemStyle;
 import org.openstreetmap.josm.gui.mappaint.ElemStyle;
+import org.openstreetmap.josm.gui.mappaint.ElemStyles;
 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
-import org.openstreetmap.josm.gui.mappaint.StyleSource;
 
 public class MultipolygonTest extends Test {
@@ -41,5 +41,5 @@
     protected static final int NO_STYLE_POLYGON = 1611;
 
-    private static StyleSource styles;
+    private static ElemStyles styles;
 
     private final List<List<Node>> nonClosedWays = new ArrayList<List<Node>>();
@@ -52,5 +52,5 @@
     @Override
     public void initialize() throws Exception {
-        styles = MapPaintStyles.getStyles().getStyleSet();
+        styles = MapPaintStyles.getStyles();
     }
 
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java	(revision 3802)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java	(revision 3803)
@@ -45,5 +45,5 @@
     }
 
-    public ElemStyle getLineStyle() {
+    public LineElemStyle getLineStyle() {
         return line;
     }
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyleHandler.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyleHandler.java	(revision 3802)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyleHandler.java	(revision 3803)
@@ -15,9 +15,9 @@
 public class ElemStyleHandler extends DefaultHandler
 {
-    boolean inDoc, inRule, inCondition, inLine, inLineMod, inIcon, inArea, inScaleMax, inScaleMin;
-    boolean hadLine, hadLineMod, hadIcon, hadArea;
-    ElemStyles styles;
-    String styleName;
-    RuleElem rule = new RuleElem();
+    private boolean inDoc, inRule, inCondition, inLine, inLineMod, inIcon, inArea, inScaleMax, inScaleMin;
+    private boolean hadLine, hadLineMod, hadIcon, hadArea;
+    private RuleElem rule = new RuleElem();
+
+    StyleSource style;
 
     static class RuleElem {
@@ -43,9 +43,8 @@
     }
 
-    public ElemStyleHandler(String name) {
-        styleName = name;
+    public ElemStyleHandler(StyleSource style) {
+        this.style = style;
         inDoc=inRule=inCondition=inLine=inIcon=inArea=false;
         rule.init();
-        styles = MapPaintStyles.getStyles();
     }
 
@@ -54,10 +53,10 @@
         int i = colString.indexOf("#");
         Color ret;
-        if(i < 0) {
-            ret = Main.pref.getColor("mappaint."+styleName+"."+colString, Color.red);
+        if (i < 0) {
+            ret = Main.pref.getColor("mappaint."+style.getPrefName()+"."+colString, Color.red);
         } else if(i == 0) {
             ret = ColorHelper.html2color(colString);
         } else {
-            ret = Main.pref.getColor("mappaint."+styleName+"."+colString.substring(0,i),
+            ret = Main.pref.getColor("mappaint."+style.getPrefName()+"."+colString.substring(0,i),
                     ColorHelper.html2color(colString.substring(i)));
         }
@@ -74,5 +73,5 @@
 
     private void error(String message) {
-        System.out.println(styleName + " (" + rule.rule.key + "=" + rule.rule.value + "): " + message);
+        System.out.println(style.getDisplayString() + " (" + rule.rule.key + "=" + rule.rule.value + "): " + message);
     }
 
@@ -141,11 +140,9 @@
             } else if (qName.equals("rules"))
             {
-                if(styleName == null)
-                {
-                    String n = atts.getValue("name");
-                    if(n == null) {
-                        n = "standard";
-                    }
-                    styleName = n;
+                if (style.name == null) {
+                    style.name = atts.getValue("name");
+                }
+                if (style.shortdescription == null) {
+                    style.shortdescription = atts.getValue("shortdescription");
                 }
             }
@@ -203,5 +200,5 @@
                 {
                     if (atts.getQName(count).equals("src")) {
-                        ImageIcon icon = MapPaintStyles.getIcon(atts.getValue(count), styleName);
+                        ImageIcon icon = MapPaintStyles.getIcon(atts.getValue(count), style.getPrefName());
                         hadIcon = (icon != null);
                         rule.icon.icon = icon;
@@ -242,20 +239,20 @@
             if(hadLine)
             {
-                styles.add(styleName, rule.rule, rule.rules,
+                style.add(rule.rule, rule.rules,
                         new LineElemStyle(rule.line, rule.scaleMax, rule.scaleMin));
             }
             if(hadLineMod)
             {
-                styles.addModifier(styleName, rule.rule, rule.rules,
+                style.addModifier(rule.rule, rule.rules,
                         new LineElemStyle(rule.linemod, rule.scaleMax, rule.scaleMin));
             }
             if(hadIcon)
             {
-                styles.add(styleName, rule.rule, rule.rules,
+                style.add(rule.rule, rule.rules,
                         new IconElemStyle(rule.icon, rule.scaleMax, rule.scaleMin));
             }
             if(hadArea)
             {
-                styles.add(styleName, rule.rule, rule.rules,
+                style.add(rule.rule, rule.rules,
                         new AreaElemStyle(rule.area, rule.scaleMax, rule.scaleMin));
             }
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java	(revision 3802)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java	(revision 3803)
@@ -2,109 +2,125 @@
 package org.openstreetmap.josm.gui.mappaint;
 
+import static org.openstreetmap.josm.tools.Utils.equal;
+
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.OsmUtils;
 import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.tools.FilteredCollection;
+import org.openstreetmap.josm.tools.Predicate;
 
-public class ElemStyles
-{
-    HashMap<String, StyleSource> styleSet;
+public class ElemStyles {
+    private List<StyleSource> styleSources;
+
     public ElemStyles()
     {
-        styleSet = new HashMap<String, StyleSource>();
+        styleSources = new ArrayList<StyleSource>();
     }
 
-    public void add(String name, Rule r, Collection<Rule> rules, LineElemStyle style)
-    {
-        if(rules != null)
-        {
-            style.rules = rules;
-            getStyleSet(name, true).linesList.add(style);
-        }
-        else
-        {
-            String key = r.getKey();
-            style.code = key;
-            getStyleSet(name, true).lines.put(key, style);
+    public void add(StyleSource style) {
+        styleSources.add(style);
+    }
+
+    public Collection<StyleSource> getStyleSources() {
+        return new FilteredCollection<StyleSource>(styleSources, new Predicate<StyleSource>() {
+
+            String name = Main.pref.get("mappaint.style", "standard");
+
+            @Override
+            public boolean evaluate(StyleSource s) {
+                return equal(s.getPrefName(), name);
+            }
+
+        });
+    }
+
+    public ElemStyle get(OsmPrimitive osm) {
+        return get(osm, false);
+    }
+
+    public ElemStyle get(OsmPrimitive osm, boolean forceArea) {
+        if (!osm.hasKeys())
+            return null;
+
+        if (osm instanceof Node) {
+            IconElemStyle icon = null;
+            for (StyleSource s : getStyleSources()) {
+                icon = s.getNode(osm, icon);
+            }
+            return icon;
+        } else {
+            boolean noclosed;
+            if (forceArea) {
+                noclosed = false;
+            } else {
+                noclosed = osm instanceof Way && !((Way) osm).isClosed();
+            }
+            AreaElemStyle area = null;
+            LineElemStyle line = null;
+            ElemStyle result = null;
+            for (StyleSource s : getStyleSources()) {
+                result = s.get(osm, noclosed, area, line);
+                if (result instanceof LineElemStyle) {
+                    area = null;
+                    line = (LineElemStyle) result;
+                } else if (result instanceof AreaElemStyle) {
+                    area = (AreaElemStyle) result;
+                    if (area.getLineStyle() != null) {
+                        line = area.getLineStyle();
+                    }
+                } else if (result != null)
+                    throw new AssertionError();
+            }
+            return result;
         }
     }
 
-    public void addModifier(String name, Rule r, Collection<Rule> rules, LineElemStyle style)
-    {
-        if(rules != null)
-        {
-            style.rules = rules;
-            getStyleSet(name, true).modifiersList.add(style);
+    public boolean hasAreas() {
+        for (StyleSource s : getStyleSources()) {
+            if (s.hasAreas())
+                return true;
         }
-        else
-        {
-            String key = r.getKey();
-            style.code = key;
-            getStyleSet(name, true).modifiers.put(key, style);
-        }
+        return false;
     }
 
-    public void add(String name, Rule r, Collection<Rule> rules, AreaElemStyle style)
-    {
-        if(rules != null)
-        {
-            style.rules = rules;
-            getStyleSet(name, true).areasList.add(style);
+    public boolean isArea(OsmPrimitive osm) {
+        for (StyleSource s : getStyleSources()) {
+            if (s.isArea(osm))
+                return true;
         }
-        else
-        {
-            String key = r.getKey();
-            style.code = key;
-            getStyleSet(name, true).areas.put(key, style);
-        }
+        return false;
     }
 
-    public void add(String name, Rule r, Collection<Rule> rules, IconElemStyle style)
-    {
-        if(rules != null)
-        {
-            style.rules = rules;
-            getStyleSet(name, true).iconsList.add(style);
+    public ElemStyle getArea(Way osm) {
+        if (osm.hasKeys()) {
+            /* force area mode also for unclosed ways */
+            ElemStyle style = get(osm, true);
+            if (style != null && style instanceof AreaElemStyle) {
+                return style;
+            }
         }
-        else
-        {
-            String key = r.getKey();
-            style.code = key;
-            getStyleSet(name, true).icons.put(key, style);
-        }
+        return null;
     }
 
-    private StyleSource getStyleSet(String name, boolean create)
-    {
-        if(name == null) {
-            name = Main.pref.get("mappaint.style", "standard");
-        }
-
-        StyleSource s = styleSet.get(name);
-        if(create && s == null)
-        {
-            s = new StyleSource();
-            styleSet.put(name, s);
-        }
-        return s;
+    public IconElemStyle getIcon(OsmPrimitive osm) {
+        return osm.hasKeys() ? (IconElemStyle) get(osm) : null;
     }
 
-    /* called from class users, never return null */
-    public StyleSource getStyleSet()
-    {
-        return getStyleSet(null, true);
-    }
-
-    public Collection<String> getStyleNames()
-    {
-        return styleSet.keySet();
+    public Collection<String> getStyleNames() {
+        Set<String> names = new HashSet<String>();
+        names.add("standard");
+        for (StyleSource s : styleSources) {
+            if (s.name != null) {
+                names.add(s.name);
+            }
+        }
+        return names;
     }
 }
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java	(revision 3802)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java	(revision 3803)
@@ -76,6 +76,7 @@
 
         for (SourceEntry entry : sourceEntries) {
+            StyleSource style = new StyleSource(entry);
             try {
-                XmlObjectParser parser = new XmlObjectParser(new ElemStyleHandler(entry.name));
+                XmlObjectParser parser = new XmlObjectParser(new ElemStyleHandler(style));
                 MirroredInputStream in = new MirroredInputStream(entry.url);
                 InputStream zip = in.getZipEntry("xml","style");
@@ -95,11 +96,15 @@
                 System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", entry.url, e.toString()));
                 e.printStackTrace();
+                style.hasError = true;
             } catch(SAXParseException e) {
                 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: [{1}:{2}] {3}", entry.url, e.getLineNumber(), e.getColumnNumber(), e.getMessage()));
                 e.printStackTrace();
+                style.hasError = true;
             } catch(SAXException e) {
                 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: {1}", entry.url, e.getMessage()));
                 e.printStackTrace();
+                style.hasError = true;
             }
+            styles.add(style);
         }
         iconDirs = null;
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java	(revision 3802)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java	(revision 3803)
@@ -2,4 +2,5 @@
 package org.openstreetmap.josm.gui.mappaint;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -7,65 +8,64 @@
 import java.util.LinkedList;
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.OsmUtils;
 import org.openstreetmap.josm.data.osm.Way;
-
-public class StyleSource {
-
-    public HashMap<String, IconElemStyle> icons;
-    public HashMap<String, LineElemStyle> lines;
-    public HashMap<String, AreaElemStyle> areas;
-    public HashMap<String, LineElemStyle> modifiers;
-    public LinkedList<IconElemStyle> iconsList;
-    public LinkedList<LineElemStyle> linesList;
-    public LinkedList<AreaElemStyle> areasList;
-    public LinkedList<LineElemStyle> modifiersList;
-
-    public StyleSource() {
-        icons = new HashMap<String, IconElemStyle>();
-        lines = new HashMap<String, LineElemStyle>();
-        modifiers = new HashMap<String, LineElemStyle>();
-        areas = new HashMap<String, AreaElemStyle>();
-        iconsList = new LinkedList<IconElemStyle>();
-        linesList = new LinkedList<LineElemStyle>();
-        modifiersList = new LinkedList<LineElemStyle>();
-        areasList = new LinkedList<AreaElemStyle>();
-    }
-
-    private IconElemStyle getNode(OsmPrimitive primitive) {
-        IconElemStyle ret = null;
+import org.openstreetmap.josm.gui.preferences.SourceEntry;
+
+public class StyleSource extends SourceEntry {
+
+    public final HashMap<String, IconElemStyle> icons = new HashMap<String, IconElemStyle>();
+    public final HashMap<String, LineElemStyle> lines = new HashMap<String, LineElemStyle>();
+    public final HashMap<String, LineElemStyle> modifiers = new HashMap<String, LineElemStyle>();
+    public final HashMap<String, AreaElemStyle> areas = new HashMap<String, AreaElemStyle>();
+    public final LinkedList<IconElemStyle> iconsList = new LinkedList<IconElemStyle>();
+    public final LinkedList<LineElemStyle> linesList = new LinkedList<LineElemStyle>();
+    public final LinkedList<LineElemStyle> modifiersList = new LinkedList<LineElemStyle>();
+    public final LinkedList<AreaElemStyle> areasList = new LinkedList<AreaElemStyle>();
+
+    public boolean hasError = false;
+
+    public StyleSource(String url, String name, String shortdescription) {
+        super(url, name, shortdescription, true);
+    }
+
+    public StyleSource(SourceEntry entry) {
+        super(entry.url, entry.name, entry.shortdescription, entry.active);
+    }
+
+    public IconElemStyle getNode(OsmPrimitive primitive, IconElemStyle icon) {
         for (String key : primitive.keySet()) {
             String val = primitive.get(key);
             IconElemStyle style;
             if ((style = icons.get("n" + key + "=" + val)) != null) {
-                if (ret == null || style.priority > ret.priority) {
-                    ret = style;
+                if (icon == null || style.priority > icon.priority) {
+                    icon = style;
                 }
             }
             if ((style = icons.get("b" + key + "=" + OsmUtils.getNamedOsmBoolean(val))) != null) {
-                if (ret == null || style.priority > ret.priority) {
-                    ret = style;
+                if (icon == null || style.priority > icon.priority) {
+                    icon = style;
                 }
             }
             if ((style = icons.get("x" + key)) != null) {
-                if (ret == null || style.priority > ret.priority) {
-                    ret = style;
+                if (icon == null || style.priority > icon.priority) {
+                    icon = style;
                 }
             }
         }
         for (IconElemStyle s : iconsList) {
-            if ((ret == null || s.priority > ret.priority) && s.check(primitive)) {
-                ret = s;
-            }
-        }
-        return ret;
-    }
-
-    private ElemStyle get(OsmPrimitive primitive, boolean noclosed) {
-        AreaElemStyle retArea = null;
-        LineElemStyle retLine = null;
-        String linestring = null;
-        HashMap<String, LineElemStyle> over = new HashMap<String, LineElemStyle>();
+            if ((icon == null || s.priority > icon.priority) && s.check(primitive)) {
+                icon = s;
+            }
+        }
+        return icon;
+    }
+
+    public ElemStyle get(OsmPrimitive primitive, boolean noclosed, AreaElemStyle area, LineElemStyle line) {
+        String lineIdx = null;
+        HashMap<String, LineElemStyle> overlayMap = new HashMap<String, LineElemStyle>();
         for (String key : primitive.keySet()) {
             String val = primitive.get(key);
@@ -73,85 +73,70 @@
             LineElemStyle styleLine;
             String idx = "n" + key + "=" + val;
-            if ((styleArea = areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority) && (!noclosed || !styleArea.closed)) {
-                retArea = styleArea;
-            }
-            if ((styleLine = lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) {
-                retLine = styleLine;
-                linestring = idx;
+            if ((styleArea = areas.get(idx)) != null && (area == null || styleArea.priority > area.priority) && (!noclosed || !styleArea.closed)) {
+                area = styleArea;
+            }
+            if ((styleLine = lines.get(idx)) != null && (line == null || styleLine.priority > line.priority)) {
+                line = styleLine;
+                lineIdx = idx;
             }
             if ((styleLine = modifiers.get(idx)) != null) {
-                over.put(idx, styleLine);
+                overlayMap.put(idx, styleLine);
             }
             idx = "b" + key + "=" + OsmUtils.getNamedOsmBoolean(val);
-            if ((styleArea = areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority) && (!noclosed || !styleArea.closed)) {
-                retArea = styleArea;
-            }
-            if ((styleLine = lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) {
-                retLine = styleLine;
-                linestring = idx;
+            if ((styleArea = areas.get(idx)) != null && (area == null || styleArea.priority > area.priority) && (!noclosed || !styleArea.closed)) {
+                area = styleArea;
+            }
+            if ((styleLine = lines.get(idx)) != null && (line == null || styleLine.priority > line.priority)) {
+                line = styleLine;
+                lineIdx = idx;
             }
             if ((styleLine = modifiers.get(idx)) != null) {
-                over.put(idx, styleLine);
+                overlayMap.put(idx, styleLine);
             }
             idx = "x" + key;
-            if ((styleArea = areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority) && (!noclosed || !styleArea.closed)) {
-                retArea = styleArea;
-            }
-            if ((styleLine = lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) {
-                retLine = styleLine;
-                linestring = idx;
+            if ((styleArea = areas.get(idx)) != null && (area == null || styleArea.priority > area.priority) && (!noclosed || !styleArea.closed)) {
+                area = styleArea;
+            }
+            if ((styleLine = lines.get(idx)) != null && (line == null || styleLine.priority > line.priority)) {
+                line = styleLine;
+                lineIdx = idx;
             }
             if ((styleLine = modifiers.get(idx)) != null) {
-                over.put(idx, styleLine);
+                overlayMap.put(idx, styleLine);
             }
         }
         for (AreaElemStyle s : areasList) {
-            if ((retArea == null || s.priority > retArea.priority) && (!noclosed || !s.closed) && s.check(primitive)) {
-                retArea = s;
+            if ((area == null || s.priority > area.priority) && (!noclosed || !s.closed) && s.check(primitive)) {
+                area = s;
             }
         }
         for (LineElemStyle s : linesList) {
-            if ((retLine == null || s.priority > retLine.priority) && s.check(primitive)) {
-                retLine = s;
+            if ((line == null || s.priority > line.priority) && s.check(primitive)) {
+                line = s;
             }
         }
         for (LineElemStyle s : modifiersList) {
             if (s.check(primitive)) {
-                over.put(s.getCode(), s);
-            }
-        }
-        over.remove(linestring);
-        if (over.size() != 0 && retLine != null) {
-            List<LineElemStyle> s = new LinkedList<LineElemStyle>(over.values());
-            Collections.sort(s);
-            retLine = new LineElemStyle(retLine, s);
-        }
-        if (retArea != null) {
-            if (retLine != null) {
-                return new AreaElemStyle(retArea, retLine);
+                overlayMap.put(s.getCode(), s);
+            }
+        }
+        overlayMap.remove(lineIdx); // do not use overlay if linestyle is from the same rule (example: railway=tram)
+        if (!overlayMap.isEmpty() && line != null) {
+            List<LineElemStyle> tmp = new LinkedList<LineElemStyle>();
+            if (line.overlays != null) {
+                tmp.addAll(line.overlays);
+            }
+            tmp.addAll(overlayMap.values());
+            Collections.sort(tmp);
+            line = new LineElemStyle(line, tmp);
+        }
+        if (area != null) {
+            if (line != null) {
+                return new AreaElemStyle(area, line);
             } else {
-                return retArea;
-            }
-        }
-        return retLine;
-    }
-
-    public ElemStyle get(OsmPrimitive osm) {
-        return (!osm.hasKeys()) ? null : ((osm instanceof Node) ? getNode(osm) : get(osm, osm instanceof Way && !((Way) osm).isClosed()));
-    }
-
-    public ElemStyle getArea(Way osm) {
-        if (osm.hasKeys()) {
-            /* force area mode also for unclosed ways */
-            ElemStyle style = get(osm, false);
-            if (style != null && style instanceof AreaElemStyle) {
-                return style;
-            }
-        }
-        return null;
-    }
-
-    public IconElemStyle getIcon(OsmPrimitive osm) {
-        return osm.hasKeys() ? getNode(osm) : null;
+                return area;
+            }
+        }
+        return line;
     }
 
@@ -186,3 +171,89 @@
         return areas.size() > 0;
     }
+
+    public void add(Rule r, Collection<Rule> rules, LineElemStyle style) {
+        if(rules != null)
+        {
+            style.rules = rules;
+            linesList.add(style);
+        }
+        else {
+            String key = r.getKey();
+            style.code = key;
+            lines.put(key, style);
+        }
+    }
+
+    public void addModifier(Rule r, Collection<Rule> rules, LineElemStyle style) {
+        if(rules != null)
+        {
+            style.rules = rules;
+            modifiersList.add(style);
+        }
+        else
+        {
+            String key = r.getKey();
+            style.code = key;
+            modifiers.put(key, style);
+        }
+    }
+
+    public void add(Rule r, Collection<Rule> rules, AreaElemStyle style) {
+        if(rules != null)
+        {
+            style.rules = rules;
+            areasList.add(style);
+        }
+        else
+        {
+            String key = r.getKey();
+            style.code = key;
+            areas.put(key, style);
+        }
+    }
+
+    public void add(Rule r, Collection<Rule> rules, IconElemStyle style) {
+        if(rules != null)
+        {
+            style.rules = rules;
+            iconsList.add(style);
+        }
+        else
+        {
+            String key = r.getKey();
+            style.code = key;
+            icons.put(key, style);
+        }
+    }
+
+    /**
+     * the name / identifier that should be used to save custom color values
+     * and similar stuff to the preference file
+     * @return the identifier; never null. Usually the result is "standard"
+     */
+    public String getPrefName() {
+        return name == null ? "standard" : name;
+    }
+
+    /**
+     * String to show in menus and error messages.
+     * @return Usually the shortdescription, but can be the file name
+     * if no shortdescription is available.
+     */
+    public String getDisplayString() {
+        if (shortdescription != null)
+            return shortdescription;
+        /**
+         * extract file part from url, e.g.:
+         * http://www.test.com/file.xml?format=text  --> file.xml
+         */
+        Pattern p = Pattern.compile("([^/\\\\]*?)([?].*)?$");
+        Matcher m = p.matcher(url);
+        if (m.find()) {
+            return m.group(1);
+        } else {
+            System.err.println("Warning: Unexpected URL format: "+url);
+            return url;
+        }
+    }
 }
