/*
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.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;
import org.apache.log4j.Logger;
import com.jstatcom.component.StdMessages;
import com.jstatcom.component.TopFrameReference;
import com.jstatcom.component.VarNameSelector;
/**
* A dialog for creating dummy variables. It also invokes the desired action and
* adds the created time series to the underlying TSList.
*
* @author Markus Kraetzig
*/
public final class TSDummyDialog extends JDialog {
private static final Logger log = Logger.getLogger(TSDummyDialog.class);
private JPanel ivjJDialogContentPane = null;
private JLabel ivjJLabel1 = null;
private JLabel ivjJLabel2 = null;
private JLabel ivjJLabel3 = null;
private JLabel ivjJLabel5 = null;
IvjEventHandler ivjEventHandler = new IvjEventHandler();
private JButton ivjCancel = null;
private JButton ivjOK = null;
private JPanel ivjJPanel1 = null;
private com.jstatcom.component.VarNameSelector ivjShiftName = null;
private com.jstatcom.component.VarNameSelector ivjImpulseName = null;
private JPanel ivjCreateDummies = null;
private com.jstatcom.ts.TSDateSelector ivjTSDateSelectorImpulse = null;
private com.jstatcom.ts.TSDateRangeSelector ivjTSDateRangeSelShift = null;
private JCheckBox ivjImpulseCheck = null;
private JCheckBox ivjShiftCheck = null;
private JCheckBox trendShiftCheck = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private TSDateRangeSelector trendShiftRange = null;
private VarNameSelector trendShiftName = null;
class IvjEventHandler implements java.awt.event.ActionListener {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (e.getSource() == TSDummyDialog.this.getOK())
connEtoC1();
if (e.getSource() == TSDummyDialog.this.getCancel())
connEtoC2();
if (e.getSource() == TSDummyDialog.this.getImpulseCheck())
connPtoP1SetTarget();
if (e.getSource() == TSDummyDialog.this.getShiftCheck())
connPtoP3SetTarget();
if (e.getSource() == TSDummyDialog.this.getImpulseCheck())
connPtoP2SetTarget();
if (e.getSource() == TSDummyDialog.this.getShiftCheck())
connPtoP4SetTarget();
};
};
/**
* TSDummyDialog default constructor.
*/
public TSDummyDialog() {
super();
initialize();
}
/**
* TSDummyDialog constructor.
*
* @param owner
* java.awt.Frame
* @param modal
* boolean
*/
public TSDummyDialog(JFrame owner, boolean modal) {
super(owner, modal);
initialize();
}
/**
* Comment
*/
private void cancel_ActionEvents() {
this.setVisible(false);
}
/**
* connEtoC1: (OK.action. --> TimeSeriesCreate.oK_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. --> TimeSeriesCreate.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);
}
}
/**
* connPtoP1SetTarget: (ImpulseCheck.selected <-->
* TSDateSelectorImpulse.enabled)
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void connPtoP1SetTarget() {
/* Set the target from the source */
try {
getTSDateSelectorImpulse().setEnabled(
getImpulseCheck().isSelected());
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* connPtoP2SetTarget: (ImpulseCheck.selected <-->ImpulseName.enabled)
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void connPtoP2SetTarget() {
/* Set the target from the source */
try {
getImpulseName().setEnabled(getImpulseCheck().isSelected());
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* connPtoP3SetTarget: (ShiftCheck.selected <-->
* TSDateRangeSelShift.enabled)
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void connPtoP3SetTarget() {
/* Set the target from the source */
try {
getTSDateRangeSelShift().setEnabled(getShiftCheck().isSelected());
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* connPtoP4SetTarget: (ShiftCheck.selected <-->ShiftName.enabled)
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void connPtoP4SetTarget() {
/* Set the target from the source */
try {
getShiftName().setEnabled(getShiftCheck().isSelected());
// user code begin {1}
// 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(85, 27));
ivjCancel.setText("Cancel");
ivjCancel.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 ivjCancel;
}
/**
* Return the CreateDummies property value.
*
* @return javax.swing.JPanel
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JPanel getCreateDummies() {
if (ivjCreateDummies == null) {
try {
jLabel1 = new JLabel();
jLabel = new JLabel();
ivjCreateDummies = new javax.swing.JPanel();
ivjCreateDummies.setName("CreateDummies");
ivjCreateDummies.setPreferredSize(new java.awt.Dimension(520,
245));
ivjCreateDummies
.setBorder(new BevelBorder(BevelBorder.LOWERED));
ivjCreateDummies.setLayout(null);
jLabel.setText("Shift range");
jLabel.setSize(114, 19);
jLabel.setLocation(42, 192);
jLabel1.setText("Name of new series");
jLabel1.setSize(120, 20);
jLabel1.setLocation(42, 212);
getCreateDummies().add(getImpulseCheck(),
getImpulseCheck().getName());
getCreateDummies().add(getJLabel1(), getJLabel1().getName());
getCreateDummies().add(getJLabel2(), getJLabel2().getName());
getCreateDummies().add(getShiftCheck(),
getShiftCheck().getName());
getCreateDummies().add(getJLabel3(), getJLabel3().getName());
getCreateDummies().add(getJLabel5(), getJLabel5().getName());
getCreateDummies().add(getTSDateSelectorImpulse(),
getTSDateSelectorImpulse().getName());
getCreateDummies().add(getImpulseName(),
getImpulseName().getName());
getCreateDummies().add(getTSDateRangeSelShift(),
getTSDateRangeSelShift().getName());
getCreateDummies()
.add(getShiftName(), getShiftName().getName());
// user code begin {1}
ivjCreateDummies.add(getTrendShiftCheck(), null);
// user code end
ivjCreateDummies.add(jLabel, null);
ivjCreateDummies.add(jLabel1, null);
ivjCreateDummies.add(getTrendShiftRange(), null);
ivjCreateDummies.add(getTrendShiftName(), null);
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjCreateDummies;
}
/**
* Return the JCheckBox1 property value.
*
* @return javax.swing.JCheckBox
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JCheckBox getImpulseCheck() {
if (ivjImpulseCheck == null) {
try {
ivjImpulseCheck = new javax.swing.JCheckBox();
ivjImpulseCheck.setName("ImpulseCheck");
ivjImpulseCheck.setText("Impulse dummy");
ivjImpulseCheck.setBounds(37, 12, 120, 25);
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjImpulseCheck;
}
/**
* Return the ImpulseName property value.
*
* @return javax.swing.JTextField
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private com.jstatcom.component.VarNameSelector getImpulseName() {
if (ivjImpulseName == null) {
try {
ivjImpulseName = new com.jstatcom.component.VarNameSelector();
ivjImpulseName.setName("ImpulseName");
ivjImpulseName.setVarName("impulse");
ivjImpulseName.setBounds(185, 62, 150, 20);
ivjImpulseName.setEnabled(false);
ivjImpulseName.setHorizontalAlignment(SwingConstants.LEFT);
ivjImpulseName.setEditable(true);
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjImpulseName;
}
/**
* 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(getJPanel1(), "South");
getJDialogContentPane().add(getCreateDummies(), "Center");
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjJDialogContentPane;
}
/**
* Return the JLabel1 property value.
*
* @return javax.swing.JLabel
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JLabel getJLabel1() {
if (ivjJLabel1 == null) {
try {
ivjJLabel1 = new javax.swing.JLabel();
ivjJLabel1.setName("JLabel1");
ivjJLabel1.setText("Date of impulse");
ivjJLabel1.setBounds(42, 42, 122, 20);
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjJLabel1;
}
/**
* Return the JLabel2 property value.
*
* @return javax.swing.JLabel
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JLabel getJLabel2() {
if (ivjJLabel2 == null) {
try {
ivjJLabel2 = new javax.swing.JLabel();
ivjJLabel2.setName("JLabel2");
ivjJLabel2.setText("Name of new series");
ivjJLabel2.setBounds(42, 62, 122, 20);
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjJLabel2;
}
/**
* Return the JLabel3 property value.
*
* @return javax.swing.JLabel
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JLabel getJLabel3() {
if (ivjJLabel3 == null) {
try {
ivjJLabel3 = new javax.swing.JLabel();
ivjJLabel3.setName("JLabel3");
ivjJLabel3.setText("Shift range");
ivjJLabel3.setBounds(42, 117, 122, 20);
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjJLabel3;
}
/**
* Return the JLabel5 property value.
*
* @return javax.swing.JLabel
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JLabel getJLabel5() {
if (ivjJLabel5 == null) {
try {
ivjJLabel5 = new javax.swing.JLabel();
ivjJLabel5.setName("JLabel5");
ivjJLabel5.setText("Name of new series");
ivjJLabel5.setBounds(42, 137, 122, 20);
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjJLabel5;
}
/**
* 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(520, 50));
ivjJPanel1.setLayout(getJPanel1FlowLayout());
ivjJPanel1.setMinimumSize(new java.awt.Dimension(520, 50));
ivjJPanel1.setMaximumSize(new java.awt.Dimension(520, 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 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(85, 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;
}
/**
* Return the JCheckBox2 property value.
*
* @return javax.swing.JCheckBox
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JCheckBox getShiftCheck() {
if (ivjShiftCheck == null) {
try {
ivjShiftCheck = new javax.swing.JCheckBox();
ivjShiftCheck.setName("ShiftCheck");
ivjShiftCheck.setText("Shift dummy");
ivjShiftCheck.setBounds(37, 87, 97, 25);
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjShiftCheck;
}
/**
* Return the ShiftName property value.
*
* @return javax.swing.JTextField
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private com.jstatcom.component.VarNameSelector getShiftName() {
if (ivjShiftName == null) {
try {
ivjShiftName = new com.jstatcom.component.VarNameSelector();
ivjShiftName.setName("ShiftName");
ivjShiftName.setVarName("shift");
ivjShiftName.setBounds(185, 137, 150, 20);
ivjShiftName.setEnabled(false);
ivjShiftName.setHorizontalAlignment(SwingConstants.LEFT);
ivjShiftName.setEditable(true);
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjShiftName;
}
/**
* Return the TSDateRangeSelShift property value.
*
* @return com.jstatcom.ts.TSDateRangeSelector
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private TSDateRangeSelector getTSDateRangeSelShift() {
if (ivjTSDateRangeSelShift == null) {
try {
ivjTSDateRangeSelShift = new com.jstatcom.ts.TSDateRangeSelector();
ivjTSDateRangeSelShift.setName("TSDateRangeSelShift");
ivjTSDateRangeSelShift.setBounds(185, 117, 150, 20);
ivjTSDateRangeSelShift.setEnabled(false);
ivjTSDateRangeSelShift.setEditable(true);
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjTSDateRangeSelShift;
}
/**
* Return the TSDateSelectorImpulse property value.
*
* @return com.jstatcom.ts.TSDateSelector
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private TSDateSelector getTSDateSelectorImpulse() {
if (ivjTSDateSelectorImpulse == null) {
try {
ivjTSDateSelectorImpulse = new com.jstatcom.ts.TSDateSelector();
ivjTSDateSelectorImpulse.setName("TSDateSelectorImpulse");
ivjTSDateSelectorImpulse.setBounds(185, 42, 150, 20);
ivjTSDateSelectorImpulse.setEnabled(false);
ivjTSDateSelectorImpulse.setEditable(true);
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjTSDateSelectorImpulse;
}
/**
* 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);
getImpulseCheck().addActionListener(ivjEventHandler);
getShiftCheck().addActionListener(ivjEventHandler);
connPtoP1SetTarget();
connPtoP3SetTarget();
connPtoP2SetTarget();
connPtoP4SetTarget();
}
/**
* Initialize the class.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initialize() {
try {
// user code begin {1}
// user code end
setName("TimeSeriesCreate");
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Create Dummy");
setSize(400, 340);
setResizable(false);
setContentPane(getJDialogContentPane());
initConnections();
} catch (Throwable ivjExc) {
handleException(ivjExc);
}
// user code begin {2}
// user code end
}
/**
* This method initializes jCheckBox
*
* @return javax.swing.JCheckBox
*/
private JCheckBox getTrendShiftCheck() {
if (trendShiftCheck == null) {
trendShiftCheck = new JCheckBox();
trendShiftCheck.setText("Trend shift dummy");
trendShiftCheck.setLocation(37, 162);
trendShiftCheck.setSize(173, 21);
trendShiftCheck
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
boolean sel = trendShiftCheck.isSelected();
getTrendShiftRange().setEnabled(sel);
getTrendShiftName().setEnabled(sel);
}
});
}
return trendShiftCheck;
}
/**
* This method initializes trendShiftRange
*
* @return com.jstatcom.ts.TSDateRangeSelector
*/
private TSDateRangeSelector getTrendShiftRange() {
if (trendShiftRange == null) {
trendShiftRange = new TSDateRangeSelector();
trendShiftRange.setEnabled(false);
trendShiftRange.setSize(150, 20);
trendShiftRange.setLocation(185, 192);
}
return trendShiftRange;
}
/**
* This method initializes trendShiftName
*
* @return com.jstatcom.component.VarNameSelector
*/
private VarNameSelector getTrendShiftName() {
if (trendShiftName == null) {
trendShiftName = new VarNameSelector();
trendShiftName.setEnabled(false);
trendShiftName.setLocation(185, 212);
trendShiftName.setSize(150, 20);
trendShiftName.setVarName("trendshift");
}
return trendShiftName;
}
/**
* Gather information and create dummies.
*/
private void oK_ActionEvents() {
// Impulse Dummy
if (getImpulseCheck().isSelected()) {
String name = getImpulseName().getVarName();
if (name.length() == 0) {
StdMessages.errorInput("Impulse dummy name cannot be empty.");
return;
}
TSDate date = getTSDateSelectorImpulse().getTSDate();
TSHolder.getInstance().addTS(
getTSDateSelectorImpulse().getRange().createShiftDumTS(
name, new TSDateRange(date, date)));
}
// Shift Dummy
if (getShiftCheck().isSelected()) {
String name = getShiftName().getVarName();
if (name.length() == 0) {
StdMessages.errorInput("Shift dummy name cannot be empty.");
return;
}
TSDateRange dateRange = getTSDateRangeSelShift().getTSDateRange();
TSHolder.getInstance().addTS(
getTSDateRangeSelShift().getEnclosingRange()
.createShiftDumTS(name, dateRange));
}
// Trend Shift Dummy
if (getTrendShiftCheck().isSelected()) {
String name = getTrendShiftName().getVarName();
if (name.length() == 0) {
StdMessages
.errorInput("Trend Shift dummy name cannot be empty.");
return;
}
TSDateRange dateRange = getTrendShiftRange().getTSDateRange();
TSHolder.getInstance().addTS(
getTrendShiftRange().getEnclosingRange()
.createTrendShiftDumTS(name, dateRange));
}
setVisible(false);
}
/**
* Sets TSList for this dialog. The selected time series are
* retrieved from the list and the range information is used for the dummy
* creation.
*
* @param newTimeSeriesList
* the TSList to be referenced
*/
public void setTSList(TSList newTimeSeriesList) {
TS ts = newTimeSeriesList.getSelectedTS()[0];
setTitle("Create Dummy for " + ts.range());
getTSDateRangeSelShift().setEnclosingRange(ts.range());
getTSDateSelectorImpulse().setEnclosingRange(ts.range());
getTrendShiftRange().setEnclosingRange(ts.range());
setLocationRelativeTo(TopFrameReference.getTopFrameRef());
}
}
Ads help maintain this website.