Ignore:
Timestamp:
2009-12-23T21:22:35+01:00 (14 years ago)
Author:
jttt
Message:

MapPaintVisitor - delegate drawing to styles, MapPaintVisitor should only select correct style and then let primitives draw in correct order. (not finished yet)

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java

    r1747 r2675  
    11package org.openstreetmap.josm.gui.mappaint;
    22import java.awt.Color;
     3
     4import org.openstreetmap.josm.data.osm.OsmPrimitive;
     5import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
     6import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
    37
    48public class AreaElemStyle extends ElemStyle
     
    610    public Color color;
    711    public boolean closed;
    8     public LineElemStyle line = null;
     12    private LineElemStyle line;
    913
    1014    public AreaElemStyle (AreaElemStyle a, long maxScale, long minScale) {
     
    1519        this.minScale = minScale;
    1620        this.rules = a.rules;
     21        this.line = new LineElemStyle();
     22        this.line.color = a.color;
    1723    }
    1824
     
    3642        priority = 0;
    3743    }
     44
     45    public ElemStyle getLineStyle() {
     46        return line;
     47    }
     48
     49    @Override
     50    public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected) {
     51        // TODO
     52        /*Way way = (Way)primitive;
     53        String name = painter.isShowNames() ? painter.getWayName(way) : null;
     54        painter.drawArea(getPolygon(way), selected ? paintSettings.getSelectedColor() : color, name);
     55        line.paintPrimitive(way, paintSettings, painter, selected);*/
     56    }
    3857}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java

    r2512 r2675  
    55import org.openstreetmap.josm.data.osm.OsmPrimitive;
    66import org.openstreetmap.josm.data.osm.OsmUtils;
     7import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
     8import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
    79
    8 abstract public class ElemStyle
    9 {
     10abstract public class ElemStyle {
    1011    // zoom range to display the feature
    1112    public long minScale;
     
    1617    Collection<Rule> rules = null;
    1718
    18     public Boolean equals(ElemStyle s)
    19     {
    20         return s != null && s.getCode().equals(getCode());
     19    @Override
     20    public boolean equals(Object o) {
     21        return (o instanceof ElemStyle) && (((ElemStyle) o).getCode().equals(getCode()));
    2122    }
     23
     24    @Override
     25    public int hashCode() {
     26        return getClass().hashCode();
     27    }
     28
    2229    public String getCode()
    2330    {
     
    2532        {
    2633            code = "";
    27             for(Rule r: rules)
     34            for(Rule r: rules) {
    2835                code += r.toCode();
     36            }
    2937        }
    3038        return code;
     
    3947            String bv = OsmUtils.getNamedOsmBoolean(r.boolValue);
    4048            if(k == null || (r.value != null && !k.equals(r.value))
    41             || (bv != null && !bv.equals(OsmUtils.getNamedOsmBoolean(k))))
     49                    || (bv != null && !bv.equals(OsmUtils.getNamedOsmBoolean(k))))
    4250                return false;
    4351        }
    4452        return true;
    4553    }
     54
     55    public abstract void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected);
    4656}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyleHandler.java

    r2659 r2675  
    8484                if(val.startsWith("+"))
    8585                {
    86                     line.width = Integer.parseInt(val.substring(1));
     86                    line.setWidth(Integer.parseInt(val.substring(1)));
    8787                    line.widthMode = LineElemStyle.WidthMode.OFFSET;
    8888                }
    8989                else if(val.startsWith("-"))
    9090                {
    91                     line.width = Integer.parseInt(val);
     91                    line.setWidth(Integer.parseInt(val));
    9292                    line.widthMode = LineElemStyle.WidthMode.OFFSET;
    9393                }
    9494                else if(val.endsWith("%"))
    9595                {
    96                     line.width = Integer.parseInt(val.substring(0, val.length()-1));
     96                    line.setWidth(Integer.parseInt(val.substring(0, val.length()-1)));
    9797                    line.widthMode = LineElemStyle.WidthMode.PERCENT;
    9898                } else {
    99                     line.width = Integer.parseInt(val);
     99                    line.setWidth(Integer.parseInt(val));
    100100                }
    101101            }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/IconElemStyle.java

    r2512 r2675  
    33import javax.swing.GrayFilter;
    44import javax.swing.ImageIcon;
     5
     6import org.openstreetmap.josm.data.osm.Node;
     7import org.openstreetmap.josm.data.osm.OsmPrimitive;
     8import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
     9import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
    510
    611public class IconElemStyle extends ElemStyle
     
    3338        return disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(icon.getImage()));
    3439    }
     40    @Override
     41    public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings settings, MapPainter painter, boolean selected) {
     42        if (painter.isShowIcons()) {
     43            Node n = (Node) primitive;
     44            String name = painter.isShowNames()?painter.getNodeName(n):null;
     45            painter.drawNodeIcon(n, (painter.isInactive() || n.isDisabled())?getDisabledIcon():icon,
     46                    annotate, selected, name);
     47        } else {
     48            SimpleNodeElemStyle.INSTANCE.paintPrimitive(primitive, settings, painter, selected);
     49        }
     50
     51    }
    3552}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r2659 r2675  
    44import java.util.Collection;
    55
     6import org.openstreetmap.josm.data.osm.Node;
     7import org.openstreetmap.josm.data.osm.OsmPrimitive;
     8import org.openstreetmap.josm.data.osm.Way;
     9import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
     10import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
     11import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
    612import org.openstreetmap.josm.tools.I18n;
    713
    8 public class LineElemStyle extends ElemStyle implements Comparable<LineElemStyle>
    9 {
    10     public int width;
     14public class LineElemStyle extends ElemStyle implements Comparable<LineElemStyle> {
     15
     16    public static final LineElemStyle UNTAGGED_WAY;
     17
     18    static {
     19        UNTAGGED_WAY = new LineElemStyle();
     20        UNTAGGED_WAY.color = PaintColors.UNTAGGED.get();
     21    }
     22
     23    private int width;
    1124    public int realWidth; //the real width of this line in meter
    1225    public Color color;
     
    6073    public void init()
    6174    {
    62         width = 1;
     75        width = -1;
    6376        realWidth = 0;
    6477        dashed = new float[0];
     
    124137        }
    125138    }
     139
     140    @Override
     141    public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected) {
     142        Way w = (Way)primitive;
     143        /* show direction arrows, if draw.segment.relevant_directions_only is not set,
     144        the way is tagged with a direction key
     145        (even if the tag is negated as in oneway=false) or the way is selected */
     146        boolean showDirection = selected || ((!paintSettings.isUseRealWidth()) && (paintSettings.isShowDirectionArrow()
     147                && (!paintSettings.isShowRelevantDirectionsOnly() || w.hasDirectionKeys())));
     148        /* head only takes over control if the option is true,
     149        the direction should be shown at all and not only because it's selected */
     150        boolean showOnlyHeadArrowOnly = showDirection && selected && paintSettings.isShowHeadArrowOnly();
     151        Node lastN;
     152
     153        Color myColor = color;
     154        int myWidth = getWidth();
     155
     156        if (realWidth > 0 && paintSettings.isUseRealWidth() && !showDirection) {
     157
     158            /* if we have a "width" tag, try use it */
     159            /* (this might be slow and could be improved by caching the value in the Way, on the other hand only used if "real width" is enabled) */
     160            String widthTag = w.get("width");
     161            if(widthTag == null) {
     162                widthTag = w.get("est_width");
     163            }
     164            if(widthTag != null) {
     165                try {
     166                    realWidth = Integer.parseInt(widthTag);
     167                }
     168                catch(NumberFormatException nfe) {
     169                }
     170            }
     171
     172            myWidth = (int) (100 /  (float) (painter.getCircum() / realWidth));
     173            if (myWidth < getWidth()) {
     174                myWidth = getWidth();
     175            }
     176        }
     177
     178        if(w.highlighted) {
     179            myColor = paintSettings.getHighlightColor();
     180        } else if (selected) {
     181            myColor = paintSettings.getSelectedColor();
     182        } else if(w.isDisabled()) {
     183            myColor = paintSettings.getInactiveColor();
     184        }
     185
     186        /* draw overlays under the way */
     187        if(overlays != null) {
     188            for(LineElemStyle s : overlays) {
     189                if(!s.over) {
     190                    painter.drawWay(w, s.color != null && selected ? myColor: s.color, s.getWidth(myWidth),
     191                            s.getDashed(), s.dashedColor, false, false);
     192                }
     193            }
     194        }
     195
     196        /* draw the way */
     197        painter.drawWay(w, myColor, myWidth, dashed, dashedColor, showDirection, showOnlyHeadArrowOnly);
     198
     199        /* draw overlays above the way */
     200        if(overlays != null)  {
     201            for(LineElemStyle s : overlays) {
     202                if(s.over) {
     203                    painter.drawWay(w, s.color != null && selected ? myColor : s.color, s.getWidth(myWidth),
     204                            s.getDashed(), s.dashedColor, false, false);
     205                }
     206            }
     207        }
     208
     209        if(paintSettings.isShowOrderNumber()) {
     210            int orderNumber = 0;
     211            lastN = null;
     212            for(Node n : w.getNodes()) {
     213                if(lastN != null) {
     214                    orderNumber++;
     215                    painter.drawOrderNumber(lastN, n, orderNumber);
     216                }
     217                lastN = n;
     218            }
     219        }
     220    }
     221
     222    public int getWidth() {
     223        if (width == -1)
     224            return MapPaintSettings.INSTANCE.getDefaultSegmentWidth();
     225        return width;
     226    }
     227
     228    public void setWidth(int width) {
     229        this.width = width;
     230    }
    126231}
  • trunk/src/org/openstreetmap/josm/gui/preferences/ColorPreference.java

    r2666 r2675  
    3434
    3535import org.openstreetmap.josm.Main;
    36 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintVisitor;
     36import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
    3737import org.openstreetmap.josm.gui.MapScaler;
    3838import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
     
    254254     */
    255255    private void fixColorPrefixes() {
    256         (new MapPaintVisitor()).getColors();
     256        PaintColors.getColors();
    257257        MarkerLayer.getColor(null);
    258258        MapScaler.getColor();
Note: See TracChangeset for help on using the changeset viewer.