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

Last change on this file since 8087 was 8085, checked in by bastiK, 9 years ago

fixed #10216 Offsetting node icon in MapCSS

also: rework of rendering of disabled layers and objects

  • Property svn:eol-style set to native
File size: 3.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint;
3
4import org.openstreetmap.josm.data.osm.OsmPrimitive;
5import org.openstreetmap.josm.data.osm.Way;
6import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
7import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
8import org.openstreetmap.josm.tools.CheckParameterUtil;
9
10public 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,
53 boolean selected, boolean outermember, boolean member) {
54 Way w = (Way) primitive;
55 painter.drawRepeatImage(w, pattern, painter.isInactiveMode() || w.isDisabled(), offset, spacing, phase, align);
56 }
57
58 @Override
59 public boolean isProperLineStyle() {
60 return true;
61 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (obj == null || getClass() != obj.getClass())
66 return false;
67 if (!super.equals(obj))
68 return false;
69 final RepeatImageElemStyle other = (RepeatImageElemStyle) obj;
70 if (!this.pattern.equals(other.pattern)) return false;
71 if (this.offset != other.offset) return false;
72 if (this.spacing != other.spacing) return false;
73 if (this.phase != other.phase) return false;
74 if (this.align != other.align) return false;
75 return true;
76 }
77
78 @Override
79 public int hashCode() {
80 int hash = 7;
81 hash = 83 * hash + this.pattern.hashCode();
82 hash = 83 * hash + Float.floatToIntBits(this.offset);
83 hash = 83 * hash + Float.floatToIntBits(this.spacing);
84 hash = 83 * hash + Float.floatToIntBits(this.phase);
85 hash = 83 * hash + this.align.hashCode();
86 return hash;
87 }
88
89 @Override
90 public String toString() {
91 return "RepeatImageStyle{" + super.toString() + "pattern=[" + pattern +
92 "], offset=" + offset + ", spacing=" + spacing +
93 ", phase=" + (-phase) + ", align=" + align + "}";
94 }
95}
Note: See TracBrowser for help on using the repository browser.