/*
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.event.TableModelEvent;
import com.jstatcom.component.MatrixBorder;
import com.jstatcom.table.JSCCellRendererTypes;
import com.jstatcom.table.JSCSArrayTable;
/**
* Displays variable names with or without a time index to indicate
* a certain lag, e.g. invest(t-1).
*
* @author A. Benkwitz, Markus Kraetzig
*/
public final class VarNamesVector extends JSCSArrayTable {
/**
* Name of the intercept variable.
*/
public final static String VARIABLE_NAME_CONSTANT = "CONST";
/**
* Name of the trend variable.
*/
public final static String VARIABLE_NAME_TREND = "TREND";
/**
* The index that is printed in the label.
*/
private int index;
private CoeffTable coeffTable = null;
private boolean showingTimeIndex = true;
/**
* Creates a default VarNamesVector.
*/
public VarNamesVector() {
this(0);
}
/**
* Creates a VarNamesVector for an index.
*
* @param index denoting part of equation
*/
public VarNamesVector(int index) {
super();
this.index = index;
setBorder(new MatrixBorder());
setCellRenderer(JSCCellRendererTypes.VARIABLE_NAMES);
setRowSelectionAllowed(false);
setDynamicColumnWidth(true);
}
/**
* Gets the index denoting the part of the equation
* that this component belongs to.
*
* @return equation index
*/
public int getIndex() {
return index;
}
/**
* Helper method to get the formatted index string.
*
* @return String formatted string
* if index < 0 return (t-index)
* if index > 0 return (t+index)
* if index = 0 return (t)
*/
public String getIndexString() {
String str;
if (index == 0)
str = "(t)";
else
str = "(t" + ((index < 0) ? "" + index : "+" + index) + ")";
return str;
}
/**
* Gets whether the time index should be shown. Should be
* false for deterministics.
*
* @return true if shown
*/
public boolean isShowingTimeIndex() {
return showingTimeIndex;
}
/**
* Sets the coefficients table to be referenced.
*
* @param newCoeffTable coefficients table
*/
public void setCoeffTable(CoeffTable newCoeffTable) {
coeffTable = newCoeffTable;
}
/**
* Sets the current lag index to be shown.
*
* @param newIndex int
*/
public void setIndex(int newIndex) {
index = newIndex;
}
/**
* Sets whether the time index should be shown. Should be
* false for deterministics.
*
* @param isShowingTimeIndex true if shown
*/
public void setShowingTimeIndex(boolean isShowingTimeIndex) {
showingTimeIndex = isShowingTimeIndex;
}
/**
* Extends the super method by firing the (boolean) property change "visible".
*
* @param aFlag true to make the component visible
*/
public void setVisible(boolean aFlag) {
boolean oldValue = isVisible();
super.setVisible(aFlag);
firePropertyChange("visible", oldValue, isVisible());
}
/**
* Updates the column count and the "visible" property.
*/
public void tableChanged(TableModelEvent e) {
super.tableChanged(e);
if (getColumnCount() < 1 && isVisible())
setVisible(false);
if (getColumnCount() > 0 && !isVisible())
setVisible(true);
if (coeffTable != null) {
coeffTable.setColumnCount(getRowCount());
}
}
}
Ads help maintain this website.