001package jmri.jmrit.consisttool;
002
003import java.awt.*;
004
005import javax.swing.*;
006import javax.swing.table.TableCellRenderer;
007
008import jmri.InstanceManager;
009import jmri.jmrit.roster.*;
010
011/**
012 * A TableCellRender to graphicaly display a consists in the consist table
013 * 
014 * @author Lionel Jeanson - 2023
015 * 
016 */
017
018public class ConsistTableRosterEntryColumnCellRenderer implements TableCellRenderer {
019
020    @Override
021    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
022        JPanel retPanel = new JPanel();
023        retPanel.setLayout(new BorderLayout());
024
025        if (value == null) {
026            return retPanel;
027        }
028        if (value instanceof String) {
029            String reName = (String) value;        
030            JLabel label = new JLabel(reName);
031            ImageIcon icon;
032            Boolean dir = (Boolean) table.getModel().getValueAt(row, ConsistDataModel.DIRECTIONCOLUMN);
033            if (dir) {
034                icon = InstanceManager.getDefault(RosterIconFactory.class).getIcon(reName);
035            } else {
036                icon = InstanceManager.getDefault(RosterIconFactory.class).getReversedIcon(reName);
037            }
038            if (icon != null) {
039                icon.setImageObserver(table);
040                label.setIcon(icon);
041            }                    
042            retPanel.add(label, BorderLayout.CENTER);
043        }
044        return retPanel;
045    }
046
047}