Changeset 5054 in josm
- Timestamp:
- 2012-03-08T12:11:38+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
r5045 r5054 22 22 import java.awt.geom.Point2D; 23 23 import java.awt.geom.Rectangle2D; 24 import java.awt.image.BufferedImage;25 24 import java.util.Arrays; 26 25 import java.util.Collection; … … 738 737 * 739 738 */ 739 Rectangle box = bs.getBox(); 740 740 if (bs.hAlign == HorizontalTextAlignment.RIGHT) { 741 x += b s.box.x + bs.box.width + 2;741 x += box.x + box.width + 2; 742 742 } else { 743 743 FontRenderContext frc = g.getFontRenderContext(); … … 747 747 x -= textWidth / 2; 748 748 } else if (bs.hAlign == HorizontalTextAlignment.LEFT) { 749 x -= - b s.box.x + 4 + textWidth;749 x -= - box.x + 4 + textWidth; 750 750 } else throw new AssertionError(); 751 751 } 752 752 753 753 if (bs.vAlign == VerticalTextAlignment.BOTTOM) { 754 y += b s.box.y + bs.box.height;754 y += box.y + box.height; 755 755 } else { 756 756 FontRenderContext frc = g.getFontRenderContext(); 757 757 LineMetrics metrics = text.font.getLineMetrics(s, frc); 758 758 if (bs.vAlign == VerticalTextAlignment.ABOVE) { 759 y -= - b s.box.y + metrics.getDescent();759 y -= - box.y + metrics.getDescent(); 760 760 } else if (bs.vAlign == VerticalTextAlignment.TOP) { 761 y -= - b s.box.y - metrics.getAscent();761 y -= - box.y - metrics.getAscent(); 762 762 } else if (bs.vAlign == VerticalTextAlignment.CENTER) { 763 763 y += (metrics.getAscent() - metrics.getDescent()) / 2; 764 764 } else if (bs.vAlign == VerticalTextAlignment.BELOW) { 765 y += b s.box.y + bs.box.height + metrics.getAscent() + 2;765 y += box.y + box.height + metrics.getAscent() + 2; 766 766 } else throw new AssertionError(); 767 767 } … … 803 803 } 804 804 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) { 806 806 drawArea(w, getPath(w), color, fillImage, text); 807 807 } 808 808 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) { 810 810 811 811 Shape area = path.createTransformedShape(nc.getAffineTransform()); … … 816 816 g.fill(area); 817 817 } else { 818 TexturePaint texture = new TexturePaint(fillImage. img,818 TexturePaint texture = new TexturePaint(fillImage.getImage(), 819 819 // 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())); 821 821 g.setPaint(texture); 822 822 Float alpha = Utils.color_int2float(fillImage.alpha); … … 873 873 } 874 874 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) { 876 876 Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, r); 877 877 if (!r.isDisabled() && !multipolygon.getOuterWays().isEmpty()) { … … 915 915 } 916 916 917 public void drawRestriction(Relation r, MapImage <Image>icon) {917 public void drawRestriction(Relation r, MapImage icon) { 918 918 Way fromWay = null; 919 919 Way toWay = null; … … 1086 1086 } 1087 1087 1088 drawRestriction(inactive || r.isDisabled() ? icon.getDisabled() : icon. img,1088 drawRestriction(inactive || r.isDisabled() ? icon.getDisabled() : icon.getImage(), 1089 1089 pVia, vx, vx2, vy, vy2, iconAngle, r.isSelected()); 1090 1090 } -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r4627 r5054 460 460 * Draw the component. 461 461 */ 462 @Override public void paint(Graphics g) { 462 @Override public synchronized void paint(Graphics g) { 463 463 if (BugReportExceptionHandler.exceptionHandlingInProgress()) 464 464 return; … … 833 833 } 834 834 835 public void preferenceChanged(PreferenceChangeEvent e) { 835 public synchronized void preferenceChanged(PreferenceChangeEvent e) { 836 836 paintPreferencesChanged = true; 837 837 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r4960 r5054 5 5 6 6 import java.awt.Color; 7 import java.awt.image.BufferedImage;8 9 import javax.swing.ImageIcon;10 7 11 8 import org.openstreetmap.josm.Main; … … 27 24 */ 28 25 public Color color; 29 public MapImage <BufferedImage>fillImage;26 public MapImage fillImage; 30 27 public TextElement text; 31 28 32 protected AreaElemStyle(Cascade c, Color color, MapImage <BufferedImage>fillImage, TextElement text) {29 protected AreaElemStyle(Cascade c, Color color, MapImage fillImage, TextElement text) { 33 30 super(c, -1000f); 34 31 CheckParameterUtil.ensureParameterNotNull(color); … … 39 36 40 37 public static AreaElemStyle create(Cascade c) { 41 MapImage <BufferedImage>fillImage = null;38 MapImage fillImage = null; 42 39 Color color = null; 43 40 44 41 IconReference iconRef = c.get("fill-image", null, IconReference.class); 45 42 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(); 52 45 53 img.getRGB(54 .img.getWidth() / 2, fillImage.img.getHeight() / 2)55 46 color = new Color(fillImage.getImage().getRGB( 47 fillImage.getWidth() / 2, fillImage.getHeight() / 2) 48 ); 56 49 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; 62 54 } 63 55 } else { … … 78 70 text = TextElement.create(c, PaintColors.AREA_TEXT.get(), true); 79 71 } 80 72 81 73 if (color != null) 82 74 return new AreaElemStyle(c, color, fillImage, text); -
trunk/src/org/openstreetmap/josm/gui/mappaint/BoxTextElemStyle.java
r4869 r5054 22 22 public enum VerticalTextAlignment { ABOVE, TOP, CENTER, BOTTOM, BELOW } 23 23 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 24 80 public static final Rectangle ZERO_BOX = new Rectangle(0, 0, 0, 0); 25 81 26 82 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; 28 88 public HorizontalTextAlignment hAlign; 29 89 public VerticalTextAlignment vAlign; 30 90 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) { 32 92 super(c, 2000f); 33 93 CheckParameterUtil.ensureParameterNotNull(text); … … 35 95 CheckParameterUtil.ensureParameterNotNull(vAlign); 36 96 this.text = text; 97 this.boxProvider = boxProvider; 37 98 this.box = box == null ? ZERO_BOX : box; 38 99 this.hAlign = hAlign; … … 40 101 } 41 102 103 public static BoxTextElemStyle create(Environment env, BoxProvider boxProvider) { 104 return create(env, boxProvider, null); 105 } 106 42 107 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) { 43 112 initDefaultParameters(); 44 113 Cascade c = env.mc.getCascade(env.layer); … … 74 143 } 75 144 76 return new BoxTextElemStyle(c, text, box, hAlign, vAlign); 145 return new BoxTextElemStyle(c, text, boxProvider, box, hAlign, vAlign); 146 } 147 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; 77 158 } 78 159 … … 84 165 Node n = new Node(); 85 166 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()); 87 168 if (SIMPLE_NODE_TEXT_ELEMSTYLE == null) throw new AssertionError(); 88 169 } … … 113 194 return false; 114 195 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; 119 207 } 120 208 … … 123 211 int hash = super.hashCode(); 124 212 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 } 126 218 hash = 97 * hash + hAlign.hashCode(); 127 219 hash = 97 * hash + vAlign.hashCode(); -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r4682 r5054 29 29 private boolean defaultNodes, defaultLines; 30 30 private int defaultNodesIdx, defaultLinesIdx; 31 31 32 32 public ElemStyles() 33 33 { … … 317 317 if (nodeStyle != null) { 318 318 sl.add(nodeStyle); 319 addIfNotNull(sl, BoxTextElemStyle.create(env, nodeStyle.getBox())); 319 addIfNotNull(sl, BoxTextElemStyle.create(env, nodeStyle.getBoxProvider())); 320 320 } else { 321 addIfNotNull(sl, BoxTextElemStyle.create(env, NodeElemStyle.SIMPLE_NODE_ELEMSTYLE.getBox())); 321 addIfNotNull(sl, BoxTextElemStyle.create(env, NodeElemStyle.SIMPLE_NODE_ELEMSTYLE.getBoxProvider())); 322 322 } 323 323 } else if (osm instanceof Relation) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java
r4822 r5054 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.mappaint; 3 4 import java.awt.Image;5 6 import javax.swing.ImageIcon;7 3 8 4 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 17 13 public class LinePatternElemStyle extends ElemStyle { 18 14 19 public MapImage <Image>pattern;15 public MapImage pattern; 20 16 21 public LinePatternElemStyle(Cascade c, MapImage <Image>pattern) {17 public LinePatternElemStyle(Cascade c, MapImage pattern) { 22 18 super(c, -1f); 23 19 this.pattern = pattern; … … 30 26 if (iconRef == null) 31 27 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); 37 29 return new LinePatternElemStyle(c, pattern); 38 30 } … … 41 33 public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member) { 42 34 Way w = (Way)primitive; 43 painter.drawLinePattern(w, pattern. img);35 painter.drawLinePattern(w, pattern.getImage()); 44 36 } 45 37 -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapImage.java
r4823 r5054 3 3 4 4 import static org.openstreetmap.josm.tools.Utils.equal; 5 5 6 import java.awt.Image; 7 import java.awt.Rectangle; 8 import java.awt.image.BufferedImage; 6 9 7 10 import javax.swing.GrayFilter; 8 11 import javax.swing.ImageIcon; 9 12 10 public class MapImage<I extends Image> { 13 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.BoxProvider; 15 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.BoxProviderResult; 16 import org.openstreetmap.josm.tools.ImageProvider; 17 import org.openstreetmap.josm.tools.ImageProvider.ImageCallback; 18 import org.openstreetmap.josm.tools.Utils; 19 20 public class MapImage { 11 21 /** 12 22 * ImageIcon can chage while the image is loading. 13 23 */ 14 public I img; 15 16 public int alpha = 255; 24 private BufferedImage img; 17 25 18 26 /** 19 * The 4following fields are only used to check for equality.27 * The 5 following fields are only used to check for equality. 20 28 */ 29 public int alpha = 255; 21 30 public String name; 22 31 public StyleSource source; … … 24 33 public int height = -1; 25 34 35 private boolean temporary; 26 36 private Image disabledImg; 27 37 … … 37 47 } 38 48 39 // img changes when image is fully loaded and can't be used for equality check. 49 public BufferedImage getImage() { 50 if (img != null) 51 return img; 52 temporary = false; 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 if (result == null) { 65 img = (BufferedImage) MapPaintStyles.getNoIcon_Icon(source).getImage(); 66 } else { 67 img = (BufferedImage) result.getImage(); 68 } 69 if (temporary) { 70 Main.map.mapView.preferenceChanged(null); // otherwise repaint is ignored, because layer hasn't changed 71 Main.map.mapView.repaint(); 72 } 73 temporary = false; 74 } 75 } 76 } 77 ); 78 synchronized (this) { 79 if (img == null) { 80 img = (BufferedImage) ImageProvider.get("clock").getImage(); 81 temporary = true; 82 } 83 } 84 return img; 85 } 86 87 public int getWidth() { 88 return getImage().getWidth(null); 89 } 90 91 public int getHeight() { 92 return getImage().getHeight(null); 93 } 94 95 public float getAlphaFloat() { 96 return Utils.color_int2float(alpha); 97 } 98 99 /** 100 * Returns true, if image is not completely loaded and getImage() returns a temporary image. 101 */ 102 public boolean isTemporary() { 103 return temporary; 104 } 105 106 protected class MapImageBoxProvider implements BoxProvider { 107 @Override 108 public BoxProviderResult get() { 109 return new BoxProviderResult(box(), temporary); 110 } 111 112 private Rectangle box() { 113 int w = getWidth(), h = getHeight(); 114 return new Rectangle(-w/2, -h/2, w, h); 115 } 116 117 private MapImage getParent() { 118 return MapImage.this; 119 } 120 121 @Override 122 public int hashCode() { 123 return MapImage.this.hashCode(); 124 } 125 126 @Override 127 public boolean equals(Object obj) { 128 if (obj == null || !(obj instanceof BoxProvider)) 129 return false; 130 if (obj instanceof MapImageBoxProvider) { 131 MapImageBoxProvider other = (MapImageBoxProvider) obj; 132 return MapImage.this.equals(other.getParent()); 133 } else if (temporary) { 134 return false; 135 } else { 136 final BoxProvider other = (BoxProvider) obj; 137 BoxProviderResult resultOther = other.get(); 138 if (resultOther.isTemporary()) return false; 139 return box().equals(resultOther.getBox()); 140 } 141 } 142 } 143 144 public BoxProvider getBoxProvider() { 145 return new MapImageBoxProvider(); 146 } 147 40 148 @Override 41 149 public boolean equals(Object obj) { … … 43 151 return false; 44 152 final MapImage other = (MapImage) obj; 153 // img changes when image is fully loaded and can't be used for equality check. 45 154 return alpha == other.alpha && 46 155 equal(name, other.name) && -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r4968 r5054 119 119 } 120 120 121 p rivatestatic List<String> getIconSourceDirs(StyleSource source) {121 public static List<String> getIconSourceDirs(StyleSource source) { 122 122 List<String> dirs = new LinkedList<String>(); 123 123 -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r4822 r5054 6 6 import java.awt.BasicStroke; 7 7 import java.awt.Color; 8 import java.awt.Image;9 8 import java.awt.Rectangle; 10 9 import java.awt.Stroke; 11 12 import javax.swing.ImageIcon;13 10 14 11 import org.openstreetmap.josm.Main; … … 20 17 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 21 18 import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList; 19 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.BoxProvider; 20 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.SimpleBoxProvider; 22 21 import org.openstreetmap.josm.tools.Pair; 23 22 import org.openstreetmap.josm.tools.Utils; … … 27 26 */ 28 27 public class NodeElemStyle extends ElemStyle { 29 public MapImage <Image>mapImage;28 public MapImage mapImage; 30 29 public Symbol symbol; 31 32 private ImageIcon disabledIcon;33 30 34 31 public enum SymbolShape { SQUARE, CIRCLE, TRIANGLE, PENTAGON, HEXAGON, HEPTAGON, OCTAGON, NONAGON, DECAGON } … … 95 92 public static final StyleList DEFAULT_NODE_STYLELIST_TEXT = new StyleList(NodeElemStyle.SIMPLE_NODE_ELEMSTYLE, BoxTextElemStyle.SIMPLE_NODE_TEXT_ELEMSTYLE); 96 93 97 protected NodeElemStyle(Cascade c, MapImage <Image>mapImage, Symbol symbol) {94 protected NodeElemStyle(Cascade c, MapImage mapImage, Symbol symbol) { 98 95 super(c, 1000f); 99 96 this.mapImage = mapImage; … … 108 105 Cascade c = env.mc.getCascade(env.layer); 109 106 110 MapImage <Image>mapImage = createIcon(env);107 MapImage mapImage = createIcon(env); 111 108 Symbol symbol = null; 112 109 if (mapImage == null) { … … 122 119 } 123 120 124 private static MapImage <Image>createIcon(Environment env) {121 private static MapImage createIcon(Environment env) { 125 122 Cascade c = env.mc.getCascade(env.layer); 126 123 Cascade c_def = env.mc.getCascade("default"); 127 124 128 IconReference iconRef = c.get("icon-image", null, IconReference.class); 125 final IconReference iconRef = c.get("icon-image", null, IconReference.class); 129 126 if (iconRef == null) 130 127 return null; … … 145 142 int height = heightF == null ? -1 : Math.round(heightF); 146 143 147 MapImage<Image> mapImage = new MapImage<Image>(iconRef.iconName, iconRef.source); 148 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; 144 final MapImage mapImage = new MapImage(iconRef.iconName, iconRef.source); 145 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; 161 153 } 162 154 return mapImage; … … 243 235 Node n = (Node) primitive; 244 236 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(), 246 238 Utils.color_int2float(mapImage.alpha), selected, member); 247 239 } else if (symbol != null) { … … 309 301 } 310 302 311 public RectanglegetBox() {303 public BoxProvider getBoxProvider() { 312 304 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(); 315 306 } 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)); 317 308 } else { 318 309 // This is only executed once, so no performance concerns. … … 324 315 Main.pref.getInteger("mappaint.node.tagged-size", 3) 325 316 ); 326 return new Rectangle(-size/2, -size/2, size, size); 317 return new SimpleBoxProvider(new Rectangle(-size/2, -size/2, size, size)); 327 318 } 328 319 } -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r5033 r5054 32 32 import java.util.HashMap; 33 33 import java.util.Map; 34 import java.util.concurrent.Executors; 35 import java.util.concurrent.ExecutorService; 34 36 import java.util.regex.Matcher; 35 37 import java.util.regex.Pattern; … … 104 106 private static Map<String, ImageResource> cache = new HashMap<String, ImageResource>(); 105 107 108 private final static ExecutorService imageFetcher = Executors.newSingleThreadExecutor(); 109 110 public interface ImageCallback { 111 void finished(ImageIcon result); 112 } 113 106 114 /** 107 115 * @param subdir Subdirectory the image lies in. … … 256 264 else 257 265 return ir.getImageIcon(new Dimension(width, height)); 266 } 267 268 /** 269 * Load the image in a background thread. 270 * 271 * This method returns immediately and runs the image request 272 * asynchronously. 273 * 274 * @param callback is called, when the image is ready. This can happen 275 * before the call to getInBackground returns or it may be invoked some 276 * time (seconds) later. 277 * If no image is available, a null value is returned to callback (just 278 * like ImageProvider.get). 279 */ 280 public void getInBackground(final ImageCallback callback) { 281 if (name.startsWith("http://") || name.startsWith("wiki://")) { 282 Runnable fetch = new Runnable() { 283 @Override 284 public void run() { 285 ImageIcon result = get(); 286 callback.finished(result); 287 } 288 }; 289 imageFetcher.submit(fetch); 290 } else { 291 ImageIcon result = get(); 292 callback.finished(result); 293 } 258 294 } 259 295
Note:
See TracChangeset
for help on using the changeset viewer.