/*
 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.equation;

import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.TableColumn;

/**
 * A special table column model for the CoeffTable.
 *
 * @author A. Benkwitz, Markus Kraetzig
 */
public final class SubMatModel extends DefaultTableColumnModel {
	private int part = 0;
	private int n = 0; // number of columns

	/**
	 * Creates a SubMatModel for an index denoting the
	 * part and a table.
	 * 
	 * @param part index running from 0,...,n
	 */
	public SubMatModel(int part) {
		setIndex(part);
	}

	/**
	 * Adds only those columns that are in the sub matrix range.
	 * 
	 * 
	 * @param tc the column to add
	 */
	public void addColumn(TableColumn tc) {
		if (part < 0) {
			super.addColumn(tc);
		} else { // display only columns for the given lag
			int i = tc.getModelIndex();
			if ((part * n) <= i && i < ((part + 1) * n))
				super.addColumn(tc);
		}
	}

	/**
	 * Gets the index represented by this part.
	 * 
	 * @return index
	 */
	public int getIndex() {
		return part;
	}

	/**
	 * Gets the number of columns of this table model.
	 * 
	 * @return col number
	 */
	public int getNumberOfColumns() {
		return n;
	}

	/**
	 * Sets the index of this part of the equation.
	 * 
	 * @param arg index
	 */
	public void setIndex(int arg) {
		if (part != arg)
			part = arg;

	}

	/**
	 * Sets the number of columns in this model.
	 * 
	 * @param arg number of columns
	 */
	public void setNumberOfColumns(int arg) {
		n = Math.max(0, arg);
	}
}
 

Ads help maintain this website.