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.variable;
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.variable.Variable;
035    import org.ujmp.gui.plot.MatrixPlot;
036    import org.ujmp.gui.renderer.MatrixRenderer;
037    
038    public class VariableTableCellRenderer implements TableCellRenderer {
039            private static final long serialVersionUID = 990917492575992066L;
040    
041            private final DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
042    
043            private final MatrixRenderer matrixRenderer = new MatrixRenderer();
044    
045            private final MatrixPlot matrixPlot = new MatrixPlot();
046    
047            private Variable variable = null;
048    
049            private Object o = null;
050    
051            public VariableTableCellRenderer() {
052                    matrixPlot.getPlotSettings().setShowXAxis(false);
053                    matrixPlot.getPlotSettings().setShowYAxis(false);
054                    matrixPlot.getPlotSettings().setShowXGrid(false);
055                    matrixPlot.getPlotSettings().setShowYGrid(false);
056                    matrixPlot.getPlotSettings().setTimeLimit(10);
057            }
058    
059            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
060                            boolean hasFocus, int row, int column) {
061    
062                    JLabel l = null;
063    
064                    if (value instanceof Variable)
065                            variable = (Variable) value;
066                    else
067                            variable = null;
068    
069                    if (variable != null) {
070                            switch (column) {
071                            case VariableListTableModel.LABELCOLUMN:
072                                    o = variable.getLabel();
073                                    break;
074                            case VariableListTableModel.MATRIXCOUNTCOLUMN:
075                                    o = variable.getMatrixCount();
076                                    break;
077                            case VariableListTableModel.SIZECOLUMN:
078                                    o = "" + variable.getRowCount() + "x" + variable.getColumnCount();
079                                    break;
080                            case VariableListTableModel.MEMORYSIZECOLUMN:
081                                    o = "?";
082                                    break;
083                            case VariableListTableModel.PLOTCOLUMN:
084                                    return matrixPlot.getTableCellRendererComponent(table, variable.getMatrix(),
085                                                    isSelected, hasFocus, row, column);
086                            case VariableListTableModel.MATRIXCOLUMN:
087                                    return matrixRenderer.getTableCellRendererComponent(table, variable.getMatrix(),
088                                                    isSelected, hasFocus, row, column);
089                            default:
090                                    o = null;
091                                    break;
092                            }
093    
094                            l = (JLabel) renderer.getTableCellRendererComponent(table, o, isSelected, hasFocus,
095                                            row, column);
096    
097                            switch (column) {
098                            case VariableListTableModel.ICONCOLUMN:
099                                    l.setIcon(UIManager.getIcon("Variable.icon"));
100                                    break;
101                            default:
102                                    l.setIcon(null);
103                                    break;
104                            }
105    
106                            l.setHorizontalAlignment(JLabel.CENTER);
107    
108                    }
109    
110                    return l;
111            }
112    }