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

Last change on this file since 5622 was 4566, checked in by stoecker, 12 years ago

fix #6652 - patch by olejorgenb - Members list in history panel for relations and ways is broken

  • Property svn:eol-style set to native
File size: 2.3 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.tools.ImageProvider;
15
16public class NodeListTableCellRenderer extends JLabel implements TableCellRenderer {
17
18 public final static Color BGCOLOR_EMPTY_ROW = new Color(234,234,234);
19 public final static Color BGCOLOR_DELETED = new Color(255,197,197);
20 public final static Color BGCOLOR_INSERTED = new Color(0xDD, 0xFF, 0xDD);
21 public final static Color BGCOLOR_CHANGED = new Color(255,234,213);
22 public final static Color BGCOLOR_SELECTED = new Color(143,170,255);
23
24 private ImageIcon nodeIcon;
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 switch(item.state) {
40 case TwoColumnDiff.Item.EMPTY:
41 text = "";
42 bgColor = BGCOLOR_EMPTY_ROW;
43 setIcon(null);
44 break;
45 case TwoColumnDiff.Item.CHANGED:
46 bgColor = BGCOLOR_CHANGED;
47 break;
48 case TwoColumnDiff.Item.INSERTED:
49 bgColor = BGCOLOR_INSERTED;
50 break;
51 case TwoColumnDiff.Item.DELETED:
52 bgColor = BGCOLOR_DELETED;
53 break;
54 default:
55 bgColor = BGCOLOR_EMPTY_ROW;
56 }
57 if (isSelected) {
58 bgColor = BGCOLOR_SELECTED;
59 }
60 setText(text);
61 setBackground(bgColor);
62 }
63
64 // Warning: The model pads with null-rows to match the size of the opposite table. 'value' could be null
65 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
66 int row, int column) {
67
68 renderNode((TwoColumnDiff.Item)value, isSelected);
69 return this;
70 }
71}
Note: See TracBrowser for help on using the repository browser.