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

Last change on this file since 32395 was 32395, checked in by donvip, 10 years ago

checkstyle, update to JOSM 10279

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package relcontext;
3
4import javax.swing.JLabel;
5
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 //private ChosenRelation chRel;
18
19 public ChosenRelationComponent(ChosenRelation rel) {
20 super("");
21 /* setBackground(Color.white);
22 setOpaque(true);
23 setBorder(new LineBorder(Color.black, 1, true));*/
24 //this.chRel = rel;
25 rel.addChosenRelationListener(this);
26 }
27
28 @Override
29 public void chosenRelationChanged(Relation oldRelation, Relation newRelation) {
30 setText(prepareText(newRelation));
31 repaint();
32 }
33
34 private final static String[] TYPE_KEYS = new String[] {
35 "natural", "landuse", "place", "waterway", "leisure", "amenity", "restriction", "public_transport", "route", "enforcement"
36 };
37
38 private final static String[] NAMING_TAGS = new String[] {
39 "name", "place_name", "ref", "destination", "note"
40 };
41
42 protected String prepareText(Relation rel) {
43 if (rel == null )
44 return "";
45
46 String type = rel.get("type");
47 if (type == null || type.length() == 0 ) {
48 type = "-";
49 }
50
51 String tag = null;
52 for (int i = 0; i < TYPE_KEYS.length && tag == null; i++ )
53 if (rel.hasKey(TYPE_KEYS[i])) {
54 tag = TYPE_KEYS[i];
55 }
56 if (tag != null ) {
57 tag = tag.substring(0, 2) + "=" + rel.get(tag);
58 }
59
60 String name = null;
61 for (int i = 0; i < NAMING_TAGS.length && name == null; i++ )
62 if (rel.hasKey(NAMING_TAGS[i]) ) {
63 name = rel.get(NAMING_TAGS[i]);
64 }
65
66 StringBuilder sb = new StringBuilder();
67 sb.append(type.substring(0, 1));
68 if (type.equals("boundary") && rel.hasKey("admin_level") ) {
69 sb.append(rel.get("admin_level"));
70 }
71 if (name != null ) {
72 sb.append(" \"").append(name).append('"');
73 }
74 if (tag != null ) {
75 sb.append("; ").append(tag);
76 }
77 sb.append(" (").append(rel.getMembersCount()).append(')');
78
79 return sb.toString();
80 }
81}
Note: See TracBrowser for help on using the repository browser.