Changeset 3862 in josm for trunk/src/org
- Timestamp:
- 2011-02-06T15:48:58+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintSettings.java
r3858 r3862 81 81 82 82 outlineOnly = Main.pref.getBoolean("draw.data.area_outline_only", false); 83 83 84 84 } 85 85 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java
r3836 r3862 101 101 styles = MapPaintStyles.getStyles(); 102 102 103 this.paintSettings = MapPaintSettings.INSTANCE; 104 103 105 circum = nc.getDist100Pixel(); 104 boolean drawArea = circum <= Main.pref.getInteger("mappaint.fillareas", 10000000) ;106 boolean drawArea = circum <= Main.pref.getInteger("mappaint.fillareas", 10000000) && !paintSettings.isOutlineOnly(); 105 107 boolean drawMultipolygon = drawArea && Main.pref.getBoolean("mappaint.multipolygon", true); 106 108 styles.setDrawMultipolygon(drawMultipolygon); … … 112 114 RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); 113 115 114 this.paintSettings = MapPaintSettings.INSTANCE;115 116 this.painter = new MapPainter(paintSettings, g, inactive, nc, virtual, circum, leftHandTraffic); 116 117 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
r3860 r3862 11 11 import java.awt.Polygon; 12 12 import java.awt.Rectangle; 13 import java.awt.TexturePaint; 13 14 import java.awt.geom.GeneralPath; 14 15 import java.awt.geom.Rectangle2D; 16 import java.awt.image.BufferedImage; 15 17 import java.util.Arrays; 16 18 import java.util.Collection; … … 42 44 private final boolean showNames; 43 45 private final boolean showIcons; 44 private final boolean outlineOnly;45 46 46 47 private final Color inactiveColor; … … 78 79 this.showNames = settings.getShowNamesDistance() > circum; 79 80 this.showIcons = settings.getShowIconsDistance() > circum; 80 this.outlineOnly = settings.isOutlineOnly();81 81 82 82 this.inactiveColor = PaintColors.INACTIVE.get(); … … 258 258 } 259 259 260 public void drawArea(Way w, Color color, String name) {260 public void drawArea(Way w, Color color, BufferedImage fillImage, String name) { 261 261 Polygon polygon = getPolygon(w); 262 drawArea(polygon, color, name); 263 } 264 265 protected void drawArea(Polygon polygon, Color color, String name) { 266 267 g.setColor(color); 268 269 if (outlineOnly) { 270 g.drawPolygon(polygon); 262 drawArea(polygon, color, fillImage, name); 263 } 264 265 protected void drawArea(Polygon polygon, Color color, BufferedImage fillImage, String name) { 266 267 if (fillImage == null) { 268 g.setColor(color); 269 g.fillPolygon(polygon); 271 270 } else { 272 g.fillPolygon(polygon); 273 } 274 271 TexturePaint texture = new TexturePaint(fillImage, 272 new Rectangle(polygon.xpoints[0], polygon.ypoints[0], fillImage.getWidth(), fillImage.getHeight())); 273 274 g.setPaint(texture); 275 g.fill(polygon); 276 } 275 277 276 278 if (name != null) { … … 311 313 } 312 314 313 public void drawArea(Relation r, Color color, String name) {315 public void drawArea(Relation r, Color color, BufferedImage fillImage, String name) { 314 316 Multipolygon multipolygon = new Multipolygon(nc); 315 317 multipolygon.load(r); … … 320 322 continue; 321 323 } 322 drawArea(p, color, getAreaName(r));324 drawArea(p, color, fillImage, getAreaName(r)); 323 325 } 324 326 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java
r3848 r3862 7 7 import java.awt.Font; 8 8 import java.awt.GridBagLayout; 9 import java.util.ArrayList; 9 10 import java.util.Collection; 10 11 import java.util.List; … … 34 35 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 35 36 import org.openstreetmap.josm.gui.mappaint.MultiCascade; 37 import org.openstreetmap.josm.gui.mappaint.StyleCache; 36 38 import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList; 37 39 import org.openstreetmap.josm.gui.mappaint.StyleSource; … … 300 302 txtMappaint.append("\n\n"); 301 303 } 304 305 if (sel.size() == 2) { 306 List<OsmPrimitive> selList = new ArrayList<OsmPrimitive>(sel); 307 StyleCache sc1 = selList.get(0).mappaintStyle; 308 StyleCache sc2 = selList.get(1).mappaintStyle; 309 if (sc1 == sc2) { 310 txtMappaint.append("The 2 selected Objects have identical style caches."); 311 } 312 if (!sc1.equals(sc2)) { 313 txtMappaint.append("The 2 selected Objects have different style caches."); 314 } 315 if (sc1.equals(sc2) && sc1 != sc2) { 316 txtMappaint.append("Warning: The 2 selected Objects have equal, but not identical style caches."); 317 } 318 } 302 319 } 303 320 -
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r3859 r3862 3 3 4 4 import java.awt.Color; 5 import java.awt.Rectangle; 6 import java.awt.TexturePaint; 7 import java.awt.image.BufferedImage; 8 9 import javax.swing.ImageIcon; 5 10 6 11 import org.openstreetmap.josm.Main; … … 10 15 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings; 11 16 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 17 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 12 18 import org.openstreetmap.josm.tools.Utils; 19 13 20 14 21 public class AreaElemStyle extends ElemStyle 15 22 { 16 23 public Color color; 24 public BufferedImage fillImage; 17 25 18 protected AreaElemStyle(Cascade c, Color color ) {26 protected AreaElemStyle(Cascade c, Color color, BufferedImage fillImage) { 19 27 super(c); 20 28 this.color = color; 29 this.fillImage = fillImage; 21 30 } 22 31 23 32 public static AreaElemStyle create(Cascade c) { 33 BufferedImage fillImage = null; 34 IconReference iconRef = c.get("fill-image", null, IconReference.class); 35 if (iconRef != null) { 36 ImageIcon icon = MapPaintStyles.getIcon(iconRef, false); 37 if (icon != null) { 38 if (!(icon.getImage() instanceof BufferedImage)) { 39 icon = MapPaintStyles.getIcon(iconRef, true); 40 } 41 if (!(icon.getImage() instanceof BufferedImage)) 42 throw new RuntimeException(); 43 fillImage = (BufferedImage) icon.getImage(); 44 } 45 } 46 24 47 Color color = c.get("fill-color", null, Color.class); 25 if (color == null) 48 if (color != null) { 49 50 int alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50)))); 51 Integer pAlpha = color_float2int(c.get("fill-opacity", null, float.class)); 52 if (pAlpha != null) { 53 alpha = pAlpha; 54 } 55 color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha); 56 } 57 58 if (fillImage != null || color != null) 59 return new AreaElemStyle(c, color, fillImage); 60 else 26 61 return null; 27 int alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50))));28 Integer pAlpha = color_float2int(c.get("fill-opacity", null, float.class));29 if (pAlpha != null) {30 alpha = pAlpha;31 }32 color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);33 return new AreaElemStyle(c, color);34 62 } 35 63 … … 38 66 if (osm instanceof Way) 39 67 { 40 painter.drawArea((Way) osm, 41 osm.isSelected() ? paintSettings.getSelectedColor(color.getAlpha()) : color, 68 Color myColor = color; 69 if (color != null) { 70 if (osm.isSelected()) { 71 myColor = paintSettings.getSelectedColor(color.getAlpha()); 72 } 73 } 74 painter.drawArea((Way) osm, myColor, fillImage, 42 75 painter.isShowNames() ? painter.getAreaName(osm) : null); 43 76 } else if (osm instanceof Relation) 44 77 { 45 painter.drawArea((Relation) osm, 46 selected ? paintSettings.getRelationSelectedColor(color.getAlpha()) : color, 78 Color myColor = color; 79 if (color != null) { 80 if (selected) { 81 myColor = paintSettings.getRelationSelectedColor(color.getAlpha()); 82 } 83 } 84 painter.drawArea((Relation) osm, myColor, fillImage, 47 85 painter.getAreaName(osm)); 48 86 } … … 55 93 if (!super.equals(obj)) 56 94 return false; 57 return Utils.equal(color, ((AreaElemStyle) obj).color); 95 AreaElemStyle other = (AreaElemStyle) obj; 96 // we should get the same image object due to caching 97 if (fillImage != other.fillImage && (fillImage == null || other.fillImage == null || fillImage != other.fillImage)) 98 return false; 99 if (!Utils.equal(color, other.color)) 100 return false; 101 return true; 58 102 } 59 103 60 104 @Override 61 105 public int hashCode() { 62 return 11 * super.hashCode() + color.hashCode(); 106 int hash = 3; 107 hash = 61 * hash + (this.color != null ? this.color.hashCode() : 0); 108 hash = 61 * hash + (this.fillImage != null ? this.fillImage.hashCode() : 0); 109 return hash; 63 110 } 64 111 -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r3858 r3862 60 60 } 61 61 62 public static ImageIcon getIcon(IconReference ref )62 public static ImageIcon getIcon(IconReference ref, boolean sanitize) 63 63 { 64 64 String styleName = ref.source.getPrefName(); … … 78 78 } 79 79 } 80 ImageIcon i = ImageProvider.getIfAvailable(dirs, "mappaint."+styleName, null, ref.iconName, ref.source.zipIcons );80 ImageIcon i = ImageProvider.getIfAvailable(dirs, "mappaint."+styleName, null, ref.iconName, ref.source.zipIcons, sanitize); 81 81 if(i == null) 82 82 { -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r3855 r3862 37 37 if (iconRef == null) 38 38 return null; 39 40 ImageIcon icon = MapPaintStyles.getIcon(iconRef);39 ImageIcon icon = MapPaintStyles.getIcon(iconRef, false); 40 41 41 String text = c.get("text", null, String.class); 42 42 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Instruction.java
r3860 r3862 36 36 public void execute(Environment env) { 37 37 Object value = (val instanceof Expression) ? ((Expression) val).evaluate(env) : val; 38 if (key.equals("icon-image") ) {38 if (key.equals("icon-image") || key.equals("fill-image")) { 39 39 if (value instanceof String) { 40 40 value = new IconReference((String) value, env.source); -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r3512 r3862 52 52 53 53 /** 54 * remember whether the image has been sanitized 55 */ 56 private static class ImageWrapper { 57 Image img; 58 boolean sanitized; 59 60 public ImageWrapper(Image img, boolean sanitized) { 61 this.img = img; 62 this.sanitized = sanitized; 63 } 64 } 65 66 /** 54 67 * The icon cache 55 68 */ 56 private static Map<String, Image > cache = new HashMap<String, Image>();69 private static Map<String, ImageWrapper> cache = new HashMap<String, ImageWrapper>(); 57 70 58 71 /** … … 84 97 } 85 98 86 public static finalImageIcon getIfAvailable(String[] dirs, String id, String subdir, String name) {99 public static ImageIcon getIfAvailable(String[] dirs, String id, String subdir, String name) { 87 100 return getIfAvailable(Arrays.asList(dirs), id, subdir, name); 88 101 } … … 95 108 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name) { 96 109 return getIfAvailable(dirs, id, subdir, name, null); 110 } 111 112 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive) { 113 return getIfAvailable(dirs, id, subdir, name, archive, false); 97 114 } 98 115 … … 106 123 * @param name The name of the image. If it contains no '.', a png extension is added. 107 124 * @param archive A zip file where the image is located. 108 */ 109 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive) { 125 * @param sanitize If the image should be repainted to a new BufferedImage to work 126 * around certain issues. 127 */ 128 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive, boolean sanitize) { 129 ImageWrapper iw = getIfAvailableImpl(dirs, id, subdir, name, archive); 130 if (iw == null) 131 return null; 132 if (sanitize && !iw.sanitized) { 133 iw.img = sanitize(iw.img); 134 iw.sanitized = true; 135 } 136 return new ImageIcon(iw.img); 137 } 138 139 private static ImageWrapper getIfAvailableImpl(Collection<String> dirs, String id, String subdir, String name, File archive) { 110 140 if (name == null) 111 141 return null; 112 142 if (name.startsWith("http://")) { 113 Image img= cache.get(name);114 if (i mg== null) {143 ImageWrapper iw = cache.get(name); 144 if (iw == null) { 115 145 try { 116 146 MirroredInputStream is = new MirroredInputStream(name, new File(Main.pref.getPreferencesDir(), 117 147 "images").toString()); 118 img = Toolkit.getDefaultToolkit().createImage(is.getFile().toURI().toURL()); 119 cache.put(name, img); 148 Image img = Toolkit.getDefaultToolkit().createImage(is.getFile().toURI().toURL()); 149 iw = new ImageWrapper(img, false); 150 cache.put(name, iw); 120 151 } catch (IOException e) { 121 152 } 122 153 } 123 return i mg == null ? null : new ImageIcon(img);154 return iw; 124 155 } 125 156 if (subdir == null) { … … 139 170 } 140 171 141 Image img= cache.get(cache_name);142 if (i mg== null) {172 ImageWrapper iw = cache.get(cache_name); 173 if (iw == null) { 143 174 if(archive != null) 144 175 { … … 162 193 size -= l; 163 194 } 164 img = Toolkit.getDefaultToolkit().createImage(buf); 195 Image img = Toolkit.getDefaultToolkit().createImage(buf); 196 iw = new ImageWrapper(img, false); 165 197 } finally { 166 198 if (is != null) { … … 185 217 // and don't bother to create a URL unless we're actually 186 218 // creating the image. 187 if(i mg== null)219 if(iw == null) 188 220 { 189 221 URL path = getImageUrl(full_name, dirs); 190 222 if (path == null) 191 223 return null; 192 img = Toolkit.getDefaultToolkit().createImage(path); 193 } 194 cache.put(cache_name, img); 195 } 196 197 return new ImageIcon(img); 224 Image img = Toolkit.getDefaultToolkit().createImage(path); 225 iw = new ImageWrapper(img, false); 226 } 227 cache.put(cache_name, iw); 228 } 229 230 return iw; 198 231 } 199 232 … … 405 438 return get("data", type.getAPIName()); 406 439 } 440 441 public static BufferedImage sanitize(Image img) { 442 (new ImageIcon(img)).getImage(); // load competely 443 int width = img.getWidth(null); 444 int height = img.getHeight(null); 445 BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 446 result.getGraphics().drawImage(img, 0, 0, null); 447 return result; 448 } 407 449 }
Note:
See TracChangeset
for help on using the changeset viewer.