Changeset 2675 in josm


Ignore:
Timestamp:
2009-12-23T21:22:35+01:00 (15 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
Files:
3 added
10 edited

Legend:

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

    r2657 r2675  
    12661266        return incomplete;
    12671267    }
     1268
     1269    public boolean isSelected() {
     1270        return dataSet != null && dataSet.isSelected(this);
     1271    }
    12681272}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java

    r2671 r2675  
    66import static org.openstreetmap.josm.tools.I18n.tr;
    77
    8 import java.awt.Color;
    98import java.awt.Graphics2D;
    109import java.awt.Point;
     
    1312import java.awt.geom.Point2D;
    1413import java.util.ArrayList;
    15 import java.util.Arrays;
    1614import java.util.Collection;
    1715import java.util.Collections;
     
    4139import org.openstreetmap.josm.gui.mappaint.LineElemStyle;
    4240import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    43 import org.openstreetmap.josm.tools.LanguageInfo;
     41import org.openstreetmap.josm.gui.mappaint.SimpleNodeElemStyle;
    4442
    4543public class MapPaintVisitor implements PaintVisitor {
    4644
    47     protected Graphics2D g;
    48     protected NavigatableComponent nc;
    49 
    50     protected boolean useRealWidth;
    51     protected boolean zoomLevelDisplay;
    52     protected boolean drawMultipolygon;
    53     protected boolean drawRestriction;
    54     protected boolean leftHandTraffic;
    55     protected int showNames;
    56     protected int showIcons;
    57     protected int useStrokes;
    58     protected int fillAlpha;
    59     protected Color untaggedColor;
    60     protected Color textColor;
    61     protected Color areaTextColor;
    62     protected ElemStyles.StyleSet styles;
    63     protected double circum;
    64     protected double dist;
    65     protected boolean useStyleCache;
     45    private Graphics2D g;
     46    private NavigatableComponent nc;
     47
     48    private boolean zoomLevelDisplay;
     49    private boolean drawMultipolygon;
     50    private boolean drawRestriction;
     51    private boolean leftHandTraffic;
     52    private ElemStyles.StyleSet styles;
     53    private double circum;
     54    private double dist;
     55    private boolean useStyleCache;
    6656    private static int paintid = 0;
    6757    private EastNorth minEN;
    6858    private EastNorth maxEN;
    6959    private MapPainter painter;
    70     protected Collection<String> regionalNameOrder;
    71 
    72     public boolean inactive;
    73     protected boolean fillSelectedNode;
    74     protected boolean fillUnselectedNode;
    75     protected int defaultSegmentWidth;
    76     protected boolean showOrderNumber;
    77 
    78     protected boolean showRelevantDirectionsOnly;
    79     protected boolean showHeadArrowOnly;
    80     protected boolean showDirectionArrow;
    81 
    82     protected int selectedNodeRadius;
    83     protected int selectedNodeSize;
    84     protected int taggedNodeSize;
    85     protected int taggedNodeRadius;
    86     protected int unselectedNodeRadius;
    87     protected int unselectedNodeSize;
    88 
    89     protected Color selectedColor;
    90     protected Color highlightColor;
    91     protected Color inactiveColor;
    92     protected Color nodeColor;
     60    private MapPaintSettings paintSettings;
     61
     62    private boolean inactive;
    9363
    9464    protected boolean isZoomOk(ElemStyle e) {
     
    11282            }
    11383        }
     84
     85        if (osm.mappaintStyle == null && osm instanceof Node) {
     86            osm.mappaintStyle = SimpleNodeElemStyle.INSTANCE;
     87        }
     88
    11489        return osm.mappaintStyle;
    11590    }
     
    145120            return;
    146121
    147         IconElemStyle nodeStyle = (IconElemStyle)getPrimitiveStyle(n);
    148 
    149         if (nodeStyle != null && isZoomOk(nodeStyle) && showIcons > dist) {
    150             painter.drawNodeIcon(n, (inactive || n.isDisabled())?nodeStyle.getDisabledIcon():nodeStyle.icon,
    151                     nodeStyle.annotate, data.isSelected(n), getNodeName(n));
    152         } else {
    153             if (isZoomOk(null)) {
    154                 if (n.highlighted) {
    155                     painter.drawNode(n, highlightColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode,
    156                             getNodeName(n));
    157                 } else if (data.isSelected(n)) {
    158                     painter.drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode,
    159                             getNodeName(n));
    160                 } else if (n.isTagged()) {
    161                     painter.drawNode(n, nodeColor, taggedNodeSize, taggedNodeRadius, fillUnselectedNode,
    162                             getNodeName(n));
    163                 } else if (inactive || n.isDisabled()) {
    164                     painter.drawNode(n, inactiveColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode,
    165                             getNodeName(n));
    166                 } else {
    167                     painter.drawNode(n, nodeColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode,
    168                             getNodeName(n));
    169                 }
    170             }
     122        ElemStyle nodeStyle = getPrimitiveStyle(n);
     123
     124        if (isZoomOk(nodeStyle)) {
     125            nodeStyle.paintPrimitive(n, paintSettings, painter, n.isSelected());
    171126        }
    172127    }
     
    212167            return;
    213168
    214         if(wayStyle==null)
    215         {
    216             /* way without style */
    217             drawWay(w, null, untaggedColor, data.isSelected(w));
    218         }
    219         else if(wayStyle instanceof LineElemStyle)
    220         {
    221             /* way with line style */
    222             drawWay(w, (LineElemStyle)wayStyle, untaggedColor, data.isSelected(w));
    223         }
    224         else if (wayStyle instanceof AreaElemStyle)
    225         {
     169        if (wayStyle == null) {
     170            wayStyle = LineElemStyle.UNTAGGED_WAY;
     171        }
     172
     173        if(wayStyle instanceof LineElemStyle) {
     174            wayStyle.paintPrimitive(w, paintSettings, painter, data.isSelected(w));
     175        } else if (wayStyle instanceof AreaElemStyle) {
    226176            AreaElemStyle areaStyle = (AreaElemStyle) wayStyle;
    227177            /* way with area style */
    228178            if (fillAreas > dist)
    229179            {
    230                 painter.drawArea(getPolygon(w), (data.isSelected(w) ? selectedColor : areaStyle.color), getWayName(w));
     180                painter.drawArea(getPolygon(w), (data.isSelected(w) ? paintSettings.getSelectedColor() : areaStyle.color), painter.getWayName(w));
    231181                if(!w.isClosed()) {
    232182                    putError(w, tr("Area style way is not closed."), true);
    233183                }
    234184            }
    235             drawWay(w, areaStyle.line, areaStyle.color, data.isSelected(w));
    236         }
    237     }
    238 
    239     public void drawWay(Way w, LineElemStyle l, Color color, boolean selected) {
    240         /* show direction arrows, if draw.segment.relevant_directions_only is not set,
    241            the way is tagged with a direction key
    242            (even if the tag is negated as in oneway=false) or the way is selected */
    243         boolean showDirection = data.isSelected(w) || ((!useRealWidth) && (showDirectionArrow
    244                 && (!showRelevantDirectionsOnly || w.hasDirectionKeys())));
    245         /* head only takes over control if the option is true,
    246            the direction should be shown at all and not only because it's selected */
    247         boolean showOnlyHeadArrowOnly = showDirection && !data.isSelected(w) && showHeadArrowOnly;
    248         int width = defaultSegmentWidth;
    249         int realWidth = 0; /* the real width of the element in meters */
    250         float dashed[] = new float[0];
    251         Color dashedColor = null;
    252         Node lastN;
    253 
    254         if(l != null) {
    255             if (l.color != null) {
    256                 color = l.color;
    257             }
    258             width = l.width;
    259             realWidth = l.realWidth;
    260             dashed = l.getDashed();
    261             dashedColor = l.dashedColor;
    262         }
    263         if(selected) {
    264             color = selectedColor;
    265         }
    266         if (realWidth > 0 && useRealWidth && !showDirection) {
    267 
    268             /* if we have a "width" tag, try use it */
    269             /* (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) */
    270             String widthTag = w.get("width");
    271             if(widthTag == null) {
    272                 widthTag = w.get("est_width");
    273             }
    274             if(widthTag != null) {
    275                 try {
    276                     realWidth = Integer.parseInt(widthTag);
    277                 }
    278                 catch(NumberFormatException nfe) {
    279                 }
    280             }
    281 
    282             int tmpWidth = (int) (100 /  (float) (circum / realWidth));
    283             if (tmpWidth > width) {
    284                 width = tmpWidth;
    285             }
    286         }
    287 
    288         if(w.highlighted) {
    289             color = highlightColor;
    290         } else if(data.isSelected(w)) {
    291             color = selectedColor;
    292         } else if(w.isDisabled()) {
    293             color = inactiveColor;
    294         }
    295 
    296         /* draw overlays under the way */
    297         if(l != null && l.overlays != null) {
    298             for(LineElemStyle s : l.overlays) {
    299                 if(!s.over) {
    300                     painter.drawWay(w, s.color != null && !data.isSelected(w) ? s.color : color, s.getWidth(width),
    301                             s.getDashed(), s.dashedColor, false, false);
    302                 }
    303             }
    304         }
    305 
    306         /* draw the way */
    307         painter.drawWay(w, color, width, dashed, dashedColor, showDirection, showOnlyHeadArrowOnly);
    308 
    309         /* draw overlays above the way */
    310         if(l != null && l.overlays != null)  {
    311             for(LineElemStyle s : l.overlays) {
    312                 if(s.over) {
    313                     painter.drawWay(w, s.color != null && !data.isSelected(w) ? s.color : color, s.getWidth(width),
    314                             s.getDashed(), s.dashedColor, false, false);
    315                 }
    316             }
    317         }
    318 
    319         if(showOrderNumber) {
    320             int orderNumber = 0;
    321             lastN = null;
    322             for(Node n : w.getNodes()) {
    323                 if(lastN != null) {
    324                     orderNumber++;
    325                     drawOrderNumber(lastN, n, orderNumber);
    326                 }
    327                 lastN = n;
    328             }
     185            areaStyle.getLineStyle().paintPrimitive(w, paintSettings, painter, data.isSelected(w));
    329186        }
    330187    }
     
    441298        if(osm instanceof Way)
    442299        {
    443             if(style instanceof AreaElemStyle)
    444             {
     300            if(style instanceof AreaElemStyle) {
    445301                Way way = (Way)osm;
    446302                AreaElemStyle areaStyle = (AreaElemStyle)style;
    447                 drawWay(way, areaStyle.line, selectedColor, true);
     303                areaStyle.getLineStyle().paintPrimitive(way, paintSettings, painter, true);
    448304                if(area) {
    449                     painter.drawArea(getPolygon(way), (areaselected ? selectedColor : areaStyle.color), getWayName(way));
    450                 }
    451             }
    452             else
    453             {
    454                 drawWay((Way)osm, (LineElemStyle)style, selectedColor, true);
     305                    painter.drawArea(getPolygon(way), (areaselected ? paintSettings.getSelectedColor() : areaStyle.color), painter.getWayName(way));
     306                }
     307            } else {
     308                style.paintPrimitive(osm, paintSettings, painter, true);
    455309            }
    456310        }
    457311        else if(osm instanceof Node)
    458312        {
    459             if(style != null && isZoomOk(style)) {
    460                 painter.drawNodeIcon((Node)osm, ((IconElemStyle)style).icon,
    461                         ((IconElemStyle)style).annotate, true, getNodeName((Node)osm));
    462             } else if (isZoomOk(null)) {
    463                 painter.drawNode((Node)osm, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode,
    464                         getNodeName((Node)osm));
     313            if(isZoomOk(style)) {
     314                style.paintPrimitive(osm, paintSettings, painter, true);
    465315            }
    466316        }
     
    917767
    918768                    boolean selected = pd.selected || data.isSelected(pd.way) || data.isSelected(r);
    919                     painter.drawArea(p, selected ? selectedColor : areaStyle.color, null);
     769                    painter.drawArea(p, selected ? paintSettings.getSelectedColor() : areaStyle.color, null);
    920770                    visible = true;
    921771                }
     
    934784                            || outer.size() == 0))
    935785                    {
    936                         drawWay(wInner, ((AreaElemStyle)wayStyle).line,
    937                                 ((AreaElemStyle)wayStyle).color, data.isSelected(wInner)
    938                                 || data.isSelected(r));
     786                        ((AreaElemStyle)wayStyle).getLineStyle().paintPrimitive(wInner, paintSettings, painter, (data.isSelected(wInner)
     787                                || data.isSelected(r)));
    939788                    }
    940789                    wInner.mappaintDrawnCode = paintid;
     
    968817                    if(zoomok)
    969818                    {
    970                         drawWay(wOuter, ((AreaElemStyle)wayStyle).line,
    971                                 ((AreaElemStyle)wayStyle).color, data.isSelected(wOuter)
    972                                 || data.isSelected(r));
     819                        ((AreaElemStyle)wayStyle).getLineStyle().paintPrimitive(wOuter, paintSettings, painter, (data.isSelected(wOuter) || data.isSelected(r)));
    973820                    }
    974821                    wOuter.mappaintDrawnCode = paintid;
     
    1043890        }
    1044891        return Math.abs(sum/2.0);
    1045     }
    1046 
    1047     protected String getNodeName(Node n) {
    1048         if (showNames > dist) {
    1049             String name = null;
    1050             if (n.hasKeys()) {
    1051                 for (String rn : regionalNameOrder) {
    1052                     name = n.get(rn);
    1053                     if (name != null) {
    1054                         break;
    1055                     }
    1056                 }
    1057             }
    1058             return name;
    1059         } else
    1060             return null;
    1061     }
    1062 
    1063     protected String getWayName(Way w) {
    1064         if (showNames > dist) {
    1065             String name = null;
    1066             if (w.hasKeys()) {
    1067                 for (String rn : regionalNameOrder) {
    1068                     name = w.get(rn);
    1069                     if (name != null) {
    1070                         break;
    1071                     }
    1072                 }
    1073             }
    1074             return name;
    1075         } else
    1076             return null;
    1077     }
    1078 
    1079     public void getColors() {
    1080         selectedColor  = PaintColors.SELECTED.get();
    1081         highlightColor = PaintColors.HIGHLIGHT.get();
    1082         inactiveColor = PaintColors.INACTIVE.get();
    1083         nodeColor = PaintColors.NODE.get();
    1084         untaggedColor = PaintColors.UNTAGGED.get();
    1085         textColor = PaintColors.TEXT.get();
    1086         areaTextColor = PaintColors.AREA_TEXT.get();
    1087892    }
    1088893
     
    1113918        useStyleCache = Main.pref.getBoolean("mappaint.cache", true);
    1114919        int fillAreas = Main.pref.getInteger("mappaint.fillareas", 10000000);
    1115         fillAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50))));
    1116         showNames = Main.pref.getInteger("mappaint.shownames", 10000000);
    1117         showIcons = Main.pref.getInteger("mappaint.showicons", 10000000);
    1118         useStrokes = Main.pref.getInteger("mappaint.strokes", 10000000);
    1119920        LatLon ll1 = nc.getLatLon(0, 0);
    1120921        LatLon ll2 = nc.getLatLon(100, 0);
    1121922        dist = ll1.greatCircleDistance(ll2);
    1122923
    1123         getColors();
    1124 
    1125         showDirectionArrow = Main.pref.getBoolean("draw.segment.direction", true);
    1126         showRelevantDirectionsOnly = Main.pref.getBoolean("draw.segment.relevant_directions_only", true);
    1127         showHeadArrowOnly = Main.pref.getBoolean("draw.segment.head_only", false);
    1128         showOrderNumber = Main.pref.getBoolean("draw.segment.order_number", false);
    1129         selectedNodeRadius = Main.pref.getInteger("mappaint.node.selected-size", 5) / 2;
    1130         selectedNodeSize = selectedNodeRadius * 2;
    1131         unselectedNodeRadius = Main.pref.getInteger("mappaint.node.unselected-size", 3) / 2;
    1132         unselectedNodeSize = unselectedNodeRadius * 2;
    1133         taggedNodeRadius = Main.pref.getInteger("mappaint.node.tagged-size", 5) / 2;
    1134         taggedNodeSize = taggedNodeRadius * 2;
    1135         defaultSegmentWidth = Main.pref.getInteger("mappaint.segment.default-width", 2);
    1136         fillSelectedNode = Main.pref.getBoolean("mappaint.node.fill-selected", true);
    1137         fillUnselectedNode = Main.pref.getBoolean("mappaint.node.fill-unselected", false);
    1138 
    1139         useRealWidth = Main.pref.getBoolean("mappaint.useRealWidth", false);
    1140924        zoomLevelDisplay = Main.pref.getBoolean("mappaint.zoomLevelDisplay", false);
    1141925        circum = Main.map.mapView.getDist100Pixel();
     
    1144928        drawRestriction = Main.pref.getBoolean("mappaint.restriction", true);
    1145929        leftHandTraffic = Main.pref.getBoolean("mappaint.lefthandtraffic", false);
    1146         String[] names = {"name:" + LanguageInfo.getJOSMLocaleCode(), "name", "int_name", "ref", "operator", "brand", "addr:housenumber"};
    1147930        minEN = nc.getEastNorth(0, nc.getHeight() - 1);
    1148931        maxEN = nc.getEastNorth(nc.getWidth() - 1, 0);
    1149         regionalNameOrder = Main.pref.getCollection("mappaint.nameOrder", Arrays.asList(names));
    1150 
    1151         this.painter = new MapPainter(g, inactive, nc, useStrokes > dist, virtual);
     932
     933        this.paintSettings = MapPaintSettings.INSTANCE;
     934        this.painter = new MapPainter(paintSettings, g, inactive, nc, virtual, dist, circum);
    1152935
    1153936        data.clearErrors();
     
    12351018    }
    12361019
    1237     /**
    1238      * Draw a number of the order of the two consecutive nodes within the
    1239      * parents way
    1240      */
    1241     protected void drawOrderNumber(Node n1, Node n2, int orderNumber) {
    1242         Point p1 = nc.getPoint(n1);
    1243         Point p2 = nc.getPoint(n2);
    1244         painter.drawOrderNumber(p1, p2, orderNumber);
    1245     }
    1246 
    12471020    public void putError(OsmPrimitive p, String text, boolean isError)
    12481021    {
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java

    r2671 r2675  
    1313import java.awt.geom.GeneralPath;
    1414import java.awt.geom.Rectangle2D;
     15import java.util.Arrays;
    1516import java.util.Collection;
    1617import java.util.Iterator;
     
    2324import org.openstreetmap.josm.gui.NavigatableComponent;
    2425import org.openstreetmap.josm.tools.ImageProvider;
     26import org.openstreetmap.josm.tools.LanguageInfo;
    2527
    2628public class MapPainter {
     
    3032    private final NavigatableComponent nc;
    3133    private final boolean inactive;
     34
    3235    private final boolean useStrokes;
     36    private final boolean showNames;
     37    private final boolean showIcons;
    3338
    3439    private final Color inactiveColor;
     
    4550    private final int segmentNumberSpace;
    4651
    47 
    48     public MapPainter(Graphics2D g, boolean inactive, NavigatableComponent nc, boolean useStrokes, boolean virtual) {
     52    private final double circum;
     53
     54    private final Collection<String> regionalNameOrder;
     55
     56
     57    public MapPainter(MapPaintSettings settings, Graphics2D g, boolean inactive, NavigatableComponent nc, boolean virtual, double dist, double circum) {
    4958        this.g = g;
    5059        this.inactive = inactive;
    5160        this.nc = nc;
    52         this.useStrokes = useStrokes;
     61        this.useStrokes = settings.getUseStrokesDistance() > dist;
     62        this.showNames = settings.getShowNamesDistance() > dist;
     63        this.showIcons = settings.getShowIconsDistance() > dist;
    5364
    5465        this.inactiveColor = PaintColors.INACTIVE.get();
     
    6475        this.virtualNodeSpace = Main.pref.getInteger("mappaint.node.virtual-space", 70);
    6576        this.segmentNumberSpace = Main.pref.getInteger("mappaint.segmentnumber.space", 40);
     77
     78        String[] names = {"name:" + LanguageInfo.getJOSMLocaleCode(), "name", "int_name", "ref", "operator", "brand", "addr:housenumber"};
     79        this.regionalNameOrder = Main.pref.getCollection("mappaint.nameOrder", Arrays.asList(names));
     80        this.circum = circum;
    6681    }
    6782
     
    137152
    138153
    139     protected void drawNodeIcon(Node n, ImageIcon icon, boolean annotate, boolean selected, String name) {
     154    public void drawNodeIcon(Node n, ImageIcon icon, boolean annotate, boolean selected, String name) {
    140155        Point p = nc.getPoint(n);
    141156        if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return;
     
    168183     * @param color The color of the node.
    169184     */
    170     public void drawNode(Node n, Color color, int size, int radius, boolean fill, String name) {
     185    public void drawNode(Node n, Color color, int size, boolean fill, String name) {
    171186        if (size > 1) {
     187            int radius = size / 2;
    172188            Point p = nc.getPoint(n);
    173189            if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth())
     
    305321
    306322    /**
     323     * Draw a number of the order of the two consecutive nodes within the
     324     * parents way
     325     */
     326    public void drawOrderNumber(Node n1, Node n2, int orderNumber) {
     327        Point p1 = nc.getPoint(n1);
     328        Point p2 = nc.getPoint(n2);
     329        drawOrderNumber(p1, p2, orderNumber);
     330    }
     331
     332    /**
    307333     * Draw an number of the order of the two consecutive nodes within the
    308334     * parents way
     
    328354    }
    329355
     356    //TODO Not a good place for this method
     357    public String getNodeName(Node n) {
     358        String name = null;
     359        if (n.hasKeys()) {
     360            for (String rn : regionalNameOrder) {
     361                name = n.get(rn);
     362                if (name != null) {
     363                    break;
     364                }
     365            }
     366        }
     367        return name;
     368    }
     369
     370    //TODO Not a good place for this method
     371    public String getWayName(Way w) {
     372        String name = null;
     373        if (w.hasKeys()) {
     374            for (String rn : regionalNameOrder) {
     375                name = w.get(rn);
     376                if (name != null) {
     377                    break;
     378                }
     379            }
     380        }
     381        return name;
     382    }
     383
     384    public boolean isInactive() {
     385        return inactive;
     386    }
     387
     388    public boolean isShowNames() {
     389        return showNames;
     390    }
     391
     392    public double getCircum() {
     393        return circum;
     394    }
     395
     396    public boolean isShowIcons() {
     397        return showIcons;
     398    }
     399
    330400}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/PaintColors.java

    r2666 r2675  
    4848        return Main.pref.getColor(this);
    4949    }
     50
     51    public static void getColors() {
     52        for (PaintColors c:values()) {
     53            c.get();
     54        }
     55    }
    5056}
  • 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.