| 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.MapPainter; | 
|---|
| 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, 2f); | 
|---|
| 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 | return new LineTextElemStyle(c, text); | 
|---|
| 28 | } | 
|---|
| 29 |  | 
|---|
| 30 | @Override | 
|---|
| 31 | public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member) { | 
|---|
| 32 | Way w = (Way)primitive; | 
|---|
| 33 | painter.drawTextOnPath(w, text); | 
|---|
| 34 | } | 
|---|
| 35 |  | 
|---|
| 36 | @Override | 
|---|
| 37 | public boolean equals(Object obj) { | 
|---|
| 38 | if (obj == null || getClass() != obj.getClass()) | 
|---|
| 39 | return false; | 
|---|
| 40 | if (!super.equals(obj)) | 
|---|
| 41 | return false; | 
|---|
| 42 | final LineTextElemStyle other = (LineTextElemStyle) obj; | 
|---|
| 43 | return Utils.equal(text, other.text); | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | @Override | 
|---|
| 47 | public int hashCode() { | 
|---|
| 48 | return text.hashCode(); | 
|---|
| 49 | } | 
|---|
| 50 | } | 
|---|