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 021 public static LineTextElemStyle create(final Environment env) { 022 final Cascade c = env.mc.getCascade(env.layer); 023 024 Keyword textPos = c.get(TEXT_POSITION, null, Keyword.class); 025 if (textPos != null && !"line".equals(textPos.val)) 026 return null; 027 028 TextElement text = TextElement.create(env, PaintColors.TEXT.get(), false); 029 if (text == null) 030 return null; 031 return new LineTextElemStyle(c, text); 032 } 033 034 @Override 035 public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, StyledMapRenderer painter, 036 boolean selected, boolean outermember, boolean member) { 037 Way w = (Way) primitive; 038 painter.drawTextOnPath(w, text); 039 } 040 041 @Override 042 public boolean equals(Object obj) { 043 if (obj == null || getClass() != obj.getClass()) 044 return false; 045 if (!super.equals(obj)) 046 return false; 047 final LineTextElemStyle other = (LineTextElemStyle) obj; 048 return Objects.equals(text, other.text); 049 } 050 051 @Override 052 public int hashCode() { 053 return text.hashCode(); 054 } 055 056 @Override 057 public String toString() { 058 return "LineTextElemStyle{" + super.toString() + "text=" + text + '}'; 059 } 060}