001package jmri.jmrit.roster.swing.functiontable; 002 003import java.awt.*; 004import javax.swing.*; 005import javax.swing.table.TableCellRenderer; 006 007/** 008 * A TableCellRenderer that provides a way for the user to view details of functions of a decoder in the roster. 009 * It is used in the FunctionLabelPane. 010 * 011 * <hr> 012 * This file is part of JMRI. 013 * <p> 014 * JMRI is free software; you can redistribute it and/or modify it under the 015 * terms of version 2 of the GNU General Public License as published by the Free 016 * Software Foundation. See the "COPYING" file for a copy of this license. 017 * <p> 018 * JMRI is distributed in the hope that it will be useful, but WITHOUT ANY 019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 020 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 021 * 022 * @author Lionel Jeanson 2009-2026 023 */ 024 025public class FunctionTableCellRenderer implements TableCellRenderer { 026 027 public static final int CELL_HEIGHT = 48; 028 public static final int LABEL_WIDTH = 200; 029 public static final int[] columnWidths = new int[FunctionTableModel.NBCOL]; 030 public static final String[] columnTooltips = new String[FunctionTableModel.NBCOL]; 031 032 public FunctionTableCellRenderer() { 033 super(); 034 035 columnWidths[FunctionTableModel.COL_FN]=CELL_HEIGHT; 036 columnWidths[FunctionTableModel.COL_DO]=CELL_HEIGHT; 037 columnWidths[FunctionTableModel.COL_VI]=CELL_HEIGHT; 038 columnWidths[FunctionTableModel.COL_LK]=CELL_HEIGHT; 039 columnWidths[FunctionTableModel.COL_OF]=CELL_HEIGHT; 040 columnWidths[FunctionTableModel.COL_ON]=CELL_HEIGHT; 041 columnWidths[FunctionTableModel.COL_SH]=CELL_HEIGHT; 042 columnWidths[FunctionTableModel.COL_LA]=LABEL_WIDTH; 043 044 columnTooltips[FunctionTableModel.COL_FN]=null; 045 columnTooltips[FunctionTableModel.COL_DO]=Bundle.getMessage("FunctionButtonDisplayOrderToolTip"); 046 columnTooltips[FunctionTableModel.COL_VI]=Bundle.getMessage("FunctionButtonVisibleToolTip"); 047 columnTooltips[FunctionTableModel.COL_LK]=Bundle.getMessage("FunctionButtonLockableToolTip"); 048 columnTooltips[FunctionTableModel.COL_OF]=Bundle.getMessage("FunctionButtonRosterImageToolTip"); 049 columnTooltips[FunctionTableModel.COL_ON]=Bundle.getMessage("FunctionButtonPressedRosterImageToolTip"); 050 columnTooltips[FunctionTableModel.COL_SH]=Bundle.getMessage("ShuntButtonToolTip"); 051 columnTooltips[FunctionTableModel.COL_LA]=null; 052 } 053 054 @Override 055 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 056 JPanel retPanel = new JPanel(); 057 retPanel.setLayout(new BorderLayout()); 058 if (isSelected) { 059 retPanel.setBackground(javax.swing.UIManager.getDefaults().getColor("List.selectionBackground")); 060 } 061 if (value == null) { 062 return retPanel; 063 } 064 065 int fn = ((FunctionTableModel)table.getModel()).getFnForRow(row); 066 switch (column) { 067 case FunctionTableModel.COL_FN: 068 retPanel.add( new JLabel("" + fn), BorderLayout.CENTER); 069 break; 070 case FunctionTableModel.COL_DO: 071 retPanel.add(new JLabel( ""+ value), BorderLayout.CENTER); 072 break; 073 case FunctionTableModel.COL_VI: 074 JCheckBox visibleCheckBox = new JCheckBox(); 075 visibleCheckBox.setSelected((Boolean) value); 076 retPanel.add(visibleCheckBox, BorderLayout.CENTER); 077 break; 078 case FunctionTableModel.COL_LK: 079 JCheckBox lockableCheckBox = new JCheckBox(); 080 lockableCheckBox.setSelected((Boolean) value); 081 retPanel.add(lockableCheckBox, BorderLayout.CENTER); 082 break; 083 case FunctionTableModel.COL_OF: 084 retPanel.add( ((FunctionTableModel)table.getModel()).getFunctionImagePanel(fn), BorderLayout.CENTER); 085 break; 086 case FunctionTableModel.COL_ON: 087 retPanel.add( ((FunctionTableModel)table.getModel()).getFunctionSelectedImagePanel(fn), BorderLayout.CENTER); 088 break; 089 case FunctionTableModel.COL_SH: 090 JCheckBox shuntingCB = new JCheckBox(); 091 shuntingCB.setSelected((Boolean)value); 092 retPanel.add(shuntingCB, BorderLayout.CENTER); 093 break; 094 case FunctionTableModel.COL_LA: 095 retPanel.add(new JTextField((String) value), BorderLayout.CENTER); 096 break; 097 default: 098 break; 099 } 100 return retPanel; 101 } 102}