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

Last change on this file since 26290 was 25695, checked in by zverik, 14 years ago

fix all strings for translation, update relation types (relcontext plugin)

File size: 2.3 KB
Line 
1package relcontext;
2
3import java.awt.Color;
4import javax.swing.JLabel;
5import javax.swing.border.BevelBorder;
6import javax.swing.border.LineBorder;
7import org.openstreetmap.josm.data.osm.Relation;
8
9/**
10 * Renderer for chosen relation.
11 * [Icon] na=wood U
12 * key is 2-letter; type = icon; to the right — symbol of relation topology (closed, lines, broken).
13 *
14 * @author Zverik
15 */
16public class ChosenRelationComponent extends JLabel implements ChosenRelationListener {
17
18 private ChosenRelation chRel;
19
20 public ChosenRelationComponent(ChosenRelation rel) {
21 super("");
22/* setBackground(Color.white);
23 setOpaque(true);
24 setBorder(new LineBorder(Color.black, 1, true));*/
25 this.chRel = rel;
26 rel.addChosenRelationListener(this);
27 }
28
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 String tag = null;
51 for( int i = 0; i < TYPE_KEYS.length && tag == null; i++ )
52 if( rel.hasKey(TYPE_KEYS[i]))
53 tag = TYPE_KEYS[i];
54 if( tag != null )
55 tag = tag.substring(0, 2) + "=" + rel.get(tag);
56
57 String name = null;
58 for( int i = 0; i < NAMING_TAGS.length && name == null; i++ )
59 if( rel.hasKey(NAMING_TAGS[i]) )
60 name = rel.get(NAMING_TAGS[i]);
61
62 StringBuilder sb = new StringBuilder();
63 sb.append(type.substring(0, 1));
64 if( type.equals("boundary") && rel.hasKey("admin_level") )
65 sb.append(rel.get("admin_level"));
66 if( name != null )
67 sb.append(" \"").append(name).append('"');
68 if( tag != null )
69 sb.append("; ").append(tag);
70 sb.append(" (").append(rel.getMembersCount()).append(')');
71
72 return sb.toString();
73 }
74}
Note: See TracBrowser for help on using the repository browser.