001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.mappaint.xml;
003
004import java.awt.Color;
005import java.util.List;
006
007import org.openstreetmap.josm.Main;
008import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
009import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
010import org.openstreetmap.josm.gui.mappaint.Range;
011import org.openstreetmap.josm.tools.I18n;
012
013public class LinePrototype extends Prototype {
014
015    protected int width;
016    public Integer realWidth; // the real width of this line in meter
017    public Color color;
018    protected List<Float> dashed;
019    public Color dashedColor;
020
021    public LinePrototype(LinePrototype s, Range range) {
022        super(range);
023        this.width = s.width;
024        this.realWidth = s.realWidth;
025        this.color = s.color;
026        this.dashed = s.dashed;
027        this.dashedColor = s.dashedColor;
028        this.priority = s.priority;
029        this.conditions = s.conditions;
030    }
031
032    /**
033     * Constructs a new {@code LinePrototype}.
034     */
035    public LinePrototype() {
036        init();
037    }
038
039    public void init() {
040        priority = 0;
041        range = Range.ZERO_TO_INFINITY;
042        width = -1;
043        realWidth = null;
044        dashed = null;
045        dashedColor = null;
046        color = PaintColors.UNTAGGED.get();
047    }
048
049    public List<Float> getDashed() {
050        return dashed;
051    }
052
053    public void setDashed(List<Float> dashed) {
054        if (dashed == null || dashed.isEmpty()) {
055            this.dashed = null;
056            return;
057        }
058
059        boolean found = false;
060        for (Float f : dashed) {
061            if (f == null) {
062                this.dashed = null;
063                return;
064            }
065            if (f > 0) {
066                found = true;
067            }
068            if (f < 0) {
069                Main.error(I18n.tr("Illegal dash pattern, values must be positive"));
070                this.dashed = null;
071                return;
072            }
073        }
074        if (found) {
075            this.dashed = dashed;
076        } else {
077            Main.error(I18n.tr("Illegal dash pattern, at least one value must be > 0"));
078        }
079    }
080
081    public int getWidth() {
082        if (width == -1)
083            return MapPaintSettings.INSTANCE.getDefaultSegmentWidth();
084        return width;
085    }
086
087    public void setWidth(int width) {
088        this.width = width;
089    }
090}