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