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.StyledMapRenderer;
|
---|
8 | import org.openstreetmap.josm.tools.CheckParameterUtil;
|
---|
9 |
|
---|
10 | public class RepeatImageElemStyle extends ElemStyle implements StyleKeys {
|
---|
11 |
|
---|
12 | public enum LineImageAlignment { TOP, CENTER, BOTTOM }
|
---|
13 |
|
---|
14 | public MapImage pattern;
|
---|
15 | public float offset;
|
---|
16 | public float spacing;
|
---|
17 | public float phase;
|
---|
18 | public LineImageAlignment align;
|
---|
19 |
|
---|
20 | public RepeatImageElemStyle(Cascade c, MapImage pattern, float offset, float spacing, float phase, LineImageAlignment align) {
|
---|
21 | super(c, 2.9f);
|
---|
22 | CheckParameterUtil.ensureParameterNotNull(pattern);
|
---|
23 | CheckParameterUtil.ensureParameterNotNull(align);
|
---|
24 | this.pattern = pattern;
|
---|
25 | this.offset = offset;
|
---|
26 | this.spacing = spacing;
|
---|
27 | this.phase = phase;
|
---|
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 | float phase = - c.get(REPEAT_IMAGE_PHASE, 0f, Float.class);
|
---|
39 |
|
---|
40 | LineImageAlignment align = LineImageAlignment.CENTER;
|
---|
41 | Keyword alignKW = c.get(REPEAT_IMAGE_ALIGN, Keyword.CENTER, Keyword.class);
|
---|
42 | if ("top".equals(alignKW.val)) {
|
---|
43 | align = LineImageAlignment.TOP;
|
---|
44 | } else if ("bottom".equals(alignKW.val)) {
|
---|
45 | align = LineImageAlignment.BOTTOM;
|
---|
46 | }
|
---|
47 |
|
---|
48 | return new RepeatImageElemStyle(c, pattern, offset, spacing, phase, align);
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, StyledMapRenderer painter, boolean selected, boolean member) {
|
---|
53 | Way w = (Way) primitive;
|
---|
54 | painter.drawRepeatImage(w, pattern.getImage(), offset, spacing, phase, align);
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public boolean isProperLineStyle() {
|
---|
59 | return true;
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Override
|
---|
63 | public boolean equals(Object obj) {
|
---|
64 | if (obj == null || getClass() != obj.getClass())
|
---|
65 | return false;
|
---|
66 | if (!super.equals(obj))
|
---|
67 | return false;
|
---|
68 | final RepeatImageElemStyle other = (RepeatImageElemStyle) obj;
|
---|
69 | if (!this.pattern.equals(other.pattern)) return false;
|
---|
70 | if (this.offset != other.offset) return false;
|
---|
71 | if (this.spacing != other.spacing) return false;
|
---|
72 | if (this.phase != other.phase) return false;
|
---|
73 | if (this.align != other.align) return false;
|
---|
74 | return true;
|
---|
75 | }
|
---|
76 |
|
---|
77 | @Override
|
---|
78 | public int hashCode() {
|
---|
79 | int hash = 7;
|
---|
80 | hash = 83 * hash + this.pattern.hashCode();
|
---|
81 | hash = 83 * hash + Float.floatToIntBits(this.offset);
|
---|
82 | hash = 83 * hash + Float.floatToIntBits(this.spacing);
|
---|
83 | hash = 83 * hash + Float.floatToIntBits(this.phase);
|
---|
84 | hash = 83 * hash + this.align.hashCode();
|
---|
85 | return hash;
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override
|
---|
89 | public String toString() {
|
---|
90 | return "RepeatImageStyle{" + super.toString() + "pattern=[" + pattern +
|
---|
91 | "], offset=" + offset + ", spacing=" + spacing +
|
---|
92 | ", phase=" + (-phase) + ", align=" + align + "}";
|
---|
93 | }
|
---|
94 | }
|
---|