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