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 javax.swing.event.ListDataEvent;
027    import javax.swing.event.ListDataListener;
028    import javax.swing.table.AbstractTableModel;
029    
030    import org.jdmp.core.variable.HasVariables;
031    import org.jdmp.core.variable.Variable;
032    
033    public class VariableListTableModel extends AbstractTableModel implements ListDataListener {
034            private static final long serialVersionUID = -1032855724069297926L;
035    
036            public static final int ICONCOLUMN = 0;
037    
038            public static final int LABELCOLUMN = 1;
039    
040            public static final int SIZECOLUMN = 2;
041    
042            public static final int MATRIXCOLUMN = 3;
043    
044            public static final int PLOTCOLUMN = 4;
045    
046            public static final int MATRIXCOUNTCOLUMN = 5;
047    
048            public static final int MEMORYSIZECOLUMN = 6;
049    
050            private HasVariables iVariables = null;
051    
052            public VariableListTableModel(HasVariables iVariables) {
053                    this.iVariables = iVariables;
054                    iVariables.getVariables().addListDataListener(this);
055            }
056    
057            public int getRowCount() {
058                    return iVariables.getVariables().getSize();
059            }
060    
061            public int getColumnCount() {
062                    return 7;
063            }
064    
065            @Override
066            public String getColumnName(int columnIndex) {
067                    switch (columnIndex) {
068                    case ICONCOLUMN:
069                            return "";
070                    case LABELCOLUMN:
071                            return "Label";
072                    case SIZECOLUMN:
073                            return "Size";
074                    case MATRIXCOLUMN:
075                            return "Matrix";
076                    case PLOTCOLUMN:
077                            return "Plot";
078                    case MATRIXCOUNTCOLUMN:
079                            return "MatrixCount";
080                    case MEMORYSIZECOLUMN:
081                            return "MemorySize";
082                    default:
083                            return ("unknown");
084                    }
085            }
086    
087            @Override
088            public Class<?> getColumnClass(int columnIndex) {
089                    return Variable.class;
090            }
091    
092            public Object getValueAt(int rowIndex, int columnIndex) {
093                    return iVariables.getVariables().getElementAt(rowIndex);
094            }
095    
096            @Override
097            public void contentsChanged(ListDataEvent e) {
098                    fireTableRowsUpdated(e.getIndex0(), e.getIndex1());
099            }
100    
101            @Override
102            public void intervalAdded(ListDataEvent e) {
103                    fireTableRowsInserted(e.getIndex0(), e.getIndex1());
104            }
105    
106            @Override
107            public void intervalRemoved(ListDataEvent e) {
108                    fireTableRowsDeleted(e.getIndex0(), e.getIndex1());
109            }
110    
111    }