Ticket #2667: dashpattern4.patch

File dashpattern4.patch, 6.8 KB (added by Daeron, 17 years ago)

Small correction

  • styles/standard/elemstyles.xml

     
    354354        <rule>
    355355                <condition k="barrier" v="bollard"/>
    356356                <icon annotate="true" src="vehicle/restriction/bollard.png"/>
    357                 <line width="3" colour="barrier#F0F050" closed="true"/>
     357                <line width="3" colour="barrier#F0F050" dashed="3,9"/>
     358                <area colour="barrier#F0F050" closed="true"/>
    358359                <scale_min>1</scale_min>
    359360                <scale_max>50000</scale_max>
    360361        </rule>
  • src/org/openstreetmap/josm/gui/mappaint/ElemStyleHandler.java

     
    104104            else if (atts.getQName(count).equals("dashed")) {
    105105                try
    106106                {
    107                     line.dashed=Integer.parseInt(atts.getValue(count));
     107                    String[] parts = atts.getValue(count).split(",");
     108                    line.dashed = new float[parts.length];
     109                    for (int i = 0; i < parts.length; i++) {
     110                        line.dashed[i] = (float)(Integer.parseInt(parts[i]));
     111                    }
    108112                } catch (NumberFormatException nfe) {
    109113                    boolean dashed=Boolean.parseBoolean(atts.getValue(count));
    110114                    if(dashed) {
    111                         line.dashed = 9;
     115                        line.dashed = new float[]{9};
    112116                    }
    113117                }
    114118            } else if (atts.getQName(count).equals("dashedcolour"))
  • src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

     
    88    public int width;
    99    public int realWidth; //the real width of this line in meter
    1010    public Color color;
    11     public int dashed;
     11    public float[] dashed;
    1212    public Color dashedColor;
    1313
    1414    public boolean over;
     
    5656    {
    5757        width = 1;
    5858        realWidth = 0;
    59         dashed = 0;
     59        dashed = new float[0];
    6060        dashedColor = null;
    6161        priority = 0;
    6262        color = null;
  • src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

     
    5454    protected int fillAlpha;
    5555    protected Color untaggedColor;
    5656    protected Color textColor;
    57     protected int currentDashed = 0;
     57    protected float[] currentDashed = new float[0];
    5858    protected Color currentDashedColor;
    5959    protected int currentWidth = 0;
    6060    protected Stroke currentStroke = null;
     
    249249        boolean showOnlyHeadArrowOnly = showDirection && !w.selected && showHeadArrowOnly;
    250250        int width = defaultSegmentWidth;
    251251        int realWidth = 0; /* the real width of the element in meters */
    252         int dashed = 0;
     252        float dashed[] = new float[0];
    253253        Color dashedColor = null;
    254254        Node lastN;
    255255
     
    11241124        return name;
    11251125    }
    11261126
    1127     private void drawSeg(Node n1, Node n2, Color col, boolean showDirection, int width, int dashed, Color dashedColor) {
     1127    private void drawSeg(Node n1, Node n2, Color col, boolean showDirection, int width, float dashed[], Color dashedColor) {
    11281128        //profilerSegments++;
    1129         if (col != currentColor || width != currentWidth || dashed != currentDashed || dashedColor != currentDashedColor) {
     1129        if (col != currentColor || width != currentWidth || !Arrays.equals(dashed,currentDashed) || dashedColor != currentDashedColor) {
    11301130            displaySegments(col, width, dashed, dashedColor);
    11311131        }
    11321132        Point p1 = nc.getPoint(n1.eastNorth);
     
    11481148    }
    11491149
    11501150    protected void displaySegments() {
    1151         displaySegments(null, 0, 0, null);
     1151        displaySegments(null, 0, new float[0], null);
    11521152    }
    11531153
    1154     protected void displaySegments(Color newColor, int newWidth, int newDash, Color newDashedColor) {
     1154    protected void displaySegments(Color newColor, int newWidth, float newDash[], Color newDashedColor) {
    11551155        if (currentPath != null) {
    11561156            Graphics2D g2d = (Graphics2D)g;
    11571157            g2d.setColor(inactive ? inactiveColor : currentColor);
    11581158            if (currentStroke == null && useStrokes > dist) {
    1159                 if (currentDashed != 0)
    1160                     g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,new float[] {currentDashed},0));
     1159                if (currentDashed.length > 0) {
     1160                    try {
     1161                        g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,currentDashed,0));
     1162                    } catch (IllegalArgumentException e) {
     1163                        g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
     1164                    }
     1165                }
    11611166                else
    11621167                    g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
    11631168            }
     
    11661171            if(currentDashedColor != null) {
    11671172                g2d.setColor(currentDashedColor);
    11681173                if (currentStroke == null && useStrokes > dist) {
    1169                     if (currentDashed != 0)
    1170                         g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,new float[] {currentDashed},currentDashed));
     1174                    if (currentDashed.length > 0) {
     1175                        float[] currentDashedOffset = new float[currentDashed.length];
     1176                        System.arraycopy(currentDashed, 1, currentDashedOffset, 0, currentDashed.length - 1);
     1177                        currentDashedOffset[currentDashed.length-1] = currentDashed[0];
     1178                        float offset = currentDashedOffset[0];
     1179                        try {
     1180                            g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,currentDashedOffset,offset));
     1181                        } catch (IllegalArgumentException e) {
     1182                            g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
     1183                        }
     1184                    }
    11711185                    else
    11721186                        g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
    11731187                }