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

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.util.ArrayList;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

import org.apache.log4j.Logger;

import com.jstatcom.component.CompSettings;
import com.jstatcom.component.StdMessages;
import com.jstatcom.model.JSCConstants;
import com.jstatcom.model.JSCDRange;
import com.jstatcom.model.JSCNArray;
import com.jstatcom.model.JSCSArray;
import com.jstatcom.model.JSCTypeDef;
import com.jstatcom.model.JSCTypes;
import com.jstatcom.model.ModelPanel;
import com.jstatcom.model.Scope;
import com.jstatcom.model.SymbolTable;

/**
 * Configurable selection tool for time series. It manages the selection of
 * endogenous, exogenous and deterministic variables and builds the
 * corresponding data objects to be reused by other components via the
 * symboltable. Selection is only allowed for series with the same periodicity
 * and at least 2 observations time overlap.
 * 

* If the underlying symbols are referenced, JSCTypeDef objects * with the correct types should be specified for the corresponding data: *

    *
  1. dRange -JSCTypes.DRANGE
  2. *
  3. endogenous names -JSCTypes.SARRAY
  4. *
  5. exogenous names -JSCTypes.SARRAY
  6. *
  7. deterministic names - JSCTypes.SARRAY
  8. *
  9. all names - JSCTypes.SARRAY
  10. *
  11. endogenous data - JSCTypes.NARRAY
  12. *
  13. exogenous data - JSCTypes.NARRAY
  14. *
  15. deterministic data - JSCTypes.NARRAY
  16. *
  17. all data - JSCTypes.NARRAY
  18. *
*

* It can be configured by specifying several selection options * as well as the names of the various data objects. *

* Data objects are only created if the respective name has been specified. * The selected data is automatically truncated if there are missings at * the beginning or the end. * The objects are created and stored in the following order: *

    *
  1. dRange
  2. *
  3. endogenous names
  4. *
  5. exogenous names
  6. *
  7. deterministic names
  8. *
  9. all names
  10. *
  11. endogenous data
  12. *
  13. exogenous data
  14. *
  15. deterministic data
  16. *
  17. all data
  18. *
*

* The ordering might be important when installing symbol listeners. If the listener reacts * to a change in a variable, then it should only reference variables that have * been created before, e.g. a listener to "all data" can reference "all names" in its * action method, but not vice versa. When "all names" changes, "all data" is still * empty. *

*

* A save way around this problem is to install a listener to the selectionChanged * property of the TSSel. A PropertyChangeEvent for "selectionChanged" is fired * only after all data objects have been created. * * @author Markus Kraetzig */ public final class TSSel extends ModelPanel { private static final Logger log = Logger.getLogger(TSSel.class); /** * Handles Selection of TimeSeriesList. Extra class to prevent overwriting * by IDE VCE. */ class MyEventHandler implements javax.swing.event.ListSelectionListener { public void valueChanged(javax.swing.event.ListSelectionEvent e) { // Important to perform operation only for "real" selection events. if (e.getValueIsAdjusting()) return; if (e.getSource() == TSSel.this.getTSList()) TSSel.this.tSList_ListSelectionEvents(); }; } private Scope symbolScope = Scope.GLOBAL; private static class MyNonSelectableListCellRenderer extends DefaultListCellRenderer { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { return super.getListCellRendererComponent(list, value, index, false, false); } } private static final MyNonSelectableListCellRenderer myCellRenderer = new MyNonSelectableListCellRenderer(); /** * Holds the selected indices that are currently confirmed. */ private int[] lastConfirmedSelection = new int[0]; private MyEventHandler myEventHandler = new MyEventHandler(); /** * Periodicity of the first selected time series. */ private int referencePeriodicity = -1; /** * The list models for the selection. */ private JScrollPane ivjJScrollPane2 = null; private JPanel ivjJPanel2 = null; private JScrollPane ivjJScrollPane1 = null; private boolean checkNaN = true; private final DefaultListModel endListModel = new DefaultListModel(); private final DefaultListModel exListModel = new DefaultListModel(); private final DefaultListModel detListModel = new DefaultListModel(); private boolean fieldDatesEditable = true; private JLabel rangeLabel = null; IvjEventHandler ivjEventHandler = new IvjEventHandler(); // fields with typedefs for the symbols from the selection private JSCTypeDef endogenousDataDef = null; private JSCTypeDef exogenousDataDef = null; private JSCTypeDef deterministicDataDef = null; private JSCTypeDef allDataDef = null; private JSCTypeDef endogenousStringsDef = null; private JSCTypeDef exogenousStringsDef = null; private JSCTypeDef deterministicStringsDef = null; private JSCTypeDef allStringsDef = null; private JSCTypeDef dateRangeDef = null; private final List actualSelection = new ArrayList(); private TSHolder timeSeriesData = TSHolder.getInstance(); private boolean oneEndogenousOnly = false; private JList ivjDetSelList = null; private JList ivjEndSelList = null; private JList ivjExSelList = null; private JScrollPane ivjJScrollPane3 = null; private JScrollPane ivjJScrollPane4 = null; private JPanel ivjJPanel1 = null; private JSplitPane ivjJSplitPane = null; private JPanel ivjJPanel3 = null; private JButton ivjConfirmButton = null; private JPanel ivjJPanel4 = null; private JButton ivjMaxRangeButton = null; private TSDateRangeSelector ivjTSDateRangeSelector = null; private TSList ivjTSList = null; class IvjEventHandler implements java.awt.event.ActionListener, java.awt.event.ComponentListener { public void actionPerformed(java.awt.event.ActionEvent e) { if (e.getSource() == TSSel.this.getConfirmButton()) connEtoC1(); if (e.getSource() == TSSel.this.getMaxRangeButton()) connEtoC2(); }; public void componentHidden(java.awt.event.ComponentEvent e) { }; public void componentMoved(java.awt.event.ComponentEvent e) { }; public void componentResized(java.awt.event.ComponentEvent e) { if (e.getSource() == TSSel.this) connEtoC3(); }; public void componentShown(java.awt.event.ComponentEvent e) { }; }; /** * Default constructor. */ public TSSel() { super(); initialize(); } /** * Checks if only one endogenous selection is allowed and removes additional * selections automatically. Useful for univariate models. */ private void checkOneEndogenousOnly() { TSList list = getTSList(); if (!isOneEndogenousOnly()) return; TS toCheck = null; int index = -1; boolean firstEndogenousAlreadyEncountered = false; for (int i = 0; i < actualSelection.size(); i++) { index = actualSelection.get(i).intValue(); toCheck = timeSeriesData .getTS((list.getModel().getElementAt(index)).toString()); if (toCheck.type() == TSTypes.ENDOGENOUS) { // Already another endogenous variable selected, // remove all others. if (firstEndogenousAlreadyEncountered) { actualSelection.remove(i); // list.removeSelectionInterval(index, index); // Because the vectorSize is smaller now. i--; } // As soon as an endogenous variable has been encountered, // set the check variable. firstEndogenousAlreadyEncountered = true; } } } /** * Clear all data objects. */ private void clearDataObjects() { SymbolTable sTable = symbolScope.getSymbolTable(this); if (dateRangeDef != null) sTable.get(dateRangeDef).clear(); if (endogenousStringsDef != null) sTable.get(endogenousStringsDef).clear(); if (exogenousStringsDef != null) sTable.get(exogenousStringsDef).clear(); if (deterministicStringsDef != null) sTable.get(deterministicStringsDef).clear(); if (allStringsDef != null) sTable.get(allStringsDef).clear(); if (endogenousDataDef != null) sTable.get(endogenousDataDef).clear(); if (exogenousDataDef != null) sTable.get(exogenousDataDef).clear(); if (deterministicDataDef != null) sTable.get(deterministicDataDef).clear(); if (allDataDef != null) sTable.get(allDataDef).clear(); } /** * Confirm that the current selection has changed. */ private void confirmButton_ActionEvents() { TSList list = getTSList(); String[] allVarNames = new String[actualSelection.size()]; lastConfirmedSelection = new int[actualSelection.size()]; for (int sel = 0, index = 0; sel < actualSelection.size(); sel++) { index = actualSelection.get(sel).intValue(); lastConfirmedSelection[sel] = index; TS toCheck = timeSeriesData.getTS(((String) list.getModel() .getElementAt(index)).toString()); allVarNames[sel] = toCheck.name(); } if (checkNaN) { double[][] allData = getDataArray(allVarNames); for (int i = 0; i < allData.length; i++) { for (int j = 0; j < allData[0].length; j++) { if (Double.isNaN(allData[i][j])) { TSDate startDate = getTSDateRangeSelector() .getTSDateRange().lowerBound(); String msg = "There is a missing value in [\"" + allVarNames[j] + "\"" + ", " + startDate.addPeriods(i) + "].\n"; msg = msg + "Please adjust the selection to avoid NaN's.\nThe previous selection is kept."; StdMessages.error(msg, "Missing Value Encountered"); return; } } } } if (getTSDateRangeSelector().getTSDateRange().numOfObs() < 3) { StdMessages .errorSpecification("There are less than 3 observations in the selection."); return; } // Clear selection display. endListModel.clear(); exListModel.clear(); detListModel.clear(); if (list.getModel().getSize() == 0) return; for (int sel = 0; sel < actualSelection.size(); sel++) { int index = actualSelection.get(sel).intValue(); TS toCheck = timeSeriesData.getTS(((String) list.getModel() .getElementAt(index)).toString()); if (toCheck.type() == TSTypes.ENDOGENOUS) endListModel.addElement(toCheck.name()); if (toCheck.type() == TSTypes.EXOGENOUS) exListModel.addElement(toCheck.name()); if (toCheck.type() == TSTypes.DETERMINISTIC) detListModel.addElement(toCheck.name()); } // Compute number of observations and set the textfields. if (endListModel.size() == 0 && exListModel.size() == 0 && detListModel.size() == 0) { getRangeLabel().setText(""); getRangeLabel().setToolTipText(""); } else { String range = getTSDateRangeSelector().getTSDateRange().format("", 0); getRangeLabel().setText(range); getRangeLabel().setToolTipText(range); } // Create the JSCData objects with the specified names. createJSCData(); } /** * connEtoC1: (ConfirmButton.action. --> * TSSel.confirmButton_ActionEvents()V) */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private void connEtoC1() { try { // user code begin {1} // user code end this.confirmButton_ActionEvents(); // user code begin {2} // user code end } catch (Throwable ivjExc) { // user code begin {3} // user code end handleException(ivjExc); } } /** * connEtoC2: (MaxRangeButton.action. --> * TSSel.maxRangeButton_ActionEvents()V) */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private void connEtoC2() { try { // user code begin {1} // user code end this.maxRangeButton_ActionEvents(); // user code begin {2} // user code end } catch (Throwable ivjExc) { // user code begin {3} // user code end handleException(ivjExc); } } /** * connEtoC3: * (SelectPanel.component.componentResized(java.awt.event.ComponentEvent) * --> TSSel.selectPanel_ComponentResized(Ljava.awt.event.ComponentEvent;)V) * * @param arg1 * java.awt.event.ComponentEvent */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private void connEtoC3() { try { // user code begin {1} // user code end this.selectPanel_ComponentResized(); // user code begin {2} // user code end } catch (Throwable ivjExc) { // user code begin {3} // user code end handleException(ivjExc); } } /** * Creates the data object for the double[][] of observations and stores it * with a given name. * * @param dataName * String * @param variableNames * String array with the names of the time series containing the * data */ private void createDataObject(String dataName, String[] variableNames, SymbolTable sTable) { if (dataName == null || variableNames == null) throw new IllegalArgumentException("Arg was null"); sTable.set(new JSCNArray(dataName, getDataArray(variableNames))); } /** * Gets the data array according to the names. * * @param variableNames * the names of the selected TS * @return a double[][] with all data points */ private double[][] getDataArray(String[] variableNames) { TSDateRange selRange = getTSDateRangeSelector().getTSDateRange(); int obs = selRange.numOfObs(); double dataArray[][] = new double[0][0]; if (variableNames.length > 0) { dataArray = new double[obs][variableNames.length]; for (int a = 0; a < variableNames.length; a++) { TS toCheck = timeSeriesData.getTS(variableNames[a]); TSDate begin = toCheck.start(); TSDate date = selRange.lowerBound(); // startindex int start = begin.compareTo(date); for (int b = 0; b < obs; b++) dataArray[b][a] = toCheck.valueAt(start + b); } } return dataArray; } /** * All data objects are created and stored in the symboltable if the * respective name is set. The data is created in the following order: *

    *
  1. date range
  2. *
  3. endogenous names
  4. *
  5. exogenous names
  6. *
  7. deterministic names
  8. *
  9. all names
  10. *
  11. endogenous data
  12. *
  13. exogenous data
  14. *
  15. deterministic data
  16. *
  17. all data
  18. *
* The ordering might be important when installing data listeners. If the * listener reacts to a change in a variable then it should only reference * variables that have been created before, e.g. a listener to "all data" * can reference "all names" in its action method, but not vice versa. When * "all names" changes, "all data" is still null. A save way around this * problem is to install a listener to the selectionChanged property of the * selector. */ private void createJSCData() { if (actualSelection.size() == 0) { clearDataObjects(); setSelectionChanged(); return; } SymbolTable sTable = symbolScope.getSymbolTable(this); // Data is in the same order as the corresponding lists. // The list elements have been added before in the correct order. int numberOfEndVars = getEndSelList().getModel().getSize(); int numberOfExVars = getExSelList().getModel().getSize(); int numberOfDetVars = getDetSelList().getModel().getSize(); // All variable names are created together with the other String arrays. String[] allStrings = new String[numberOfEndVars + numberOfExVars + numberOfDetVars]; // Endogenous variable names. String[] endStrings = new String[numberOfEndVars]; for (int i = 0; i < endStrings.length; i++) { endStrings[i] = getEndSelList().getModel().getElementAt(i) .toString(); allStrings[i] = endStrings[i]; } // Exogenous variable names. String[] exStrings = new String[numberOfExVars]; for (int i = 0; i < exStrings.length; i++) { exStrings[i] = getExSelList().getModel().getElementAt(i).toString(); allStrings[i + numberOfEndVars] = exStrings[i]; } // Deterministic variable names. String[] detStrings = new String[numberOfDetVars]; for (int i = 0; i < detStrings.length; i++) { detStrings[i] = getDetSelList().getModel().getElementAt(i) .toString(); allStrings[i + numberOfEndVars + numberOfExVars] = detStrings[i]; } // Store date range if (dateRangeDef != null) sTable.set(new JSCDRange(dateRangeDef.name, getTSDateRangeSelector().getTSDateRange())); // Store endogenous Strings. if (endogenousStringsDef != null) sTable.set(new JSCSArray(endogenousStringsDef.name, endStrings)); // Store exogenous Strings. if (exogenousStringsDef != null) sTable.set(new JSCSArray(exogenousStringsDef.name, exStrings)); // Store deterministic Strings. if (deterministicStringsDef != null) sTable.set(new JSCSArray(deterministicStringsDef.name, detStrings)); // Store all strings. if (allStringsDef != null) sTable.set(new JSCSArray(allStringsDef.name, allStrings)); // Create endogenous data only if necessary. if (endogenousDataDef != null) createDataObject(endogenousDataDef.name, endStrings, sTable); // Create exogenous data only if necessary. if (exogenousDataDef != null) createDataObject(exogenousDataDef.name, exStrings, sTable); // Create deterministic data only if necessary. if (deterministicDataDef != null) createDataObject(deterministicDataDef.name, detStrings, sTable); // Create all data only if necessary. if (allDataDef != null) createDataObject(allDataDef.name, allStrings, sTable); setSelectionChanged(); } /** * Gets the allDataName property (String) value. * * @return the allDataName property value. * @see #setAllDataName */ public String getAllDataName() { if (allDataDef == null) return null; return allDataDef.name; } /** * Gets the allStringsName property (String) value. * * @return the allStringsName property value. * @see #setAllStringsName */ public String getAllStringsName() { if (allStringsDef == null) return null; return allStringsDef.name; } /** * Return the ConfirmButton property value. * * @return javax.swing.JButton */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private javax.swing.JButton getConfirmButton() { if (ivjConfirmButton == null) { try { ivjConfirmButton = new javax.swing.JButton(); ivjConfirmButton.setName("ConfirmButton"); ivjConfirmButton .setToolTipText("Sets selection for series, order and dates."); ivjConfirmButton.setPreferredSize(new java.awt.Dimension(135, 23)); ivjConfirmButton.setText("Confirm Selection"); // user code begin {1} // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjConfirmButton; } /** * @return boolean editable/not editable * @see #setDatesEditable */ public boolean getDatesEditable() { return fieldDatesEditable; } /** * Gets the deterministicDataName property (String) value. * * @return The deterministicDataName property value. * @see #setDeterministicDataName */ public String getDeterministicDataName() { if (deterministicDataDef == null) return null; return deterministicDataDef.name; } /** * Gets whether deterministic series can be selected. * * @return boolean * @see #setDeterministicEnabled */ public boolean getDeterministicEnabled() { return getDetSelList().isEnabled(); } /** * Gets the deterministicStringsName property (String) value. * * @return The deterministicStringsName property value. * @see #setDeterministicStringsName */ public String getDeterministicStringsName() { if (deterministicStringsDef == null) return null; return deterministicStringsDef.name; } /** * Return the DetSelList property value. * * @return javax.swing.JList */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private javax.swing.JList getDetSelList() { if (ivjDetSelList == null) { try { ivjDetSelList = new javax.swing.JList(); ivjDetSelList.setName("DetSelList"); ivjDetSelList.setFixedCellHeight(10); ivjDetSelList.setBounds(0, 0, 160, 120); // user code begin {1} ivjDetSelList.setFont(CompSettings.smallFontDefault); ivjDetSelList.setModel(detListModel); ivjDetSelList.setForeground(Color.blue); ivjDetSelList.setCellRenderer(myCellRenderer); // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjDetSelList; } /** * Gets the range label. * * @return label */ private JLabel getRangeLabel() { if (rangeLabel == null) { rangeLabel = new JLabel(); rangeLabel.setFont(CompSettings.smallFontDefault); rangeLabel.setPreferredSize(new Dimension(100, 20)); rangeLabel.setMinimumSize(new Dimension(100, 20)); } return rangeLabel; } /** * Gets the endogenousDataName property (String) value. * * @return The endogenousDataName property value. * @see #setEndogenousDataName */ public String getEndogenousDataName() { if (endogenousDataDef == null) return null; return endogenousDataDef.name; } /** * Gets the endogenousStringsName property (String) value. * * @return The endogenousStringsName property value. * @see #setEndogenousStringsName */ public String getEndogenousStringsName() { if (endogenousStringsDef == null) return null; return endogenousStringsDef.name; } /** * Return the EndSelList property value. * * @return javax.swing.JList */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private javax.swing.JList getEndSelList() { if (ivjEndSelList == null) { try { ivjEndSelList = new javax.swing.JList(); ivjEndSelList.setName("EndSelList"); ivjEndSelList.setFixedCellHeight(10); ivjEndSelList.setBounds(0, 0, 160, 120); // user code begin {1} ivjEndSelList.setFont(CompSettings.smallFontDefault); ivjEndSelList.setModel(endListModel); ivjEndSelList.setForeground(Color.red); ivjEndSelList.setCellRenderer(myCellRenderer); // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjEndSelList; } /** * Gets the exogenousDataName property (String) value. * * @return The exogenousDataName property value. * @see #setExogenousDataName */ public String getExogenousDataName() { if (exogenousDataDef == null) return null; return exogenousDataDef.name; } /** * Gets the dateRangeName property (String) value. * * @return The dateRangeName property value. * @see #setDateRangeName */ public String getDateRangeName() { if (dateRangeDef == null) return null; return dateRangeDef.name; } /** * Gets whether exogenous series can be selected. * * @return boolean * @see #setExogenousEnabled */ public boolean getExogenousEnabled() { return getExSelList().isEnabled(); } /** * Gets the exogenousStringsName property (String) value. * * @return The exogenousStringsName property value. * @see #setExogenousStringsName */ public String getExogenousStringsName() { if (exogenousStringsDef == null) return null; return exogenousStringsDef.name; } /** * Return the ExSelList property value. * * @return javax.swing.JList */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private javax.swing.JList getExSelList() { if (ivjExSelList == null) { try { ivjExSelList = new javax.swing.JList(); ivjExSelList.setName("ExSelList"); ivjExSelList.setFixedCellHeight(10); ivjExSelList.setBounds(0, 0, 160, 120); // user code begin {1} ivjExSelList.setFont(CompSettings.smallFontDefault); ivjExSelList.setModel(exListModel); ivjExSelList.setForeground(Color.green); ivjExSelList.setCellRenderer(myCellRenderer); // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjExSelList; } /** * Return the JPanel1 property value. * * @return javax.swing.JPanel */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private javax.swing.JPanel getJPanel1() { if (ivjJPanel1 == null) { try { ivjJPanel1 = new javax.swing.JPanel(); ivjJPanel1.setName("JPanel1"); ivjJPanel1.setPreferredSize(new java.awt.Dimension(204, 150)); ivjJPanel1.setLayout(new java.awt.GridLayout()); getJPanel1() .add(getJScrollPane2(), getJScrollPane2().getName()); getJPanel1() .add(getJScrollPane3(), getJScrollPane3().getName()); getJPanel1() .add(getJScrollPane4(), getJScrollPane4().getName()); // user code begin {1} TitledBorder title = new TitledBorder(new EtchedBorder(), "Selection Order sets Variable Order", TitledBorder.RIGHT, TitledBorder.TOP); title.setTitleFont(CompSettings.smallFontDefault); getJPanel1().setBorder(title); // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjJPanel1; } /** * Return the JPanel2 property value. * * @return javax.swing.JPanel */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private javax.swing.JPanel getJPanel2() { if (ivjJPanel2 == null) { try { ivjJPanel2 = new javax.swing.JPanel(); ivjJPanel2.setName("JPanel2"); ivjJPanel2.setPreferredSize(new java.awt.Dimension(205, 170)); ivjJPanel2.setLayout(new java.awt.GridBagLayout()); ivjJPanel2.setMinimumSize(new java.awt.Dimension(205, 170)); java.awt.GridBagConstraints constraintsJPanel1 = new java.awt.GridBagConstraints(); constraintsJPanel1.gridx = 0; constraintsJPanel1.gridy = 1; constraintsJPanel1.fill = java.awt.GridBagConstraints.BOTH; constraintsJPanel1.weightx = 1.0; constraintsJPanel1.weighty = 1.0; getJPanel2().add(getJPanel1(), constraintsJPanel1); java.awt.GridBagConstraints constraintsJPanel3 = new java.awt.GridBagConstraints(); constraintsJPanel3.gridx = 0; constraintsJPanel3.gridy = 0; constraintsJPanel3.fill = java.awt.GridBagConstraints.BOTH; getJPanel2().add(getJPanel3(), constraintsJPanel3); // user code begin {1} // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjJPanel2; } /** * Return the JPanel3 property value. * * @return javax.swing.JPanel */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private javax.swing.JPanel getJPanel3() { if (ivjJPanel3 == null) { try { ivjJPanel3 = new javax.swing.JPanel(); ivjJPanel3.setName("JPanel3"); ivjJPanel3.setPreferredSize(new java.awt.Dimension(10, 80)); ivjJPanel3.setLayout(new java.awt.GridBagLayout()); ivjJPanel3.setMinimumSize(new java.awt.Dimension(10, 80)); java.awt.GridBagConstraints constraintsObsLabel = new java.awt.GridBagConstraints(); java.awt.GridBagConstraints constraintsRangeLabel = new java.awt.GridBagConstraints(); constraintsRangeLabel.gridx = 0; constraintsRangeLabel.gridy = 1; constraintsRangeLabel.weighty = 1.0; constraintsRangeLabel.gridwidth = 2; constraintsRangeLabel.fill = java.awt.GridBagConstraints.BOTH; constraintsRangeLabel.insets = new java.awt.Insets(0, 3, 2, 2); java.awt.GridBagConstraints constraintsJPanel4 = new java.awt.GridBagConstraints(); constraintsObsLabel.anchor = java.awt.GridBagConstraints.WEST; constraintsJPanel4.gridx = 0; constraintsJPanel4.gridy = 0; constraintsJPanel4.gridwidth = 2; constraintsJPanel4.fill = java.awt.GridBagConstraints.HORIZONTAL; constraintsJPanel4.weightx = 1.0; constraintsJPanel4.insets = new java.awt.Insets(3, 0, 0, 0); ivjJPanel3.add(getRangeLabel(), constraintsRangeLabel); getJPanel3().add(getJPanel4(), constraintsJPanel4); // user code begin {1} // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjJPanel3; } /** * Return the JPanel4 property value. * * @return javax.swing.JPanel */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private javax.swing.JPanel getJPanel4() { if (ivjJPanel4 == null) { try { ivjJPanel4 = new javax.swing.JPanel(); ivjJPanel4.setName("JPanel4"); ivjJPanel4.setPreferredSize(new java.awt.Dimension(205, 50)); ivjJPanel4.setLayout(new java.awt.GridBagLayout()); ivjJPanel4.setMinimumSize(new java.awt.Dimension(205, 50)); java.awt.GridBagConstraints constraintsConfirmButton = new java.awt.GridBagConstraints(); constraintsConfirmButton.gridx = 1; constraintsConfirmButton.gridy = 1; constraintsConfirmButton.fill = java.awt.GridBagConstraints.HORIZONTAL; constraintsConfirmButton.insets = new java.awt.Insets(4, 2, 2, 2); java.awt.GridBagConstraints constraintsTSDateRangeSelector = new java.awt.GridBagConstraints(); constraintsTSDateRangeSelector.gridx = 0; constraintsTSDateRangeSelector.gridy = 0; constraintsTSDateRangeSelector.gridwidth = 2; constraintsTSDateRangeSelector.fill = java.awt.GridBagConstraints.HORIZONTAL; constraintsTSDateRangeSelector.anchor = java.awt.GridBagConstraints.NORTH; constraintsTSDateRangeSelector.weightx = 1.0; getJPanel4().add(getTSDateRangeSelector(), constraintsTSDateRangeSelector); java.awt.GridBagConstraints constraintsMaxRangeButton = new java.awt.GridBagConstraints(); constraintsMaxRangeButton.gridx = 0; constraintsMaxRangeButton.gridy = 1; constraintsMaxRangeButton.fill = java.awt.GridBagConstraints.HORIZONTAL; constraintsMaxRangeButton.insets = new java.awt.Insets(4, 2, 2, 2); ivjJPanel4.add(getConfirmButton(), constraintsConfirmButton); getJPanel4() .add(getMaxRangeButton(), constraintsMaxRangeButton); // user code begin {1} // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjJPanel4; } /** * Return the JScrollPane1 property value. * * @return javax.swing.JScrollPane */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private javax.swing.JScrollPane getJScrollPane1() { if (ivjJScrollPane1 == null) { try { ivjJScrollPane1 = new javax.swing.JScrollPane(); ivjJScrollPane1.setName("JScrollPane1"); ivjJScrollPane1.setPreferredSize(new java.awt.Dimension(205, 260)); ivjJScrollPane1 .setMinimumSize(new java.awt.Dimension(205, 200)); getJScrollPane1().setViewportView(getTSList()); // user code begin {1} // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjJScrollPane1; } /** * Return the JScrollPane2 property value. * * @return javax.swing.JScrollPane */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private javax.swing.JScrollPane getJScrollPane2() { if (ivjJScrollPane2 == null) { try { ivjJScrollPane2 = new javax.swing.JScrollPane(); ivjJScrollPane2.setName("JScrollPane2"); ivjJScrollPane2 .setPreferredSize(new java.awt.Dimension(68, 68)); getJScrollPane2().setViewportView(getEndSelList()); // user code begin {1} // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjJScrollPane2; } /** * Return the JScrollPane3 property value. * * @return javax.swing.JScrollPane */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private javax.swing.JScrollPane getJScrollPane3() { if (ivjJScrollPane3 == null) { try { ivjJScrollPane3 = new javax.swing.JScrollPane(); ivjJScrollPane3.setName("JScrollPane3"); ivjJScrollPane3 .setPreferredSize(new java.awt.Dimension(68, 68)); getJScrollPane3().setViewportView(getExSelList()); // user code begin {1} // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjJScrollPane3; } /** * Return the JScrollPane4 property value. * * @return javax.swing.JScrollPane */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private javax.swing.JScrollPane getJScrollPane4() { if (ivjJScrollPane4 == null) { try { ivjJScrollPane4 = new javax.swing.JScrollPane(); ivjJScrollPane4.setName("JScrollPane4"); ivjJScrollPane4 .setPreferredSize(new java.awt.Dimension(68, 68)); getJScrollPane4().setViewportView(getDetSelList()); // user code begin {1} // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjJScrollPane4; } /** * Return the JSplitPane property value. * * @return javax.swing.JSplitPane */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private javax.swing.JSplitPane getJSplitPane() { if (ivjJSplitPane == null) { try { ivjJSplitPane = new javax.swing.JSplitPane( javax.swing.JSplitPane.VERTICAL_SPLIT); ivjJSplitPane.setName("JSplitPane"); ivjJSplitPane.setDividerSize(2); ivjJSplitPane.setDividerLocation(260); ivjJSplitPane.setBorder(null); getJSplitPane().add(getJPanel2(), "bottom"); getJSplitPane().add(getJScrollPane1(), "top"); // user code begin {1} // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjJSplitPane; } /** * Return the MaxRangeButton property value. * * @return javax.swing.JButton */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private javax.swing.JButton getMaxRangeButton() { if (ivjMaxRangeButton == null) { try { ivjMaxRangeButton = new javax.swing.JButton(); ivjMaxRangeButton.setName("MaxRangeButton"); ivjMaxRangeButton .setToolTipText("Sets maximum possible time range."); ivjMaxRangeButton.setText("Max"); ivjMaxRangeButton.setPreferredSize(new java.awt.Dimension(60, 23)); ivjMaxRangeButton .setMinimumSize(new java.awt.Dimension(60, 25)); // user code begin {1} // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjMaxRangeButton; } /** * Gets the current selection mode. * * @return int a valid JList selection mode */ public int getSelectionMode() { return getTSList().getSelectionMode(); } /** * Return the TSDateRangeSelector property value. * * @return com.jstatcom.ts.TSDateRangeSelector */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private TSDateRangeSelector getTSDateRangeSelector() { if (ivjTSDateRangeSelector == null) { try { ivjTSDateRangeSelector = new com.jstatcom.ts.TSDateRangeSelector(); ivjTSDateRangeSelector.setName("TSDateRangeSelector"); ivjTSDateRangeSelector.setPreferredSize(new java.awt.Dimension( 80, 20)); ivjTSDateRangeSelector.setEnabled(false); ivjTSDateRangeSelector.setMinimumSize(new java.awt.Dimension( 80, 20)); ivjTSDateRangeSelector.setEditable(false); // user code begin {1} // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjTSDateRangeSelector; } /** * Return the TSList property value. * * @return com.jstatcom.ts.TSList */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private TSList getTSList() { if (ivjTSList == null) { try { ivjTSList = new com.jstatcom.ts.TSList(); ivjTSList.setName("TSList"); ivjTSList.setBounds(0, 0, 210, 255); // user code begin {1} // user code end } catch (Throwable ivjExc) { // user code begin {2} // user code end handleException(ivjExc); } } return ivjTSList; } /** * Called whenever the part throws an exception. * * @param exception * Exception */ private void handleException(Throwable exception) { log.error("Unhandled Exception", exception); } /** * Initializes connections * * @exception Exception * The exception description. */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private void initConnections() throws Exception { // user code begin {1} getTSList().addListSelectionListener(myEventHandler); // user code end getConfirmButton().addActionListener(ivjEventHandler); getMaxRangeButton().addActionListener(ivjEventHandler); this.addComponentListener(ivjEventHandler); } /** * Initialize the class. */ /* WARNING: THIS METHOD WILL BE REGENERATED. */ private void initialize() { try { // user code begin {1} // user code end setName("SelectPanel"); setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.X_AXIS)); setPreferredSize(new java.awt.Dimension(216, 400)); setSize(215, 477); setMinimumSize(new java.awt.Dimension(216, 400)); add(getJSplitPane(), getJSplitPane().getName()); initConnections(); } catch (Throwable ivjExc) { handleException(ivjExc); } // user code begin {2} // actualSelection.add(new Integer(-1)); TitledBorder title = BorderFactory.createTitledBorder(null, "Ctrl/Shift for Multiple Selection", TitledBorder.RIGHT, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)); /* TitledBorder title = new TitledBorder(new BevelBorder( BevelBorder.LOWERED), "Ctrl/Shift for Multiple Selection", TitledBorder.RIGHT, TitledBorder.TOP);*/ title.setTitleFont(CompSettings.smallFontDefault); this.setBorder(title); int vmCheck = System.getProperty("java.vm.version").toString().indexOf( "1.4"); if (vmCheck > -1) getTSList().setLayoutOrientation(JList.VERTICAL_WRAP); getTSList().setVisibleRowCount(0); getJSplitPane().setDividerLocation( new Double(getHeight() - getJPanel2().getMinimumSize().getHeight() - 80) .intValue()); getTSDateRangeSelector().setMinNumberOfObs(2); // user code end } /** * @see #setOneEndogenousOnly * @return boolean */ public boolean isOneEndogenousOnly() { return oneEndogenousOnly; } /** * Maximizes range of current date selection. */ private void maxRangeButton_ActionEvents() { TSList list = getTSList(); if (list.getSelectedIndex() == -1) return; // To prevent ListSelectionEvents when removing a selection // automatically. list.removeListSelectionListener(myEventHandler); // Savety belt to ensure that ListSelectionListener is added again, even // if something goes wrong. This should not happen. try { // Select max possible range in time series. tsDateRangeCheck(true); } catch (Throwable ex) { log.error("Failed to set maximum range", ex); } // Adds the ListSelectionListener again. list.addListSelectionListener(myEventHandler); return; } /** * This method saves the order of the selection in the Lists. It takes SHIFT * selection into account for adding several series at the same time. */ private void saveSelectionOrderToVector() { TSList list = getTSList(); if (list.getSelectedIndex() == -1) { actualSelection.clear(); return; } int start = 0; if (actualSelection.size() == 0) actualSelection.add(new Integer(list.getLeadSelectionIndex())); if (actualSelection.size() > 0) start = actualSelection.get(actualSelection.size() - 1).intValue(); int end = list.getLeadSelectionIndex(); /** * Checks if there is a SHIFT key selection of more than one series. All * series between the last selection and the new one must be added. */ if ((end - start) > 0) for (int i = start + 1; i <= end; i++) { Integer intI = new Integer(i); if (list.isSelectedIndex(i) && !actualSelection.contains(intI)) actualSelection.add(intI); } if ((end - start) < 0) for (int i = start - 1; i >= end; i--) { Integer intI = new Integer(i); if (list.isSelectedIndex(i) && !actualSelection.contains(intI)) actualSelection.add(intI); } /** * Check, if all series are selected that are in the vector. */ for (int i = 0; i < actualSelection.size(); i++) if (!list.isSelectedIndex(actualSelection.get(i).intValue())) { actualSelection.remove(i); // Because the vectorSize is smaller now. i--; } return; } /** * Adjust split pane divider after resize event. */ private void selectPanel_ComponentResized() { getJSplitPane().setDividerLocation( new Double(getHeight() - getJPanel2().getMinimumSize().getHeight() - 40) .intValue()); } /** * Sets the name of the object holding the data array for all series. * * @param allDataName * The new value for the property. * @see #getAllDataName * @throws IllegalArgumentException * if argument is not a valid symbolname */ public void setAllDataName(String allDataName) { if (allDataName == null) allDataDef = null; else allDataDef = new JSCTypeDef(allDataName, JSCTypes.NARRAY); } /** * Sets the name of dataobject that holds the string array of all names. * * @param allStringsName * The new value for the property. * @see #getAllStringsName * @throws IllegalArgumentException * if argument is not a valid symbolname */ public void setAllStringsName(String allStringsName) { if (allStringsName == null) allStringsDef = null; else allStringsDef = new JSCTypeDef(allStringsName, JSCTypes.SARRAY); } /** * Enables/disables editing of date range. * * @param newDatesEditable * true to enable range editing */ public void setDatesEditable(boolean newDatesEditable) { fieldDatesEditable = newDatesEditable; getTSDateRangeSelector().setEditable(fieldDatesEditable); } /** * Sets the name of the object holding the deterministic data array. * * @param deterministicDataName * The new value for the property. * @see #getDeterministicDataName * @throws IllegalArgumentException * if argument is not a valid symbolname */ public void setDeterministicDataName(String deterministicDataName) { if (deterministicDataName == null) deterministicDataDef = null; else deterministicDataDef = new JSCTypeDef(deterministicDataName, JSCTypes.NARRAY); } /** * Enables/disables the selection of deterministic variables. This property * merely sets the list displaying the deterministic variables to * enabled or disabled. It has no effect on * the data creation, but it should communicate to the user, that * deterministic variables are ignored in the respective modeling context. * * @param arg1 * true to enable selection of determinisic variables */ public void setDeterministicEnabled(boolean arg1) { getDetSelList().setEnabled(arg1); } /** * Sets the name of dataobject that holds the string array of deterministic * names. * * @param deterministicStringsName * The new value for the property. * @see #getDeterministicStringsName * @throws IllegalArgumentException * if argument is not a valid symbolname */ public void setDeterministicStringsName(String deterministicStringsName) { if (deterministicStringsName == null) deterministicStringsDef = null; else deterministicStringsDef = new JSCTypeDef(deterministicStringsName, JSCTypes.SARRAY); } /** * Enables/disables the component. If disabled, time series cannot be * selected anymore. * * @param enabled * boolean */ public void setEnabled(boolean enabled) { super.setEnabled(enabled); getTSList().setEnabled(enabled); if (getDatesEditable() && (getTSList().getSelectedIndex() > -1)) { getTSDateRangeSelector().setEnabled(enabled); } } /** * Sets the name of the object holding the endogenous data array. * * @param endogenousDataName * The new value for the property. * @see #getEndogenousDataName * @throws IllegalArgumentException * if argument is not a valid symbolname */ public void setEndogenousDataName(String endogenousDataName) { if (endogenousDataName == null) endogenousDataDef = null; else endogenousDataDef = new JSCTypeDef(endogenousDataName, JSCTypes.NARRAY); } /** * Sets the name of dataobject that holds the string array of endogenous * names. * * @param endogenousStringsName * The new value for the property. * @see #getEndogenousStringsName * @throws IllegalArgumentException * if argument is not a valid symbolname */ public void setEndogenousStringsName(String endogenousStringsName) { if (endogenousStringsName == null) endogenousStringsDef = null; else endogenousStringsDef = new JSCTypeDef(endogenousStringsName, JSCTypes.SARRAY); } /** * Sets the name of the object holding the exogenous data array. * * @param exogenousDataName * The new value for the property. * @see #getExogenousDataName * @throws IllegalArgumentException * if argument is not a valid symbolname */ public void setExogenousDataName(String exogenousDataName) { if (exogenousDataName == null) exogenousDataDef = null; else exogenousDataDef = new JSCTypeDef(exogenousDataName, JSCTypes.NARRAY); } /** * Enables/disables selection of exogenous variables. This property merely * sets the list displaying the exogenous variables to enabled * or disabled. It has no effect on the data creation, but * it should communicate to the user, that exogenous variables are ignored * in the respective modeling context. * * @param arg1 * true to enable selection of exogenous variables */ public void setExogenousEnabled(boolean arg1) { getExSelList().setEnabled(arg1); } /** * Sets the name of dataobject that holds the string array of exogenous * names. * * @param exogenousStringsName * The new value for the property. * @see #getExogenousStringsName * @throws IllegalArgumentException * if argument is not a valid symbolname */ public void setExogenousStringsName(String exogenousStringsName) { if (exogenousStringsName == null) exogenousStringsDef = null; else exogenousStringsDef = new JSCTypeDef(exogenousStringsName, JSCTypes.SARRAY); } /** * Sets the name of dataobject that holds the date range of the selected * series. * * @param dateRangeName * The new value for the property. * @see #getDateRangeName * @throws IllegalArgumentException * if argument is not a valid symbolname */ public void setDateRangeName(String dateRangeName) { if (dateRangeName == null) dateRangeDef = null; else dateRangeDef = new JSCTypeDef(dateRangeName, JSCTypes.DRANGE); } /** * Sets whether only one endogenous variable should be selectable or more. * Useful for univariate models with possibly exogenous variables. * * @param newOneEndogenousOnly * true if only one endogenous variable should be selectable */ public void setOneEndogenousOnly(boolean newOneEndogenousOnly) { oneEndogenousOnly = newOneEndogenousOnly; } /** * Sets the selection changed property and fires * PropertyChangeEvent if the value changed. */ public void setSelectionChanged() { firePropertyChange("selectionChanged", Boolean.valueOf("TRUE"), Boolean .valueOf("FALSE")); } /** * Sets the selection mode to be a valid mode for JList. * * @param selectionMode * int */ public void setSelectionMode(int selectionMode) { getTSList().setSelectionMode(selectionMode); } /** * This method checks that only series with the same periodicity and an * overlapping TSDateRange are selected. * * @param setMaxRange * if true, the largest possible range is selected,
* if false, the selected range is not changed unless necessary */ private void tsDateRangeCheck(boolean setMaxRange) { TSList list = getTSList(); if (actualSelection.size() == 0) { referencePeriodicity = -1; return; } int index = actualSelection.get(0).intValue(); TS toCheck = timeSeriesData.getTS((list.getModel().getElementAt(index)) .toString()); // Stores the common date range. TSDateRange refDateRange = toCheck.range(); int period = toCheck.start().subPeriodicity(); // Periodicity has changed, reset the date range unconditionally. if (period != referencePeriodicity) { getTSDateRangeSelector().setEnclosingRange(toCheck.range()); referencePeriodicity = period; } // Loop through rest of selection, compute common date range and // throw out series with invalid ranges. for (int sel = 1; sel < actualSelection.size(); sel++) { index = actualSelection.get(sel).intValue(); TSDateRange dateRange = timeSeriesData.getTS( (list.getModel().getElementAt(index)).toString()).range(); TSDateRange tmpDateRange = refDateRange.commonRange(dateRange); // No common date range or less than 2 common observations. if (tmpDateRange == null || tmpDateRange.numOfObs() < 2) { actualSelection.remove(sel); // list.removeSelectionInterval(index, index); // Because the vectorSize is smaller now. sel--; } // Range is overlapping, update common date range. else refDateRange = tmpDateRange; } // Set overall range, but user values are preserved as much as possible // unless setMaxRange is set. getTSDateRangeSelector().setEnclosingRange(refDateRange); if (setMaxRange) getTSDateRangeSelector().maxRange(); return; } /** * List has changed, store all changes until they are confirmed. */ private void tSList_ListSelectionEvents() { TSList list = getTSList(); // Set max range, if nothing was selected before (range selector was // disabled). boolean setMaxRange = !getTSDateRangeSelector().isEnabled(); // If range is not editable, always display maximum range. if (!getTSDateRangeSelector().isEditable()) setMaxRange = true; if (list.getSelectedIndex() == -1) { getTSDateRangeSelector().setEnabled(false); getTSDateRangeSelector().setEditable(false); } else { getTSDateRangeSelector().setEnabled(true); getTSDateRangeSelector().setEditable(fieldDatesEditable); } // To prevent ListSelectionEvents when removing a selection // automatically. list.removeListSelectionListener(myEventHandler); // Savety belt to ensure that ListSelectionListener is added again, even // if something goes wrong. This should not happen. try { // Save the order in which the selections are made. saveSelectionOrderToVector(); // Check whether only one endogenous variable is allowed (univariate // modeling). checkOneEndogenousOnly(); // Select only series with the same periodicity and overlapping // range. tsDateRangeCheck(setMaxRange); int[] indizes = new int[actualSelection.size()]; for (int i = 0; i < indizes.length; i++) { indizes[i] = actualSelection.get(i).intValue(); } list.setSelectedIndices(indizes); } catch (Throwable ex) { log.error("Failed to set selection", ex); } // Adds the ListSelectionListener again. list.addListSelectionListener(myEventHandler); } /** * Sets whether UPPER or default GLOBAL scope * should be used. * * @param isUpper * if true Scope.UPPER is used, otherwise * Scope.GLOBAL */ public void setUpperScope(boolean isUpper) { if (isUpper) symbolScope = Scope.UPPER; else symbolScope = Scope.GLOBAL; } /** * Gets whether Scope.UPPER or Scope.GLOBAL is * used. * * @return true true Scope.UPPER is used, * otherwise Scope.GLOBAL */ public boolean isUpperScope() { return symbolScope == Scope.UPPER; } /** * Gets whether it is checked whether missing values are in the selection. * In this case the selection will not be allowed. The default is * true. * * @return true if NaN's are not allowed */ public boolean isCheckNaN() { return checkNaN; } /** * Sets whether it is checked whether missing values are in the selection. * In this case the selection will not be allowed. The default is * true. * * @param checkNaN * true if NaN's are not allowed, * false series with missing values can be * selected */ public void setCheckNaN(boolean checkNaN) { this.checkNaN = checkNaN; } /** * Sets the selection of this component according to sel. * The method does nothing if (sel == null). * * @param sel * holds the selection */ public void setSelection(Selection sel) { if (sel == null) return; JSCNArray i = sel.getSelectedIndices(); JSCDRange e = sel.getEnclosingRange(); JSCDRange r = sel.getSelectedRange(); getTSList().clearSelection(); int[][] index = i.intArray(); int[] toSet = new int[index.length]; for (int j = 0; j < toSet.length; j++) toSet[j] = index[j][0]; getTSList().setSelectedIndices(toSet); if (!r.isEmpty() && !e.isEmpty()) { getTSDateRangeSelector().setEnclosingRange(e.getTSDateRange()); getTSDateRangeSelector().setTSDateRange(r.getTSDateRange()); } tSList_ListSelectionEvents(); confirmButton_ActionEvents(); } /** * Gets the current selection set by this component. * * @return selection instance */ public Selection getSelection() { Selection sel = new Selection(); if (getEndSelList().getModel().getSize() == 0) return sel; sel.setSelectedIndices(new JSCNArray("selIndices", lastConfirmedSelection)); sel.setEnclosingRange(new JSCDRange("enclosing", getTSDateRangeSelector().getEnclosingRange())); sel.setSelectedRange(new JSCDRange("range", getTSDateRangeSelector() .getTSDateRange())); return sel; } }

Ads help maintain this website.