/*
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.engine;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.BevelBorder;
import org.apache.log4j.Logger;
import com.jstatcom.component.StdMessages;
import com.jstatcom.component.TopFrameReference;
/**
* A JDialog to collect configuration information about the
* engine from the user. This dialog is initially empty and contains only
* OK and CANCEL options. It should be invoked via
* showConfigDialog for a specific ConfigHolder.
* This automatically inserts the engine specific implementation of
* AbstractConfigPanel.
*
* If the static method showConfigDialog is used, then only one
* instance of this class will be created.
*
* @author Markus Kraetzig
*
* @see com.jstatcom.engine.AbstractConfigPanel
* @see com.jstatcom.engine.EngineTypes
* @see com.jstatcom.engine.ConfigKeys
* @see com.jstatcom.engine.ConfigHolder
*/
public final class ConfigDialog extends JDialog {
private static final Logger log = Logger.getLogger(ConfigDialog.class);
private ConfigHolder configHolder = null;
private static boolean isOK = true;
private static ConfigDialog configDialog = null;
private AbstractConfigPanel configPanel = null;
private JPanel ivjJDialogContentPane = null;
private JButton ivjCancelButton = null;
IvjEventHandler ivjEventHandler = new IvjEventHandler();
private JButton ivjOKButton = null;
private JPanel ivjButtonPanel = null;
class IvjEventHandler implements java.awt.event.ActionListener {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (e.getSource() == ConfigDialog.this.getOKButton())
connEtoC1();
if (e.getSource() == ConfigDialog.this.getCancelButton())
connEtoC2();
};
};
/**
* Default constructor.
*/
public ConfigDialog() {
super(TopFrameReference.getTopFrameRef(), true);
initialize();
}
/**
* Hides the Dialog.
*/
private void cancelButton_ActionEvents() {
isOK = false;
setVisible(false);
}
/**
* connEtoC1: (OKButton.action. --> ConfigDialog.oKButton_ActionEvents()V)
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void connEtoC1() {
try {
// user code begin {1}
// user code end
this.oKButton_ActionEvents();
// user code begin {2}
// user code end
} catch (Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* connEtoC2: (CancelButton.action. -->
* ConfigDialog.cancelButton_ActionEvents()V)
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void connEtoC2() {
try {
// user code begin {1}
// user code end
this.cancelButton_ActionEvents();
// user code begin {2}
// user code end
} catch (Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* Return the JPanel1 property value.
*
* @return javax.swing.JPanel
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JPanel getButtonPanel() {
if (ivjButtonPanel == null) {
try {
ivjButtonPanel = new javax.swing.JPanel();
ivjButtonPanel.setName("ButtonPanel");
ivjButtonPanel.setPreferredSize(new java.awt.Dimension(0, 80));
ivjButtonPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
ivjButtonPanel.setLayout(getButtonPanelFlowLayout());
getButtonPanel().add(getOKButton(), getOKButton().getName());
getButtonPanel().add(getCancelButton(),
getCancelButton().getName());
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjButtonPanel;
}
/**
* Return the ButtonPanelFlowLayout property value.
*
* @return java.awt.FlowLayout
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private java.awt.FlowLayout getButtonPanelFlowLayout() {
java.awt.FlowLayout ivjButtonPanelFlowLayout = null;
try {
/* Create part */
ivjButtonPanelFlowLayout = new java.awt.FlowLayout();
ivjButtonPanelFlowLayout.setVgap(20);
ivjButtonPanelFlowLayout.setHgap(60);
} catch (Throwable ivjExc) {
handleException(ivjExc);
}
;
return ivjButtonPanelFlowLayout;
}
/**
* Return the CancelButton property value.
*
* @return javax.swing.JButton
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JButton getCancelButton() {
if (ivjCancelButton == null) {
try {
ivjCancelButton = new javax.swing.JButton();
ivjCancelButton.setName("CancelButton");
ivjCancelButton
.setPreferredSize(new java.awt.Dimension(100, 25));
ivjCancelButton.setText("Cancel");
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjCancelButton;
}
/**
* Return the JDialogContentPane property value.
*
* @return javax.swing.JPanel
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JPanel getJDialogContentPane() {
if (ivjJDialogContentPane == null) {
try {
ivjJDialogContentPane = new javax.swing.JPanel();
ivjJDialogContentPane.setName("JDialogContentPane");
ivjJDialogContentPane.setLayout(new java.awt.BorderLayout());
ivjJDialogContentPane.setMinimumSize(new java.awt.Dimension(
500, 400));
getJDialogContentPane().add(getButtonPanel(), "South");
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjJDialogContentPane;
}
/**
* Return the OKButton property value.
*
* @return javax.swing.JButton
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JButton getOKButton() {
if (ivjOKButton == null) {
try {
ivjOKButton = new javax.swing.JButton();
ivjOKButton.setName("OKButton");
ivjOKButton.setPreferredSize(new java.awt.Dimension(100, 25));
ivjOKButton.setText("OK");
// user code begin {1}
// user code end
} catch (Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjOKButton;
}
/**
* 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
getOKButton().addActionListener(ivjEventHandler);
getCancelButton().addActionListener(ivjEventHandler);
}
/**
* Initialize the class.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initialize() {
try {
// user code begin {1}
// user code end
setName("ConfigDialog");
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setSize(500, 400);
setResizable(true);
setContentPane(getJDialogContentPane());
initConnections();
} catch (Throwable ivjExc) {
handleException(ivjExc);
}
// user code begin {2}
setLocationRelativeTo(TopFrameReference.getTopFrameRef());
// user code end
}
/**
* Checks the user input and hides dialog if ok.
*/
private void oKButton_ActionEvents() {
String error = null;
error = configPanel.storeConfig(configHolder);
if (error == null)
error = configHolder.getEngineType().checkConfig(configHolder);
isOK = error == null;
if (isOK)
setVisible(false);
else
StdMessages.errorInput(error);
}
/**
* Displays this with a user input mask specific for an engine. All
* information is stored in newConfigHolder.
*
* @param newConfigHolder
* contains the necessary engine specific information
* @return false if dialog was canceled
* true if input was ok
* @throws IllegalArgumentException
* if (newConfigHolder == null)
*/
public static boolean showConfigDialog(ConfigHolder newConfigHolder) {
if (newConfigHolder == null)
throw new IllegalArgumentException("Argument was null.");
if (configDialog == null) // Only one instance of this is needed.
configDialog = new ConfigDialog();
configDialog.configHolder = newConfigHolder;
EngineTypes engineType = configDialog.configHolder.getEngineType();
configDialog.configPanel = engineType.getConfigPanel();
configDialog.configPanel.setConfig(configDialog.configHolder);
configDialog.setTitle("Configuration Settings for "
+ engineType.toString());
// Remove previous component.
configDialog.getJDialogContentPane().removeAll();
// Add the current component containing the user input mask.
configDialog.getJDialogContentPane().add(
new JScrollPane(configDialog.configPanel), "Center");
configDialog.getJDialogContentPane().add(configDialog.getButtonPanel(),
"South");
configDialog.setVisible(true);
return isOK;
}
}
Ads help maintain this website.