source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/RepeatImageElemStyle.java@ 7081

Last change on this file since 7081 was 5812, checked in by bastiK, 11 years ago

mapcss: add phase for repeat-image

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