source: josm/trunk/src/org/openstreetmap/josm/gui/history/NodeListTableCellRenderer.java@ 7801

Last change on this file since 7801 was 6986, checked in by Don-vip, 10 years ago

sonar - fix various minor issues

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.history;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Color;
7import java.awt.Component;
8
9import javax.swing.ImageIcon;
10import javax.swing.JLabel;
11import javax.swing.JTable;
12import javax.swing.table.TableCellRenderer;
13
14import org.openstreetmap.josm.gui.history.TwoColumnDiff.Item.DiffItemType;
15import org.openstreetmap.josm.tools.ImageProvider;
16
17public class NodeListTableCellRenderer extends JLabel implements TableCellRenderer {
18
19 public static final Color BGCOLOR_SELECTED = new Color(143,170,255);
20
21 private ImageIcon nodeIcon;
22
23 /**
24 * Constructs a new {@code NodeListTableCellRenderer}.
25 */
26 public NodeListTableCellRenderer(){
27 setOpaque(true);
28 nodeIcon = ImageProvider.get("data", "node");
29 setIcon(nodeIcon);
30 }
31
32 protected void renderNode(TwoColumnDiff.Item item, boolean isSelected) {
33 String text = "";
34 Color bgColor = Color.WHITE;
35 setIcon(nodeIcon);
36 if (item.value != null) {
37 text = tr("Node {0}", item.value.toString());
38 }
39 bgColor = item.state.getColor();
40 if (item.state == DiffItemType.EMPTY) {
41 text = "";
42 setIcon(null);
43 }
44 if (isSelected) {
45 bgColor = BGCOLOR_SELECTED;
46 }
47 setText(text);
48 setBackground(bgColor);
49 }
50
51 // Warning: The model pads with null-rows to match the size of the opposite table. 'value' could be null
52 @Override
53 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
54 int row, int column) {
55
56 renderNode((TwoColumnDiff.Item)value, isSelected);
57 return this;
58 }
59}
Note: See TracBrowser for help on using the repository browser.