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/data/osm/visitor
Files:
2 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;
Note: See TracChangeset for help on using the changeset viewer.