Ignore:
Timestamp:
2012-05-06T08:09:19+02:00 (12 years ago)
Author:
bastiK
Message:

minor coding style change

File:
1 edited

Legend:

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

    r5206 r5212  
    3737
    3838    private BasicStroke dashesLine;
     39
     40    protected enum LineType {
     41        NORMAL(""),
     42        CASING("casing-"),
     43        LEFT_CASING("left-casing-"),
     44        RIGHT_CASING("right-casing");
     45
     46        public String prefix;
     47
     48        LineType(String prefix) {
     49            this.prefix = prefix;
     50        }
     51    }
    3952
    4053    protected LineElemStyle(Cascade c, BasicStroke line, Color color, BasicStroke dashesLine, Color dashesBackground, float offset, float realWidth) {
     
    4962
    5063    public static LineElemStyle createLine(Environment env) {
    51         return createImpl(env, "");
     64        return createImpl(env, LineType.NORMAL);
    5265    }
    5366
    5467    public static LineElemStyle createLeftCasing(Environment env) {
    55         LineElemStyle leftCasing = createImpl(env, "left-casing-");
     68        LineElemStyle leftCasing = createImpl(env, LineType.LEFT_CASING);
    5669        if (leftCasing != null) {
    5770            leftCasing.z_index += -90;
     
    6275
    6376    public static LineElemStyle createRightCasing(Environment env) {
    64         LineElemStyle rightCasing = createImpl(env, "right-casing-");
     77        LineElemStyle rightCasing = createImpl(env, LineType.RIGHT_CASING);
    6578        if (rightCasing != null) {
    6679            rightCasing.z_index += -90;
     
    7184
    7285    public static LineElemStyle createCasing(Environment env) {
    73         LineElemStyle casing = createImpl(env, "casing-");
     86        LineElemStyle casing = createImpl(env, LineType.CASING);
    7487        if (casing != null) {
    7588            casing.z_index += -100;
     
    7992    }
    8093
    81     private static LineElemStyle createImpl(Environment env, String prefix) {
     94    private static LineElemStyle createImpl(Environment env, LineType type) {
    8295        Cascade c = env.mc.getCascade(env.layer);
    8396        Cascade c_def = env.mc.getCascade("default");
    84 
    8597        Float widthOnDefault = getWidth(c_def, "width", null);
    8698        Float width = getWidth(c, "width", widthOnDefault);
    87         if (!prefix.isEmpty()) {
    88             width = getWidth(c, prefix + "width", width);
     99        if (type != LineType.NORMAL) {
     100            width = getWidth(c, type.prefix + "width", width);
    89101        }
    90102        if (width == null)
    91103            return null;
    92104
    93         float realWidth = c.get(prefix + "real-width", 0f, Float.class);
     105        float realWidth = c.get(type.prefix + "real_width", 0f, Float.class);
    94106        if (realWidth > 0 && MapPaintSettings.INSTANCE.isUseRealWidth()) {
    95107
     
    113125            offset = 0f;
    114126        }
    115         if (!prefix.isEmpty()) {
    116             Float base_width = getWidth(c, "width", widthOnDefault);
     127        if (type != LineType.NORMAL) {
     128            /* pre-calculate an offset */
    117129            Float base_offset = offset;
    118             if (base_width == null || base_width < 2f) {
    119                 base_width = 2f;
    120             }
    121             /* pre-calculate an offset */
    122             if (prefix.startsWith("left") || prefix.startsWith("right")) {
     130            if (type == LineType.LEFT_CASING || type == LineType.RIGHT_CASING) {
     131                Float base_width = getWidth(c, "width", widthOnDefault);
     132                if (base_width == null || base_width < 2f) {
     133                    base_width = 2f;
     134                }
    123135                offset = base_width/2 + width/2;
    124136            } else {
     
    126138            }
    127139            /* overwrites (e.g. "4") or adjusts (e.g. "+4") a prefixed -offset */
    128             if (getWidth(c, prefix + "offset", offset) != null) {
    129                 offset = getWidth(c, prefix + "offset", offset);
     140            if (getWidth(c, type.prefix + "offset", offset) != null) {
     141                offset = getWidth(c, type.prefix + "offset", offset);
    130142            }
    131143            /* flip sign for the right-casing-offset */
    132             if (prefix.startsWith("right")) {
     144            if (type == LineType.RIGHT_CASING) {
    133145                offset *= -1f;
    134146            }
     
    137149        }
    138150
    139         Color color = c.get(prefix + "color", null, Color.class);
    140         if (prefix.isEmpty() && color == null) {
     151        Color color = c.get(type.prefix + "color", null, Color.class);
     152        if (type == LineType.NORMAL && color == null) {
    141153            color = c.get("fill-color", null, Color.class);
    142154        }
     
    152164        color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
    153165
    154         float[] dashes = c.get(prefix + "dashes", null, float[].class);
     166        float[] dashes = c.get(type.prefix + "dashes", null, float[].class);
    155167        if (dashes != null) {
    156168            boolean hasPositive = false;
     
    168180            }
    169181        }
    170         float dashesOffset = c.get(prefix + "dashes-offset", 0f, Float.class);
    171         Color dashesBackground = c.get(prefix + "dashes-background-color", null, Color.class);
     182        float dashesOffset = c.get(type.prefix + "dashes-offset", 0f, Float.class);
     183        Color dashesBackground = c.get(type.prefix + "dashes-background-color", null, Color.class);
    172184        if (dashesBackground != null) {
    173             pAlpha = Utils.color_float2int(c.get(prefix + "dashes-background-opacity", null, Float.class));
     185            pAlpha = Utils.color_float2int(c.get(type.prefix + "dashes-background-opacity", null, Float.class));
    174186            if (pAlpha != null) {
    175187                alpha = pAlpha;
     
    180192
    181193        Integer cap = null;
    182         Keyword capKW = c.get(prefix + "linecap", null, Keyword.class);
     194        Keyword capKW = c.get(type.prefix + "linecap", null, Keyword.class);
    183195        if (capKW != null) {
    184196            if (equal(capKW.val, "none")) {
     
    195207
    196208        Integer join = null;
    197         Keyword joinKW = c.get(prefix + "linejoin", null, Keyword.class);
     209        Keyword joinKW = c.get(type.prefix + "linejoin", null, Keyword.class);
    198210        if (joinKW != null) {
    199211            if (equal(joinKW.val, "round")) {
     
    209221        }
    210222
    211         float miterlimit = c.get(prefix + "miterlimit", 10f, Float.class);
     223        float miterlimit = c.get(type.prefix + "miterlimit", 10f, Float.class);
    212224        if (miterlimit < 1f) {
    213225            miterlimit = 10f;
     
    235247        boolean showOrientation = !isModifier && (selected || paintSettings.isShowDirectionArrow()) && !paintSettings.isUseRealWidth();
    236248        boolean showOneway = !isModifier && !selected &&
    237         !paintSettings.isUseRealWidth() &&
    238         paintSettings.isShowOnewayArrow() && w.hasDirectionKeys();
     249                !paintSettings.isUseRealWidth() &&
     250                paintSettings.isShowOnewayArrow() && w.hasDirectionKeys();
    239251        boolean onewayReversed = w.reversedDirection();
    240252        /* head only takes over control if the option is true,
Note: See TracChangeset for help on using the changeset viewer.