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.matrix;
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.util.ObservableList;
031    import org.jdmp.core.variable.Variable;
032    import org.ujmp.core.Matrix;
033    import org.ujmp.gui.MatrixGUIObject;
034    
035    public class MatrixListTableModel extends AbstractTableModel implements ListDataListener {
036            private static final long serialVersionUID = 1820859033991171760L;
037    
038            private ObservableList<Matrix> matrixList = null;
039    
040            public static final int INDEXCOLUMN = 0;
041    
042            public static final int MATRIXCOLUMN = 1;
043    
044            public static final int MATRIXPLOTCOLUMN = 2;
045    
046            public static final int SIZECOLUMN = 3;
047    
048            public static final int LABELCOLUMN = 4;
049    
050            public MatrixListTableModel(Variable v) {
051                    this.matrixList = v.getMatrixList();
052                    matrixList.addListDataListener(this);
053            }
054    
055            public int getRowCount() {
056                    return matrixList.getSize();
057            }
058    
059            public int getColumnCount() {
060                    return 5;
061            }
062    
063            @Override
064            public String getColumnName(int columnIndex) {
065                    switch (columnIndex) {
066                    case INDEXCOLUMN:
067                            return "Index";
068                    case MATRIXCOLUMN:
069                            return "Matrix";
070                    case MATRIXPLOTCOLUMN:
071                            return "Plot";
072                    case SIZECOLUMN:
073                            return "Size";
074                    case LABELCOLUMN:
075                            return "Label";
076                    default:
077                            return "x";
078                    }
079            }
080    
081            @Override
082            public Class<?> getColumnClass(int columnIndex) {
083                    return MatrixGUIObject.class;
084            }
085    
086            public Object getValueAt(int rowIndex, int columnIndex) {
087                    return matrixList.getElementAt(rowIndex);
088            }
089    
090            @Override
091            public void contentsChanged(ListDataEvent e) {
092                    fireTableRowsUpdated(e.getIndex0(), e.getIndex1());
093            }
094    
095            @Override
096            public void intervalAdded(ListDataEvent e) {
097                    fireTableRowsInserted(e.getIndex0(), e.getIndex1());
098            }
099    
100            @Override
101            public void intervalRemoved(ListDataEvent e) {
102                    fireTableRowsDeleted(e.getIndex0(), e.getIndex1());
103            }
104    
105    }