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

Last change on this file since 10217 was 10021, checked in by bastiK, 8 years ago

see #6301 - fix issues detected by the test

  • Property svn:eol-style set to native
File size: 1.9 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
18public 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 Color bgColor = Color.WHITE;
36 setIcon(nodeIcon);
37 if (item.value != null) {
38 text = tr("Node {0}", item.value.toString());
39 }
40 bgColor = item.state.getColor();
41 if (item.state == DiffItemType.EMPTY) {
42 text = "";
43 setIcon(null);
44 }
45 if (isSelected) {
46 bgColor = BGCOLOR_SELECTED;
47 }
48 setText(text);
49 GuiHelper.setBackgroundReadable(this, bgColor);
50 }
51
52 // Warning: The model pads with null-rows to match the size of the opposite table. 'value' could be null
53 @Override
54 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
55 int row, int column) {
56
57 if (value != null) {
58 renderNode((TwoColumnDiff.Item) value, isSelected);
59 }
60 return this;
61 }
62}
Note: See TracBrowser for help on using the repository browser.