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 | /**
|
---|
19 | * A {@link TableCellRenderer} for the {@link NodeListViewer}.
|
---|
20 | *
|
---|
21 | * Renders information about a node when comparing the node list of two
|
---|
22 | * historical versions of a way.
|
---|
23 | */
|
---|
24 | public class NodeListTableCellRenderer extends JLabel implements TableCellRenderer {
|
---|
25 |
|
---|
26 | public static final Color BGCOLOR_SELECTED = new Color(143, 170, 255);
|
---|
27 |
|
---|
28 | private final ImageIcon nodeIcon;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Constructs a new {@code NodeListTableCellRenderer}.
|
---|
32 | */
|
---|
33 | public NodeListTableCellRenderer() {
|
---|
34 | setOpaque(true);
|
---|
35 | nodeIcon = ImageProvider.get("data", "node");
|
---|
36 | setIcon(nodeIcon);
|
---|
37 | }
|
---|
38 |
|
---|
39 | protected void renderNode(TwoColumnDiff.Item item, boolean isSelected) {
|
---|
40 | String text = "";
|
---|
41 | setIcon(nodeIcon);
|
---|
42 | if (item.value != null) {
|
---|
43 | text = tr("Node {0}", item.value.toString());
|
---|
44 | }
|
---|
45 | Color bgColor = item.state.getColor();
|
---|
46 | if (item.state == DiffItemType.EMPTY) {
|
---|
47 | text = "";
|
---|
48 | setIcon(null);
|
---|
49 | }
|
---|
50 | if (isSelected) {
|
---|
51 | bgColor = BGCOLOR_SELECTED;
|
---|
52 | }
|
---|
53 | setText(text);
|
---|
54 | GuiHelper.setBackgroundReadable(this, bgColor);
|
---|
55 | }
|
---|
56 |
|
---|
57 | // Warning: The model pads with null-rows to match the size of the opposite table. 'value' could be null
|
---|
58 | @Override
|
---|
59 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
|
---|
60 | int row, int column) {
|
---|
61 |
|
---|
62 | if (value != null) {
|
---|
63 | renderNode((TwoColumnDiff.Item) value, isSelected);
|
---|
64 | }
|
---|
65 | return this;
|
---|
66 | }
|
---|
67 | }
|
---|