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