source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/LineTextElemStyle.java@ 6340

Last change on this file since 6340 was 5571, checked in by Don-vip, 11 years ago

fix #7979 - fix ArrayIndexOutOfBoundsException when rendering ways with the "quick and dirty" approach, and a TODO note to code a better approach on the next development cycle

  • Property svn:eol-style set to native
File size: 1.8 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.data.osm.visitor.paint.PaintColors;
9import org.openstreetmap.josm.tools.Utils;
10
11public class LineTextElemStyle extends ElemStyle {
12
13 private TextElement text;
14
15 protected LineTextElemStyle(Cascade c, TextElement text) {
16 super(c, 4.9f);
17 this.text = text;
18 }
19 public static LineTextElemStyle create(Environment env) {
20 Cascade c = env.mc.getCascade(env.layer);
21
22 Keyword textPos = c.get(TEXT_POSITION, null, Keyword.class);
23 if (textPos != null && !Utils.equal(textPos.val, "line"))
24 return null;
25
26 TextElement text = TextElement.create(c, PaintColors.TEXT.get(), false);
27 if (text == null)
28 return null;
29 return new LineTextElemStyle(c, text);
30 }
31
32 @Override
33 public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, StyledMapRenderer painter, boolean selected, boolean member) {
34 Way w = (Way)primitive;
35 painter.drawTextOnPath(w, text);
36 }
37
38 @Override
39 public boolean equals(Object obj) {
40 if (obj == null || getClass() != obj.getClass())
41 return false;
42 if (!super.equals(obj))
43 return false;
44 final LineTextElemStyle other = (LineTextElemStyle) obj;
45 return Utils.equal(text, other.text);
46 }
47
48 @Override
49 public int hashCode() {
50 return text.hashCode();
51 }
52
53 @Override
54 public String toString() {
55 return "LineTextElemStyle{" + super.toString() + "text=" + text + "}";
56 }
57
58}
Note: See TracBrowser for help on using the repository browser.