001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.mappaint; 003 004import java.util.Objects; 005 006import org.openstreetmap.josm.data.osm.OsmPrimitive; 007import org.openstreetmap.josm.data.osm.Way; 008import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings; 009import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 010import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer; 011 012public class LineTextElemStyle extends ElemStyle { 013 014 private TextElement text; 015 016 protected LineTextElemStyle(Cascade c, TextElement text) { 017 super(c, 4.9f); 018 this.text = text; 019 } 020 public static LineTextElemStyle create(final Environment env) { 021 final Cascade c = env.mc.getCascade(env.layer); 022 023 Keyword textPos = c.get(TEXT_POSITION, null, Keyword.class); 024 if (textPos != null && !"line".equals(textPos.val)) 025 return null; 026 027 TextElement text = TextElement.create(env, PaintColors.TEXT.get(), false); 028 if (text == null) 029 return null; 030 return new LineTextElemStyle(c, text); 031 } 032 033 @Override 034 public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, StyledMapRenderer painter, 035 boolean selected, boolean outermember, boolean member) { 036 Way w = (Way)primitive; 037 painter.drawTextOnPath(w, text); 038 } 039 040 @Override 041 public boolean equals(Object obj) { 042 if (obj == null || getClass() != obj.getClass()) 043 return false; 044 if (!super.equals(obj)) 045 return false; 046 final LineTextElemStyle other = (LineTextElemStyle) obj; 047 return Objects.equals(text, other.text); 048 } 049 050 @Override 051 public int hashCode() { 052 return text.hashCode(); 053 } 054 055 @Override 056 public String toString() { 057 return "LineTextElemStyle{" + super.toString() + "text=" + text + "}"; 058 } 059}