Changeset 4822 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint
- Timestamp:
- 2012-01-19T19:58:08+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint
- Files:
-
- 3 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 BufferedImagefillImage = 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 Float pAlpha = 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 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java
r4820 r4822 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.mappaint; 3 4 import java.awt.Image; 3 5 4 6 import javax.swing.ImageIcon; … … 15 17 public class LinePatternElemStyle extends ElemStyle { 16 18 17 public ImageIconpattern;19 public MapImage<Image> pattern; 18 20 19 public LinePatternElemStyle(Cascade c, ImageIconpattern) {21 public LinePatternElemStyle(Cascade c, MapImage<Image> pattern) { 20 22 super(c, -1f); 21 23 this.pattern = pattern; … … 31 33 if (icon == null) 32 34 return null; 33 return new LinePatternElemStyle(c, icon); 35 MapImage<Image> pattern = new MapImage<Image>(iconRef.iconName, iconRef.source); 36 pattern.img = icon.getImage(); 37 return new LinePatternElemStyle(c, pattern); 34 38 } 35 39 … … 37 41 public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member) { 38 42 Way w = (Way)primitive; 39 painter.drawLinePattern(w, pattern );43 painter.drawLinePattern(w, pattern.img); 40 44 } 41 45 … … 52 56 return false; 53 57 final LinePatternElemStyle other = (LinePatternElemStyle) obj; 54 return pattern. getImage() == other.pattern.getImage();58 return pattern.equals(other.pattern); 55 59 } 56 60 … … 62 66 @Override 63 67 public String toString() { 64 return "LinePatternElemStyle{" + super.toString() + "pattern= " + pattern + '}';68 return "LinePatternElemStyle{" + super.toString() + "pattern=[" + pattern + "]}"; 65 69 } 66 70 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r4820 r4822 6 6 import java.awt.BasicStroke; 7 7 import java.awt.Color; 8 import java.awt.Image; 8 9 import java.awt.Rectangle; 9 10 import java.awt.Stroke; 10 11 11 import javax.swing.GrayFilter;12 12 import javax.swing.ImageIcon; 13 13 … … 27 27 */ 28 28 public class NodeElemStyle extends ElemStyle { 29 public ImageIcon icon; 30 public int iconAlpha; 29 public MapImage<Image> mapImage; 31 30 public Symbol symbol; 32 31 … … 96 95 public static final StyleList DEFAULT_NODE_STYLELIST_TEXT = new StyleList(NodeElemStyle.SIMPLE_NODE_ELEMSTYLE, BoxTextElemStyle.SIMPLE_NODE_TEXT_ELEMSTYLE); 97 96 98 protected NodeElemStyle(Cascade c, ImageIcon icon, Integer iconAlpha, Symbol symbol) {97 protected NodeElemStyle(Cascade c, MapImage<Image> mapImage, Symbol symbol) { 99 98 super(c, 1000f); 100 this.icon = icon; 101 this.iconAlpha = iconAlpha == null ? 0 : iconAlpha; 99 this.mapImage = mapImage; 102 100 this.symbol = symbol; 103 101 } … … 110 108 Cascade c = env.mc.getCascade(env.layer); 111 109 112 Pair<ImageIcon, Integer> icon= createIcon(env);110 MapImage<Image> mapImage = createIcon(env); 113 111 Symbol symbol = null; 114 if ( icon== null) {112 if (mapImage == null) { 115 113 symbol = createSymbol(env); 116 114 } 117 115 118 // optimization: if we neither have a symbol, nor a n icon116 // optimization: if we neither have a symbol, nor a mapImage 119 117 // we don't have to check for the remaining style properties and we don't 120 118 // have to allocate a node element style. 121 if (!allowDefault && symbol == null && icon == null) return null; 122 123 return new NodeElemStyle(c, 124 icon == null ? null : icon.a, 125 icon == null ? null : icon.b, 126 symbol); 127 } 128 129 private static Pair<ImageIcon, Integer> createIcon(Environment env) { 119 if (!allowDefault && symbol == null && mapImage == null) return null; 120 121 return new NodeElemStyle(c, mapImage, symbol); 122 } 123 124 private static MapImage<Image> createIcon(Environment env) { 130 125 Cascade c = env.mc.getCascade(env.layer); 131 126 Cascade c_def = env.mc.getCascade("default"); … … 150 145 int height = heightF == null ? -1 : Math.round(heightF); 151 146 147 MapImage<Image> mapImage = new MapImage<Image>(iconRef.iconName, iconRef.source); 148 152 149 ImageIcon icon = MapPaintStyles.getIcon(iconRef, width, height); 153 if (icon == null) 154 return new Pair<ImageIcon, Integer>(MapPaintStyles.getNoIcon_Icon(iconRef.source), 255); 155 int iconAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255)))); 156 Integer pAlpha = Utils.color_float2int(c.get("icon-opacity", null, float.class)); 157 if (pAlpha != null) { 158 iconAlpha = pAlpha; 159 } 160 161 return new Pair<ImageIcon, Integer>(icon, iconAlpha); 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; 161 } 162 return mapImage; 162 163 } 163 164 … … 241 242 if (primitive instanceof Node) { 242 243 Node n = (Node) primitive; 243 if ( icon!= null && painter.isShowIcons()) {244 painter.drawNodeIcon(n, (painter.isInactiveMode() || n.isDisabled()) ? getDisabledIcon() : icon,245 Utils.color_int2float( iconAlpha), selected, member);244 if (mapImage != null && painter.isShowIcons()) { 245 painter.drawNodeIcon(n, (painter.isInactiveMode() || n.isDisabled()) ? mapImage.getDisabled() : mapImage.img, 246 Utils.color_int2float(mapImage.alpha), selected, member); 246 247 } else if (symbol != null) { 247 248 Color fillColor = symbol.fillColor; … … 303 304 304 305 } 305 } else if (primitive instanceof Relation && icon != null) { 306 painter.drawRestriction((Relation) primitive, this); 307 } 308 } 309 310 public ImageIcon getDisabledIcon() { 311 if (disabledIcon != null) 312 return disabledIcon; 313 if (icon == null) 314 return null; 315 return disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(icon.getImage())); 306 } else if (primitive instanceof Relation && mapImage != null) { 307 painter.drawRestriction((Relation) primitive, mapImage); 308 } 316 309 } 317 310 318 311 public Rectangle getBox() { 319 if ( icon!= null) {320 int w = icon.getIconWidth(), h=icon.getIconHeight();312 if (mapImage != null) { 313 int w = mapImage.img.getWidth(null), h = mapImage.img.getHeight(null); 321 314 return new Rectangle(-w/2, -h/2, w, h); 322 315 } else if (symbol != null) { … … 338 331 public int hashCode() { 339 332 int hash = super.hashCode(); 340 hash = 17 * hash + (icon != null ? icon.getImage().hashCode() : 0); 341 hash = 17 * hash + iconAlpha; 333 hash = 17 * hash + (mapImage != null ? mapImage.hashCode() : 0); 342 334 hash = 17 * hash + (symbol != null ? symbol.hashCode() : 0); 343 335 return hash; … … 353 345 final NodeElemStyle other = (NodeElemStyle) obj; 354 346 // we should get the same image object due to caching 355 if (icon != other.icon && (icon == null || other.icon == null || icon.getImage() != other.icon.getImage())) 356 return false; 357 if (this.iconAlpha != other.iconAlpha) 347 if (!equal(mapImage, other.mapImage)) 358 348 return false; 359 349 if (!equal(symbol, other.symbol)) … … 362 352 } 363 353 364 365 354 @Override 366 355 public String toString() { 367 356 StringBuilder s = new StringBuilder("NodeElemStyle{"); 368 357 s.append(super.toString()); 369 if ( icon!= null) {370 s.append(" icon= " + icon + " iconAlpha=" + iconAlpha);358 if (mapImage != null) { 359 s.append(" icon=[" + mapImage + "]"); 371 360 } 372 361 if (symbol != null) {
Note:
See TracChangeset
for help on using the changeset viewer.