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 public LinePrototype() { init(); } 033 034 public void init() 035 { 036 priority = 0; 037 range = Range.ZERO_TO_INFINITY; 038 width = -1; 039 realWidth = null; 040 dashed = null; 041 dashedColor = null; 042 color = PaintColors.UNTAGGED.get(); 043 } 044 045 public List<Float> getDashed() { 046 return dashed; 047 } 048 049 public void setDashed(List<Float> dashed) { 050 if (dashed == null || dashed.isEmpty()) { 051 this.dashed = null; 052 return; 053 } 054 055 boolean found = false; 056 for (Float f : dashed) { 057 if (f == null) { 058 this.dashed = null; 059 return; 060 } 061 if (f > 0) { 062 found = true; 063 } 064 if (f < 0) { 065 Main.error(I18n.tr("Illegal dash pattern, values must be positive")); 066 this.dashed = null; 067 return; 068 } 069 } 070 if (found) { 071 this.dashed = dashed; 072 } else { 073 Main.error(I18n.tr("Illegal dash pattern, at least one value must be > 0")); 074 } 075 } 076 077 public int getWidth() { 078 if (width == -1) 079 return MapPaintSettings.INSTANCE.getDefaultSegmentWidth(); 080 return width; 081 } 082 083 public void setWidth(int width) { 084 this.width = width; 085 } 086}