001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.mappaint;
003
004import org.openstreetmap.josm.data.osm.OsmPrimitive;
005import org.openstreetmap.josm.data.osm.Way;
006import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
007import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
008import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
009
010/**
011 * Similar to mapnik's LinePatternSymbolizer.
012 *
013 * @deprecated superseded by #{@link RepeatImageElemStyle}
014 */
015@Deprecated
016public class LinePatternElemStyle extends ElemStyle {
017
018    public MapImage pattern;
019
020    public LinePatternElemStyle(Cascade c, MapImage pattern) {
021        super(c, 2.9f);
022        this.pattern = pattern;
023    }
024
025    public static LinePatternElemStyle create(Environment env) {
026        Cascade c = env.mc.getCascade(env.layer);
027
028        IconReference iconRef = c.get("pattern-image", null, IconReference.class);
029        if (iconRef == null)
030            return null;
031        MapImage pattern = new MapImage(iconRef.iconName, iconRef.source);
032        return new LinePatternElemStyle(c, pattern);
033    }
034
035    @Override
036    public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, StyledMapRenderer painter, boolean selected, boolean member) {
037        Way w = (Way)primitive;
038        painter.drawLinePattern(w, pattern.getImage());
039    }
040
041    @Override
042    public boolean isProperLineStyle() {
043        return true;
044    }
045
046    @Override
047    public boolean equals(Object obj) {
048        if (obj == null || getClass() != obj.getClass())
049            return false;
050        if (!super.equals(obj))
051            return false;
052        final LinePatternElemStyle other = (LinePatternElemStyle) obj;
053        return pattern.equals(other.pattern);
054    }
055
056    @Override
057    public int hashCode() {
058        return pattern.hashCode();
059    }
060
061    @Override
062    public String toString() {
063        return "LinePatternElemStyle{" + super.toString() + "pattern=[" + pattern + "]}";
064    }
065}