/*
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 javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.BevelBorder;
import org.apache.log4j.Logger;
import com.jstatcom.component.StdMessages;
import com.jstatcom.component.TopFrameReference;
/**
* Dialog for specification of basic time series transformations. It also
* invokes the desired transformation and adds the created time series to the
* underlying TSList.
*
* @author Markus Kraetzig
*/
public class TSTransDialog extends JDialog {
private static final Logger log = Logger.getLogger(TSTransDialog.class);
private JPanel ivjJDialogContentPane = null;
private JPanel ivjJPanel2 = null;
private TSList tSList;
private JButton ivjCancel = null;
private JButton ivjOK = null;
IvjEventHandler ivjEventHandler = new IvjEventHandler();
private JPanel ivjJPanel1 = null;
private JRadioButton ivjDiff1Check = null;
private JRadioButton ivjDiff2Check = null;
private JRadioButton ivjDiffSeasCheck = null;
private JRadioButton ivjLevelCheck = null;
private JCheckBox ivjLogCheck = null;
class IvjEventHandler implements java.awt.event.ActionListener {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (e.getSource() == TSTransDialog.this.getOK())
connEtoC1();
if (e.getSource() == TSTransDialog.this.getCancel())
connEtoC2();
};
};
/**
* TSTransDialog constructor.
*/
public TSTransDialog() {
super();
initialize();
}
/**
* TSTransDialog constructor.
*
* @param owner
* java.awt.Frame
* @param modal
* boolean
*/
public TSTransDialog(java.awt.Frame owner, boolean modal) {
super(owner, modal);
initialize();
}
/**
* Comment
*/
private void cancel_ActionEvents() {
this.setVisible(false);
return;
}
/**
* connEtoC1: (OK.action. --> TimeSeriesTransform.transform_ActionEvents()V)
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void connEtoC1() {
try {
// user code begin {1}
// user code end
this.oK_ActionEvents();
// user code begin {2}
// user code end
} catch (Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* connEtoC2: (Cancel.action. -->
* TimeSeriesTransform.cancel_ActionEvents()V)
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void connEtoC2() {
try {
// user code begin {1}
// user code end
this.cancel_ActionEvents();
// user code begin {2}
// user code end
} catch (Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* Return the Cancel property value.
*
* @return javax.swing.JButton
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JButton getCancel() {
if (ivjCancel == null) {
try {
ivjCancel = new javax.swing.JButton();
ivjCancel.setName("Cancel");
ivjCancel.setPreferredSize(new java.awt.Dimension(100, 27));
ivjCancel.setText("Cancel");
ivjCancel.setMinimumSize(new java.awt.Dimension(80, 27));
ivjCancel.setMaximumSize(new java.awt.Dimension(80, 27));
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjCancel;
}
/**
* Return the JRadioButton2 property value.
*
* @return javax.swing.JRadioButton
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JRadioButton getDiff1Check() {
if (ivjDiff1Check == null) {
try {
ivjDiff1Check = new javax.swing.JRadioButton();
ivjDiff1Check.setName("Diff1Check");
ivjDiff1Check.setText("1st differences Y(t) - Y(t-1)");
ivjDiff1Check.setBounds(20, 75, 273, 25);
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjDiff1Check;
}
/**
* Return the JRadioButton3 property value.
*
* @return javax.swing.JRadioButton
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JRadioButton getDiff2Check() {
if (ivjDiff2Check == null) {
try {
ivjDiff2Check = new javax.swing.JRadioButton();
ivjDiff2Check.setName("Diff2Check");
ivjDiff2Check
.setText("2nd differences [Y(t)-Y(t-1)] - [Y(t-1)-Y(t-2)]");
ivjDiff2Check.setBounds(20, 105, 271, 25);
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjDiff2Check;
}
/**
* Return the JRadioButton4 property value.
*
* @return javax.swing.JRadioButton
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JRadioButton getDiffSeasCheck() {
if (ivjDiffSeasCheck == null) {
try {
ivjDiffSeasCheck = new javax.swing.JRadioButton();
ivjDiffSeasCheck.setName("DiffSeasCheck");
ivjDiffSeasCheck
.setText("Seasonal differences Y(t) - Y(t-freq)");
ivjDiffSeasCheck.setSize(278, 25);
ivjDiffSeasCheck.setLocation(20, 135);
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjDiffSeasCheck;
}
/**
* Return the JDialogContentPane property value.
*
* @return javax.swing.JPanel
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private JPanel getJDialogContentPane() {
if (ivjJDialogContentPane == null) {
try {
ivjJDialogContentPane = new JPanel();
ivjJDialogContentPane.setName("JDialogContentPane");
ivjJDialogContentPane.setLayout(new java.awt.BorderLayout());
getJDialogContentPane().add(getJPanel2(), "Center");
getJDialogContentPane().add(getJPanel1(), "South");
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjJDialogContentPane;
}
/**
* 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(210, 50));
ivjJPanel1.setLayout(getJPanel1FlowLayout());
ivjJPanel1.setMaximumSize(new java.awt.Dimension(210, 50));
ivjJPanel1.setMinimumSize(new java.awt.Dimension(210, 50));
getJPanel1().add(getOK(), getOK().getName());
getJPanel1().add(getCancel(), getCancel().getName());
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjJPanel1;
}
/**
* Return the JPanel1FlowLayout property value.
*
* @return java.awt.FlowLayout
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private java.awt.FlowLayout getJPanel1FlowLayout() {
java.awt.FlowLayout ivjJPanel1FlowLayout = null;
try {
/* Create part */
ivjJPanel1FlowLayout = new java.awt.FlowLayout();
ivjJPanel1FlowLayout.setVgap(10);
ivjJPanel1FlowLayout.setHgap(50);
} catch (Throwable ivjExc) {
handleException(ivjExc);
}
;
return ivjJPanel1FlowLayout;
}
/**
* 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.setBorder(new BevelBorder(BevelBorder.LOWERED));
ivjJPanel2.setLayout(null);
ivjJPanel2.setMaximumSize(new java.awt.Dimension(210, 180));
ivjJPanel2.setPreferredSize(new java.awt.Dimension(210, 180));
ivjJPanel2.setMinimumSize(new java.awt.Dimension(210, 180));
getJPanel2().add(getLevelCheck(), getLevelCheck().getName());
getJPanel2().add(getDiff1Check(), getDiff1Check().getName());
getJPanel2().add(getDiff2Check(), getDiff2Check().getName());
getJPanel2().add(getDiffSeasCheck(),
getDiffSeasCheck().getName());
getJPanel2().add(getLogCheck(), getLogCheck().getName());
// user code begin {1}
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjJPanel2;
}
/**
* Return the JRadioButton1 property value.
*
* @return javax.swing.JRadioButton
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JRadioButton getLevelCheck() {
if (ivjLevelCheck == null) {
try {
ivjLevelCheck = new javax.swing.JRadioButton();
ivjLevelCheck.setName("LevelCheck");
ivjLevelCheck.setSelected(true);
ivjLevelCheck.setText("Level");
ivjLevelCheck.setBounds(20, 45, 180, 25);
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjLevelCheck;
}
/**
* Return the JCheckBox1 property value.
*
* @return javax.swing.JCheckBox
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JCheckBox getLogCheck() {
if (ivjLogCheck == null) {
try {
ivjLogCheck = new javax.swing.JCheckBox();
ivjLogCheck.setName("LogCheck");
ivjLogCheck.setText("Logarithm");
ivjLogCheck.setBounds(20, 10, 180, 25);
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjLogCheck;
}
/**
* Return the OK property value.
*
* @return javax.swing.JButton
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JButton getOK() {
if (ivjOK == null) {
try {
ivjOK = new javax.swing.JButton();
ivjOK.setName("OK");
ivjOK.setPreferredSize(new java.awt.Dimension(100, 27));
ivjOK.setText("OK");
ivjOK.setMaximumSize(new java.awt.Dimension(80, 27));
ivjOK.setMinimumSize(new java.awt.Dimension(80, 27));
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjOK;
}
/**
* 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}
// user code end
getOK().addActionListener(ivjEventHandler);
getCancel().addActionListener(ivjEventHandler);
}
/**
* Initialize the class.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initialize() {
try {
// user code begin {1}
// user code end
setName("TimeSeriesTransform");
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
setSize(400, 280);
setTitle("Transform");
setContentPane(getJDialogContentPane());
initConnections();
} catch (Throwable ivjExc) {
handleException(ivjExc);
}
// user code begin {2}
ButtonGroup selectGroup = new ButtonGroup();
selectGroup.add(getLevelCheck());
selectGroup.add(getDiff1Check());
selectGroup.add(getDiff2Check());
selectGroup.add(getDiffSeasCheck());
// user code end
}
/**
* Invokes the transform operation and adds the created TS to the TSHolder.
*/
private void oK_ActionEvents() {
// Nothing to be done.
if (!getLogCheck().isSelected() && getLevelCheck().isSelected()) {
setVisible(false);
return;
}
TS[] selectedTS = tSList.getSelectedTS();
// Seasonal diffs not possible for subperiodicity 1.
int subPeriodicity = selectedTS[0].start().subPeriodicity();
if (subPeriodicity == 1 && getDiffSeasCheck().isSelected()) {
StdMessages
.errorSpecification("Seasonal differences not possible for annual data.");
return;
}
TS[] transformedTS = new TS[selectedTS.length];
// Do the log and diffs.
for (int i = 0; i < selectedTS.length; i++) {
TS newTS = null;
if (getLogCheck().isSelected())
newTS = selectedTS[i].createLog();
// log and diff
if (getDiff1Check().isSelected() || getDiffSeasCheck().isSelected()) {
int period = 0;
if (getDiff1Check().isSelected())
period = 1;
if (getDiffSeasCheck().isSelected())
period = subPeriodicity;
if (newTS != null)
newTS = newTS.createDiff(period);
// diff only
else
newTS = selectedTS[i].createDiff(period);
} else if (getDiff2Check().isSelected()) {
if (newTS != null)
newTS = newTS.createDiff(1).createDiff(1);
// diff only
else
newTS = selectedTS[i].createDiff(1).createDiff(1);
}
transformedTS[i] = newTS;
}
// Add the new TS
for (TS ts : transformedTS) {
if (ts != null) {
int accept = TSHolder.getInstance().addTS(ts);
if (accept == JOptionPane.CANCEL_OPTION)
break;
}
}
setVisible(false);
}
/**
* Sets TSList for this dialog. The selected time series are
* retrieved from the list and used for the transformation.
*
* @param newTimeSeriesList
* a TSList that should not be not null
*/
public void setTSList(TSList newTimeSeriesList) {
int maxSel = newTimeSeriesList.getSelectedIndices().length;
String seriesNames = "";
seriesNames = newTimeSeriesList.getSelectedTS()[0].name();
for (int i = 1; i < maxSel; i++) {
seriesNames = seriesNames + ", "
+ newTimeSeriesList.getSelectedTS()[i].name();
}
setTitle("Transform: " + seriesNames);
tSList = newTimeSeriesList;
setLocationRelativeTo(TopFrameReference.getTopFrameRef());
}
} // @jve:decl-index=0:visual-constraint="10,10"
Ads help maintain this website.