001 /*
002 * Copyright (C) 2008-2009 Holger Aimport java.awt.Component;
003
004 import javax.swing.JLabel;
005 import javax.swing.JTable;
006 import javax.swing.UIManager;
007 import javax.swing.table.DefaultTableCellRenderer;
008 import javax.swing.table.TableCellRenderer;
009
010 import org.jdmp.core.module.Module;
011 ree software; you can redistribute it and/or modify
012 * it under the terms of the GNU Lesser General Public License as
013 * published by the Free Software Foundation; either version 2
014 * of the License, or (at your option) any later version.
015 *
016 * JDMP is distributed in the hope that it will be useful,
017 * but WITHOUT ANY WARRANTY; without even the implied warranty of
018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
019 * GNU Lesser General Public License for more details.
020 *
021 * You should have received a copy of the GNU Lesser General Public
022 * License along with JDMP; if not, write to the
023 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
024 * Boston, MA 02110-1301 USA
025 */
026
027 package org.jdmp.gui.module;
028
029 import java.awt.Component;
030
031 import javax.swing.JLabel;
032 import javax.swing.JTable;
033 import javax.swing.UIManager;
034 import javax.swing.table.DefaultTableCellRenderer;
035 import javax.swing.table.TableCellRenderer;
036
037 import org.jdmp.core.module.Module;
038
039 public class ModuleTableCellRenderer implements TableCellRenderer {
040 private static final long serialVersionUID = 990917492575992066L;
041
042 private final DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
043
044 private Module module = null;
045
046 private Object o = null;
047
048 private JLabel c = null;
049
050 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
051 boolean hasFocus, int row, int column) {
052
053 c = null;
054
055 if (value instanceof Module)
056 module = (Module) value;
057 else
058 module = null;
059
060 if (module != null) {
061
062 switch (column) {
063 case ModuleListTableModel.LABELCOLUMN:
064 o = module.getLabel();
065 break;
066 case ModuleListTableModel.DATASETCOUNTCOLUMN:
067 o = module.getDataSets().getSize();
068 break;
069 case ModuleListTableModel.VARIABLECOUNTCOLUMN:
070 o = module.getVariables().getSize();
071 break;
072 case ModuleListTableModel.MODULECOUNTCOLUMN:
073 o = null;
074 break;
075 case ModuleListTableModel.ALGORITHMCOUNTCOLUMN:
076 o = module.getAlgorithms().getSize();
077 break;
078 default:
079 o = null;
080 break;
081 }
082
083 c = (JLabel) renderer.getTableCellRendererComponent(table, o, isSelected, hasFocus,
084 row, column);
085
086 switch (column) {
087 case ModuleListTableModel.ICONCOLUMN:
088 c.setIcon(UIManager.getIcon("Module.icon"));
089 break;
090 default:
091 c.setIcon(null);
092 break;
093 }
094
095 c.setHorizontalAlignment(JLabel.CENTER);
096
097 }
098
099 return c;
100 }
101 }