source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/LineTextElemStyle.java@ 4040

Last change on this file since 4040 was 4006, checked in by bastiK, 14 years ago

mapcss: new LinePattern style element similar to mapnik's LinePatternSymbolizer; split off the text part of LineElemStyle, so it also works for LinePattern

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint;
3
4import org.openstreetmap.josm.data.osm.OsmPrimitive;
5import org.openstreetmap.josm.data.osm.Way;
6import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
7import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
8import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
9import org.openstreetmap.josm.tools.Utils;
10
11public 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}
Note: See TracBrowser for help on using the repository browser.