001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.history; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.awt.Color; 007import java.awt.Component; 008 009import javax.swing.ImageIcon; 010import javax.swing.JLabel; 011import javax.swing.JTable; 012import javax.swing.table.TableCellRenderer; 013 014import org.openstreetmap.josm.gui.history.TwoColumnDiff.Item.DiffItemType; 015import org.openstreetmap.josm.gui.util.GuiHelper; 016import org.openstreetmap.josm.tools.ImageProvider; 017 018public class NodeListTableCellRenderer extends JLabel implements TableCellRenderer { 019 020 public static final Color BGCOLOR_SELECTED = new Color(143, 170, 255); 021 022 private final ImageIcon nodeIcon; 023 024 /** 025 * Constructs a new {@code NodeListTableCellRenderer}. 026 */ 027 public NodeListTableCellRenderer() { 028 setOpaque(true); 029 nodeIcon = ImageProvider.get("data", "node"); 030 setIcon(nodeIcon); 031 } 032 033 protected void renderNode(TwoColumnDiff.Item item, boolean isSelected) { 034 String text = ""; 035 Color bgColor = Color.WHITE; 036 setIcon(nodeIcon); 037 if (item.value != null) { 038 text = tr("Node {0}", item.value.toString()); 039 } 040 bgColor = item.state.getColor(); 041 if (item.state == DiffItemType.EMPTY) { 042 text = ""; 043 setIcon(null); 044 } 045 if (isSelected) { 046 bgColor = BGCOLOR_SELECTED; 047 } 048 setText(text); 049 GuiHelper.setBackgroundReadable(this, bgColor); 050 } 051 052 // Warning: The model pads with null-rows to match the size of the opposite table. 'value' could be null 053 @Override 054 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, 055 int row, int column) { 056 057 renderNode((TwoColumnDiff.Item) value, isSelected); 058 return this; 059 } 060}