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