source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/LineTextElement.java@ 9341

Last change on this file since 9341 was 9341, checked in by bastiK, 8 years ago

mapcss: basic support for :selected pseudoclass (see #9891)

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint.styleelement;
3
4import java.util.Objects;
5
6import org.openstreetmap.josm.data.osm.OsmPrimitive;
7import org.openstreetmap.josm.data.osm.Way;
8import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
9import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
10import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
11import org.openstreetmap.josm.gui.mappaint.Cascade;
12import org.openstreetmap.josm.gui.mappaint.Environment;
13import org.openstreetmap.josm.gui.mappaint.Keyword;
14
15public class LineTextElement extends StyleElement {
16
17 private final TextLabel text;
18
19 protected LineTextElement(Cascade c, TextLabel text) {
20 super(c, 4.9f);
21 this.text = text;
22 }
23
24 public static LineTextElement create(final Environment env) {
25 final Cascade c = env.mc.getCascade(env.layer);
26
27 Keyword textPos = c.get(TEXT_POSITION, null, Keyword.class);
28 if (textPos != null && !"line".equals(textPos.val))
29 return null;
30
31 TextLabel text = TextLabel.create(env, PaintColors.TEXT.get(), false);
32 if (text == null)
33 return null;
34 return new LineTextElement(c, text);
35 }
36
37 @Override
38 public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, StyledMapRenderer painter,
39 boolean selected, boolean outermember, boolean member) {
40 Way w = (Way) primitive;
41 painter.drawTextOnPath(w, text);
42 }
43
44 @Override
45 public boolean equals(Object obj) {
46 if (obj == null || getClass() != obj.getClass())
47 return false;
48 if (!super.equals(obj))
49 return false;
50 final LineTextElement other = (LineTextElement) obj;
51 return Objects.equals(text, other.text);
52 }
53
54 @Override
55 public int hashCode() {
56 int hash = super.hashCode();
57 hash = 43 * hash + text.hashCode();
58 return hash;
59 }
60
61 @Override
62 public String toString() {
63 return "LineTextElemStyle{" + super.toString() + "text=" + text + '}';
64 }
65}
Note: See TracBrowser for help on using the repository browser.