source: osm/applications/editors/josm/plugins/reltoolbox/src/relcontext/ChosenRelationComponent.java

Last change on this file was 36102, checked in by taylor.smock, 21 months ago

reltoolbox: Clean up a bunch of lint warnings

  • Property svn:eol-style set to native
File size: 2.2 KB
RevLine 
[32395]1// License: GPL. For details, see LICENSE file.
[25667]2package relcontext;
3
4import javax.swing.JLabel;
[29535]5
[25667]6import org.openstreetmap.josm.data.osm.Relation;
7
8/**
9 * Renderer for chosen relation.
10 * [Icon] na=wood U
11 * key is 2-letter; type = icon; to the right — symbol of relation topology (closed, lines, broken).
12 *
13 * @author Zverik
14 */
15public class ChosenRelationComponent extends JLabel implements ChosenRelationListener {
16
17 public ChosenRelationComponent(ChosenRelation rel) {
18 super("");
19 rel.addChosenRelationListener(this);
20 }
21
[32395]22 @Override
23 public void chosenRelationChanged(Relation oldRelation, Relation newRelation) {
[25669]24 setText(prepareText(newRelation));
[25667]25 repaint();
26 }
[32395]27
[32398]28 private static final String[] TYPE_KEYS = new String[] {
[32395]29 "natural", "landuse", "place", "waterway", "leisure", "amenity", "restriction", "public_transport", "route", "enforcement"
[25669]30 };
31
[32398]32 private static final String[] NAMING_TAGS = new String[] {
[32395]33 "name", "place_name", "ref", "destination", "note"
[25685]34 };
35
[32395]36 protected String prepareText(Relation rel) {
[32398]37 if (rel == null)
[25669]38 return "";
39
40 String type = rel.get("type");
[32398]41 if (type == null || type.length() == 0) {
[25669]42 type = "-";
[32395]43 }
[25669]44
45 String tag = null;
[32398]46 for (int i = 0; i < TYPE_KEYS.length && tag == null; i++) {
[32395]47 if (rel.hasKey(TYPE_KEYS[i])) {
[25685]48 tag = TYPE_KEYS[i];
[32395]49 }
[32398]50 }
51 if (tag != null) {
[25669]52 tag = tag.substring(0, 2) + "=" + rel.get(tag);
[32395]53 }
[25669]54
[25685]55 String name = null;
[32398]56 for (int i = 0; i < NAMING_TAGS.length && name == null; i++) {
57 if (rel.hasKey(NAMING_TAGS[i])) {
[25685]58 name = rel.get(NAMING_TAGS[i]);
[32395]59 }
[32398]60 }
[25669]61
62 StringBuilder sb = new StringBuilder();
[36102]63 sb.append(type.charAt(0));
[32398]64 if (type.equals("boundary") && rel.hasKey("admin_level")) {
[25669]65 sb.append(rel.get("admin_level"));
[32395]66 }
[32398]67 if (name != null) {
[25669]68 sb.append(" \"").append(name).append('"');
[32395]69 }
[32398]70 if (tag != null) {
[25669]71 sb.append("; ").append(tag);
[32395]72 }
[25682]73 sb.append(" (").append(rel.getMembersCount()).append(')');
[25669]74
75 return sb.toString();
76 }
[25667]77}
Note: See TracBrowser for help on using the repository browser.