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.algorithm;
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.algorithm.Algorithm;
031    import org.jdmp.core.algorithm.HasAlgorithms;
032    
033    public class AlgorithmListTableModel extends AbstractTableModel implements ListDataListener {
034            private static final long serialVersionUID = -3779798282436020436L;
035    
036            public static final int ICONCOLUMN = 0;
037    
038            public static final int LABELCOLUMN = 1;
039    
040            public static final int VARIABLECOLUMN = 2;
041    
042            public static final int ALGORITHMLISTCOLUMN = 3;
043    
044            private HasAlgorithms iAlgorithms = null;
045    
046            public AlgorithmListTableModel(HasAlgorithms iAlgorithms) {
047                    this.iAlgorithms = iAlgorithms;
048                    iAlgorithms.getAlgorithms().addListDataListener(this);
049            }
050    
051            public int getRowCount() {
052                    return iAlgorithms.getAlgorithms().getSize();
053            }
054    
055            public int getColumnCount() {
056                    return 4;
057            }
058    
059            @Override
060            public String getColumnName(int columnIndex) {
061                    switch (columnIndex) {
062                    case ICONCOLUMN:
063                            return "";
064                    case VARIABLECOLUMN:
065                            return "Variables";
066                    case ALGORITHMLISTCOLUMN:
067                            return "Algorithms";
068                    case LABELCOLUMN:
069                            return "Label";
070                    default:
071                            return "x";
072                    }
073            }
074    
075            @Override
076            public Class<?> getColumnClass(int columnIndex) {
077                    return Algorithm.class;
078            }
079    
080            public Object getValueAt(int rowIndex, int columnIndex) {
081                    return iAlgorithms.getAlgorithms().getElementAt(rowIndex);
082            }
083    
084            @Override
085            public void contentsChanged(ListDataEvent e) {
086                    fireTableRowsUpdated(e.getIndex0(), e.getIndex1());
087            }
088    
089            @Override
090            public void intervalAdded(ListDataEvent e) {
091                    fireTableRowsInserted(e.getIndex0(), e.getIndex1());
092            }
093    
094            @Override
095            public void intervalRemoved(ListDataEvent e) {
096                    fireTableRowsDeleted(e.getIndex0(), e.getIndex1());
097            }
098    
099    }