/*
 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 java.awt.FlowLayout;
import java.awt.event.MouseListener;
import java.beans.PropertyChangeListener;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.table.TableCellRenderer;

import com.jstatcom.component.MatrixBorder;
import com.jstatcom.model.Scope;

/**
 * A special equation term for the error correction term
 * in a VEC model. It contains a coefficients table for 
 * the alpha, beta and beta_d (for restricted deterministics) 
 * parameters. The variable names are separated between
 * endogenous variables and deterministic variables restricted
 * to the EC term. In addition it is possible to set subset restrictions
 * corresponding to the respective parameters.
 * 

* Clients should make sure that the underlying data objects * have the correct dimensions and ordering of variables * for the display to be in sync with the data. * * @author Alexander Benkwitz, Markus Kraetzig */ public final class EqTermEC extends EqTerm implements PropertyChangeListener { private Border border = MatrixBorder.getInstanceThick(); private JLabel leadingSign; private CoeffTable alpha; private JPanel ecPanel; private EqTermDefault ecTerm1; private EqTermDefault ecTerm2; private MouseListener mouseListenerCoeff; /** * Constructor. */ public EqTermEC() { super(new FlowLayout(FlowLayout.LEFT, 0, 0)); leadingSign = new JLabel(" + "); alpha = new CoeffTable(); alpha.addPropertyChangeListener(this); add(leadingSign); add(alpha); add(getECPanel()); } /** * Gets the column width of the alpha table. * * @return column width */ public int getColumnWidth() { return alpha.getColumnWidth(); } /** * Initializes the panel. * * @return javax.swing.JPanel */ private JPanel getECPanel() { if (ecPanel != null) return ecPanel; ecTerm1 = new EqTermDefault(); ecTerm1.setMatrixCentered(false); ecTerm1.setLagIndex(-1); ecTerm1.setLeadingSignVisible(false); ecTerm1.setCoeffMatRequired(true); ecTerm1.addPropertyChangeListener(this); ecTerm2 = new EqTermDefault(); ecTerm2.setMatrixCentered(false); ecTerm2.setShowingTimeIndex(false); ecTerm2.setCoeffMatRequired(true); ecTerm2.addPropertyChangeListener(this); ecPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); ecPanel.add(ecTerm1); ecPanel.add(ecTerm2); return ecPanel; } /** * Gets the mouse listener of the underlying coefficients * tables. * * @return java.awt.event.MouseListener */ public MouseListener getMouseListenerCoeff() { return mouseListenerCoeff; } /** * Gets the precision of the underlying coefficients * tables. * * @return precision */ public int getPrecision() { return alpha.getPrecision(); } /** * Gets the cell renderer of the underlying coefficients * tables. * * @return javax.swing.table.TableCellRenderer */ public TableCellRenderer getRendererCoeff() { return alpha.getCellRenderer(); } /** * Gets the symbolname for the alpha coefficients. * * @return symbol name */ public String getSymbolNameAlphaCoeff() { return alpha.getSymbolName(); } /** * Gets the symbolname for the subset restrictions * corresponding to the alpha coefficients. * * @return symbol name */ public String getSymbolNameAlphaSubsetRes() { return alpha.getSymbolNameSubsetRes(); } /** * Gets the symbolname for the beta coefficients * of the endogenous variables. * * @return symbol name */ public String getSymbolNameBetaCoeff() { return ecTerm1.getSymbolNameCoeff(); } /** * Gets the symbolname for the beta coefficients * of the restricted deterministic variables. * * @return symbol name */ public String getSymbolNameBetaDetCoeff() { return ecTerm2.getSymbolNameCoeff(); } /** * Gets the symbolname for the subset restrictions * corresponding to the beta coefficients of the * restricted deterministic variables. * * @return symbol name */ public String getSymbolNameBetaDetSubsetRes() { return ecTerm2.getSymbolNameSubsetRes(); } /** * Gets the symbolname for the subset restrictions * corresponding to the beta coefficients of the * endogenous variables. * * @return symbol name */ public String getSymbolNameBetaSubsetRes() { return ecTerm1.getSymbolNameSubsetRes(); } /** * Gets the symbolname for the names of the deterministic * variables. * * @return symbol name */ public String getSymbolNameDetVarNames() { return ecTerm2.getSymbolNameVariables(); } /** * Gets the symbolname for the names of the endogenous * variables. * * @return symbol name */ public String getSymbolNameEndVarNames() { return ecTerm1.getSymbolNameVariables(); } /** * Gets whether the underlying coefficients tables * are editable. * * @return true if editable */ public boolean isEditable() { return alpha.isEditable(); } /** * Manages visibility of all terms with respect to * the available coefficients. * * @param evt property change event */ public void propertyChange(java.beans.PropertyChangeEvent evt) { Object source = evt.getSource(); if (source.equals(ecTerm1) || source.equals(ecTerm2)) { if (ecTerm1.isVisible() && ecTerm2.isVisible()) { ecPanel.setBorder(border); } else { ecPanel.setBorder(null); } if ((!ecTerm1.isVisible() && !ecTerm2.isVisible()) || !alpha.isVisible()) { // also sets term visible/invisible setDataAvailable(false); } } if (source.equals(ecTerm1) || source.equals(ecTerm2) || source.equals(alpha)) { if ((!ecTerm1.isVisible() && !ecTerm2.isVisible()) || !alpha.isVisible()) { // also sets term visible/invisible setDataAvailable(false); } if ((ecTerm1.isVisible() || ecTerm2.isVisible()) && alpha.isVisible()) { // also sets term visible/invisible setDataAvailable(true); } } } /** * Sets the column width of the underlying * coefficients tables. * * @param colWidth column width */ public void setColumnWidth(int colWidth) { alpha.setColumnWidth(colWidth); ecTerm1.setColumnWidth(colWidth); ecTerm2.setColumnWidth(colWidth); } /** * Sets whether the underlying coefficients tables * are editable. * * @param isEditable true if editable */ public void setEditable(boolean isEditable) { alpha.setEditable(isEditable); ecTerm1.setEditable(isEditable); ecTerm2.setEditable(isEditable); } /** * Manages visibility of the leading sign label. * * @param isVisible true if visible */ public void setLeadingSignVisible(boolean isVisible) { leadingSign.setVisible(isVisible); } /** * Sets the symbol scope, which defines which symbol * table to use (local, global * or upper). * * @param scope the symbol scope * @throws IllegalArgumentException if (scope == null) */ public void setSymbolScope(Scope scope) { super.setSymbolScope(scope); ecTerm1.setSymbolScope(scope); ecTerm2.setSymbolScope(scope); alpha.setSymbolScope(scope); } /** * Sets the mouse listener for the underlying coefficients tables. * * @param arg java.awt.event.MouseListener */ public void setMouseListenerCoeff(MouseListener arg) { if (mouseListenerCoeff != null) { alpha.removeMouseListener(mouseListenerCoeff); ecTerm1.removeMouseListener(mouseListenerCoeff); ecTerm2.removeMouseListener(mouseListenerCoeff); } mouseListenerCoeff = arg; if (mouseListenerCoeff != null) { alpha.addMouseListener(mouseListenerCoeff); ecTerm1.addMouseListener(mouseListenerCoeff); ecTerm2.addMouseListener(mouseListenerCoeff); } } /** * Sets the precision for the underlying coefficients tables. * * @param precision */ public void setPrecision(int precision) { alpha.setPrecision(precision); ecTerm1.setPrecision(precision); ecTerm2.setPrecision(precision); } /** * Sets the cell renderer for the underlying coefficients tables. * * @param renderer javax.swing.table.TableCellRenderer */ public void setRendererCoeff(TableCellRenderer renderer) { alpha.setCellRenderer(renderer); ecTerm1.setRendererCoeff(renderer); ecTerm2.setRendererCoeff(renderer); } /** * Sets the symbolname for the alpha coefficients. * * @param symbolName for alpha */ public void setSymbolNameAlphaCoeff(String symbolName) { alpha.setSymbolName(symbolName); } /** * Sets the symbolname for the subset restrictions * corresponding to the alpha coefficients. * * @param symbolName for alpha restrictions */ public void setSymbolNameAlphaSubsetRes(String symbolName) { alpha.setSymbolNameSubsetRes(symbolName); } /** * Sets the symbolname for the beta coefficients * of the endogenous variables. * * @param symbolName for beta */ public void setSymbolNameBetaCoeff(String symbolName) { ecTerm1.setSymbolNameCoeff(symbolName); } /** * Sets the symbolname for the beta coefficients * of the restricted deterministic variables. * * @param symbolName for beta_d */ public void setSymbolNameBetaDetCoeff(String symbolName) { ecTerm2.setSymbolNameCoeff(symbolName); } /** * Sets the symbolname for the subset restrictions * corresponding to the beta coefficients of the * restricted deterministic variables. * * @param symbolName for beta_d subset restrictions */ public void setSymbolNameBetaDetSubsetRes(String symbolName) { ecTerm2.setSymbolNameSubsetRes(symbolName); } /** * Sets the symbolname for the subset restrictions * corresponding to the beta coefficients of the * endogenous variables. * * @param symbolName for beta subset restrictions */ public void setSymbolNameBetaSubsetRes(String symbolName) { ecTerm1.setSymbolNameSubsetRes(symbolName); } /** * Sets the symbolname for the names of the deterministic * variables. * * @param symbolName for deterministics variable names */ public void setSymbolNameDetVarNames(String symbolName) { ecTerm2.setSymbolNameVariables(symbolName); } /** * Sets the symbolname for the names of the endogenous * variables. * * @param symbolName for endogenous variable names */ public void setSymbolNameEndVarNames(String symbolName) { ecTerm1.setSymbolNameVariables(symbolName); } }

Ads help maintain this website.