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.tools.ImageProvider; 016 017public class NodeListTableCellRenderer extends JLabel implements TableCellRenderer { 018 019 public final static Color BGCOLOR_SELECTED = new Color(143,170,255); 020 021 private ImageIcon nodeIcon; 022 023 public NodeListTableCellRenderer(){ 024 setOpaque(true); 025 nodeIcon = ImageProvider.get("data", "node"); 026 setIcon(nodeIcon); 027 } 028 029 protected void renderNode(TwoColumnDiff.Item item, boolean isSelected) { 030 String text = ""; 031 Color bgColor = Color.WHITE; 032 setIcon(nodeIcon); 033 if (item.value != null) { 034 text = tr("Node {0}", item.value.toString()); 035 } 036 bgColor = item.state.getColor(); 037 if (item.state == DiffItemType.EMPTY) { 038 text = ""; 039 setIcon(null); 040 } 041 if (isSelected) { 042 bgColor = BGCOLOR_SELECTED; 043 } 044 setText(text); 045 setBackground(bgColor); 046 } 047 048 // Warning: The model pads with null-rows to match the size of the opposite table. 'value' could be null 049 @Override 050 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, 051 int row, int column) { 052 053 renderNode((TwoColumnDiff.Item)value, isSelected); 054 return this; 055 } 056}