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