source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java@ 4822

Last change on this file since 4822 was 4822, checked in by bastiK, 12 years ago

make identity of map icons depend on the name and not the image data (see #6797)

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint;
3
4import java.awt.Image;
5
6import javax.swing.ImageIcon;
7
8import org.openstreetmap.josm.data.osm.OsmPrimitive;
9import org.openstreetmap.josm.data.osm.Way;
10import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
11import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
12import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
13
14/**
15 * similar to mapnik's LinePatternSymbolizer
16 */
17public class LinePatternElemStyle extends ElemStyle {
18
19 public MapImage<Image> pattern;
20
21 public LinePatternElemStyle(Cascade c, MapImage<Image> pattern) {
22 super(c, -1f);
23 this.pattern = pattern;
24 }
25
26 public static LinePatternElemStyle create(Environment env) {
27 Cascade c = env.mc.getCascade(env.layer);
28
29 IconReference iconRef = c.get("pattern-image", null, IconReference.class);
30 if (iconRef == null)
31 return null;
32 ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1);
33 if (icon == null)
34 return null;
35 MapImage<Image> pattern = new MapImage<Image>(iconRef.iconName, iconRef.source);
36 pattern.img = icon.getImage();
37 return new LinePatternElemStyle(c, pattern);
38 }
39
40 @Override
41 public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member) {
42 Way w = (Way)primitive;
43 painter.drawLinePattern(w, pattern.img);
44 }
45
46 @Override
47 public boolean isProperLineStyle() {
48 return true;
49 }
50
51 @Override
52 public boolean equals(Object obj) {
53 if (obj == null || getClass() != obj.getClass())
54 return false;
55 if (!super.equals(obj))
56 return false;
57 final LinePatternElemStyle other = (LinePatternElemStyle) obj;
58 return pattern.equals(other.pattern);
59 }
60
61 @Override
62 public int hashCode() {
63 return pattern.hashCode();
64 }
65
66 @Override
67 public String toString() {
68 return "LinePatternElemStyle{" + super.toString() + "pattern=[" + pattern + "]}";
69 }
70}
Note: See TracBrowser for help on using the repository browser.