Ignore:
Timestamp:
2012-07-15T14:59:10+02:00 (12 years ago)
Author:
Don-vip
Message:

mappaint: fix "real width" painting, broken since r5212 because of a typo error on "real-width" key. Introduction of a StyleKeys interface centralizing key definitions at the same place to avoid same mistake in the future.

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java

    r5217 r5342  
    3939        Color color = null;
    4040
    41         IconReference iconRef = c.get("fill-image", null, IconReference.class);
     41        IconReference iconRef = c.get(FILL_IMAGE, null, IconReference.class);
    4242        if (iconRef != null) {
    4343            fillImage = new MapImage(iconRef.iconName, iconRef.source);
     
    5454            }
    5555        } else {
    56             color = c.get("fill-color", null, Color.class);
     56            color = c.get(FILL_COLOR, null, Color.class);
    5757            if (color != null) {
    5858                int alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50))));
     
    6666
    6767        TextElement text = null;
    68         Keyword textPos = c.get("text-position", null, Keyword.class);
     68        Keyword textPos = c.get(TEXT_POSITION, null, Keyword.class);
    6969        if (textPos == null || Utils.equal(textPos.val, "center")) {
    7070            text = TextElement.create(c, PaintColors.AREA_TEXT.get(), true);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/BoxTextElemStyle.java

    r5217 r5342  
    162162        MultiCascade mc = new MultiCascade();
    163163        Cascade c = mc.getOrCreateCascade("default");
    164         c.put("text", Keyword.AUTO);
     164        c.put(TEXT, Keyword.AUTO);
    165165        Node n = new Node();
    166166        n.put("name", "dummy");
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java

    r5217 r5342  
    1414import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.RelativeFloat;
    1515
    16 abstract public class ElemStyle {
     16abstract public class ElemStyle implements StyleKeys {
    1717
    1818    public float major_z_index;
     
    3131    protected ElemStyle(Cascade c, float default_major_z_index) {
    3232        major_z_index = c.get("major-z-index", default_major_z_index, Float.class);
    33         z_index = c.get("z-index", 0f, Float.class);
    34         object_z_index = c.get("object-z-index", 0f, Float.class);
    35         isModifier = c.get("modifier", false, Boolean.class);
     33        z_index = c.get(Z_INDEX, 0f, Float.class);
     34        object_z_index = c.get(OBJECT_Z_INDEX, 0f, Float.class);
     35        isModifier = c.get(MODIFIER, false, Boolean.class);
    3636    }
    3737
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r5217 r5342  
    2222        MultiCascade mc = new MultiCascade();
    2323        Cascade c = mc.getOrCreateCascade("default");
    24         c.put("width", Keyword.DEFAULT);
    25         c.put("color", color != null ? color : PaintColors.UNTAGGED.get());
     24        c.put(WIDTH, Keyword.DEFAULT);
     25        c.put(COLOR, color != null ? color : PaintColors.UNTAGGED.get());
    2626        if (isAreaEdge) {
    27             c.put("z-index", -3f);
     27            c.put(Z_INDEX, -3f);
    2828        }
    2929        return createLine(new Environment(null, mc, "default", null));
     
    9999            case NORMAL:
    100100            {
    101                 Float widthOnDefault = getWidth(c_def, "width", null);
    102                 width = getWidth(c, "width", widthOnDefault);
     101                Float widthOnDefault = getWidth(c_def, WIDTH, null);
     102                width = getWidth(c, WIDTH, widthOnDefault);
    103103                break;
    104104            }
    105105            case CASING:
    106106            {
    107                 Float casingWidth = c.get(type.prefix + "width", null, Float.class, true);
     107                Float casingWidth = c.get(type.prefix + WIDTH, null, Float.class, true);
    108108                if (casingWidth == null) {
    109                     RelativeFloat rel_casingWidth = c.get(type.prefix + "width", null, RelativeFloat.class, true);
     109                    RelativeFloat rel_casingWidth = c.get(type.prefix + WIDTH, null, RelativeFloat.class, true);
    110110                    if (rel_casingWidth != null) {
    111111                        casingWidth = rel_casingWidth.val / 2;
     
    114114                if (casingWidth == null)
    115115                    return null;
    116                 Float widthOnDefault = getWidth(c_def, "width", null);
    117                 width = getWidth(c, "width", widthOnDefault);
     116                Float widthOnDefault = getWidth(c_def, WIDTH, null);
     117                width = getWidth(c, WIDTH, widthOnDefault);
    118118                if (width == null) {
    119119                    width = 0f;
     
    124124            case LEFT_CASING:
    125125            case RIGHT_CASING:
    126                 width = getWidth(c, type.prefix + "width", null);
     126                width = getWidth(c, type.prefix + WIDTH, null);
    127127                break;
    128128            default:
     
    132132            return null;
    133133
    134         float realWidth = c.get(type.prefix + "real_width", 0f, Float.class);
     134        float realWidth = c.get(type.prefix + REAL_WIDTH, 0f, Float.class);
    135135        if (realWidth > 0 && MapPaintSettings.INSTANCE.isUseRealWidth()) {
    136136
     
    149149        }
    150150
    151         Float offset = c.get("offset", 0f, Float.class);
     151        Float offset = c.get(OFFSET, 0f, Float.class);
    152152        switch (type) {
    153153            case NORMAL:
    154154                break;
    155155            case CASING:
    156                 offset += c.get(type.prefix + "offset", 0f, Float.class);
     156                offset += c.get(type.prefix + OFFSET, 0f, Float.class);
    157157                break;
    158158            case LEFT_CASING:
    159159            case RIGHT_CASING:
    160160            {
    161                 Float baseWidthOnDefault = getWidth(c_def, "width", null);
    162                 Float baseWidth = getWidth(c, "width", baseWidthOnDefault);
     161                Float baseWidthOnDefault = getWidth(c_def, WIDTH, null);
     162                Float baseWidth = getWidth(c, WIDTH, baseWidthOnDefault);
    163163                if (baseWidth == null || baseWidth < 2f) {
    164164                    baseWidth = 2f;
    165165                }
    166                 float casingOffset = c.get(type.prefix + "offset", 0f, Float.class);
     166                float casingOffset = c.get(type.prefix + OFFSET, 0f, Float.class);
    167167                casingOffset += baseWidth / 2 + width / 2;
    168168                /* flip sign for the right-casing-offset */
     
    175175        }
    176176
    177         Color color = c.get(type.prefix + "color", null, Color.class);
     177        Color color = c.get(type.prefix + COLOR, null, Color.class);
    178178        if (type == LineType.NORMAL && color == null) {
    179             color = c.get("fill-color", null, Color.class);
     179            color = c.get(FILL_COLOR, null, Color.class);
    180180        }
    181181        if (color == null) {
     
    184184
    185185        int alpha = 255;
    186         Integer pAlpha = Utils.color_float2int(c.get("opacity", null, Float.class));
     186        Integer pAlpha = Utils.color_float2int(c.get(OPACITY, null, Float.class));
    187187        if (pAlpha != null) {
    188188            alpha = pAlpha;
     
    190190        color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
    191191
    192         float[] dashes = c.get(type.prefix + "dashes", null, float[].class);
     192        float[] dashes = c.get(type.prefix + DASHES, null, float[].class);
    193193        if (dashes != null) {
    194194            boolean hasPositive = false;
     
    206206            }
    207207        }
    208         float dashesOffset = c.get(type.prefix + "dashes-offset", 0f, Float.class);
    209         Color dashesBackground = c.get(type.prefix + "dashes-background-color", null, Color.class);
     208        float dashesOffset = c.get(type.prefix + DASHES_OFFSET, 0f, Float.class);
     209        Color dashesBackground = c.get(type.prefix + DASHES_BACKGROUND_COLOR, null, Color.class);
    210210        if (dashesBackground != null) {
    211             pAlpha = Utils.color_float2int(c.get(type.prefix + "dashes-background-opacity", null, Float.class));
     211            pAlpha = Utils.color_float2int(c.get(type.prefix + DASHES_BACKGROUND_OPACITY, null, Float.class));
    212212            if (pAlpha != null) {
    213213                alpha = pAlpha;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineTextElemStyle.java

    r5219 r5342  
    2020        Cascade c = env.mc.getCascade(env.layer);
    2121
    22         Keyword textPos = c.get("text-position", null, Keyword.class);
     22        Keyword textPos = c.get(TEXT_POSITION, null, Keyword.class);
    2323        if (textPos != null && !Utils.equal(textPos.val, "line"))
    2424            return null;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MultiCascade.java

    r3987 r5342  
    1414 * StyleSources apply zoom level dependent properties.
    1515 */
    16 public class MultiCascade {
     16public class MultiCascade implements StyleKeys {
    1717
    1818    private Map<String, Cascade> layers;
     
    4040                // be a modifier. Can be overridden in style definition.
    4141                if (!layer.equals("default") && !layer.equals("*")) {
    42                     c.put("modifier", true);
     42                    c.put(MODIFIER, true);
    4343                }
    4444            }
     
    6161            c = new Cascade();
    6262            if (!layer.equals("default") && !layer.equals("*")) {
    63                 c.put("modifier", true);
     63                c.put(MODIFIER, true);
    6464            }
    6565        }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

    r5217 r5342  
    122122        Cascade c_def = env.mc.getCascade("default");
    123123
    124         final IconReference iconRef = c.get("icon-image", null, IconReference.class);
     124        final IconReference iconRef = c.get(ICON_IMAGE, null, IconReference.class);
    125125        if (iconRef == null)
    126126            return null;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/TextElement.java

    r4415 r5342  
    1919 *
    2020 */
    21 public class TextElement {
     21public class TextElement implements StyleKeys {
    2222    static public final LabelCompositionStrategy AUTO_LABEL_COMPOSITION_STRATEGY = new DeriveLabelFromNameTagsCompositionStrategy();
    2323
     
    8585         * from a tag value.
    8686         */
    87         TagKeyReference tkr = c.get("text", null, TagKeyReference.class, true);
     87        TagKeyReference tkr = c.get(TEXT, null, TagKeyReference.class, true);
    8888        if (tkr != null)
    8989            return new TagLookupCompositionStrategy(tkr.key);
     
    9393         * a keyword
    9494         */
    95         Keyword keyword = c.get("text", null, Keyword.class, true);
     95        Keyword keyword = c.get(TEXT, null, Keyword.class, true);
    9696        if (equal(keyword, Keyword.AUTO))
    9797            return AUTO_LABEL_COMPOSITION_STRATEGY;
     
    100100         * Do we have a static text label?
    101101         */
    102         String text = c.get("text", null, String.class, true);
     102        String text = c.get(TEXT, null, String.class, true);
    103103        if (text != null)
    104104            return new StaticLabelCompositionStrategy(text);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Instruction.java

    r4191 r5342  
    99import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    1010import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
     11import org.openstreetmap.josm.gui.mappaint.StyleKeys;
    1112
    12 abstract public class Instruction {
     13abstract public class Instruction implements StyleKeys {
    1314
    1415    public abstract void execute(Environment env);
     
    3536            if (val instanceof Expression.LiteralExpression) {
    3637                Object litValue = ((Expression.LiteralExpression) val).evaluate(null);
    37                 if (key.equals("text")) {
     38                if (key.equals(TEXT)) {
    3839                    /* Special case for declaration 'text: ...'
    3940                     *
     
    7273                value = val;
    7374            }
    74             if (key.equals("icon-image") || key.equals("fill-image") || key.equals("pattern-image")) {
     75            if (key.equals(ICON_IMAGE) || key.equals(FILL_IMAGE) || key.equals("pattern-image")) {
    7576                if (value instanceof String) {
    7677                    value = new IconReference((String) value, env.source);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java

    r5144 r5342  
    2323import org.openstreetmap.josm.gui.mappaint.MultiCascade;
    2424import org.openstreetmap.josm.gui.mappaint.Range;
     25import org.openstreetmap.josm.gui.mappaint.StyleKeys;
    2526import org.openstreetmap.josm.gui.mappaint.StyleSource;
    2627import org.openstreetmap.josm.gui.preferences.SourceEntry;
     
    3132import org.xml.sax.SAXParseException;
    3233
    33 public class XmlStyleSource extends StyleSource {
     34public class XmlStyleSource extends StyleSource implements StyleKeys {
    3435
    3536    protected final HashMap<String, IconPrototype> icons = new HashMap<String, IconPrototype>();
     
    286287            IconPrototype icon = getNode(osm, (useMinMaxScale ? scale : null), mc);
    287288            if (icon != null) {
    288                 def.put("icon-image", icon.icon);
     289                def.put(ICON_IMAGE, icon.icon);
    289290                if (osm instanceof Node) {
    290291                    if (icon.annotate != null) {
    291292                        if (icon.annotate) {
    292                             def.put("text", Keyword.AUTO);
     293                            def.put(TEXT, Keyword.AUTO);
    293294                        } else {
    294                             def.remove("text");
     295                            def.remove(TEXT);
    295296                        }
    296297                    }
     
    301302            get(osm, pretendWayIsClosed || !(osm instanceof Way) || ((Way) osm).isClosed(), p, (useMinMaxScale ? scale : null), mc);
    302303            if (p.line != null) {
    303                 def.put("width", new Float(p.line.getWidth()));
    304                 def.putOrClear("real-width", p.line.realWidth != null ? new Float(p.line.realWidth) : null);
    305                 def.putOrClear("color", p.line.color);
     304                def.put(WIDTH, new Float(p.line.getWidth()));
     305                def.putOrClear(REAL_WIDTH, p.line.realWidth != null ? new Float(p.line.realWidth) : null);
     306                def.putOrClear(COLOR, p.line.color);
    306307                if (p.line.color != null) {
    307308                    int alpha = p.line.color.getAlpha();
    308309                    if (alpha != 255) {
    309                         def.put("opacity", Utils.color_int2float(alpha));
     310                        def.put(OPACITY, Utils.color_int2float(alpha));
    310311                    }
    311312                }
    312                 def.putOrClear("dashes", p.line.getDashed());
    313                 def.putOrClear("dashes-background-color", p.line.dashedColor);
    314             }
    315             Float refWidth = def.get("width", null, Float.class);
     313                def.putOrClear(DASHES, p.line.getDashed());
     314                def.putOrClear(DASHES_BACKGROUND_COLOR, p.line.dashedColor);
     315            }
     316            Float refWidth = def.get(WIDTH, null, Float.class);
    316317            if (refWidth != null && p.linemods != null) {
    317318                int numOver = 0, numUnder = 0;
     
    325326                        String layer = String.format("over_%d", numOver);
    326327                        c = mc.getOrCreateCascade(layer);
    327                         c.put("object-z-index", new Float(numOver));
     328                        c.put(OBJECT_Z_INDEX, new Float(numOver));
    328329                        ++numOver;
    329330                    } else {
    330331                        String layer = String.format("under_%d", numUnder);
    331332                        c = mc.getOrCreateCascade(layer);
    332                         c.put("object-z-index", new Float(-numUnder));
     333                        c.put(OBJECT_Z_INDEX, new Float(-numUnder));
    333334                        ++numUnder;
    334335                    }
    335                     c.put("width", new Float(mod.getWidth(refWidth)));
    336                     c.putOrClear("color", mod.color);
     336                    c.put(WIDTH, new Float(mod.getWidth(refWidth)));
     337                    c.putOrClear(COLOR, mod.color);
    337338                    if (mod.color != null) {
    338339                        int alpha = mod.color.getAlpha();
    339340                        if (alpha != 255) {
    340                             c.put("opacity", Utils.color_int2float(alpha));
     341                            c.put(OPACITY, Utils.color_int2float(alpha));
    341342                        }
    342343                    }
    343                     c.putOrClear("dashes", mod.getDashed());
    344                     c.putOrClear("dashes-background-color", mod.dashedColor);
     344                    c.putOrClear(DASHES, mod.getDashed());
     345                    c.putOrClear(DASHES_BACKGROUND_COLOR, mod.dashedColor);
    345346                }
    346347            }
     
    353354            }
    354355            if (p.area != null) {
    355                 def.putOrClear("fill-color", p.area.color);
    356                 def.putOrClear("text-position", Keyword.CENTER);
    357                 def.putOrClear("text", Keyword.AUTO);
    358                 def.remove("fill-image");
     356                def.putOrClear(FILL_COLOR, p.area.color);
     357                def.putOrClear(TEXT_POSITION, Keyword.CENTER);
     358                def.putOrClear(TEXT, Keyword.AUTO);
     359                def.remove(FILL_IMAGE);
    359360            }
    360361        }
Note: See TracChangeset for help on using the changeset viewer.