/*
This file is part of the software framework JStatCom,
a library for building applications for data based analysis.
Copyright (C) 2000-2005 Markus Kraetzig
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
package com.jstatcom.table;
import com.jstatcom.model.JSCTypes;
import com.jstatcom.model.Symbol;
/**
* Implementation of JSCAbstractTableModel for
* JSCNArray data objects. It takes the transposed
* property into account.
*
* @author Markus Kraetzig
*/
public class JSCNArrayTableModel extends JSCAbstractTableModel {
/**
* Constructs a table model for a symbol of type
* JSCTypes.NARRAY. The argument can be null.
*
* @param symbol
* must be of type JSCTypes.NARRAY, can be
* null
* @throws IllegalArgumentException
* if (symbol.type != JSCTypes.NARRAY)
*/
public JSCNArrayTableModel(Symbol symbol) {
super(symbol);
if (symbol != null)
if (symbol.type != JSCTypes.NARRAY)
throw new IllegalArgumentException("Symbol type " + symbol.type
+ " different from table type " + JSCTypes.NARRAY + ".");
}
/*
* @see javax.swing.table.TableModel#getColumnCount()
*/
public int getColumnCount() {
if (getCurrentSymbol() == null || getCurrentSymbol().isEmpty())
return 0;
return getCurrentSymbol().getJSCNArray().cols();
}
/*
* @see javax.swing.table.TableModel#getRowCount()
*/
public int getRowCount() {
if (getCurrentSymbol() == null || getCurrentSymbol().isEmpty())
return 0;
return getCurrentSymbol().getJSCNArray().rows();
}
/*
* @see javax.swing.table.TableModel#getValueAt(int, int)
*/
public Object getValueAt(int rowIndex, int columnIndex) {
if (getCurrentSymbol() == null || getCurrentSymbol().isEmpty())
return null;
return new Double(getCurrentSymbol().getJSCNArray().doubleAt(rowIndex,
columnIndex));
}
/**
* The data model is editable. This method sets a value in the underlying
* data.
*
* @param aValue
* must be a Double
* @param rowIndex
* the row index, will be treated with taking
* transposed into account
* @param columnIndex
* the column index, will be treated with taking
* transposed into account
* @throws IllegalArgumentException
* if (!aValue instanceof Double)
*/
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
if (!(aValue instanceof Double))
throw new IllegalArgumentException("Value at [" + rowIndex + ":"
+ columnIndex + "] is not a Double.");
if (getCurrentSymbol() == null || getCurrentSymbol().isEmpty())
throw new IllegalStateException("Symbol is empty or null.");
getCurrentSymbol().getJSCNArray().setValAt(
((Double) aValue).doubleValue(), rowIndex, columnIndex);
}
/**
* Returns the Double.class regardless of
* columnIndex.
*
* @param columnIndex
* ignored
* @return Double.class
*/
public Class getColumnClass(int columnIndex) {
return Double.class;
}
}
Ads help maintain this website.