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

Last change on this file since 10760 was 9371, checked in by simon04, 8 years ago

Java 7: use Objects.equals and Objects.hash

  • Property svn:eol-style set to native
File size: 2.0 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 (this == obj) return true;
47 if (obj == null || getClass() != obj.getClass()) return false;
48 if (!super.equals(obj)) return false;
49 LineTextElement that = (LineTextElement) obj;
50 return Objects.equals(text, that.text);
51 }
52
53 @Override
54 public int hashCode() {
55 return Objects.hash(super.hashCode(), text);
56 }
57
58 @Override
59 public String toString() {
60 return "LineTextElemStyle{" + super.toString() + "text=" + text + '}';
61 }
62}
Note: See TracBrowser for help on using the repository browser.