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