Changeset 4822 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2012-01-19T19:58:08+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
r4724 r4822 46 46 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.HorizontalTextAlignment; 47 47 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.VerticalTextAlignment; 48 import org.openstreetmap.josm.gui.mappaint.MapImage; 48 49 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle; 49 50 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.Symbol; … … 505 506 } 506 507 507 public void drawLinePattern(Way way, Image Iconpattern) {508 final int width = pattern.get IconWidth();509 final int height = pattern.get IconHeight();508 public void drawLinePattern(Way way, Image pattern) { 509 final int width = pattern.getWidth(null); 510 final int height = pattern.getHeight(null); 510 511 511 512 Point lastP = null; … … 530 531 531 532 if (dist > 0) { 532 g.drawImage(pattern .getImage(), 0, 0, (int) dist, height,533 g.drawImage(pattern, 0, 0, (int) dist, height, 533 534 width - (int) dist, 0, width, height, null); 534 535 } 535 536 while (dist < segmentLength) { 536 537 if (dist + width > segmentLength) { 537 g.drawImage(pattern .getImage(), (int) dist, 0, (int) segmentLength, height,538 g.drawImage(pattern, (int) dist, 0, (int) segmentLength, height, 538 539 0, 0, (int) segmentLength - (int) dist, height, null); 539 540 } else { 540 pattern.paintIcon(nc, g, (int) dist, 0);541 g.drawImage(pattern, (int) dist, 0, nc); 541 542 } 542 543 dist += width; … … 550 551 } 551 552 552 public void drawNodeIcon(Node n, Image Icon icon, float iconAlpha, boolean selected, boolean member) {553 public void drawNodeIcon(Node n, Image img, float alpha, boolean selected, boolean member) { 553 554 Point p = nc.getPoint(n); 554 555 555 final int w = i con.getIconWidth(), h=icon.getIconHeight();556 final int w = img.getWidth(null), h=img.getHeight(null); 556 557 if(n.isHighlighted()) { 557 558 drawPointHighlight(p, Math.max(w, h)); 558 559 } 559 560 560 if ( iconAlpha != 1f) {561 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, iconAlpha));562 } 563 icon.paintIcon ( nc, g, p.x-w/2, p.y-h/2);561 if (alpha != 1f) { 562 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); 563 } 564 g.drawImage(img, p.x-w/2, p.y-h/2, nc); 564 565 g.setPaintMode(); 565 566 if (selected || member) … … 802 803 } 803 804 804 public void drawArea(Way w, Color color, BufferedImage fillImage, float fillImageAlpha, TextElement text) {805 drawArea(w, getPath(w), color, fillImage, fillImageAlpha,text);806 } 807 808 protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, BufferedImage fillImage, float fillImageAlpha, TextElement text) {805 public void drawArea(Way w, Color color, MapImage<BufferedImage> fillImage, TextElement text) { 806 drawArea(w, getPath(w), color, fillImage, text); 807 } 808 809 protected void drawArea(OsmPrimitive osm, Path2D.Double path, Color color, MapImage<BufferedImage> fillImage, TextElement text) { 809 810 810 811 Shape area = path.createTransformedShape(nc.getAffineTransform()); … … 815 816 g.fill(area); 816 817 } else { 817 TexturePaint texture = new TexturePaint(fillImage ,818 TexturePaint texture = new TexturePaint(fillImage.img, 818 819 // new Rectangle(polygon.xpoints[0], polygon.ypoints[0], fillImage.getWidth(), fillImage.getHeight())); 819 new Rectangle(0, 0, fillImage. getWidth(), fillImage.getHeight()));820 new Rectangle(0, 0, fillImage.img.getWidth(null), fillImage.img.getHeight(null))); 820 821 g.setPaint(texture); 821 if (fillImage Alpha != 1f) {822 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, fillImage Alpha));822 if (fillImage.alpha != 1f) { 823 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, fillImage.alpha)); 823 824 } 824 825 g.fill(area); … … 871 872 } 872 873 873 public void drawArea(Relation r, Color color, BufferedImage fillImage, float fillImageAlpha, TextElement text) {874 public void drawArea(Relation r, Color color, MapImage<BufferedImage> fillImage, TextElement text) { 874 875 Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, r); 875 876 if (!r.isDisabled() && !multipolygon.getOuterWays().isEmpty()) { … … 881 882 drawArea(r, p, 882 883 pd.selected ? settings.getRelationSelectedColor(color.getAlpha()) : color, 883 fillImage, fillImageAlpha,text);884 fillImage, text); 884 885 } 885 886 } … … 898 899 } 899 900 900 public void drawRestriction(Image Icon icon, Point pVia, double vx, double vx2, double vy, double vy2, double iconAngle, boolean selected) {901 /* rotate i conwith direction last node in from to */902 Image Icon rotatedIcon = ImageProvider.createRotatedImage(null /*icon2*/, icon, iconAngle);903 904 /* scale down i conto 16*16 pixels */905 Image Icon smallIcon = new ImageIcon(rotatedIcon.getImage().getScaledInstance(16 , 16, Image.SCALE_SMOOTH));906 int w = smallI con.getIconWidth(), h=smallIcon.getIconHeight();907 smallIcon.paintIcon (nc, g, (int)(pVia.x+vx+vx2)-w/2, (int)(pVia.y+vy+vy2)-h/2);901 public void drawRestriction(Image img, Point pVia, double vx, double vx2, double vy, double vy2, double angle, boolean selected) { 902 /* rotate image with direction last node in from to */ 903 Image rotatedImg = ImageProvider.createRotatedImage(null , img, angle); 904 905 /* scale down image to 16*16 pixels */ 906 Image smallImg = new ImageIcon(rotatedImg.getScaledInstance(16 , 16, Image.SCALE_SMOOTH)).getImage(); 907 int w = smallImg.getWidth(null), h=smallImg.getHeight(null); 908 g.drawImage(smallImg, (int)(pVia.x+vx+vx2)-w/2, (int)(pVia.y+vy+vy2)-h/2, nc); 908 909 909 910 if (selected) { … … 913 914 } 914 915 915 public void drawRestriction(Relation r, NodeElemStyleicon) {916 public void drawRestriction(Relation r, MapImage<Image> icon) { 916 917 Way fromWay = null; 917 918 Way toWay = null; … … 1084 1085 } 1085 1086 1086 drawRestriction(inactive || r.isDisabled() ? icon.getDisabled Icon() : icon.icon,1087 drawRestriction(inactive || r.isDisabled() ? icon.getDisabled() : icon.img, 1087 1088 pVia, vx, vx2, vy, vy2, iconAngle, r.isSelected()); 1088 1089 } -
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) { -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r4820 r4822 760 760 * @return the image after rotating. 761 761 */ 762 public static Image Icon createRotatedImage(Component c, Icon icon, double rotatedAngle) {762 public static Image createRotatedImage(Component c, Image img, double rotatedAngle) { 763 763 // convert rotatedAngle to a value from 0 to 360 764 764 double originalAngle = rotatedAngle % 360; … … 775 775 double radian = Math.toRadians(angle); 776 776 777 int iw = i con.getIconWidth();778 int ih = i con.getIconHeight();777 int iw = img.getWidth(null); 778 int ih = img.getHeight(null); 779 779 int w; 780 780 int h; … … 802 802 803 803 g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); 804 icon.paintIcon(c, g2d, -cx, -cy);804 g2d.drawImage(img, -cx, -cy, c); 805 805 806 806 g2d.dispose(); 807 return new ImageIcon(image); 807 new ImageIcon(image); // load completely 808 return image; 808 809 } 809 810
Note:
See TracChangeset
for help on using the changeset viewer.