Ignore:
Timestamp:
2012-01-19T19:58:08+01:00 (14 years ago)
Author:
bastiK
Message:

make identity of map icons depend on the name and not the image data (see #6797)

File:
1 edited

Legend:

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

    r4820 r4822  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.mappaint;
     3
     4import static org.openstreetmap.josm.tools.Utils.equal;
    35
    46import java.awt.Color;
     
    2628     */
    2729    public Color color;
    28     public BufferedImage fillImage;
    29     public float fillImageAlpha;
     30    public MapImage<BufferedImage> fillImage;
    3031    public TextElement text;
    3132
    32     protected AreaElemStyle(Cascade c, Color color, BufferedImage fillImage, float fillImageAlpha, TextElement text) {
     33    protected AreaElemStyle(Cascade c, Color color, MapImage<BufferedImage> fillImage, TextElement text) {
    3334        super(c, -1000f);
    3435        CheckParameterUtil.ensureParameterNotNull(color);
    3536        this.color = color;
    3637        this.fillImage = fillImage;
    37         this.fillImageAlpha = fillImageAlpha;
    3838        this.text = text;
    3939    }
    4040
    4141    public static AreaElemStyle create(Cascade c) {
    42         BufferedImage fillImage = null;
     42        MapImage<BufferedImage> fillImage = null;
    4343        Color color = null;
    44         float fillImageAlpha = 1f;
    4544
    4645        IconReference iconRef = c.get("fill-image", null, IconReference.class);
     
    5049                if (!(icon.getImage() instanceof BufferedImage))
    5150                    throw new RuntimeException();
    52                 fillImage = (BufferedImage) icon.getImage();
     51                fillImage = new MapImage<BufferedImage>(iconRef.iconName, iconRef.source);
     52                fillImage.img = (BufferedImage) icon.getImage();
    5353
    54                 color = new Color(fillImage.getRGB(fillImage.getWidth() / 2, fillImage.getHeight() / 2));
     54                color = new Color(fillImage.img.getRGB(
     55                        fillImage.img.getWidth() / 2, fillImage.img.getHeight() / 2)
     56                );
    5557
    56                 fillImageAlpha = Utils.color_int2float(Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fill-image-alpha", 255)))));
    57                 Float pAlpha = c.get("fill-opacity", null, Float.class);
     58                fillImage.alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fill-image-alpha", 255))));
     59                Integer pAlpha = Utils.color_float2int(c.get("fill-opacity", null, float.class));
    5860                if (pAlpha != null) {
    59                     if (pAlpha < 0f || pAlpha > 1f) {
    60                         pAlpha= 1f;
    61                     }
    62                     fillImageAlpha = pAlpha;
     61                    fillImage.alpha = pAlpha;
    6362                }
    6463            }
     
    8281       
    8382        if (color != null)
    84             return new AreaElemStyle(c, color, fillImage, fillImageAlpha, text);
     83            return new AreaElemStyle(c, color, fillImage, text);
    8584        else
    8685            return null;
     
    9796                }
    9897            }
    99             painter.drawArea((Way) osm, myColor, fillImage, fillImageAlpha, text);
     98            painter.drawArea((Way) osm, myColor, fillImage, text);
    10099        } else if (osm instanceof Relation)
    101100        {
     
    106105                }
    107106            }
    108             painter.drawArea((Relation) osm, myColor, fillImage, fillImageAlpha, text);
     107            painter.drawArea((Relation) osm, myColor, fillImage, text);
    109108        }
    110109    }
     
    118117        AreaElemStyle other = (AreaElemStyle) obj;
    119118        // we should get the same image object due to caching
    120         if (fillImage != other.fillImage)
     119        if (!equal(fillImage, other.fillImage))
    121120            return false;
    122         if (!Utils.equal(color, other.color))
     121        if (!equal(color, other.color))
    123122            return false;
    124         if (fillImageAlpha != other.fillImageAlpha)
    125             return false;
    126         if (!Utils.equal(text, other.text))
     123        if (!equal(text, other.text))
    127124            return false;
    128125        return true;
     
    134131        hash = 61 * hash + color.hashCode();
    135132        hash = 61 * hash + (fillImage != null ? fillImage.hashCode() : 0);
    136         hash = 61 * hash + Float.floatToIntBits(fillImageAlpha);
    137133        hash = 61 * hash + (text != null ? text.hashCode() : 0);
    138134        return hash;
     
    142138    public String toString() {
    143139        return "AreaElemStyle{" + super.toString() + "color=" + Utils.toString(color) +
    144                 " fillImageAlpha=" + fillImageAlpha + " fillImage=[" + fillImage + "]}";
     140                " fillImage=[" + fillImage + "]}";
    145141    }
    146142}
Note: See TracChangeset for help on using the changeset viewer.