Changeset 2659 in josm


Ignore:
Timestamp:
2009-12-19T18:12:03+01:00 (14 years ago)
Author:
jttt
Message:

Minor fixes in mappaint code

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

Legend:

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

    r2603 r2659  
    1111import java.awt.Font;
    1212import java.awt.FontMetrics;
    13 import java.awt.Graphics2D;
    1413import java.awt.Image;
    1514import java.awt.Point;
     
    9291    public ElemStyle getPrimitiveStyle(OsmPrimitive osm) {
    9392        if(!useStyleCache)
    94             return (styles != null) ? styles.get(osm) : null;
    95 
    96             if(osm.mappaintStyle == null && styles != null) {
    97                 osm.mappaintStyle = styles.get(osm);
    98                 if(osm instanceof Way) {
    99                     ((Way)osm).isMappaintArea = styles.isArea(osm);
    100                 }
    101             }
    102             return osm.mappaintStyle;
     93            return ((styles != null) ? styles.get(osm) : null);
     94
     95        if(osm.mappaintStyle == null && styles != null) {
     96            osm.mappaintStyle = styles.get(osm);
     97            if(osm instanceof Way) {
     98                ((Way)osm).isMappaintArea = styles.isArea(osm);
     99            }
     100        }
     101        return osm.mappaintStyle;
    103102    }
    104103
     
    255254            width = l.width;
    256255            realWidth = l.realWidth;
    257             dashed = l.dashed;
     256            dashed = l.getDashed();
    258257            dashedColor = l.dashedColor;
    259258        }
     
    292291
    293292        /* draw overlays under the way */
    294         if(l != null && l.overlays != null)
    295         {
    296             for(LineElemStyle s : l.overlays)
    297             {
    298                 if(!s.over)
    299                 {
     293        if(l != null && l.overlays != null) {
     294            for(LineElemStyle s : l.overlays) {
     295                if(!s.over) {
    300296                    lastN = null;
    301                     for(Node n : w.getNodes())
    302                     {
    303                         if(lastN != null)
    304                         {
     297                    for(Node n : w.getNodes()) {
     298                        if(lastN != null) {
    305299                            drawSeg(lastN, n, s.color != null  && !data.isSelected(w) ? s.color : color,
    306                                     false, s.getWidth(width), s.dashed, s.dashedColor);
     300                                    false, s.getWidth(width), s.getDashed(), s.dashedColor);
    307301                        }
    308302                        lastN = n;
     
    338332                        {
    339333                            drawSeg(lastN, n, s.color != null && !data.isSelected(w) ? s.color : color,
    340                                     false, s.getWidth(width), s.dashed, s.dashedColor);
     334                                    false, s.getWidth(width), s.getDashed(), s.dashedColor);
    341335                        }
    342336                        lastN = n;
     
    11561150        int w = icon.getIconWidth(), h=icon.getIconHeight();
    11571151        icon.paintIcon ( Main.map.mapView, g, p.x-w/2, p.y-h/2 );
    1158         if(showNames > dist)
    1159         {
     1152        if(showNames > dist && annotate) {
    11601153            String name = getNodeName(n);
    1161             if (name!=null && annotate)
    1162             {
     1154            if (name!=null) {
    11631155                if (inactive || n.isDisabled()) {
    11641156                    g.setColor(inactiveColor);
     
    12191211    protected void displaySegments(Color newColor, int newWidth, float newDash[], Color newDashedColor) {
    12201212        if (currentPath != null) {
    1221             Graphics2D g2d = (Graphics2D)g;
    1222             g2d.setColor(inactive ? inactiveColor : currentColor);
     1213            g.setColor(inactive ? inactiveColor : currentColor);
    12231214            if (currentStroke == null && useStrokes > dist) {
    12241215                if (currentDashed.length > 0) {
    1225                     try {
    1226                         g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,currentDashed,0));
    1227                     } catch (IllegalArgumentException e) {
    1228                         g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
    1229                     }
     1216                    g.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,currentDashed,0));
    12301217                } else {
    1231                     g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
    1232                 }
    1233             }
    1234             g2d.draw(currentPath);
     1218                    g.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
     1219                }
     1220            }
     1221            g.draw(currentPath);
    12351222
    12361223            if(currentDashedColor != null) {
    1237                 g2d.setColor(currentDashedColor);
     1224                g.setColor(currentDashedColor);
    12381225                if (currentStroke == null && useStrokes > dist) {
    12391226                    if (currentDashed.length > 0) {
     
    12421229                        currentDashedOffset[currentDashed.length-1] = currentDashed[0];
    12431230                        float offset = currentDashedOffset[0];
    1244                         try {
    1245                             g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,currentDashedOffset,offset));
    1246                         } catch (IllegalArgumentException e) {
    1247                             g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
    1248                         }
     1231                        g.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,currentDashedOffset,offset));
    12491232                    } else {
    1250                         g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
    1251                     }
    1252                 }
    1253                 g2d.draw(currentPath);
     1233                        g.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
     1234                    }
     1235                }
     1236                g.draw(currentPath);
    12541237            }
    12551238
    12561239            if(useStrokes > dist) {
    1257                 g2d.setStroke(new BasicStroke(1));
     1240                g.setStroke(new BasicStroke(1));
    12581241            }
    12591242
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r2578 r2659  
    88import java.awt.BasicStroke;
    99import java.awt.Color;
    10 import java.awt.Graphics;
    1110import java.awt.Graphics2D;
    1211import java.awt.Point;
     
    4544     * The environment to paint to.
    4645     */
    47     protected Graphics g;
     46    protected Graphics2D g;
    4847    /**
    4948     * MapView to get screen coordinates.
     
    9089    protected GeneralPath currentPath = new GeneralPath();
    9190
    92     Rectangle bbox = new Rectangle();
    93 
    9491    public void getColors()
    9592    {
     
    124121        getColors();
    125122
    126         ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
     123        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    127124                Main.pref.getBoolean("mappaint.use-antialiasing", false) ?
    128125                        RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
     
    386383                }
    387384
    388                 ((Graphics2D) g).draw(relatedWayStroke.createStrokedShape(path));
     385                g.draw(relatedWayStroke.createStrokedShape(path));
    389386            }
    390387        }
     
    477474    }
    478475
    479     public void setGraphics(Graphics g) {
     476    public void setGraphics(Graphics2D g) {
    480477        this.g = g;
    481478    }
     
    491488        if (currentPath != null) {
    492489            g.setColor(currentColor);
    493             ((Graphics2D) g).draw(currentPath);
     490            g.draw(currentPath);
    494491            currentPath = new GeneralPath();
    495492            currentColor = newColor;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyleHandler.java

    r2626 r2659  
    1414public class ElemStyleHandler extends DefaultHandler
    1515{
    16     boolean inDoc, inRule, inCondition, inElemStyle, inLine, inLineMod, inIcon, inArea, inScaleMax, inScaleMin;
     16    boolean inDoc, inRule, inCondition, inLine, inLineMod, inIcon, inArea, inScaleMax, inScaleMin;
    1717    boolean hadLine, hadLineMod, hadIcon, hadArea;
    1818    ElemStyles styles;
     
    4444    public ElemStyleHandler(String name) {
    4545        styleName = name;
    46         inDoc=inRule=inCondition=inElemStyle=inLine=inIcon=inArea=false;
     46        inDoc=inRule=inCondition=inLine=inIcon=inArea=false;
    4747        rule.init();
    4848        styles = MapPaintStyles.getStyles();
     
    105105                line.realWidth=Integer.parseInt(atts.getValue(count));
    106106            } else if (atts.getQName(count).equals("dashed")) {
    107                 try
    108                 {
     107                float[] dashed;
     108                try {
    109109                    String[] parts = atts.getValue(count).split(",");
    110                     line.dashed = new float[parts.length];
     110                    dashed = new float[parts.length];
    111111                    for (int i = 0; i < parts.length; i++) {
    112                         line.dashed[i] = (Integer.parseInt(parts[i]));
     112                        dashed[i] = (Integer.parseInt(parts[i]));
    113113                    }
    114114                } catch (NumberFormatException nfe) {
    115                     boolean dashed=Boolean.parseBoolean(atts.getValue(count));
    116                     if(dashed) {
    117                         line.dashed = new float[]{9};
    118                     }
    119                 }
     115                    boolean isDashed = Boolean.parseBoolean(atts.getValue(count));
     116                    if(isDashed) {
     117                        dashed = new float[]{9};
     118                    } else {
     119                        dashed = new float[0];
     120                    }
     121                }
     122                line.setDashed(dashed);
    120123            } else if (atts.getQName(count).equals("dashedcolour")) {
    121124                line.dashedColor=convertColor(atts.getValue(count));
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r1747 r2659  
    33import java.awt.Color;
    44import java.util.Collection;
     5
     6import org.openstreetmap.josm.tools.I18n;
    57
    68public class LineElemStyle extends ElemStyle implements Comparable<LineElemStyle>
     
    911    public int realWidth; //the real width of this line in meter
    1012    public Color color;
    11     public float[] dashed;
     13    private float[] dashed;
    1214    public Color dashedColor;
    1315
     
    4951        this.overlays = overlays;
    5052        this.code = s.code;
    51         for (LineElemStyle o : overlays)
     53        for (LineElemStyle o : overlays) {
    5254            this.code += o.code;
     55        }
    5356    }
    5457
     
    7275    {
    7376        int res;
    74         if(widthMode == WidthMode.ABSOLUTE)
     77        if(widthMode == WidthMode.ABSOLUTE) {
    7578            res = width;
    76         else if(widthMode == WidthMode.OFFSET)
     79        } else if(widthMode == WidthMode.OFFSET) {
    7780            res = ref + width;
    78         else
     81        } else
    7982        {
    80             if(width < 0)
     83            if(width < 0) {
    8184                res = 0;
    82             else
     85            } else {
    8386                res = ref*width/100;
     87            }
    8488        }
    8589        return res <= 0 ? 1 : res;
    8690    }
    8791
    88     public int compareTo(LineElemStyle s)
    89     {
     92    public int compareTo(LineElemStyle s) {
    9093        if(s.priority != priority)
    9194            return s.priority > priority ? 1 : -1;
    92         if(!over && s.over)
    93             return -1;
    94         // we have no idea how to order other objects :-)
    95         return 0;
     95            if(!over && s.over)
     96                return -1;
     97            // we have no idea how to order other objects :-)
     98            return 0;
     99    }
     100
     101    public float[] getDashed() {
     102        return dashed;
     103    }
     104
     105    public void setDashed(float[] dashed) {
     106        if (dashed.length == 0) {
     107            this.dashed = dashed;
     108            return;
     109        }
     110
     111        boolean found = false;
     112        for (int i=0; i<dashed.length; i++) {
     113            if (dashed[i] > 0) {
     114                found = true;
     115            }
     116            if (dashed[i] < 0) {
     117                System.out.println(I18n.tr("Illegal dash pattern, values must be positive"));
     118            }
     119        }
     120        if (found) {
     121            this.dashed = dashed;
     122        } else {
     123            System.out.println(I18n.tr("Illegal dash pattern, at least one value must be > 0"));
     124        }
    96125    }
    97126}
Note: See TracChangeset for help on using the changeset viewer.