Changeset 874 in josm for trunk/src


Ignore:
Timestamp:
2008-08-26T23:58:16+02:00 (16 years ago)
Author:
stoecker
Message:

allow to combine mappaint line and area styles.

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

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

    r863 r874  
    114114
    115115                Color colour = untaggedColor;
     116                Color areacolour = untaggedColor;
    116117                int width = defaultSegmentWidth;
    117118                int realWidth = 0; //the real width of the element in meters
     
    126127                if(wayStyle!=null)
    127128                {
     129                        LineElemStyle l = null;
    128130                        if(wayStyle instanceof LineElemStyle)
    129131                        {
    130                                 colour = ((LineElemStyle)wayStyle).colour;
    131                                 width = ((LineElemStyle)wayStyle).width;
    132                                 realWidth = ((LineElemStyle)wayStyle).realWidth;
    133                                 dashed = ((LineElemStyle)wayStyle).dashed;
     132                                l = (LineElemStyle)wayStyle;
    134133                        }
    135134                        else if (wayStyle instanceof AreaElemStyle)
    136135                        {
    137                                 colour = ((AreaElemStyle)wayStyle).getColour();
     136                                areacolour = ((AreaElemStyle)wayStyle).colour;
     137                                l = ((AreaElemStyle)wayStyle).line;
    138138                                area = true;
    139139                        }
     140                        if(l != null)
     141                        {
     142                                colour = l.colour;
     143                                width = l.width;
     144                                realWidth = l.realWidth;
     145                                dashed = l.dashed;
     146                        }
    140147                }
    141148
    142149                if (area && fillAreas)
    143                         drawWayAsArea(w, colour);
     150                        drawWayAsArea(w, areacolour);
    144151                int orderNumber = 0;
    145152
     
    152159                        orderNumber++;
    153160
    154                         if (!area && realWidth > 0 && useRealWidth && !showDirection) {
     161                        if (realWidth > 0 && useRealWidth && !showDirection)
     162                        {
    155163                                int tmpWidth = (int) (100 /  (float) (circum / realWidth));
    156164                                if (tmpWidth > width) width = tmpWidth;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java

    r627 r874  
    44public class AreaElemStyle extends ElemStyle
    55{
    6         Color colour;
     6        public Color colour;
     7        public LineElemStyle line = null;
    78
    89        public AreaElemStyle (Color colour, long maxScale, long minScale) {
     
    1213        }
    1314
    14         public Color getColour() {
    15                 return colour;
     15        public AreaElemStyle(AreaElemStyle a, LineElemStyle l)
     16        {
     17                this.colour = a.colour;
     18                this.maxScale = a.maxScale;
     19                this.minScale = a.minScale;
     20                this.line = l;
    1621        }
    1722
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyleHandler.java

    r801 r874  
    145145                                                curLineDashed, curScaleMax, curScaleMin);
    146146                                MapPaintStyles.add(curKey, curValue, curBoolean, newStyle);
    147                                 curLineWidth    = -1;
     147                                curLineWidth = -1;
    148148                                curLineRealWidth= 0;
    149                                 curLineDashed   = false;
    150                                 curLineColour   = null;
     149                                curLineDashed = false;
     150                                curLineColour = null;
    151151                        }
    152152                       
     
    154154                                newStyle = new IconElemStyle(curIcon, curIconAnnotate, curScaleMax, curScaleMin);
    155155                                MapPaintStyles.add(curKey, curValue, curBoolean, newStyle);
    156                                 curIcon                 = null;
     156                                curIcon = null;
    157157                                curIconAnnotate = true;
    158158                        }
     
    160160                                newStyle = new AreaElemStyle (curAreaColour, curScaleMax, curScaleMin);
    161161                                MapPaintStyles.add(curKey, curValue, curBoolean, newStyle);
    162                                 curAreaColour   = null;
     162                                curAreaColour = null;
    163163                        }
    164164                        curScaleMax = 1000000000;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r791 r874  
    55
    66import org.openstreetmap.josm.data.osm.OsmPrimitive;
     7import org.openstreetmap.josm.data.osm.OsmUtils;
     8
    79public class ElemStyles
    810{
    9         HashMap<String, ElemStyle> styles;
    10         // static int nr = 0;
    11 
     11        private HashMap<String, ElemStyle> styles;
    1212
    1313        public ElemStyles()
     
    1616        }
    1717
    18         public void add (String k, String v, ElemStyle style)
     18        public void add(String k, String v, String b, ElemStyle style)
    1919        {
    2020                ElemStyle  old_style;
    21                 String key = k + "=" + v;
    22                
     21                String key;
     22
    2323                /* unfortunately, there don't seem to be an efficient way to */
    2424                /* find out, if a given OsmPrimitive is an area or not, */
    2525                /* so distinguish only between way and node here - for now */
    26                 if(style instanceof AreaElemStyle) {
    27                         key = key + "way";
    28                 }
    29                 else if(style instanceof LineElemStyle) {
    30                         key = key + "way";
    31                 }
    32                 else if(style instanceof IconElemStyle) {
    33                         key = key + "node";
    34                 }
     26                if (style instanceof AreaElemStyle)
     27                        key = "w";
     28                else if (style instanceof LineElemStyle)
     29                        key = "w";
     30                else if (style instanceof IconElemStyle)
     31                        key = "n";
     32                else
     33                        key = "";
     34
     35                if(v != null)
     36                        key += "n" + k + "=" + v;
     37                else if(b != null)
     38                        key += "b" + k  + "=" + OsmUtils.getNamedOsmBoolean(b);
     39                else
     40                        key += "x" + k;
     41
    3542                /* avoid duplicates - for now */
    3643                old_style = styles.get(key);
    37                 if(old_style == null) {
     44                if (old_style == null) {
    3845                        /* new key/value, insert */
    3946                        styles.put(key, style);
    4047                } else {
    41                         if(style.getMaxScale() < old_style.getMaxScale()) {
     48                        if (style.getMaxScale() < old_style.getMaxScale()) {
    4249                                /* existing larger scale key/value, replace */
    4350                                styles.remove(old_style);
     
    4754        }
    4855
    49         public ElemStyle getStyle (OsmPrimitive p)
     56        public ElemStyle get(OsmPrimitive p, Boolean area)
    5057        {
    51                 if(p.keys!=null)
    52                 {
     58                if (p.keys!=null) {
    5359                        String classname;
    5460                        String kv = null;
    55                        
    56                         if(p instanceof org.openstreetmap.josm.data.osm.Node) {
    57                                 classname = "node";
     61
     62                        if (p instanceof org.openstreetmap.josm.data.osm.Node) {
     63                                if(area)
     64                                        return null;
     65                                classname = "n";
    5866                        } else {
    59                                 classname = "way";
     67                                classname = "w";
    6068                        }
    6169                        Iterator<String> iterator = p.keys.keySet().iterator();
    62                         while(iterator.hasNext())       
     70                        while (iterator.hasNext())
    6371                        {
    6472                                String key = iterator.next();
    65                                 kv = key + "=" + p.keys.get(key) + classname;
    66                                 if(styles.containsKey(kv))
     73                                ElemStyle style = null;
     74                                kv = classname + "n" + key + "=" + p.keys.get(key);
     75                                if (styles.containsKey(kv))
    6776                                {
    68                                         return styles.get(kv);
     77                                        style = styles.get(kv);
     78                                        if(area == style instanceof AreaElemStyle)
     79                                                return style;
     80                                }
     81                                kv = classname + "b" + key + "=" + OsmUtils.getNamedOsmBoolean(p.keys.get(key));
     82                                if (styles.containsKey(kv))
     83                                {
     84                                        style = styles.get(kv);
     85                                        if(area == style instanceof AreaElemStyle)
     86                                                return style;
     87                                }
     88                                kv = classname + "x" + key;
     89                                if (styles.containsKey(kv))
     90                                {
     91                                        style = styles.get(kv);
     92                                        if(area == style instanceof AreaElemStyle)
     93                                                return style;
    6994                                }
    7095                        }
    71 /**
    72             // not a known key/value combination
    73                         boolean first_line = true;
     96                }
    7497
    75             // filter out trivial tags and show the rest
    76                         iterator = p.keys.keySet().iterator();
    77                         while(iterator.hasNext())       
    78                         {
    79                                 String key = iterator.next();
    80                                 kv = key + "=" + p.keys.get(key);
    81                                 if(     !kv.startsWith("created_by=") &&
    82                                         !kv.startsWith("converted_by=") &&
    83                                         !kv.startsWith("source=") &&
    84                                         !kv.startsWith("note=") &&
    85                                         !kv.startsWith("layer=") &&
    86                                         !kv.startsWith("bridge=") &&
    87                                         !kv.startsWith("tunnel=") &&
    88                                         !kv.startsWith("oneway=") &&
    89                                         !kv.startsWith("speedlimit=") &&
    90                                         !kv.startsWith("motorcar=") &&
    91                                         !kv.startsWith("horse=") &&
    92                                         !kv.startsWith("bicycle=") &&
    93                                         !kv.startsWith("foot=")
    94                                         ) {
    95                                                
    96                                         if (first_line) {
    97                                                 nr++;
    98                                                 //System.out.println("mappaint - rule not found[" + nr + "]: " + kv + " id:" + p.id);
    99                                         } else {
    100                                                 //System.out.println("mappaint - rule not found[" + nr + "]: " + kv);
    101                                         }
    102                                         first_line=false;
    103                                 }
    104                         }
    105 */             
    106                 }
    10798                return null;
    10899        }
     
    110101        public boolean isArea(OsmPrimitive p)
    111102        {
    112                 return getStyle(p) instanceof AreaElemStyle;
     103                return get(p, true) instanceof AreaElemStyle;
    113104        }
    114105}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r851 r874  
    99import org.openstreetmap.josm.Main;
    1010import org.openstreetmap.josm.data.osm.OsmPrimitive;
    11 import org.openstreetmap.josm.data.osm.OsmUtils;
     11import org.openstreetmap.josm.gui.mappaint.ElemStyles;
    1212import org.xml.sax.InputSource;
    1313import org.xml.sax.XMLReader;
     
    2020        private static String internalImageDir;
    2121        private static Boolean isInternal = false;
    22         private static HashMap<String, ElemStyle> styles = new HashMap<String, ElemStyle>();
     22        private static ElemStyles styles = new ElemStyles();
    2323       
    2424        public static String getStyleDir(){
     
    3333        public static Boolean isInternal(){
    3434                return isInternal;
     35        }
     36        public static void add(String k, String v, String b, ElemStyle style)
     37        {
     38                styles.add(k, v, b, style);
     39        }
     40        public static ElemStyle getStyle(OsmPrimitive osm)
     41        {
     42                ElemStyle s = styles.get(osm, true);
     43                if(s != null)
     44                {
     45                        ElemStyle l = styles.get(osm, false);
     46                        if(l != null && l instanceof LineElemStyle)
     47                        {
     48                                s = new AreaElemStyle((AreaElemStyle)s, (LineElemStyle)l);
     49                        }
     50                }
     51                else
     52                        s = styles.get(osm, false);
     53                return s;
     54        }
     55        public static boolean isArea(OsmPrimitive osm)
     56        {
     57                return styles.isArea(osm);
    3558        }
    3659
     
    93116        }
    94117
    95 //      static int nr = 0;
    96 
    97         public static void add (String k, String v, String b, ElemStyle style) {
    98                 ElemStyle  old_style;
    99                 String key;
    100 
    101                 /* unfortunately, there don't seem to be an efficient way to */
    102                 /* find out, if a given OsmPrimitive is an area or not, */
    103                 /* so distinguish only between way and node here - for now */
    104                 if (style instanceof AreaElemStyle)
    105                         key = "way";
    106                 else if (style instanceof LineElemStyle)
    107                         key = "way";
    108                 else if (style instanceof IconElemStyle)
    109                         key = "node";
    110                 else
    111                         key = "";
    112 
    113                 if(v != null)
    114                         key += "n" + k + "=" + v;
    115                 else if(b != null)
    116                         key += "b" + k  + "=" + OsmUtils.getNamedOsmBoolean(b);
    117                 else
    118                         key += "x" + k;
    119 
    120                 /* avoid duplicates - for now */
    121                 old_style = styles.get(key);
    122                 if (old_style == null) {
    123                         /* new key/value, insert */
    124                         styles.put(key, style);
    125                 } else {
    126                         if (style.getMaxScale() < old_style.getMaxScale()) {
    127                                 /* existing larger scale key/value, replace */
    128                                 styles.remove(old_style);
    129                                 styles.put(key, style);
    130                         }
    131                 }
    132         }
    133 
    134         public static ElemStyle getStyle (OsmPrimitive p)
    135         {
    136                 if (p.keys!=null) {
    137                         String classname;
    138                         String kv = null;
    139 
    140                         if (p instanceof org.openstreetmap.josm.data.osm.Node) {
    141                                 classname = "node";
    142                         } else {
    143                                 classname = "way";
    144                         }
    145                         Iterator<String> iterator = p.keys.keySet().iterator();
    146                         while (iterator.hasNext())     
    147                         {
    148                                 String key = iterator.next();
    149                                 kv = classname + "n" + key + "=" + p.keys.get(key);
    150                                 if (styles.containsKey(kv))
    151                                         return styles.get(kv);
    152                                 kv = classname + "b" + key + "=" + OsmUtils.getNamedOsmBoolean(p.keys.get(key));
    153                                 if (styles.containsKey(kv))
    154                                         return styles.get(kv);
    155                                 kv = classname + "x" + key;
    156                                 if (styles.containsKey(kv))
    157                                         return styles.get(kv);
    158                         }
    159 
    160                         // not a known key/value combination
    161 //                      boolean first_line = true;
    162 
    163                         // filter out trivial tags and show the rest
    164 //                      iterator = p.keys.keySet().iterator();
    165 //                      while (iterator.hasNext()) {
    166 //                              String key = iterator.next();
    167 //                              kv = key + "=" + p.keys.get(key);
    168 //                              if (!kv.startsWith("created_by=") &&
    169 //                                              !kv.startsWith("converted_by=") &&
    170 //                                              !kv.startsWith("source=") &&
    171 //                                              !kv.startsWith("note=") &&
    172 //                                              !kv.startsWith("layer=") &&
    173 //                                              !kv.startsWith("bridge=") &&
    174 //                                              !kv.startsWith("tunnel=") &&
    175 //                                              !kv.startsWith("oneway=") &&
    176 //                                              !kv.startsWith("speedlimit=") &&
    177 //                                              !kv.startsWith("motorcar=") &&
    178 //                                              !kv.startsWith("horse=") &&
    179 //                                              !kv.startsWith("bicycle=") &&
    180 //                                              !kv.startsWith("foot=")
    181 //                              ) {
    182 
    183 //                                      if (first_line) {
    184 //                                              nr++;
    185 //                                              System.out.println("mappaint - rule not found[" + nr + "]: " + kv + " id:" + p.id);
    186 //                                      } else {
    187 //                                              System.out.println("mappaint - rule not found[" + nr + "]: " + kv);
    188 //                                      }
    189 //                                      first_line=false;
    190 //                              }
    191 //                      }
    192                 }
    193 
    194                 return null;
    195         }
    196 
    197         public static boolean isArea(OsmPrimitive p)
    198         {
    199                 return getStyle(p) instanceof AreaElemStyle;
    200         }
    201118}
Note: See TracChangeset for help on using the changeset viewer.