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.data.osm.visitor.paint.PaintColors;
|
---|
9 | import org.openstreetmap.josm.tools.Utils;
|
---|
10 |
|
---|
11 | public 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 | }
|
---|