Changeset 4822 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
- Timestamp:
- 2012-01-19T19:58:08+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r4820 r4822 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.mappaint; 3 4 import static org.openstreetmap.josm.tools.Utils.equal; 3 5 4 6 import java.awt.Color; … … 26 28 */ 27 29 public Color color; 28 public BufferedImage fillImage; 29 public float fillImageAlpha; 30 public MapImage<BufferedImage> fillImage; 30 31 public TextElement text; 31 32 32 protected AreaElemStyle(Cascade c, Color color, BufferedImage fillImage , float fillImageAlpha, TextElement text) {33 protected AreaElemStyle(Cascade c, Color color, MapImage<BufferedImage> fillImage, TextElement text) { 33 34 super(c, -1000f); 34 35 CheckParameterUtil.ensureParameterNotNull(color); 35 36 this.color = color; 36 37 this.fillImage = fillImage; 37 this.fillImageAlpha = fillImageAlpha;38 38 this.text = text; 39 39 } 40 40 41 41 public static AreaElemStyle create(Cascade c) { 42 BufferedImage fillImage = null; 42 MapImage<BufferedImage> fillImage = null; 43 43 Color color = null; 44 float fillImageAlpha = 1f;45 44 46 45 IconReference iconRef = c.get("fill-image", null, IconReference.class); … … 50 49 if (!(icon.getImage() instanceof BufferedImage)) 51 50 throw new RuntimeException(); 52 fillImage = (BufferedImage) icon.getImage(); 51 fillImage = new MapImage<BufferedImage>(iconRef.iconName, iconRef.source); 52 fillImage.img = (BufferedImage) icon.getImage(); 53 53 54 color = new Color(fillImage.getRGB(fillImage.getWidth() / 2, fillImage.getHeight() / 2)); 54 color = new Color(fillImage.img.getRGB( 55 fillImage.img.getWidth() / 2, fillImage.img.getHeight() / 2) 56 ); 55 57 56 fillImage Alpha =Utils.color_int2float(Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fill-image-alpha", 255)))));57 FloatpAlpha = c.get("fill-opacity", null,Float.class);58 fillImage.alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fill-image-alpha", 255)))); 59 Integer pAlpha = Utils.color_float2int(c.get("fill-opacity", null, float.class)); 58 60 if (pAlpha != null) { 59 if (pAlpha < 0f || pAlpha > 1f) { 60 pAlpha= 1f; 61 } 62 fillImageAlpha = pAlpha; 61 fillImage.alpha = pAlpha; 63 62 } 64 63 } … … 82 81 83 82 if (color != null) 84 return new AreaElemStyle(c, color, fillImage, fillImageAlpha,text);83 return new AreaElemStyle(c, color, fillImage, text); 85 84 else 86 85 return null; … … 97 96 } 98 97 } 99 painter.drawArea((Way) osm, myColor, fillImage, fillImageAlpha,text);98 painter.drawArea((Way) osm, myColor, fillImage, text); 100 99 } else if (osm instanceof Relation) 101 100 { … … 106 105 } 107 106 } 108 painter.drawArea((Relation) osm, myColor, fillImage, fillImageAlpha,text);107 painter.drawArea((Relation) osm, myColor, fillImage, text); 109 108 } 110 109 } … … 118 117 AreaElemStyle other = (AreaElemStyle) obj; 119 118 // we should get the same image object due to caching 120 if (fillImage !=other.fillImage)119 if (!equal(fillImage, other.fillImage)) 121 120 return false; 122 if (! Utils.equal(color, other.color))121 if (!equal(color, other.color)) 123 122 return false; 124 if (fillImageAlpha != other.fillImageAlpha) 125 return false; 126 if (!Utils.equal(text, other.text)) 123 if (!equal(text, other.text)) 127 124 return false; 128 125 return true; … … 134 131 hash = 61 * hash + color.hashCode(); 135 132 hash = 61 * hash + (fillImage != null ? fillImage.hashCode() : 0); 136 hash = 61 * hash + Float.floatToIntBits(fillImageAlpha);137 133 hash = 61 * hash + (text != null ? text.hashCode() : 0); 138 134 return hash; … … 142 138 public String toString() { 143 139 return "AreaElemStyle{" + super.toString() + "color=" + Utils.toString(color) + 144 " fillImage Alpha=" + fillImageAlpha + " fillImage=[" + fillImage + "]}";140 " fillImage=[" + fillImage + "]}"; 145 141 } 146 142 }
Note:
See TracChangeset
for help on using the changeset viewer.
