1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.Utils.equal;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
7 | import org.openstreetmap.josm.data.osm.Way;
|
---|
8 | import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
|
---|
9 | import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
|
---|
10 | import org.openstreetmap.josm.tools.CheckParameterUtil;
|
---|
11 |
|
---|
12 | public class RepeatImageElemStyle extends ElemStyle implements StyleKeys {
|
---|
13 |
|
---|
14 | public enum LineImageAlignment { TOP, CENTER, BOTTOM }
|
---|
15 |
|
---|
16 | public MapImage pattern;
|
---|
17 | public float offset;
|
---|
18 | public float spacing;
|
---|
19 | public LineImageAlignment align;
|
---|
20 |
|
---|
21 | public RepeatImageElemStyle(Cascade c, MapImage pattern, float offset, float spacing, LineImageAlignment align) {
|
---|
22 | super(c, 2.9f);
|
---|
23 | CheckParameterUtil.ensureParameterNotNull(pattern);
|
---|
24 | CheckParameterUtil.ensureParameterNotNull(align);
|
---|
25 | this.pattern = pattern;
|
---|
26 | this.offset = offset;
|
---|
27 | this.spacing = spacing;
|
---|
28 | this.align = align;
|
---|
29 | }
|
---|
30 |
|
---|
31 | public static RepeatImageElemStyle create(Environment env) {
|
---|
32 | MapImage pattern = NodeElemStyle.createIcon(env, REPEAT_IMAGE_KEYS);
|
---|
33 | if (pattern == null)
|
---|
34 | return null;
|
---|
35 | Cascade c = env.mc.getCascade(env.layer);
|
---|
36 | Float offset = c.get(REPEAT_IMAGE_OFFSET, 0f, Float.class);
|
---|
37 | Float spacing = c.get(REPEAT_IMAGE_SPACING, 0f, Float.class);
|
---|
38 |
|
---|
39 | LineImageAlignment align = LineImageAlignment.CENTER;
|
---|
40 | Keyword alignKW = c.get(REPEAT_IMAGE_ALIGN, Keyword.CENTER, Keyword.class);
|
---|
41 | if (equal(alignKW.val, "top")) {
|
---|
42 | align = LineImageAlignment.TOP;
|
---|
43 | } else if (equal(alignKW.val, "bottom")) {
|
---|
44 | align = LineImageAlignment.BOTTOM;
|
---|
45 | }
|
---|
46 |
|
---|
47 | return new RepeatImageElemStyle(c, pattern, offset, spacing, align);
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, StyledMapRenderer painter, boolean selected, boolean member) {
|
---|
52 | Way w = (Way)primitive;
|
---|
53 | painter.drawRepeatImage(w, pattern.getImage(), offset, spacing, align);
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public boolean isProperLineStyle() {
|
---|
58 | return true;
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Override
|
---|
62 | public boolean equals(Object obj) {
|
---|
63 | if (obj == null || getClass() != obj.getClass())
|
---|
64 | return false;
|
---|
65 | if (!super.equals(obj))
|
---|
66 | return false;
|
---|
67 | final RepeatImageElemStyle other = (RepeatImageElemStyle) obj;
|
---|
68 | if (!this.pattern.equals(other.pattern)) return false;
|
---|
69 | if (this.offset != other.offset) return false;
|
---|
70 | if (this.spacing != other.spacing) return false;
|
---|
71 | if (this.align != other.align) return false;
|
---|
72 | return true;
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Override
|
---|
76 | public int hashCode() {
|
---|
77 | int hash = 7;
|
---|
78 | hash = 83 * hash + this.pattern.hashCode();
|
---|
79 | hash = 83 * hash + Float.floatToIntBits(this.offset);
|
---|
80 | hash = 83 * hash + Float.floatToIntBits(this.spacing);
|
---|
81 | hash = 83 * hash + this.align.hashCode();
|
---|
82 | return hash;
|
---|
83 | }
|
---|
84 |
|
---|
85 | @Override
|
---|
86 | public String toString() {
|
---|
87 | return "RepeatImageStyle{" + super.toString() + "pattern=[" + pattern +
|
---|
88 | "], offset=" + offset + ", spacing=" + spacing + ", align=" + align + "}";
|
---|
89 | }
|
---|
90 | }
|
---|