Changeset 3879 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
- Timestamp:
- 2011-02-09T19:13:04+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r3865 r3879 14 14 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 15 15 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 16 import org.openstreetmap.josm.tools.CheckParameterUtil; 16 17 import org.openstreetmap.josm.tools.Utils; 17 18 18 19 public class AreaElemStyle extends ElemStyle 19 20 { 21 /** 22 * If fillImage == null, color is the fill-color, otherwise 23 * an arbitrary color value sampled from the fillImage 24 */ 20 25 public Color color; 21 26 public BufferedImage fillImage; 27 public float fillImageAlpha; 22 28 23 protected AreaElemStyle(Cascade c, Color color, BufferedImage fillImage) { 29 protected AreaElemStyle(Cascade c, Color color, BufferedImage fillImage, float fillImageAlpha) { 24 30 super(c); 31 CheckParameterUtil.ensureParameterNotNull(color); 25 32 this.color = color; 26 33 this.fillImage = fillImage; 34 this.fillImageAlpha = fillImageAlpha; 27 35 } 28 36 29 37 public static AreaElemStyle create(Cascade c) { 30 38 BufferedImage fillImage = null; 39 Color color = null; 40 float fillImageAlpha = 1f; 41 31 42 IconReference iconRef = c.get("fill-image", null, IconReference.class); 32 Integer fillImageAlpha = null;33 34 43 if (iconRef != null) { 35 44 ImageIcon icon = MapPaintStyles.getIcon(iconRef, false); … … 42 51 fillImage = (BufferedImage) icon.getImage(); 43 52 44 fillImageAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fill-image-alpha", 255)))); 45 Integer pAlpha = Utils.color_float2int(c.get("fill-opacity", null, float.class)); 53 color = new Color(fillImage.getRGB(fillImage.getWidth() / 2, fillImage.getHeight() / 2)); 54 55 fillImageAlpha = Utils.color_int2float(Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fill-image-alpha", 255))))); 56 Float pAlpha = c.get("fill-opacity", null, Float.class); 46 57 if (pAlpha != null) { 58 if (pAlpha < 0f || pAlpha > 1f) { 59 pAlpha= 1f; 60 } 47 61 fillImageAlpha = pAlpha; 48 62 } 49 63 } 50 } 51 52 Color color = c.get("fill-color", null, Color.class); 53 if (color != null) { 54 55 int alpha; 56 if (fillImageAlpha != null) { 57 alpha = fillImageAlpha; 58 } else { 59 alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50)))); 64 } else { 65 color = c.get("fill-color", null, Color.class); 66 if (color != null) { 67 int alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50)))); 60 68 Integer pAlpha = Utils.color_float2int(c.get("fill-opacity", null, float.class)); 61 69 if (pAlpha != null) { 62 70 alpha = pAlpha; 63 71 } 72 color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha); 64 73 } 65 color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);66 74 } 67 75 68 if (fillImage != null || color != null) { 69 if (color == null) { 70 color = new Color(0, 0, 0, fillImageAlpha); 71 } 72 return new AreaElemStyle(c, color, fillImage); 73 } 76 if (color != null) 77 return new AreaElemStyle(c, color, fillImage, fillImageAlpha); 74 78 else 75 79 return null; … … 86 90 } 87 91 } 88 painter.drawArea((Way) osm, myColor, fillImage, 92 painter.drawArea((Way) osm, myColor, fillImage, fillImageAlpha, 89 93 painter.isShowNames() ? painter.getAreaName(osm) : null); 90 94 } else if (osm instanceof Relation) … … 96 100 } 97 101 } 98 painter.drawArea((Relation) osm, myColor, fillImage, 102 painter.drawArea((Relation) osm, myColor, fillImage, fillImageAlpha, 99 103 painter.getAreaName(osm)); 100 104 } … … 109 113 AreaElemStyle other = (AreaElemStyle) obj; 110 114 // we should get the same image object due to caching 111 if (fillImage != other.fillImage && (fillImage == null || other.fillImage == null || fillImage != other.fillImage))115 if (fillImage != other.fillImage) 112 116 return false; 113 117 if (!Utils.equal(color, other.color)) 118 return false; 119 if (fillImageAlpha != other.fillImageAlpha) 114 120 return false; 115 121 return true; … … 119 125 public int hashCode() { 120 126 int hash = 3; 121 hash = 61 * hash + (this.color != null ? this.color.hashCode() : 0); 122 hash = 61 * hash + (this.fillImage != null ? this.fillImage.hashCode() : 0); 127 hash = 61 * hash + color.hashCode(); 128 hash = 61 * hash + (fillImage != null ? fillImage.hashCode() : 0); 129 hash = 61 * hash + Float.floatToIntBits(fillImageAlpha); 123 130 return hash; 124 131 } … … 126 133 @Override 127 134 public String toString() { 128 return "AreaElemStyle{" + super.toString() + "color=" + Utils.toString(color) + '}'; 135 return "AreaElemStyle{" + super.toString() + "color=" + Utils.toString(color) + 136 " fillImageAlpha=" + fillImageAlpha + " fillImage=[" + fillImage + "]}"; 129 137 } 130 138 }
Note:
See TracChangeset
for help on using the changeset viewer.
