Ticket #6797: async3.diff

File async3.diff, 31.2 KB (added by bastiK, 14 years ago)

ready for commit

  • src/org/openstreetmap/josm/tools/ImageProvider.java

     
    3131import java.util.Collection;
    3232import java.util.HashMap;
    3333import java.util.Map;
     34import java.util.concurrent.Executors;
     35import java.util.concurrent.ExecutorService;
    3436import java.util.regex.Matcher;
    3537import java.util.regex.Pattern;
    3638import java.util.zip.ZipEntry;
     
    103105     */
    104106    private static Map<String, ImageResource> cache = new HashMap<String, ImageResource>();
    105107
     108    private final static ExecutorService imageFetcher = Executors.newSingleThreadExecutor();
     109
     110    public interface ImageCallback {
     111        void finished(ImageIcon result);
     112    }
     113
    106114    /**
    107115     * @param subdir    Subdirectory the image lies in.
    108116     * @param name      The name of the image. If it does not end with '.png' or '.svg',
     
    258266    }
    259267
    260268    /**
     269     * Load the image in a background thread.
     270     */
     271    public void getInBackground(final ImageCallback callback) {
     272        if (name.startsWith("http://") || name.startsWith("wiki://")) {
     273            Runnable fetch = new Runnable() {
     274                @Override
     275                public void run() {
     276                    ImageIcon result = get();
     277                    callback.finished(result);
     278                }
     279            };
     280            imageFetcher.submit(fetch);
     281        } else {
     282            ImageIcon result = get();
     283            callback.finished(result);
     284        }
     285    }
     286
     287    /**
    261288     * Return an image from the specified location. Throws a RuntimeException if
    262289     * the image cannot be located.
    263290     *
  • src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.mappaint;
    33
    4 import java.awt.Image;
    5 
    6 import javax.swing.ImageIcon;
    7 
    84import org.openstreetmap.josm.data.osm.OsmPrimitive;
    95import org.openstreetmap.josm.data.osm.Way;
    106import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
     
    1612 */
    1713public class LinePatternElemStyle extends ElemStyle {
    1814
    19     public MapImage<Image> pattern;
     15    public MapImage pattern;
    2016
    21     public LinePatternElemStyle(Cascade c, MapImage<Image> pattern) {
     17    public LinePatternElemStyle(Cascade c, MapImage pattern) {
    2218        super(c, -1f);
    2319        this.pattern = pattern;
    2420    }
     
    2925        IconReference iconRef = c.get("pattern-image", null, IconReference.class);
    3026        if (iconRef == null)
    3127            return null;
    32         ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1);
    33         if (icon == null)
    34             return null;
    35         MapImage<Image> pattern = new MapImage<Image>(iconRef.iconName, iconRef.source);
    36         pattern.img = icon.getImage();
     28        MapImage pattern = new MapImage(iconRef.iconName, iconRef.source);
    3729        return new LinePatternElemStyle(c, pattern);
    3830    }
    3931
    4032    @Override
    4133    public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member) {
    4234        Way w = (Way)primitive;
    43         painter.drawLinePattern(w, pattern.img);
     35        painter.drawLinePattern(w, pattern.getImage());
    4436    }
    4537
    4638    @Override
  • src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

     
    55
    66import java.awt.BasicStroke;
    77import java.awt.Color;
    8 import java.awt.Image;
    98import java.awt.Rectangle;
    109import java.awt.Stroke;
    1110
    12 import javax.swing.ImageIcon;
    13 
    1411import org.openstreetmap.josm.Main;
    1512import org.openstreetmap.josm.data.osm.Node;
    1613import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    1916import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
    2017import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
    2118import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList;
     19import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.BoxProvider;
     20import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.SimpleBoxProvider;
    2221import org.openstreetmap.josm.tools.Pair;
    2322import org.openstreetmap.josm.tools.Utils;
    2423
     
    2625 * applies for Nodes and turn restriction relations
    2726 */
    2827public class NodeElemStyle extends ElemStyle {
    29     public MapImage<Image> mapImage;
     28    public MapImage mapImage;
    3029    public Symbol symbol;
    3130
    32     private ImageIcon disabledIcon;
    33 
    3431    public enum SymbolShape { SQUARE, CIRCLE, TRIANGLE, PENTAGON, HEXAGON, HEPTAGON, OCTAGON, NONAGON, DECAGON }
    3532
    3633    public static class Symbol {
     
    9491    public static final StyleList DEFAULT_NODE_STYLELIST = new StyleList(NodeElemStyle.SIMPLE_NODE_ELEMSTYLE);
    9592    public static final StyleList DEFAULT_NODE_STYLELIST_TEXT = new StyleList(NodeElemStyle.SIMPLE_NODE_ELEMSTYLE, BoxTextElemStyle.SIMPLE_NODE_TEXT_ELEMSTYLE);
    9693
    97     protected NodeElemStyle(Cascade c, MapImage<Image> mapImage, Symbol symbol) {
     94    protected NodeElemStyle(Cascade c, MapImage mapImage, Symbol symbol) {
    9895        super(c, 1000f);
    9996        this.mapImage = mapImage;
    10097        this.symbol = symbol;
     
    107104    private static NodeElemStyle create(Environment env, boolean allowDefault) {
    108105        Cascade c = env.mc.getCascade(env.layer);
    109106
    110         MapImage<Image> mapImage = createIcon(env);
     107        MapImage mapImage = createIcon(env);
    111108        Symbol symbol = null;
    112109        if (mapImage == null) {
    113110            symbol = createSymbol(env);
     
    121118        return new NodeElemStyle(c, mapImage, symbol);
    122119    }
    123120
    124     private static MapImage<Image> createIcon(Environment env) {
     121    private static MapImage createIcon(Environment env) {
    125122        Cascade c = env.mc.getCascade(env.layer);
    126123        Cascade c_def = env.mc.getCascade("default");
    127124
    128         IconReference iconRef = c.get("icon-image", null, IconReference.class);
     125        final IconReference iconRef = c.get("icon-image", null, IconReference.class);
    129126        if (iconRef == null)
    130127            return null;
    131128
     
    144141        int width = widthF == null ? -1 : Math.round(widthF);
    145142        int height = heightF == null ? -1 : Math.round(heightF);
    146143
    147         MapImage<Image> mapImage = new MapImage<Image>(iconRef.iconName, iconRef.source);
     144        final MapImage mapImage = new MapImage(iconRef.iconName, iconRef.source);
    148145
    149         ImageIcon icon = MapPaintStyles.getIcon(iconRef, width, height);
    150         if (icon == null) {
    151             mapImage.img = MapPaintStyles.getNoIcon_Icon(iconRef.source).getImage();
    152         } else {
    153             mapImage.img = icon.getImage();
    154             mapImage.alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255))));
    155             Integer pAlpha = Utils.color_float2int(c.get("icon-opacity", null, float.class));
    156             if (pAlpha != null) {
    157                 mapImage.alpha = pAlpha;
    158             }
    159             mapImage.width = width;
    160             mapImage.height = height;
     146        mapImage.width = width;
     147        mapImage.height = height;
     148
     149        mapImage.alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255))));
     150        Integer pAlpha = Utils.color_float2int(c.get("icon-opacity", null, float.class));
     151        if (pAlpha != null) {
     152            mapImage.alpha = pAlpha;
    161153        }
    162154        return mapImage;
    163155    }
     
    242234        if (primitive instanceof Node) {
    243235            Node n = (Node) primitive;
    244236            if (mapImage != null && painter.isShowIcons()) {
    245                 painter.drawNodeIcon(n, (painter.isInactiveMode() || n.isDisabled()) ? mapImage.getDisabled() : mapImage.img,
     237                painter.drawNodeIcon(n, (painter.isInactiveMode() || n.isDisabled()) ? mapImage.getDisabled() : mapImage.getImage(),
    246238                        Utils.color_int2float(mapImage.alpha), selected, member);
    247239            } else if (symbol != null) {
    248240                Color fillColor = symbol.fillColor;
     
    308300        }
    309301    }
    310302
    311     public Rectangle getBox() {
     303    public BoxProvider getBoxProvider() {
    312304        if (mapImage != null) {
    313             int w = mapImage.img.getWidth(null), h = mapImage.img.getHeight(null);
    314             return new Rectangle(-w/2, -h/2, w, h);
     305            return mapImage.getBoxProvider();
    315306        } else if (symbol != null) {
    316             return new Rectangle(-symbol.size/2, -symbol.size/2, symbol.size, symbol.size);
     307            return new SimpleBoxProvider(new Rectangle(-symbol.size/2, -symbol.size/2, symbol.size, symbol.size));
    317308        } else {
    318309            // This is only executed once, so no performance concerns.
    319310            // However, it would be better, if the settings could be changed at runtime.
     
    323314                    Main.pref.getInteger("mappaint.node.connection-size", 5),
    324315                    Main.pref.getInteger("mappaint.node.tagged-size", 3)
    325316            );
    326             return new Rectangle(-size/2, -size/2, size, size);
     317            return new SimpleBoxProvider(new Rectangle(-size/2, -size/2, size, size));
    327318        }
    328319    }
    329320
  • src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

     
    118118                .setOptional(true).get();
    119119    }
    120120
    121     private static List<String> getIconSourceDirs(StyleSource source) {
     121    public static List<String> getIconSourceDirs(StyleSource source) {
    122122        List<String> dirs = new LinkedList<String>();
    123123
    124124        String sourceDir = source.getLocalSourceDir();
  • src/org/openstreetmap/josm/gui/mappaint/MapImage.java

     
    22package org.openstreetmap.josm.gui.mappaint;
    33
    44import static org.openstreetmap.josm.tools.Utils.equal;
     5
    56import java.awt.Image;
     7import java.awt.Rectangle;
     8import java.awt.image.BufferedImage;
    69
    710import javax.swing.GrayFilter;
    811import javax.swing.ImageIcon;
    912
    10 public class MapImage<I extends Image> {
     13import org.openstreetmap.josm.Main;
     14import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.BoxProvider;
     15import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.BoxProviderResult;
     16import org.openstreetmap.josm.tools.ImageProvider;
     17import org.openstreetmap.josm.tools.ImageProvider.ImageCallback;
     18import org.openstreetmap.josm.tools.Utils;
     19
     20public class MapImage {
    1121    /**
    1222     * ImageIcon can chage while the image is loading.
    1323     */
    14     public I img;
     24    private BufferedImage img;
    1525
    1626    public int alpha = 255;
    1727
     
    2333    public int width = -1;
    2434    public int height = -1;
    2535
     36    private boolean temporary;
    2637    private Image disabledImg;
    2738
    2839    public MapImage(String name, StyleSource source) {
     
    3647        return disabledImg = GrayFilter.createDisabledImage(img);
    3748    }
    3849
    39     // img changes when image is fully loaded and can't be used for equality check.
     50    public BufferedImage getImage() {
     51        if (img != null)
     52            return img;
     53        new ImageProvider(name)
     54                .setDirs(MapPaintStyles.getIconSourceDirs(source))
     55                .setId("mappaint."+source.getPrefName())
     56                .setArchive(source.zipIcons)
     57                .setWidth(width)
     58                .setHeight(height)
     59                .setOptional(true)
     60                .getInBackground(new ImageCallback() {
     61                    @Override
     62                    public void finished(ImageIcon result) {
     63                        synchronized (MapImage.this) {
     64                            temporary = false;
     65                            boolean repaint = img != null; // repaint only necessary, if temporary image has been assigned before
     66                            if (result == null) {
     67                                img = (BufferedImage) MapPaintStyles.getNoIcon_Icon(source).getImage();
     68                            } else {
     69                                img = (BufferedImage) result.getImage();
     70                            }
     71                            if (repaint) {
     72                                Main.map.mapView.preferenceChanged(null); // otherwise repaint is ignored, because layer hasn't changed
     73                                Main.map.mapView.repaint();
     74                            }
     75                        }
     76                    }
     77                }
     78        );
     79        synchronized (this) {
     80            if (img == null) {
     81                img = (BufferedImage) ImageProvider.get("clock").getImage();
     82                temporary = true;
     83            }
     84        }
     85        return img;
     86    }
     87
     88    public int getWidth() {
     89        return getImage().getWidth(null);
     90    }
     91
     92    public int getHeight() {
     93        return getImage().getHeight(null);
     94    }
     95
     96    public float getAlphaFloat() {
     97        return Utils.color_int2float(alpha);
     98    }
     99
     100    /**
     101     * Returns true, if image is not completely loaded and getImage() returns a temporary image.
     102     */
     103    public boolean isTemporary() {
     104        return temporary;
     105    }
     106
     107    protected class MapImageBoxProvider implements BoxProvider {
     108        @Override
     109        public BoxProviderResult get() {
     110            return new BoxProviderResult(box(), temporary);
     111        }
     112
     113        private Rectangle box() {
     114            int w = getWidth(), h = getHeight();
     115            return new Rectangle(-w/2, -h/2, w, h);
     116        }
     117
     118        private MapImage getParent() {
     119            return MapImage.this;
     120        }
     121
     122        @Override
     123        public int hashCode() {
     124            return MapImage.this.hashCode();
     125        }
     126
     127        @Override
     128        public boolean equals(Object obj) {
     129            if (obj == null || !(obj instanceof BoxProvider))
     130                return false;
     131            if (obj instanceof MapImageBoxProvider) {
     132                MapImageBoxProvider other = (MapImageBoxProvider) obj;
     133                return MapImage.this.equals(other.getParent());
     134            } else if (temporary) {
     135                return false;
     136            } else {
     137                final BoxProvider other = (BoxProvider) obj;
     138                BoxProviderResult resultOther = other.get();
     139                if (resultOther.isTemporary()) return false;
     140                return box().equals(resultOther.getBox());
     141            }
     142        }
     143    }
     144
     145    public BoxProvider getBoxProvider() {
     146        return new MapImageBoxProvider();
     147    }
     148
    40149    @Override
    41150    public boolean equals(Object obj) {
    42151        if (obj == null || getClass() != obj.getClass())
    43152            return false;
    44153        final MapImage other = (MapImage) obj;
     154        // img changes when image is fully loaded and can't be used for equality check.
    45155        return  alpha == other.alpha &&
    46156                equal(name, other.name) &&
    47157                equal(source, other.source) &&
  • src/org/openstreetmap/josm/gui/mappaint/BoxTextElemStyle.java

     
    2121    public enum HorizontalTextAlignment { LEFT, CENTER, RIGHT }
    2222    public enum VerticalTextAlignment { ABOVE, TOP, CENTER, BOTTOM, BELOW }
    2323
     24    public static interface BoxProvider {
     25        BoxProviderResult get();
     26    }
     27
     28    public static class BoxProviderResult {
     29        private Rectangle box;
     30        private boolean temporary;
     31
     32        public BoxProviderResult(Rectangle box, boolean temporary) {
     33            this.box = box;
     34            this.temporary = temporary;
     35        }
     36
     37        /**
     38         * The box
     39         */
     40        public Rectangle getBox() {
     41            return box;
     42        }
     43
     44        /**
     45         * True, if the box can change in future calls of the BoxProvider get() method
     46         */
     47        public boolean isTemporary() {
     48            return temporary;
     49        }
     50    }
     51
     52    public static class SimpleBoxProvider implements BoxProvider {
     53        private Rectangle box;
     54
     55        public SimpleBoxProvider(Rectangle box) {
     56            this.box = box;
     57        }
     58
     59        @Override
     60        public BoxProviderResult get() {
     61            return new BoxProviderResult(box, false);
     62        }
     63
     64        @Override
     65        public int hashCode() {
     66            return box.hashCode();
     67        }
     68
     69        @Override
     70        public boolean equals(Object obj) {
     71            if (obj == null || !(obj instanceof BoxProvider))
     72                return false;
     73            final BoxProvider other = (BoxProvider) obj;
     74            BoxProviderResult resultOther = other.get();
     75            if (resultOther.isTemporary()) return false;
     76            return box.equals(resultOther.getBox());
     77        }
     78    }
     79
    2480    public static final Rectangle ZERO_BOX = new Rectangle(0, 0, 0, 0);
    2581
    2682    public TextElement text;
    27     public Rectangle box;
     83    // Either boxProvider or box is not null. If boxProvider is different from
     84    // null, this means, that the box can still change in future, otherwise
     85    // it is fixed.
     86    protected BoxProvider boxProvider;
     87    protected Rectangle box;
    2888    public HorizontalTextAlignment hAlign;
    2989    public VerticalTextAlignment vAlign;
    3090
    31     public BoxTextElemStyle(Cascade c, TextElement text, Rectangle box, HorizontalTextAlignment hAlign, VerticalTextAlignment vAlign) {
     91    public BoxTextElemStyle(Cascade c, TextElement text, BoxProvider boxProvider, Rectangle box, HorizontalTextAlignment hAlign, VerticalTextAlignment vAlign) {
    3292        super(c, 2000f);
    3393        CheckParameterUtil.ensureParameterNotNull(text);
    3494        CheckParameterUtil.ensureParameterNotNull(hAlign);
    3595        CheckParameterUtil.ensureParameterNotNull(vAlign);
    3696        this.text = text;
     97        this.boxProvider = boxProvider;
    3798        this.box = box == null ? ZERO_BOX : box;
    3899        this.hAlign = hAlign;
    39100        this.vAlign = vAlign;
    40101    }
    41102
     103    public static BoxTextElemStyle create(Environment env, BoxProvider boxProvider) {
     104        return create(env, boxProvider, null);
     105    }
     106
    42107    public static BoxTextElemStyle create(Environment env, Rectangle box) {
     108        return create(env, null, box);
     109    }
     110
     111    public static BoxTextElemStyle create(Environment env, BoxProvider boxProvider, Rectangle box) {
    43112        initDefaultParameters();
    44113        Cascade c = env.mc.getCascade(env.layer);
    45114
     
    73142            vAlign = VerticalTextAlignment.BELOW;
    74143        }
    75144
    76         return new BoxTextElemStyle(c, text, box, hAlign, vAlign);
     145        return new BoxTextElemStyle(c, text, boxProvider, box, hAlign, vAlign);
    77146    }
    78147
     148    public Rectangle getBox() {
     149        if (boxProvider != null) {
     150            BoxProviderResult result = boxProvider.get();
     151            if (!result.isTemporary()) {
     152                box = result.getBox();
     153                boxProvider = null;
     154            }
     155            return result.getBox();
     156        }
     157        return box;
     158    }
     159
    79160    public static final BoxTextElemStyle SIMPLE_NODE_TEXT_ELEMSTYLE;
    80161    static {
    81162        MultiCascade mc = new MultiCascade();
     
    83164        c.put("text", Keyword.AUTO);
    84165        Node n = new Node();
    85166        n.put("name", "dummy");
    86         SIMPLE_NODE_TEXT_ELEMSTYLE = create(new Environment(n, mc, "default", null), NodeElemStyle.SIMPLE_NODE_ELEMSTYLE.getBox());
     167        SIMPLE_NODE_TEXT_ELEMSTYLE = create(new Environment(n, mc, "default", null), NodeElemStyle.SIMPLE_NODE_ELEMSTYLE.getBoxProvider());
    87168        if (SIMPLE_NODE_TEXT_ELEMSTYLE == null) throw new AssertionError();
    88169    }
    89170    /*
     
    112193        if (obj == null || getClass() != obj.getClass())
    113194            return false;
    114195        final BoxTextElemStyle other = (BoxTextElemStyle) obj;
    115         return text.equals(other.text) &&
    116                 box.equals(other.box) &&
    117                 hAlign == other.hAlign &&
    118                 vAlign == other.vAlign;
     196        if (!text.equals(other.text)) return false;
     197        if (boxProvider != null) {
     198            if (!boxProvider.equals(other.boxProvider)) return false;
     199        } else if (other.boxProvider != null) {
     200            return false;
     201        } else {
     202            if (!box.equals(other.box)) return false;
     203        }
     204        if (hAlign != other.hAlign) return false;
     205        if (vAlign != other.vAlign) return false;
     206        return true;
    119207    }
    120208
    121209    @Override
    122210    public int hashCode() {
    123211        int hash = super.hashCode();
    124212        hash = 97 * hash + text.hashCode();
    125         hash = 97 * hash + box.hashCode();
     213        if (boxProvider != null) {
     214            hash = 97 * hash + boxProvider.hashCode();
     215        } else {
     216            hash = 97 * hash + box.hashCode();
     217        }
    126218        hash = 97 * hash + hAlign.hashCode();
    127219        hash = 97 * hash + vAlign.hashCode();
    128220        return hash;
  • src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

     
    2828
    2929    private boolean defaultNodes, defaultLines;
    3030    private int defaultNodesIdx, defaultLinesIdx;
    31    
     31
    3232    public ElemStyles()
    3333    {
    3434        styleSources = new ArrayList<StyleSource>();
     
    316316                NodeElemStyle nodeStyle = NodeElemStyle.create(env);
    317317                if (nodeStyle != null) {
    318318                    sl.add(nodeStyle);
    319                     addIfNotNull(sl, BoxTextElemStyle.create(env, nodeStyle.getBox()));
     319                    addIfNotNull(sl, BoxTextElemStyle.create(env, nodeStyle.getBoxProvider()));
    320320                } else {
    321                     addIfNotNull(sl, BoxTextElemStyle.create(env, NodeElemStyle.SIMPLE_NODE_ELEMSTYLE.getBox()));
     321                    addIfNotNull(sl, BoxTextElemStyle.create(env, NodeElemStyle.SIMPLE_NODE_ELEMSTYLE.getBoxProvider()));
    322322                }
    323323            } else if (osm instanceof Relation) {
    324324                if (((Relation)osm).isMultipolygon()) {
  • src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java

     
    44import static org.openstreetmap.josm.tools.Utils.equal;
    55
    66import java.awt.Color;
    7 import java.awt.image.BufferedImage;
    87
    9 import javax.swing.ImageIcon;
    10 
    118import org.openstreetmap.josm.Main;
    129import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1310import org.openstreetmap.josm.data.osm.Relation;
     
    2623     * an arbitrary color value sampled from the fillImage
    2724     */
    2825    public Color color;
    29     public MapImage<BufferedImage> fillImage;
     26    public MapImage fillImage;
    3027    public TextElement text;
    3128
    32     protected AreaElemStyle(Cascade c, Color color, MapImage<BufferedImage> fillImage, TextElement text) {
     29    protected AreaElemStyle(Cascade c, Color color, MapImage fillImage, TextElement text) {
    3330        super(c, -1000f);
    3431        CheckParameterUtil.ensureParameterNotNull(color);
    3532        this.color = color;
     
    3835    }
    3936
    4037    public static AreaElemStyle create(Cascade c) {
    41         MapImage<BufferedImage> fillImage = null;
     38        MapImage fillImage = null;
    4239        Color color = null;
    4340
    4441        IconReference iconRef = c.get("fill-image", null, IconReference.class);
    4542        if (iconRef != null) {
    46             ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1);
    47             if (icon != null) {
    48                 if (!(icon.getImage() instanceof BufferedImage))
    49                     throw new RuntimeException();
    50                 fillImage = new MapImage<BufferedImage>(iconRef.iconName, iconRef.source);
    51                 fillImage.img = (BufferedImage) icon.getImage();
     43            fillImage = new MapImage(iconRef.iconName, iconRef.source);
     44            fillImage.getImage();
    5245
    53                 color = new Color(fillImage.img.getRGB(
    54                         fillImage.img.getWidth() / 2, fillImage.img.getHeight() / 2)
    55                 );
     46            color = new Color(fillImage.getImage().getRGB(
     47                    fillImage.getWidth() / 2, fillImage.getHeight() / 2)
     48            );
    5649
    57                 fillImage.alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fill-image-alpha", 255))));
    58                 Integer pAlpha = Utils.color_float2int(c.get("fill-opacity", null, float.class));
    59                 if (pAlpha != null) {
    60                     fillImage.alpha = pAlpha;
    61                 }
     50            fillImage.alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fill-image-alpha", 255))));
     51            Integer pAlpha = Utils.color_float2int(c.get("fill-opacity", null, float.class));
     52            if (pAlpha != null) {
     53                fillImage.alpha = pAlpha;
    6254            }
    6355        } else {
    6456            color = c.get("fill-color", null, Color.class);
     
    7769        if (textPos == null || Utils.equal(textPos.val, "center")) {
    7870            text = TextElement.create(c, PaintColors.AREA_TEXT.get(), true);
    7971        }
    80        
     72
    8173        if (color != null)
    8274            return new AreaElemStyle(c, color, fillImage, text);
    8375        else
  • src/org/openstreetmap/josm/gui/MapView.java

     
    459459    /**
    460460     * Draw the component.
    461461     */
    462     @Override public void paint(Graphics g) {
     462    @Override public synchronized void paint(Graphics g) {
    463463        if (BugReportExceptionHandler.exceptionHandlingInProgress())
    464464            return;
    465465
     
    832832        }
    833833    }
    834834
    835     public void preferenceChanged(PreferenceChangeEvent e) {
     835    public synchronized void preferenceChanged(PreferenceChangeEvent e) {
    836836        paintPreferencesChanged = true;
    837837    }
    838838
  • src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java

     
    2121import java.awt.geom.Path2D;
    2222import java.awt.geom.Point2D;
    2323import java.awt.geom.Rectangle2D;
    24 import java.awt.image.BufferedImage;
    2524import java.util.Arrays;
    2625import java.util.Collection;
    2726import java.util.Iterator;
     
    737736         *       left-below   center-below    right-below
    738737         *
    739738         */
     739        Rectangle box = bs.getBox();
    740740        if (bs.hAlign == HorizontalTextAlignment.RIGHT) {
    741             x += bs.box.x + bs.box.width + 2;
     741            x += box.x + box.width + 2;
    742742        } else {
    743743            FontRenderContext frc = g.getFontRenderContext();
    744744            Rectangle2D bounds = text.font.getStringBounds(s, frc);
     
    746746            if (bs.hAlign == HorizontalTextAlignment.CENTER) {
    747747                x -= textWidth / 2;
    748748            } else if (bs.hAlign == HorizontalTextAlignment.LEFT) {
    749                 x -= - bs.box.x + 4 + textWidth;
     749                x -= - box.x + 4 + textWidth;
    750750            } else throw new AssertionError();
    751751        }
    752752
    753753        if (bs.vAlign == VerticalTextAlignment.BOTTOM) {
    754             y += bs.box.y + bs.box.height;
     754            y += box.y + box.height;
    755755        } else {
    756756            FontRenderContext frc = g.getFontRenderContext();
    757757            LineMetrics metrics = text.font.getLineMetrics(s, frc);
    758758            if (bs.vAlign == VerticalTextAlignment.ABOVE) {
    759                 y -= - bs.box.y + metrics.getDescent();
     759                y -= - box.y + metrics.getDescent();
    760760            } else if (bs.vAlign == VerticalTextAlignment.TOP) {
    761                 y -= - bs.box.y - metrics.getAscent();
     761                y -= - box.y - metrics.getAscent();
    762762            } else if (bs.vAlign == VerticalTextAlignment.CENTER) {
    763763                y += (metrics.getAscent() - metrics.getDescent()) / 2;
    764764            } else if (bs.vAlign == VerticalTextAlignment.BELOW) {
    765                 y += bs.box.y + bs.box.height + metrics.getAscent() + 2;
     765                y += box.y + box.height + metrics.getAscent() + 2;
    766766            } else throw new AssertionError();
    767767        }
    768768        if (inactive || n.isDisabled()) {
     
    802802        return path;
    803803    }
    804804
    805     public void drawArea(Way w, Color color, MapImage<BufferedImage> fillImage, TextElement text) {
     805    public void drawArea(Way w, Color color, MapImage fillImage, TextElement text) {
    806806        drawArea(w, getPath(w), color, fillImage, text);
    807807    }
    808808
    809     protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, MapImage<BufferedImage> fillImage, TextElement text) {
     809    protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, MapImage fillImage, TextElement text) {
    810810
    811811        Shape area = path.createTransformedShape(nc.getAffineTransform());
    812812
     
    815815                g.setColor(color);
    816816                g.fill(area);
    817817            } else {
    818                 TexturePaint texture = new TexturePaint(fillImage.img,
     818                TexturePaint texture = new TexturePaint(fillImage.getImage(),
    819819                        //                        new Rectangle(polygon.xpoints[0], polygon.ypoints[0], fillImage.getWidth(), fillImage.getHeight()));
    820                         new Rectangle(0, 0, fillImage.img.getWidth(null), fillImage.img.getHeight(null)));
     820                        new Rectangle(0, 0, fillImage.getWidth(), fillImage.getHeight()));
    821821                g.setPaint(texture);
    822822                Float alpha = Utils.color_int2float(fillImage.alpha);
    823823                if (alpha != 1f) {
     
    872872        }
    873873    }
    874874
    875     public void drawArea(Relation r, Color color, MapImage<BufferedImage> fillImage, TextElement text) {
     875    public void drawArea(Relation r, Color color, MapImage fillImage, TextElement text) {
    876876        Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, r);
    877877        if (!r.isDisabled() && !multipolygon.getOuterWays().isEmpty()) {
    878878            for (PolyData pd : multipolygon.getCombinedPolygons()) {
     
    914914        }
    915915    }
    916916
    917     public void drawRestriction(Relation r, MapImage<Image> icon) {
     917    public void drawRestriction(Relation r, MapImage icon) {
    918918        Way fromWay = null;
    919919        Way toWay = null;
    920920        OsmPrimitive via = null;
     
    10851085            iconAngle = 270-fromAngleDeg;
    10861086        }
    10871087
    1088         drawRestriction(inactive || r.isDisabled() ? icon.getDisabled() : icon.img,
     1088        drawRestriction(inactive || r.isDisabled() ? icon.getDisabled() : icon.getImage(),
    10891089                pVia, vx, vx2, vy, vy2, iconAngle, r.isSelected());
    10901090    }
    10911091