1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.history;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Color;
|
---|
7 | import java.awt.Component;
|
---|
8 |
|
---|
9 | import javax.swing.ImageIcon;
|
---|
10 | import javax.swing.JLabel;
|
---|
11 | import javax.swing.JTable;
|
---|
12 | import javax.swing.table.TableCellRenderer;
|
---|
13 |
|
---|
14 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
15 |
|
---|
16 | public 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 | }
|
---|