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

Last change on this file since 12888 was 12615, checked in by bastiK, 7 years ago

see #14794 - javadoc

  • Property svn:eol-style set to native
File size: 2.0 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.gui.util.GuiHelper;
16import 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 */
24public 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}
Note: See TracBrowser for help on using the repository browser.