Ticket #2667: dashpattern2.diff

File dashpattern2.diff, 7.1 KB (added by Daeron, 16 years ago)

Updated patch

  • styles/standard/elemstyles.xml

     
    352352        <rule>
    353353                <condition k="barrier" v="bollard"/>
    354354                <icon annotate="true" src="vehicle/restriction/bollard.png"/>
    355         <line width="3" colour="barrier#F0F050"/>
     355                <line width="3" colour="barrier#F0F050" dashed="3,10" />
    356356                <scale_min>1</scale_min>
    357357                <scale_max>50000</scale_max>
    358358        </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                    System.out.println("Dashes read");
     110                    for (int i = 0; i < parts.length; i++) {
     111                        line.dashed[i] = (float)(Integer.parseInt(parts[i]));
     112                        System.out.println("dash " + line.dashed[i]);
     113                    }
    108114                } catch (NumberFormatException nfe) {
    109115                    boolean dashed=Boolean.parseBoolean(atts.getValue(count));
    110116                    if(dashed) {
    111                         line.dashed = 9;
    112                     }               
     117                        line.dashed = new float[]{9};
     118                    }
    113119                }
    114120            } else if (atts.getQName(count).equals("dashedcolour"))
    115121                line.dashedColor=convertColor(atts.getValue(count));
  • 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;
     
    248248        boolean showOnlyHeadArrowOnly = showDirection && !w.selected && showHeadArrowOnly;
    249249        int width = defaultSegmentWidth;
    250250        int realWidth = 0; /* the real width of the element in meters */
    251         int dashed = 0;
     251        float dashed[] = new float[0];
    252252        Color dashedColor = null;
    253253        Node lastN;
    254254
     
    11141114        return name;
    11151115    }
    11161116
    1117     private void drawSeg(Node n1, Node n2, Color col, boolean showDirection, int width, int dashed, Color dashedColor) {
     1117    private void drawSeg(Node n1, Node n2, Color col, boolean showDirection, int width, float dashed[], Color dashedColor) {
    11181118        //profilerSegments++;
    1119         if (col != currentColor || width != currentWidth || dashed != currentDashed || dashedColor != currentDashedColor) {
     1119        if (col != currentColor || width != currentWidth || !Arrays.equals(dashed,currentDashed) || dashedColor != currentDashedColor) {
    11201120            displaySegments(col, width, dashed, dashedColor);
    11211121        }
    11221122        Point p1 = nc.getPoint(n1.eastNorth);
     
    11381138    }
    11391139
    11401140    protected void displaySegments() {
    1141         displaySegments(null, 0, 0, null);
     1141        displaySegments(null, 0, new float[0], null);
    11421142    }
    11431143
    1144     protected void displaySegments(Color newColor, int newWidth, int newDash, Color newDashedColor) {
     1144    protected void displaySegments(Color newColor, int newWidth, float newDash[], Color newDashedColor) {
    11451145        if (currentPath != null) {
    11461146            Graphics2D g2d = (Graphics2D)g;
    11471147            g2d.setColor(inactive ? inactiveColor : currentColor);
    11481148            if (currentStroke == null && useStrokes > dist) {
    1149                 if (currentDashed != 0)
    1150                     g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,new float[] {currentDashed},0));
     1149                if (currentDashed.length > 0) {
     1150                    try {
     1151                        g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,currentDashed,0));
     1152                    } catch (IllegalArgumentException e) {
     1153                        System.out.println("dashes:");
     1154                        for (float f : currentDashed)
     1155                            System.out.println("dash: " + f);
     1156                        g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
     1157                    }
     1158                }
    11511159                else
    11521160                    g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
    11531161            }
     
    11561164            if(currentDashedColor != null) {
    11571165                g2d.setColor(currentDashedColor);
    11581166                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},currentDashed));
     1167                    if (currentDashed.length > 0) {
     1168                        float[] currentDashedOffset = new float[currentDashed.length];
     1169                        System.arraycopy(currentDashed, 1, currentDashedOffset, 0, currentDashed.length - 1);
     1170                        currentDashedOffset[currentDashed.length-1] = currentDashed[0];
     1171                        float offset = currentDashedOffset[0];
     1172                        try {
     1173                            g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,currentDashedOffset,offset));
     1174                        } catch (IllegalArgumentException e) {
     1175                            g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
     1176                        }
     1177                    }
    11611178                    else
    11621179                        g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
    11631180                }