1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint;
|
---|
3 |
|
---|
4 | import java.awt.Image;
|
---|
5 |
|
---|
6 | import javax.swing.ImageIcon;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
9 | import org.openstreetmap.josm.data.osm.Way;
|
---|
10 | import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
|
---|
11 | import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
|
---|
12 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * similar to mapnik's LinePatternSymbolizer
|
---|
16 | */
|
---|
17 | public 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 | }
|
---|