Changeset 3859 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2011-02-05T19:47:07+01:00 (14 years ago)
Author:
bastiK
Message:

mapcss: dashes

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java

    r3858 r3859  
    100100    }
    101101
    102     public void drawWay(Way way, Color color, float width, float dashed[], Color dashedColor, boolean showDirection,
     102    public void drawWay(Way way, Color color, float width, float dashed[], float dashesOffset, Color dashedColor, boolean showDirection,
    103103            boolean reversedDirection, boolean showHeadArrowOnly) {
    104104
     
    156156            lastPoint = p;
    157157        }
    158         displaySegments(path, arrows, color, width, dashed, dashedColor);
    159     }
    160 
    161     private void displaySegments(GeneralPath path, GeneralPath arrows, Color color, float width, float dashed[], Color dashedColor) {
     158        displaySegments(path, arrows, color, width, dashed, dashesOffset, dashedColor);
     159    }
     160
     161    private void displaySegments(GeneralPath path, GeneralPath arrows, Color color, float width, float dashed[], float dashesOffset, Color dashedColor) {
    162162        g.setColor(inactive ? inactiveColor : color);
    163163        if (useStrokes) {
    164164            if (dashed != null && dashed.length > 0) {
    165                 g.setStroke(new BasicStroke(width,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0, dashed,0));
     165                g.setStroke(new BasicStroke(width,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,dashed,dashesOffset));
    166166            } else {
    167167                g.setStroke(new BasicStroke(width,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
     
    175175            if (dashed != null && dashed.length > 0) {
    176176                float[] dashedOffset = new float[dashed.length];
    177                 System.arraycopy(dashed, 1, dashedOffset, 0, dashed.length - 1);
    178                 dashedOffset[dashed.length-1] = dashed[0];
    179                 float offset = dashedOffset[0];
    180                 g.setStroke(new BasicStroke(width,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,dashedOffset,offset));
     177                System.arraycopy(dashed, 0, dashedOffset, 1, dashed.length - 1);
     178                dashedOffset[0] = dashed[dashed.length-1];
     179                float offset = dashedOffset[0] + dashesOffset;
     180                g.setStroke(new BasicStroke(width,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,dashedOffset, offset));
    181181            } else {
    182182                g.setStroke(new BasicStroke(width,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
  • trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java

    r3858 r3859  
    6565    @Override
    6666    public String toString() {
    67         return "AreaElemStyle{" + super.toString() + "color=" + color + '}';
     67        return "AreaElemStyle{" + super.toString() + "color=" + Utils.toString(color) + '}';
    6868    }
    6969}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r3858 r3859  
    1616
    1717    public static LineElemStyle createSimpleLineStyle(Color color) {
    18         return new LineElemStyle(Cascade.EMPTY_CASCADE, -1f, 0f, color != null ? color : PaintColors.UNTAGGED.get(), null, null);
     18        return new LineElemStyle(Cascade.EMPTY_CASCADE, -1f, 0f, color != null ? color : PaintColors.UNTAGGED.get(), null, 0f, null);
    1919    }
    2020    public static final LineElemStyle UNTAGGED_WAY = createSimpleLineStyle(null);
     
    2424    public Color color;
    2525    private float[] dashed;
     26    private float dashesOffset;
    2627    public Color dashedColor;
    2728
    28     protected LineElemStyle(Cascade c, float width, float realWidth, Color color, float[] dashed, Color dashedColor) {
     29    protected LineElemStyle(Cascade c, float width, float realWidth, Color color, float[] dashed, float dashesOffset, Color dashedColor) {
    2930        super(c);
    3031        setWidth(width);
     
    3233        this.color = color;
    3334        this.dashed = dashed;
     35        this.dashesOffset = dashesOffset;
    3436        this.dashedColor = dashedColor;
    3537    }
     
    8486            }
    8587        }
     88        float dashesOffset = c.get(prefix + "dashes-offset", 0f, Float.class);
    8689        Color dashesBackground = c.get(prefix + "dashes-background-color", null, Color.class);
    87 
    88         return new LineElemStyle(c, width, realWidth, color, dashes, dashesBackground);
     90        if (dashesBackground != null) {
     91            pAlpha = color_float2int(c.get(prefix + "dashes-background-opacity", null, Float.class));
     92            if (pAlpha != null) {
     93                alpha = pAlpha;
     94            }
     95            dashesBackground = new Color(dashesBackground.getRed(), dashesBackground.getGreen(),
     96                    dashesBackground.getBlue(), alpha);
     97        }
     98
     99        return new LineElemStyle(c, width, realWidth, color, dashes, dashesOffset, dashesBackground);
    89100    }
    90101
     
    140151        }
    141152
    142         painter.drawWay(w, markColor != null ? markColor : color, myWidth, dashed, myDashedColor, showDirection,
    143                     selected ? false : reversedDirection, showOnlyHeadArrowOnly);
     153        painter.drawWay(w, markColor != null ? markColor : color, myWidth, dashed,
     154                dashesOffset, myDashedColor, showDirection,
     155                selected ? false : reversedDirection, showOnlyHeadArrowOnly);
    144156
    145157        if(paintSettings.isShowOrderNumber()) {
     
    177189                Utils.equal(color, other.color) &&
    178190                Arrays.equals(dashed, other.dashed) &&
     191                dashesOffset == other.dashesOffset &&
    179192                Utils.equal(dashedColor, other.dashedColor);
    180193    }
     
    187200        hash = 29 * hash + color.hashCode();
    188201        hash = 29 * hash + Arrays.hashCode(dashed);
     202        hash = 29 * hash + Float.floatToIntBits(dashesOffset);
    189203        hash = 29 * hash + (dashedColor != null ? dashedColor.hashCode() : 0);
    190204        return hash;
     
    193207    @Override
    194208    public String toString() {
    195         return "LineElemStyle{" + super.toString() + "width=" + width + " realWidth=" + realWidth + " color=" + color + " dashed=" + Arrays.toString(dashed) + " dashedColor=" + dashedColor + '}';
     209        return "LineElemStyle{" + super.toString() + "width=" + width +
     210                " realWidth=" + realWidth + " color=" + Utils.toString(color) +
     211                " dashed=" + Arrays.toString(dashed) +
     212                (dashesOffset == 0f ? "" : " dashesOffses=" + dashesOffset) +
     213                " dashedColor=" + Utils.toString(dashedColor) + '}';
    196214    }
    197215}
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r3848 r3859  
    22package org.openstreetmap.josm.tools;
    33
     4import java.awt.Color;
    45import java.util.Collection;
    56
     
    110111        return s.toString();
    111112    }
     113
     114    /**
     115     * convert Color to String
     116     * (Color.toString() omits alpha value)
     117     */
     118    public static String toString(Color c) {
     119        if (c == null)
     120            return "null";
     121        if (c.getAlpha() == 255)
     122            return String.format("#%06x", c.getRGB() & 0x00ffffff);
     123        else
     124            return String.format("#%06x(alpha=%d)", c.getRGB() & 0x00ffffff, c.getAlpha());
     125    }
    112126}
Note: See TracChangeset for help on using the changeset viewer.