source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationTreeCellRenderer.java@ 8509

Last change on this file since 8509 was 8509, checked in by Don-vip, 9 years ago

fix many checkstyle violations

  • 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.dialogs.relation;
3
4import java.awt.Color;
5import java.awt.Component;
6
7import javax.swing.ImageIcon;
8import javax.swing.JLabel;
9import javax.swing.JTree;
10import javax.swing.tree.TreeCellRenderer;
11
12import org.openstreetmap.josm.data.osm.Relation;
13import org.openstreetmap.josm.gui.DefaultNameFormatter;
14import org.openstreetmap.josm.tools.ImageProvider;
15
16/**
17 * This is the cell renderer used in {@link RelationTree}.
18 *
19 *
20 */
21public class RelationTreeCellRenderer extends JLabel implements TreeCellRenderer {
22 public static final Color BGCOLOR_SELECTED = new Color(143,170,255);
23
24 /** the relation icon */
25 private ImageIcon icon;
26
27 /**
28 * constructor
29 */
30 public RelationTreeCellRenderer() {
31 icon = ImageProvider.get("data", "relation");
32 setOpaque(true);
33 }
34
35 /**
36 * renders the icon
37 */
38 protected void renderIcon() {
39 setIcon(icon);
40 }
41
42 /**
43 * renders the textual value. Uses the relations names as value
44 *
45 * @param relation the relation
46 */
47 protected void renderValue(Relation relation) {
48 setText(relation.getDisplayName(DefaultNameFormatter.getInstance()));
49 }
50
51 /**
52 * renders the background
53 *
54 * @param selected true, if the current node is selected
55 */
56 protected void renderBackground(boolean selected) {
57 Color bgColor = Color.WHITE;
58 if (selected) {
59 bgColor = BGCOLOR_SELECTED;
60 }
61 setBackground(bgColor);
62 }
63
64 @Override
65 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
66 boolean leaf, int row, boolean hasFocus) {
67
68 // Hackish fix for #7056 - if name template for duplicated relation contains tags from parent,
69 // template will fail because getReffers doesn't work on primitives not yet in dataset
70 if (!tree.isRootVisible() && tree.getModel().getRoot() == value)
71 return this;
72
73 renderIcon();
74 renderValue((Relation)value);
75 renderBackground(selected);
76 return this;
77 }
78}
Note: See TracBrowser for help on using the repository browser.