Changeset 4087 in josm


Ignore:
Timestamp:
May 15, 2011 11:51:25 PM (2 years ago)
Author:
bastiK
Message:

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

Location:
trunk
Files:
3 added
1 deleted
15 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/WireframeToggleAction.java

    r3894 r4087  
    66import java.awt.event.ActionEvent; 
    77import java.awt.event.KeyEvent; 
    8 import java.util.ArrayList; 
    9 import java.util.List; 
    10  
    11 import javax.swing.ButtonModel; 
    128 
    139import org.openstreetmap.josm.Main; 
     10import org.openstreetmap.josm.data.osm.visitor.paint.MapRendererFactory; 
     11import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer; 
     12import org.openstreetmap.josm.data.osm.visitor.paint.WireframeMapRenderer; 
    1413import org.openstreetmap.josm.tools.Shortcut; 
    1514 
    1615public class WireframeToggleAction extends JosmAction { 
    17     private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>(); 
    18     //FIXME: replace with property Action.SELECTED_KEY when migrating to 
    19     // Java 6 
    20     private boolean selected; 
    2116    public WireframeToggleAction() { 
    2217        super( 
     
    2722                true /* register shortcut */ 
    2823        ); 
    29         selected = Main.pref.getBoolean("draw.wireframe", false); 
    30         notifySelectedState(); 
     24        putValue(SELECTED_KEY, MapRendererFactory.getInstance().isWireframeMapRendererActive()); 
    3125    } 
    3226 
    33     public void addButtonModel(ButtonModel model) { 
    34         if (model != null && !buttonModels.contains(model)) { 
    35             buttonModels.add(model); 
    36             model.setSelected(selected); 
     27    public void toggleSelectedState() { 
     28        boolean selected = (Boolean)getValue(SELECTED_KEY); 
     29 
     30        if (selected){ 
     31            MapRendererFactory.getInstance().activate(WireframeMapRenderer.class); 
     32        } else { 
     33            MapRendererFactory.getInstance().activate(StyledMapRenderer.class); 
    3734        } 
    38     } 
    39  
    40     public void removeButtonModel(ButtonModel model) { 
    41         if (model != null && buttonModels.contains(model)) { 
    42             buttonModels.remove(model); 
    43         } 
    44     } 
    45  
    46     protected void notifySelectedState() { 
    47         for (ButtonModel model: buttonModels) { 
    48             if (model.isSelected() != selected) { 
    49                 model.setSelected(selected); 
    50             } 
    51         } 
    52     } 
    53  
    54     protected void toggleSelectedState() { 
    55         selected = !selected; 
    56         Main.pref.put("draw.wireframe", selected); 
    57         notifySelectedState(); 
    5835        if (Main.map != null) { 
    5936            Main.map.mapView.repaint(); 
    6037        } 
    6138    } 
     39 
    6240    public void actionPerformed(ActionEvent e) { 
    6341        toggleSelectedState(); 
     
    6644    @Override 
    6745    protected void updateEnabledState() { 
    68         setEnabled(Main.map != null && Main.main.getEditLayer() != null); 
    69     } 
    70  
    71     public boolean isSelected() { 
    72         return selected; 
     46        setEnabled(Main.main.getEditLayer() != null); 
    7347    } 
    7448} 
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r4039 r4087  
    3737import org.openstreetmap.josm.data.osm.WaySegment; 
    3838import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor; 
    39 import org.openstreetmap.josm.data.osm.visitor.paint.SimplePaintVisitor; 
     39import org.openstreetmap.josm.data.osm.visitor.paint.WireframeMapRenderer; 
    4040import org.openstreetmap.josm.gui.ExtendedDialog; 
    4141import org.openstreetmap.josm.gui.MapFrame; 
     
    298298                Point2D p1 = mv.getPoint2D(wnp.a = w.getNode(ws.lowerIndex)); 
    299299                Point2D p2 = mv.getPoint2D(wnp.b = w.getNode(ws.lowerIndex + 1)); 
    300                 if (SimplePaintVisitor.isLargeSegment(p1, p2, virtualSpace)) { 
     300                if (WireframeMapRenderer.isLargeSegment(p1, p2, virtualSpace)) { 
    301301                    Point2D pc = new Point2D.Double((p1.getX() + p2.getX()) / 2, (p1.getY() + p2.getY()) / 2); 
    302302                    if (p.distanceSq(pc) < virtualSnapDistSq) { 
  • trunk/src/org/openstreetmap/josm/data/Bounds.java

    r4065 r4087  
    205205    } 
    206206 
     207    /** 
     208     * <p>Replies true, if this bounds are <em>collapsed</em>, i.e. if the min 
     209     * and the max corner are equal.</p> 
     210     *  
     211     * @return true, if this bounds are <em>collapsed</em> 
     212     */ 
     213    public boolean isCollapsed() { 
     214        return getMin().equals(getMax()); 
     215    } 
     216 
    207217    @Override 
    208218    public int hashCode() { 
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r4064 r4087  
    2020import java.util.concurrent.locks.ReentrantReadWriteLock; 
    2121 
     22import org.openstreetmap.josm.data.Bounds; 
    2223import org.openstreetmap.josm.data.SelectionChangedListener; 
    2324import org.openstreetmap.josm.data.coor.EastNorth; 
     
    145146    public LinkedList<Collection<? extends OsmPrimitive>> getSelectionHistory() { 
    146147        return selectionHistory; 
    147     }  
     148    } 
    148149 
    149150    /** 
     
    151152     */ 
    152153    public void clearSelectionHistory() { 
    153             selectionHistory.clear(); 
    154         } 
     154        selectionHistory.clear(); 
     155    } 
    155156 
    156157    /** 
     
    10411042        } 
    10421043    } 
     1044 
     1045    /** 
     1046     * <p>Replies the list of data source bounds.</p> 
     1047     *  
     1048     * <p>Dataset maintains a list of data sources which have been merged into the 
     1049     * data set. Each of these sources can optionally declare a bounding box of the 
     1050     * data it supplied to the dataset.</p> 
     1051     *  
     1052     * <p>This method replies the list of defined (non {@code null}) bounding boxes.</p> 
     1053     *  
     1054     * @return the list of data source bounds. An empty list, if no non-null data source 
     1055     * bounds are defined. 
     1056     */ 
     1057    public List<Bounds> getDataSourceBounds() { 
     1058        List<Bounds> ret = new ArrayList<Bounds>(dataSources.size()); 
     1059        for (DataSource ds : dataSources) { 
     1060            if (ds.bounds != null) { 
     1061                ret.add(ds.bounds); 
     1062            } 
     1063        } 
     1064        return ret; 
     1065    } 
    10431066} 
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java

    r4042 r4087  
    8080    public MapPainter(MapPaintSettings settings, Graphics2D g, 
    8181            boolean inactive, NavigatableComponent nc, boolean virtual, 
    82             double circum, boolean leftHandTraffic) 
    83     { 
     82            double circum, boolean leftHandTraffic){ 
    8483        this.settings = settings; 
    8584        this.g = g; 
     
    163162                            final double sy = l * (p1.y - p2.y); 
    164163 
    165                             double tmp = p2.x + cosPHI * sx - sinPHI * sy; 
    166164                            orientationArrows.moveTo (p2.x + cosPHI * sx - sinPHI * sy, p2.y + sinPHI * sx + cosPHI * sy); 
    167165                            orientationArrows.lineTo(p2.x, p2.y); 
     
    699697                    continue; 
    700698                } 
    701                 drawArea(r, p,  
     699                drawArea(r, p, 
    702700                        pd.selected ? settings.getRelationSelectedColor(color.getAlpha()) : color, 
    703                         fillImage, fillImageAlpha, text); 
     701                                fillImage, fillImageAlpha, text); 
    704702            } 
    705703        } 
     
    985983    } 
    986984 
    987     public boolean isInactive() { 
    988         return inactive; 
    989     } 
    990  
    991985    public boolean isShowNames() { 
    992986        return showNames; 
     
    1001995    } 
    1002996 
     997    public boolean isInactiveMode() { 
     998        return inactive; 
     999    } 
    10031000} 
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r4081 r4087  
    2424import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList; 
    2525 
    26 public class MapPaintVisitor implements PaintVisitor { 
    27  
    28     private Graphics2D g; 
    29     private boolean inactive; 
    30     private NavigatableComponent nc; 
     26/** 
     27 * <p>A map renderer which renders a map according to style rules in a set of style sheets.</p> 
     28 *  
     29 */ 
     30public class StyledMapRenderer extends AbstractMapRenderer{ 
    3131 
    3232    private ElemStyles styles; 
     
    6969                z_index2 += 600f; 
    7070            } 
    71              
     71 
    7272            int d1 = Float.compare(z_index1, z_index2); 
    7373            if (d1 != 0) 
    7474                return d1; 
    75              
     75 
    7676            // simple node on top of icons and shapes 
    7777            if (this.style == NodeElemStyle.SIMPLE_NODE_ELEMSTYLE && other.style != NodeElemStyle.SIMPLE_NODE_ELEMSTYLE) 
     
    7979            if (this.style != NodeElemStyle.SIMPLE_NODE_ELEMSTYLE && other.style == NodeElemStyle.SIMPLE_NODE_ELEMSTYLE) 
    8080                return -1; 
    81              
     81 
    8282            // newer primitives to the front 
    8383            long id = this.osm.getUniqueId() - other.osm.getUniqueId(); 
     
    8686            if (id < 0) 
    8787                return -1; 
    88              
     88 
    8989            return Float.compare(this.style.object_z_index, other.style.object_z_index); 
    9090        } 
    9191    } 
    92      
     92 
    9393    private class StyleCollector { 
    9494        private final boolean drawArea; 
     
    137137            for (StyleRecord r : styleElems) { 
    138138                r.style.paintPrimitive( 
    139                         r.osm,  
    140                         paintSettings,  
    141                         painter,  
    142                         (r.flags & FLAG_SELECTED) != 0,  
     139                        r.osm, 
     140                        paintSettings, 
     141                        painter, 
     142                        (r.flags & FLAG_SELECTED) != 0, 
    143143                        (r.flags & FLAG_MEMBER_OF_SELECTED) != 0 
    144144                ); 
     
    147147    } 
    148148 
    149     public void visitAll(final DataSet data, boolean virtual, Bounds bounds) { 
    150         //long start = System.currentTimeMillis(); 
    151         BBox bbox = new BBox(bounds); 
    152  
    153         styles = MapPaintStyles.getStyles(); 
    154  
    155         this.paintSettings = MapPaintSettings.INSTANCE; 
    156  
    157         circum = nc.getDist100Pixel(); 
    158         boolean drawArea = circum <= Main.pref.getInteger("mappaint.fillareas", 10000000); 
    159         boolean drawMultipolygon = drawArea && Main.pref.getBoolean("mappaint.multipolygon", true); 
    160         styles.setDrawMultipolygon(drawMultipolygon); 
    161         boolean drawRestriction = Main.pref.getBoolean("mappaint.restriction", true); 
    162         boolean leftHandTraffic = Main.pref.getBoolean("mappaint.lefthandtraffic", false); 
    163  
    164         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
    165                 Main.pref.getBoolean("mappaint.use-antialiasing", true) ? 
    166                         RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); 
    167  
    168         this.painter = new MapPainter(paintSettings, g, inactive, nc, virtual, circum, leftHandTraffic); 
    169  
    170         StyleCollector sc = new StyleCollector(drawArea, drawMultipolygon, drawRestriction); 
    171  
     149    /** 
     150     * {@inheritDoc} 
     151     */ 
     152    public StyledMapRenderer(Graphics2D g, NavigatableComponent nc, boolean isInactiveMode) { 
     153        super(g, nc, isInactiveMode); 
     154    } 
     155 
     156    private void collectNodeStyles(DataSet data, StyleCollector sc, BBox bbox) { 
    172157        for (final Node n: data.searchNodes(bbox)) { 
    173158            if (n.isDrawable()) { 
     
    183168            } 
    184169        } 
     170    } 
     171 
     172    private void collectWayStyles(DataSet data, StyleCollector sc, BBox bbox) { 
    185173        for (final Way w : data.searchWays(bbox)) { 
    186174            if (w.isDrawable()) { 
     
    196184            } 
    197185        } 
     186    } 
     187 
     188    private void collectRelationStyles(DataSet data, StyleCollector sc, BBox bbox) { 
    198189        for (Relation r: data.searchRelations(bbox)) { 
    199190            if (r.isDrawable()) { 
     
    207198            } 
    208199        } 
    209  
     200    } 
     201 
     202    @Override 
     203    public void render(final DataSet data, boolean renderVirtualNodes, Bounds bounds) { 
     204        //long start = System.currentTimeMillis(); 
     205        BBox bbox = new BBox(bounds); 
     206 
     207        styles = MapPaintStyles.getStyles(); 
     208 
     209        this.paintSettings = MapPaintSettings.INSTANCE; 
     210 
     211        circum = nc.getDist100Pixel(); 
     212        boolean drawArea = circum <= Main.pref.getInteger("mappaint.fillareas", 10000000); 
     213        boolean drawMultipolygon = drawArea && Main.pref.getBoolean("mappaint.multipolygon", true); 
     214        styles.setDrawMultipolygon(drawMultipolygon); 
     215        boolean drawRestriction = Main.pref.getBoolean("mappaint.restriction", true); 
     216        boolean leftHandTraffic = Main.pref.getBoolean("mappaint.lefthandtraffic", false); 
     217 
     218        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
     219                Main.pref.getBoolean("mappaint.use-antialiasing", true) ? 
     220                        RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); 
     221 
     222        this.painter = new MapPainter(paintSettings, g, isInactiveMode, nc, renderVirtualNodes, circum, leftHandTraffic); 
     223 
     224        StyleCollector sc = new StyleCollector(drawArea, drawMultipolygon, drawRestriction); 
     225        collectNodeStyles(data, sc, bbox); 
     226        collectWayStyles(data, sc, bbox); 
     227        collectRelationStyles(data, sc, bbox); 
    210228        //long phase1 = System.currentTimeMillis(); 
    211  
    212229        sc.drawAll(); 
    213230        sc = null; 
    214  
    215231        painter.drawVirtualNodes(data.searchWays(bbox)); 
    216          
     232 
    217233        //long now = System.currentTimeMillis(); 
    218234        //System.err.println(String.format("PAINTING TOOK %d [PHASE1 took %d] (at scale %s)", now - start, phase1 - start, circum)); 
    219235    } 
    220  
    221     public void setGraphics(Graphics2D g) { 
    222         this.g = g; 
    223     } 
    224  
    225     public void setInactive(boolean inactive) { 
    226         this.inactive = inactive; 
    227     } 
    228  
    229     public void setNavigatableComponent(NavigatableComponent nc) { 
    230         this.nc = nc; 
    231     } 
    232236} 
  • 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} 
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r4086 r4087  
    277277        viewMenu.add(wireframe); 
    278278        wireframe.setAccelerator(wireFrameToggleAction.getShortcut().getKeyStroke()); 
    279         wireFrameToggleAction.addButtonModel(wireframe.getModel()); 
    280279 
    281280        viewMenu.addSeparator(); 
  • trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java

    r4072 r4087  
    1313import java.awt.Rectangle; 
    1414import java.awt.event.ActionEvent; 
    15 import java.awt.event.ActionListener; 
    1615import java.awt.event.KeyEvent; 
    1716import java.awt.event.MouseEvent; 
     
    2827 
    2928import javax.swing.AbstractAction; 
    30 import javax.swing.DefaultButtonModel; 
    3129import javax.swing.DefaultListSelectionModel; 
    3230import javax.swing.JCheckBox; 
     
    9997        JLabel wfLabel = new JLabel(tr("Wireframe View"), ImageProvider.get("dialogs/mappaint", "wireframe_small"), JLabel.HORIZONTAL); 
    10098        wfLabel.setFont(wfLabel.getFont().deriveFont(Font.PLAIN)); 
    101  
    102         cbWireframe.setModel(new DefaultButtonModel() { 
    103             @Override 
    104             public void setSelected(boolean b) { 
    105                 super.setSelected(b); 
    106                 tblStyles.setEnabled(!b); 
    107                 onoffAction.updateEnabledState(); 
    108                 upAction.updateEnabledState(); 
    109                 downAction.updateEnabledState(); 
    110             } 
    111         }); 
    112         cbWireframe.addActionListener(new ActionListener() { 
    113             public void actionPerformed(ActionEvent e) { 
    114                 Main.main.menu.wireFrameToggleAction.actionPerformed(null); 
    115             } 
    116         }); 
     99        cbWireframe.setFont(cbWireframe.getFont().deriveFont(Font.PLAIN)); 
     100        cbWireframe.setAction(Main.main.menu.wireFrameToggleAction); 
    117101        cbWireframe.setBorder(new EmptyBorder(new Insets(1,1,1,1))); 
    118  
     102        cbWireframe.setText(""); 
    119103        tblStyles = new StylesTable(model); 
    120104        tblStyles.setSelectionModel(selectionModel= new DefaultListSelectionModel()); 
     
    130114        tblStyles.setShowGrid(false); 
    131115        tblStyles.setIntercellSpacing(new Dimension(0, 0)); 
     116        cbWireframe.addChangeListener(tblStyles); 
    132117 
    133118        JPanel p = new JPanel(new GridBagLayout()); 
     
    137122 
    138123        pnl.add(new JScrollPane(p), BorderLayout.CENTER); 
    139  
    140124        pnl.add(buildButtonRow(), BorderLayout.SOUTH); 
    141  
    142125        add(pnl, BorderLayout.CENTER); 
    143126    } 
    144127 
    145     protected static class StylesTable extends JTable { 
     128    protected class StylesTable extends JTable implements ChangeListener{ 
    146129 
    147130        public StylesTable(TableModel dm) { 
     
    157140            rect.setLocation(rect.x - pt.x, rect.y - pt.y); 
    158141            viewport.scrollRectToVisible(rect); 
     142        } 
     143 
     144        @Override 
     145        public void stateChanged(ChangeEvent e) { 
     146            setEnabled(!cbWireframe.isSelected()); 
    159147        } 
    160148    } 
     
    170158        selectionModel.addListSelectionListener(upAction); 
    171159        selectionModel.addListSelectionListener(downAction); 
     160        cbWireframe.addChangeListener(onoffAction); 
     161        cbWireframe.addChangeListener(upAction); 
     162        cbWireframe.addChangeListener(downAction); 
     163 
    172164        p.add(new SideButton(onoffAction)); 
    173165        p.add(new SideButton(upAction)); 
     
    180172    @Override 
    181173    public void showNotify() { 
     174        cbWireframe.setAction(Main.main.menu.wireFrameToggleAction); 
    182175        MapPaintStyles.addMapPaintSylesUpdateListener(model); 
    183         Main.main.menu.wireFrameToggleAction.addButtonModel(cbWireframe.getModel()); 
    184176    } 
    185177 
    186178    @Override 
    187179    public void hideNotify() { 
    188         Main.main.menu.wireFrameToggleAction.removeButtonModel(cbWireframe.getModel()); 
     180        cbWireframe.setAction(null); 
    189181        MapPaintStyles.removeMapPaintSylesUpdateListener(model); 
    190182    } 
     
    304296    } 
    305297 
    306     protected class OnOffAction extends AbstractAction implements ListSelectionListener { 
     298    protected abstract class EventListeningAction extends AbstractAction implements ListSelectionListener, ChangeListener { 
     299 
     300        protected abstract void updateEnabledState(); 
     301 
     302        @Override 
     303        public void valueChanged(ListSelectionEvent e) { 
     304            updateEnabledState(); 
     305        } 
     306 
     307        @Override 
     308        public void stateChanged(ChangeEvent e) { 
     309            updateEnabledState(); 
     310        } 
     311    } 
     312 
     313    protected class OnOffAction extends EventListeningAction { 
    307314        public OnOffAction() { 
    308315            putValue(SHORT_DESCRIPTION, tr("Turn selected styles on or off")); 
     
    311318        } 
    312319 
     320        @Override 
    313321        protected void updateEnabledState() { 
    314322            setEnabled(!cbWireframe.isSelected() && tblStyles.getSelectedRowCount() > 0); 
    315         } 
    316  
    317         @Override 
    318         public void valueChanged(ListSelectionEvent e) { 
    319             updateEnabledState(); 
    320323        } 
    321324 
     
    334337     * The action to move down the currently selected entries in the list. 
    335338     */ 
    336     protected class MoveUpDownAction extends AbstractAction implements ListSelectionListener { 
     339    protected class MoveUpDownAction extends EventListeningAction { 
    337340 
    338341        final int increment; 
     
    345348        } 
    346349 
     350        @Override 
    347351        public void updateEnabledState() { 
    348352            int[] sel = tblStyles.getSelectedRows(); 
     
    360364            } 
    361365            model.ensureSelectedIsVisible(); 
    362         } 
    363  
    364         public void valueChanged(ListSelectionEvent e) { 
    365             updateEnabledState(); 
    366366        } 
    367367    } 
     
    503503                    error = true; 
    504504                } finally { 
    505                     if (bis != null) { 
    506                         try { 
    507                             bis.close(); 
    508                         } catch (IOException e) { 
    509                             e.printStackTrace(); 
    510                         } 
    511                     } 
    512                     if (bos != null) { 
    513                         try { 
    514                             bos.close(); 
    515                         } catch (IOException e) { 
    516                             e.printStackTrace(); 
    517                         } 
    518                     } 
     505                    Utils.close(bis); 
     506                    Utils.close(bos); 
    519507                } 
    520508            } 
     
    648636                txtSource.append("<ERROR: failed to read file!>"); 
    649637            } finally { 
    650                 try { 
    651                     is.close(); 
    652                 } catch (IOException ex) { 
    653                 } 
     638                Utils.close(is); 
    654639            } 
    655640        } 
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r4046 r4087  
    4242import org.openstreetmap.josm.data.conflict.Conflict; 
    4343import org.openstreetmap.josm.data.conflict.ConflictCollection; 
    44 import org.openstreetmap.josm.data.coor.EastNorth; 
    4544import org.openstreetmap.josm.data.coor.LatLon; 
    4645import org.openstreetmap.josm.data.gpx.GpxData; 
     
    6160import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 
    6261import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 
    63 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintVisitor; 
    64 import org.openstreetmap.josm.data.osm.visitor.paint.PaintVisitor; 
    65 import org.openstreetmap.josm.data.osm.visitor.paint.SimplePaintVisitor; 
     62import org.openstreetmap.josm.data.osm.visitor.paint.MapRendererFactory; 
     63import org.openstreetmap.josm.data.osm.visitor.paint.Rendering; 
    6664import org.openstreetmap.josm.data.validation.TestError; 
    6765import org.openstreetmap.josm.gui.HelpAwareOptionPane; 
     
    241239            Area a = new Area(b); 
    242240 
    243             // now succesively subtract downloaded areas 
    244             for (DataSource src : data.dataSources) { 
    245                 if (src.bounds != null && !src.bounds.getMin().equals(src.bounds.getMax())) { 
    246                     EastNorth en1 = mv.getProjection().latlon2eastNorth(src.bounds.getMin()); 
    247                     EastNorth en2 = mv.getProjection().latlon2eastNorth(src.bounds.getMax()); 
    248                     Point p1 = mv.getPoint(en1); 
    249                     Point p2 = mv.getPoint(en2); 
    250                     Rectangle r = new Rectangle(Math.min(p1.x, p2.x),Math.min(p1.y, p2.y),Math.abs(p2.x-p1.x),Math.abs(p2.y-p1.y)); 
    251                     a.subtract(new Area(r)); 
     241            // now successively subtract downloaded areas 
     242            for (Bounds bounds : data.getDataSourceBounds()) { 
     243                if (bounds.isCollapsed()) { 
     244                    continue; 
    252245                } 
     246                Point p1 = mv.getPoint(bounds.getMin()); 
     247                Point p2 = mv.getPoint(bounds.getMax()); 
     248                Rectangle r = new Rectangle(Math.min(p1.x, p2.x),Math.min(p1.y, p2.y),Math.abs(p2.x-p1.x),Math.abs(p2.y-p1.y)); 
     249                a.subtract(new Area(r)); 
    253250            } 
    254251 
     
    258255        } 
    259256 
    260         PaintVisitor painter; 
    261         if (Main.pref.getBoolean("draw.wireframe")) { 
    262             painter = new SimplePaintVisitor(); 
    263         } else { 
    264             painter = new MapPaintVisitor(); 
    265         } 
    266         painter.setGraphics(g); 
    267         painter.setNavigatableComponent(mv); 
    268         painter.setInactive(inactive); 
    269         painter.visitAll(data, virtual, box); 
     257        Rendering painter = MapRendererFactory.getInstance().createActiveRenderer(g, mv, inactive); 
     258        painter.render(data, virtual, box); 
    270259        Main.map.conflictDialog.paintConflicts(g, mv); 
    271260    } 
     
    528517            } 
    529518            String name = n.get("name"); 
    530             if (name == null) 
    531                 continue; 
     519            if (name == null) { 
     520                continue; 
     521            } 
    532522            WayPoint wpt = new WayPoint(n.getCoor()); 
    533523            wpt.attr.put("name", name); 
     
    538528            String desc = n.get("description"); 
    539529            if (desc != null) { 
    540                wpt.attr.put("desc", desc); 
    541             } 
     530                wpt.attr.put("desc", desc); 
     531            } 
    542532 
    543533            gpxData.waypoints.add(wpt); 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

    r4005 r4087  
    127127        } 
    128128 
     129        @Override 
    129130        protected String toStringImpl() { 
    130131            return super.toStringImpl() + " hAlign=" + hAlign + " vAlign=" + vAlign; 
     
    207208        } 
    208209 
    209         return new NodeElemStyle(c,  
     210        return new NodeElemStyle(c, 
    210211                icon == null ? null : icon.a, 
    211212                icon == null ? null : icon.b, 
     
    342343            Node n = (Node) primitive; 
    343344            if (icon != null && painter.isShowIcons()) { 
    344                 painter.drawNodeIcon(n, (painter.isInactive() || n.isDisabled()) ? getDisabledIcon() : icon, 
     345                painter.drawNodeIcon(n, (painter.isInactiveMode() || n.isDisabled()) ? getDisabledIcon() : icon, 
    345346                        Utils.color_int2float(iconAlpha), selected, member, text); 
    346347            } else if (symbol != null) { 
     
    350351                        fillColor = settings.getHighlightColor(); 
    351352                    } else { 
    352                         if (painter.isInactive() || n.isDisabled()) { 
     353                        if (painter.isInactiveMode() || n.isDisabled()) { 
    353354                            fillColor = settings.getInactiveColor(); 
    354355                        } else if (selected) { 
     
    364365                        strokeColor = settings.getHighlightColor(); 
    365366                    } else { 
    366                         if (painter.isInactive() || n.isDisabled()) { 
     367                        if (painter.isInactiveMode() || n.isDisabled()) { 
    367368                            strokeColor = settings.getInactiveColor(); 
    368369                        } else if (selected) { 
     
    381382                    boolean isConnection = n.isConnectionNode(); 
    382383 
    383                     if (painter.isInactive() || n.isDisabled()) { 
     384                    if (painter.isInactiveMode() || n.isDisabled()) { 
    384385                        color = settings.getInactiveColor(); 
    385386                    } else if (selected) { 
     
    402403 
    403404                    final int size = Utils.max((selected ? settings.getSelectedNodeSize() : 0), 
    404                                             (n.isTagged() ? settings.getTaggedNodeSize() : 0), 
    405                                             (isConnection ? settings.getConnectionNodeSize() : 0), 
    406                                             settings.getUnselectedNodeSize()); 
     405                            (n.isTagged() ? settings.getTaggedNodeSize() : 0), 
     406                            (isConnection ? settings.getConnectionNodeSize() : 0), 
     407                            settings.getUnselectedNodeSize()); 
    407408 
    408409                    final boolean fill = (selected && settings.isFillSelectedNode()) || 
    409                                             (n.isTagged() && settings.isFillTaggedNode()) || 
    410                                             (isConnection && settings.isFillConnectionNode()) || 
    411                                             settings.isFillUnselectedNode(); 
     410                            (n.isTagged() && settings.isFillTaggedNode()) || 
     411                            (isConnection && settings.isFillConnectionNode()) || 
     412                            settings.isFillUnselectedNode(); 
    412413 
    413414                    painter.drawNode(n, color, size, fill, text); 
     
    474475        return s.toString(); 
    475476    } 
    476  
    477477} 
  • trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java

    r3530 r4087  
    2424import org.openstreetmap.josm.gui.progress.ProgressMonitor; 
    2525import org.openstreetmap.josm.tools.CheckParameterUtil; 
     26import org.openstreetmap.josm.tools.Utils; 
    2627import org.xml.sax.SAXException; 
    2728 
     
    145146            throw new PluginDownloadException(e); 
    146147        } finally { 
    147             if (in != null) { 
    148                 try { 
    149                     in.close(); 
    150                 } catch(IOException e) { /* ignore */} 
    151             } 
     148            Utils.close(in); 
    152149            synchronized(this) { 
    153150                downloadConnection = null; 
    154151            } 
    155             if (out != null) { 
    156                 try { 
    157                     out.close(); 
    158                 } catch(IOException e) { /* ignore */} 
    159             } 
     152            Utils.close(out); 
    160153        } 
    161154    } 
  • trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java

    r3874 r4087  
    1818import org.openstreetmap.josm.io.OsmTransferException; 
    1919import org.openstreetmap.josm.tools.ImageProvider; 
     20import org.openstreetmap.josm.tools.Utils; 
    2021import org.xml.sax.SAXException; 
    2122 
     
    186187            throw new PluginListParseException(e); 
    187188        } finally { 
    188             if (fin != null) { 
    189                 try { 
    190                     fin.close(); 
    191                 } catch(IOException e){ /* ignore */} 
    192             } 
     189            Utils.close(fin); 
    193190        } 
    194191    } 
  • trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java

    r3730 r4087  
    3434import org.openstreetmap.josm.io.OsmTransferException; 
    3535import org.openstreetmap.josm.tools.ImageProvider; 
     36import org.openstreetmap.josm.tools.Utils; 
    3637import org.xml.sax.SAXException; 
    3738 
     
    188189                connection = null; 
    189190            } 
    190             if (in != null) { 
    191                 try { 
    192                     in.close(); 
    193                 } catch(IOException e){/* ignore */} 
    194             } 
     191            Utils.close(in); 
    195192            monitor.finishTask(); 
    196193        } 
     
    242239                connection = null; 
    243240            } 
    244             if (in != null) { 
    245                 try { 
    246                     in.close(); 
    247                 } catch(IOException e){/* ignore */} 
    248             } 
     241            Utils.close(in); 
    249242            monitor.finishTask(); 
    250243        } 
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r4069 r4087  
    77import java.io.InputStream; 
    88import java.io.OutputStream; 
     9import java.io.Reader; 
    910import java.text.MessageFormat; 
    1011import java.util.Collection; 
     
    202203        return( path.delete() ); 
    203204    } 
     205 
     206    /** 
     207     * <p>Utility method for closing an input stream.</p> 
     208     *  
     209     * @param is the input stream. May be null. 
     210     */ 
     211    public static void close(InputStream is){ 
     212        if (is == null) return; 
     213        try { 
     214            is.close(); 
     215        } catch(IOException e){ 
     216            // ignore 
     217        } 
     218    } 
     219 
     220    /** 
     221     * <p>Utility method for closing an output stream.</p> 
     222     *  
     223     * @param os the output stream. May be null. 
     224     */ 
     225    public static void close(OutputStream os){ 
     226        if (os == null) return; 
     227        try { 
     228            os.close(); 
     229        } catch(IOException e){ 
     230            // ignore 
     231        } 
     232    } 
     233 
     234    /** 
     235     * <p>Utility method for closing a reader.</p> 
     236     *  
     237     * @param reader the reader. May be null. 
     238     */ 
     239    public static void close(Reader reader){ 
     240        if (reader == null) return; 
     241        try { 
     242            reader.close(); 
     243        } catch(IOException e){ 
     244            // ignore 
     245        } 
     246    } 
    204247} 
  • trunk/test/functional/mapcss/performance/PerformanceTest.groovy

    r4074 r4087  
    1212import org.openstreetmap.josm.data.Bounds 
    1313import org.openstreetmap.josm.data.osm.DataSet 
    14 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintVisitor 
     14import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer 
    1515import org.openstreetmap.josm.gui.MainApplication 
    1616import org.openstreetmap.josm.gui.layer.OsmDataLayer 
     
    116116        Graphics2D g = img.createGraphics() 
    117117        g.setClip(0,0, mv.getWidth(), mv.getHeight()) 
    118         def visitor = new MapPaintVisitor() 
     118        def visitor = new StyledMapRenderer() 
    119119        visitor.setNavigatableComponent(Main.map.mapView) 
    120120        visitor.setGraphics(g) 
     
    122122        print "Rendering ..." 
    123123        long time = timed { 
    124             visitor.visitAll(ds, false, new Bounds(-90,-180,90,180)) 
     124            visitor.render(ds, false, new Bounds(-90,-180,90,180)) 
    125125        } 
    126126        println "DONE" 
  • trunk/test/performance/org/openstreetmap/josm/data/osm/MapPaintVisitorPerformanceTest.java

    r3350 r4087  
    1010import org.openstreetmap.josm.Main; 
    1111import org.openstreetmap.josm.data.Bounds; 
    12 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintVisitor; 
    13 import org.openstreetmap.josm.data.osm.visitor.paint.PaintVisitor; 
     12import org.openstreetmap.josm.data.osm.visitor.paint.Rendering; 
     13import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer; 
    1414import org.openstreetmap.josm.data.projection.Mercator; 
    1515import org.openstreetmap.josm.gui.NavigatableComponent; 
     
    5252 
    5353    private static void test(int iterations, DataSet ds, Bounds bounds) throws Exception { 
    54         PaintVisitor visitor = new MapPaintVisitor(); 
     54        Rendering visitor = new StyledMapRenderer(g,nc,false); 
    5555        nc.zoomTo(bounds); 
    56         visitor.setGraphics(g); 
    57         visitor.setNavigatableComponent(nc); 
    58         visitor.setInactive(false); 
    5956        for (int i=0; i<iterations; i++) { 
    60             visitor.visitAll(ds, true, bounds); 
     57            visitor.render(ds, true, bounds); 
    6158        } 
    6259    } 
Note: See TracChangeset for help on using the changeset viewer.