1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
5 | import org.openstreetmap.josm.data.osm.Way;
|
---|
6 | import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
|
---|
7 | import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
|
---|
8 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * similar to mapnik's LinePatternSymbolizer
|
---|
12 | */
|
---|
13 | public class LinePatternElemStyle extends ElemStyle {
|
---|
14 |
|
---|
15 | public MapImage pattern;
|
---|
16 |
|
---|
17 | public LinePatternElemStyle(Cascade c, MapImage pattern) {
|
---|
18 | super(c, 2.9f);
|
---|
19 | this.pattern = pattern;
|
---|
20 | }
|
---|
21 |
|
---|
22 | public static LinePatternElemStyle create(Environment env) {
|
---|
23 | Cascade c = env.mc.getCascade(env.layer);
|
---|
24 |
|
---|
25 | IconReference iconRef = c.get("pattern-image", null, IconReference.class);
|
---|
26 | if (iconRef == null)
|
---|
27 | return null;
|
---|
28 | MapImage pattern = new MapImage(iconRef.iconName, iconRef.source);
|
---|
29 | return new LinePatternElemStyle(c, pattern);
|
---|
30 | }
|
---|
31 |
|
---|
32 | @Override
|
---|
33 | public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member) {
|
---|
34 | Way w = (Way)primitive;
|
---|
35 | painter.drawLinePattern(w, pattern.getImage());
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public boolean isProperLineStyle() {
|
---|
40 | return true;
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | public boolean equals(Object obj) {
|
---|
45 | if (obj == null || getClass() != obj.getClass())
|
---|
46 | return false;
|
---|
47 | if (!super.equals(obj))
|
---|
48 | return false;
|
---|
49 | final LinePatternElemStyle other = (LinePatternElemStyle) obj;
|
---|
50 | return pattern.equals(other.pattern);
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override
|
---|
54 | public int hashCode() {
|
---|
55 | return pattern.hashCode();
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Override
|
---|
59 | public String toString() {
|
---|
60 | return "LinePatternElemStyle{" + super.toString() + "pattern=[" + pattern + "]}";
|
---|
61 | }
|
---|
62 | }
|
---|