Ticket #6797: async3.diff
| File async3.diff, 31.2 KB (added by , 14 years ago) |
|---|
-
src/org/openstreetmap/josm/tools/ImageProvider.java
31 31 import java.util.Collection; 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; 36 38 import java.util.zip.ZipEntry; … … 103 105 */ 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. 108 116 * @param name The name of the image. If it does not end with '.png' or '.svg', … … 258 266 } 259 267 260 268 /** 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 /** 261 288 * Return an image from the specified location. Throws a RuntimeException if 262 289 * the image cannot be located. 263 290 * -
src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java
1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import java.awt.Image;5 6 import javax.swing.ImageIcon;7 8 4 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 5 import org.openstreetmap.josm.data.osm.Way; 10 6 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings; … … 16 12 */ 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; 24 20 } … … 29 25 IconReference iconRef = c.get("pattern-image", null, IconReference.class); 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 } 39 31 40 32 @Override 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 46 38 @Override -
src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
5 5 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 10 12 import javax.swing.ImageIcon;13 14 11 import org.openstreetmap.josm.Main; 15 12 import org.openstreetmap.josm.data.osm.Node; 16 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 19 16 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 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; 24 23 … … 26 25 * applies for Nodes and turn restriction relations 27 26 */ 28 27 public class NodeElemStyle extends ElemStyle { 29 public MapImage <Image>mapImage;28 public MapImage mapImage; 30 29 public Symbol symbol; 31 30 32 private ImageIcon disabledIcon;33 34 31 public enum SymbolShape { SQUARE, CIRCLE, TRIANGLE, PENTAGON, HEXAGON, HEPTAGON, OCTAGON, NONAGON, DECAGON } 35 32 36 33 public static class Symbol { … … 94 91 public static final StyleList DEFAULT_NODE_STYLELIST = new StyleList(NodeElemStyle.SIMPLE_NODE_ELEMSTYLE); 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; 100 97 this.symbol = symbol; … … 107 104 private static NodeElemStyle create(Environment env, boolean allowDefault) { 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) { 113 110 symbol = createSymbol(env); … … 121 118 return new NodeElemStyle(c, mapImage, symbol); 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; 131 128 … … 144 141 int width = widthF == null ? -1 : Math.round(widthF); 145 142 int height = heightF == null ? -1 : Math.round(heightF); 146 143 147 MapImage<Image> mapImage = new MapImage<Image>(iconRef.iconName, iconRef.source);144 final MapImage mapImage = new MapImage(iconRef.iconName, iconRef.source); 148 145 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; 161 153 } 162 154 return mapImage; 163 155 } … … 242 234 if (primitive instanceof Node) { 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) { 248 240 Color fillColor = symbol.fillColor; … … 308 300 } 309 301 } 310 302 311 public Rectangle getBox() {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. 319 310 // However, it would be better, if the settings could be changed at runtime. … … 323 314 Main.pref.getInteger("mappaint.node.connection-size", 5), 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 } 329 320 -
src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
118 118 .setOptional(true).get(); 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 124 124 String sourceDir = source.getLocalSourceDir(); -
src/org/openstreetmap/josm/gui/mappaint/MapImage.java
2 2 package org.openstreetmap.josm.gui.mappaint; 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 p ublic Iimg;24 private BufferedImage img; 15 25 16 26 public int alpha = 255; 17 27 … … 23 33 public int width = -1; 24 34 public int height = -1; 25 35 36 private boolean temporary; 26 37 private Image disabledImg; 27 38 28 39 public MapImage(String name, StyleSource source) { … … 36 47 return disabledImg = GrayFilter.createDisabledImage(img); 37 48 } 38 49 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 40 149 @Override 41 150 public boolean equals(Object obj) { 42 151 if (obj == null || getClass() != obj.getClass()) 43 152 return false; 44 153 final MapImage other = (MapImage) obj; 154 // img changes when image is fully loaded and can't be used for equality check. 45 155 return alpha == other.alpha && 46 156 equal(name, other.name) && 47 157 equal(source, other.source) && -
src/org/openstreetmap/josm/gui/mappaint/BoxTextElemStyle.java
21 21 public enum HorizontalTextAlignment { LEFT, CENTER, RIGHT } 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); 34 94 CheckParameterUtil.ensureParameterNotNull(hAlign); 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; 39 100 this.vAlign = vAlign; 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); 45 114 … … 73 142 vAlign = VerticalTextAlignment.BELOW; 74 143 } 75 144 76 return new BoxTextElemStyle(c, text, box , hAlign, vAlign);145 return new BoxTextElemStyle(c, text, boxProvider, box, hAlign, vAlign); 77 146 } 78 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; 158 } 159 79 160 public static final BoxTextElemStyle SIMPLE_NODE_TEXT_ELEMSTYLE; 80 161 static { 81 162 MultiCascade mc = new MultiCascade(); … … 83 164 c.put("text", Keyword.AUTO); 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 } 89 170 /* … … 112 193 if (obj == null || getClass() != obj.getClass()) 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 121 209 @Override 122 210 public int hashCode() { 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(); 128 220 return hash; -
src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
28 28 29 29 private boolean defaultNodes, defaultLines; 30 30 private int defaultNodesIdx, defaultLinesIdx; 31 31 32 32 public ElemStyles() 33 33 { 34 34 styleSources = new ArrayList<StyleSource>(); … … 316 316 NodeElemStyle nodeStyle = NodeElemStyle.create(env); 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) { 324 324 if (((Relation)osm).isMultipolygon()) { -
src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
4 4 import static org.openstreetmap.josm.tools.Utils.equal; 5 5 6 6 import java.awt.Color; 7 import java.awt.image.BufferedImage;8 7 9 import javax.swing.ImageIcon;10 11 8 import org.openstreetmap.josm.Main; 12 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 10 import org.openstreetmap.josm.data.osm.Relation; … … 26 23 * an arbitrary color value sampled from the fillImage 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); 35 32 this.color = color; … … 38 35 } 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 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 ); 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 { 64 56 color = c.get("fill-color", null, Color.class); … … 77 69 if (textPos == null || Utils.equal(textPos.val, "center")) { 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); 83 75 else -
src/org/openstreetmap/josm/gui/MapView.java
459 459 /** 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; 465 465 … … 832 832 } 833 833 } 834 834 835 public void preferenceChanged(PreferenceChangeEvent e) {835 public synchronized void preferenceChanged(PreferenceChangeEvent e) { 836 836 paintPreferencesChanged = true; 837 837 } 838 838 -
src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
21 21 import java.awt.geom.Path2D; 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; 27 26 import java.util.Iterator; … … 737 736 * left-below center-below right-below 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(); 744 744 Rectangle2D bounds = text.font.getStringBounds(s, frc); … … 746 746 if (bs.hAlign == HorizontalTextAlignment.CENTER) { 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 } 768 768 if (inactive || n.isDisabled()) { … … 802 802 return path; 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()); 812 812 … … 815 815 g.setColor(color); 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); 823 823 if (alpha != 1f) { … … 872 872 } 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()) { 878 878 for (PolyData pd : multipolygon.getCombinedPolygons()) { … … 914 914 } 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; 920 920 OsmPrimitive via = null; … … 1085 1085 iconAngle = 270-fromAngleDeg; 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 } 1091 1091
