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.gui.history.TwoColumnDiff.Item.DiffItemType;
|
---|
15 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
16 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
17 |
|
---|
18 | public class NodeListTableCellRenderer extends JLabel implements TableCellRenderer {
|
---|
19 |
|
---|
20 | public static final Color BGCOLOR_SELECTED = new Color(143, 170, 255);
|
---|
21 |
|
---|
22 | private final ImageIcon nodeIcon;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Constructs a new {@code NodeListTableCellRenderer}.
|
---|
26 | */
|
---|
27 | public NodeListTableCellRenderer() {
|
---|
28 | setOpaque(true);
|
---|
29 | nodeIcon = ImageProvider.get("data", "node");
|
---|
30 | setIcon(nodeIcon);
|
---|
31 | }
|
---|
32 |
|
---|
33 | protected void renderNode(TwoColumnDiff.Item item, boolean isSelected) {
|
---|
34 | String text = "";
|
---|
35 | setIcon(nodeIcon);
|
---|
36 | if (item.value != null) {
|
---|
37 | text = tr("Node {0}", item.value.toString());
|
---|
38 | }
|
---|
39 | Color 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 | GuiHelper.setBackgroundReadable(this, 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 | if (value != null) {
|
---|
57 | renderNode((TwoColumnDiff.Item) value, isSelected);
|
---|
58 | }
|
---|
59 | return this;
|
---|
60 | }
|
---|
61 | }
|
---|