1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint.styleelement;
|
---|
3 |
|
---|
4 | import java.util.Objects;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
7 | import org.openstreetmap.josm.data.osm.Way;
|
---|
8 | import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
|
---|
9 | import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
|
---|
10 | import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
|
---|
11 | import org.openstreetmap.josm.gui.mappaint.Cascade;
|
---|
12 | import org.openstreetmap.josm.gui.mappaint.Environment;
|
---|
13 | import org.openstreetmap.josm.gui.mappaint.Keyword;
|
---|
14 |
|
---|
15 | public class LineTextElement extends StyleElement {
|
---|
16 |
|
---|
17 | private final TextLabel text;
|
---|
18 |
|
---|
19 | protected LineTextElement(Cascade c, TextLabel text) {
|
---|
20 | super(c, 4.9f);
|
---|
21 | this.text = text;
|
---|
22 | }
|
---|
23 |
|
---|
24 | public static LineTextElement create(final Environment env) {
|
---|
25 | final Cascade c = env.mc.getCascade(env.layer);
|
---|
26 |
|
---|
27 | Keyword textPos = c.get(TEXT_POSITION, null, Keyword.class);
|
---|
28 | if (textPos != null && !"line".equals(textPos.val))
|
---|
29 | return null;
|
---|
30 |
|
---|
31 | TextLabel text = TextLabel.create(env, PaintColors.TEXT.get(), false);
|
---|
32 | if (text == null)
|
---|
33 | return null;
|
---|
34 | return new LineTextElement(c, text);
|
---|
35 | }
|
---|
36 |
|
---|
37 | @Override
|
---|
38 | public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, StyledMapRenderer painter,
|
---|
39 | boolean selected, boolean outermember, boolean member) {
|
---|
40 | Way w = (Way) primitive;
|
---|
41 | painter.drawTextOnPath(w, text);
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Override
|
---|
45 | public boolean equals(Object obj) {
|
---|
46 | if (obj == null || getClass() != obj.getClass())
|
---|
47 | return false;
|
---|
48 | if (!super.equals(obj))
|
---|
49 | return false;
|
---|
50 | final LineTextElement other = (LineTextElement) obj;
|
---|
51 | return Objects.equals(text, other.text);
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | public int hashCode() {
|
---|
56 | int hash = super.hashCode();
|
---|
57 | hash = 43 * hash + text.hashCode();
|
---|
58 | return hash;
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Override
|
---|
62 | public String toString() {
|
---|
63 | return "LineTextElemStyle{" + super.toString() + "text=" + text + '}';
|
---|
64 | }
|
---|
65 | }
|
---|