Ignore:
Timestamp:
2011-05-15T23:51:25+02:00 (13 years ago)
Author:
bastiK
Message:

PaintVisitor refactoring, includes hook for external MapRenderers (author: Gubaer)

File:
1 moved

Legend:

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

    r4081 r4087  
    11/* License: GPL. Copyright 2007 by Immanuel Scholz and others */
    22package org.openstreetmap.josm.data.osm.visitor.paint;
    3 
    4 /* To enable debugging or profiling remove the double / signs */
    53
    64import java.awt.BasicStroke;
     
    2018import org.openstreetmap.josm.data.Bounds;
    2119import org.openstreetmap.josm.data.osm.BBox;
     20import org.openstreetmap.josm.data.osm.Changeset;
    2221import org.openstreetmap.josm.data.osm.DataSet;
    2322import org.openstreetmap.josm.data.osm.Node;
     
    2625import org.openstreetmap.josm.data.osm.RelationMember;
    2726import org.openstreetmap.josm.data.osm.Way;
    28 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
     27import org.openstreetmap.josm.data.osm.visitor.Visitor;
    2928import org.openstreetmap.josm.gui.NavigatableComponent;
    3029
    3130/**
    32  * A visitor that paints a simple scheme of every primitive it visits to a
     31 * A map renderer that paints a simple scheme of every primitive it visits to a
    3332 * previous set graphic environment.
    3433 *
    3534 * @author imi
    3635 */
    37 public class SimplePaintVisitor extends AbstractVisitor implements PaintVisitor {
    38     /**
    39      * The environment to paint to.
    40      */
    41     protected Graphics2D g;
    42     /**
    43      * MapView to get screen coordinates.
    44      */
    45     protected NavigatableComponent nc;
    46 
    47     public boolean inactive;
     36public class WireframeMapRenderer extends AbstractMapRenderer implements Visitor {
    4837
    4938    /**
     
    8574    protected GeneralPath currentPath = new GeneralPath();
    8675
     76    /**
     77     * {@inheritDoc}
     78     */
     79    public WireframeMapRenderer(Graphics2D g, NavigatableComponent nc, boolean isInactiveMode) {
     80        super(g, nc, isInactiveMode);
     81    }
     82
    8783    public void getColors()
    8884    {
     
    132128
    133129    DataSet ds;
    134     public void visitAll(DataSet data, boolean virtual, Bounds bounds) {
     130    public void render(DataSet data, boolean virtual, Bounds bounds) {
    135131        BBox bbox = new BBox(bounds);
    136132        this.ds = data;
    137         //boolean profiler = Main.pref.getBoolean("simplepaint.profiler",false);
    138         //long profilerStart = java.lang.System.currentTimeMillis();
    139         //long profilerLast = profilerStart;
    140         //int profilerN = 0;
    141         //if(profiler)
    142         //    System.out.println("Simplepaint Profiler");
    143 
    144133        getSettings(virtual);
    145 
    146         //if(profiler)
    147         //{
    148         //    System.out.format("Prepare  : %4dms\n", (java.lang.System.currentTimeMillis()-profilerLast));
    149         //    profilerLast = java.lang.System.currentTimeMillis();
    150         //}
    151134
    152135        /* draw tagged ways first, then untagged ways. takes
    153136           time to iterate through list twice, OTOH does not
    154137           require changing the colour while painting... */
    155         //profilerN = 0;
    156138        for (final OsmPrimitive osm: data.searchRelations(bbox)) {
    157139            if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isDisabledAndHidden()) {
    158140                osm.visit(this);
    159                 //        profilerN++;
    160             }
    161         }
    162 
    163         //if(profiler)
    164         //{
    165         //    System.out.format("Relations: %4dms, n=%5d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
    166         //    profilerLast = java.lang.System.currentTimeMillis();
    167         //}
    168 
    169         //profilerN = 0;
     141            }
     142        }
     143
    170144        for (final OsmPrimitive osm:data.searchWays(bbox)){
    171145            if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isDisabledAndHidden() && osm.isTagged()) {
    172146                osm.visit(this);
    173                 //        profilerN++;
    174147            }
    175148        }
     
    179152            if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isDisabledAndHidden() && !osm.isTagged()) {
    180153                osm.visit(this);
    181                 //        profilerN++;
    182154            }
    183155        }
    184156        displaySegments();
    185 
    186         //if(profiler)
    187         //{
    188         //    System.out.format("Ways     : %4dms, n=%5d\n",
    189         //        (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
    190         //    profilerLast = java.lang.System.currentTimeMillis();
    191         //}
    192 
    193         //profilerN = 0;
    194157        for (final OsmPrimitive osm : data.getSelected()) {
    195158            if (!osm.isDeleted()) {
    196159                osm.visit(this);
    197                 //        profilerN++;
    198160            }
    199161        }
    200162        displaySegments();
    201163
    202         //if(profiler)
    203         //{
    204         //    System.out.format("Selected : %4dms, n=%5d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
    205         //    profilerLast = java.lang.System.currentTimeMillis();
    206         //}
    207 
    208         //profilerN = 0;
    209164        for (final OsmPrimitive osm: data.searchNodes(bbox)) {
    210165            if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isDisabledAndHidden())
    211166            {
    212167                osm.visit(this);
    213                 //        profilerN++;
    214             }
    215         }
    216 
    217         //if(profiler)
    218         //{
    219         //    System.out.format("Nodes    : %4dms, n=%5d\n",
    220         //        (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
    221         //    profilerLast = java.lang.System.currentTimeMillis();
    222         //}
    223 
     168            }
     169        }
    224170        drawVirtualNodes(data.searchWays(bbox));
    225 
    226         //if(profiler)
    227         //{
    228         //    System.out.format("All      : %4dms\n", (profilerLast-profilerStart));
    229         //}
    230171    }
    231172
     
    248189            Color color;
    249190
    250             if (inactive || n.isDisabled()) {
     191            if (isInactiveMode || n.isDisabled()) {
    251192                color = inactiveColor;
    252193            } else if (ds.isSelected(n)) {
     
    339280        Color wayColor;
    340281
    341         if (inactive || w.isDisabled()) {
     282        if (isInactiveMode || w.isDisabled()) {
    342283            wayColor = inactiveColor;
    343284        } else if(w.isHighlighted()) {
     
    372313
    373314        Color col;
    374         if (inactive || r.isDisabled()) {
     315        if (isInactiveMode || r.isDisabled()) {
    375316            col = inactiveColor;
    376317        } else if (ds.isSelected(r)) {
     
    415356        }
    416357    }
     358
     359    @Override
     360    public void visit(Changeset cs) {/* ignore */}
    417361
    418362    /**
     
    519463    }
    520464
    521     public void setGraphics(Graphics2D g) {
    522         this.g = g;
    523     }
    524 
    525     public void setNavigatableComponent(NavigatableComponent nc) {
    526         this.nc = nc;
    527     }
    528 
    529465    protected void displaySegments() {
    530466        displaySegments(null);
     
    538474        }
    539475    }
    540 
    541     public void setInactive(boolean inactive) {
    542         this.inactive = inactive;
    543     }
    544476}
Note: See TracChangeset for help on using the changeset viewer.