package com.jbidwatcher.ui;
import com.jbidwatcher.my.MyJBidwatcher;
import com.jbidwatcher.ui.util.JBidFrame;
import javax.swing.*;
import java.awt.event.*;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
public class SubmitLogDialog extends JDialog {
private final MyJBidwatcher myJBidwatcher;
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JTextField mEmailAddressTextField;
private JTextArea mProblemTextArea;
public SubmitLogDialog(MyJBidwatcher myJBidwatcher) {
this.myJBidwatcher = myJBidwatcher;
setContentPane(contentPane);
if (JBidFrame.getDefaultMenuBar() != null) setJMenuBar(JBidFrame.getDefaultMenuBar());
setModal(true);
getRootPane().setDefaultButton(buttonOK);
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {onOK();}
});
buttonCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {onCancel();}
});
// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}
});
// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}
public void showDialog() {
pack();
mProblemTextArea.setText("");
String email = mEmailAddressTextField.getText();
setVisible(true);
if (email != null && email.length() != 0) {
mProblemTextArea.requestFocusInWindow();
}
}
private void onOK() {
String email = mEmailAddressTextField.getText();
if (email == null || email.length() == 0) {
JOptionPane.showMessageDialog(null, "Email Address Required", "An email address is necessary so I can contact you if I need more information.", JOptionPane.ERROR_MESSAGE);
} else {
myJBidwatcher.sendLogFile(email, mProblemTextArea.getText());
dispose();
}
}
private void onCancel() {
// add your code here if necessary
dispose();
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer
* >>> IMPORTANT!! <<<
* DO NOT edit this method OR call it in your code!
*
* @noinspection ALL
*/
private void $$$setupUI$$$() {
contentPane = new JPanel();
contentPane.setLayout(new GridBagLayout());
final JPanel panel1 = new JPanel();
panel1.setLayout(new GridBagLayout());
GridBagConstraints gbc;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.weightx = 1.0;
gbc.fill = GridBagConstraints.BOTH;
contentPane.add(panel1, gbc);
final JPanel panel2 = new JPanel();
panel2.setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
panel1.add(panel2, gbc);
buttonOK = new JButton();
buttonOK.setText("Send Error Log");
buttonOK.setMnemonic('S');
buttonOK.setDisplayedMnemonicIndex(0);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.HORIZONTAL;
panel2.add(buttonOK, gbc);
buttonCancel = new JButton();
buttonCancel.setText("Cancel");
buttonCancel.setMnemonic('C');
buttonCancel.setDisplayedMnemonicIndex(0);
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.HORIZONTAL;
panel2.add(buttonCancel, gbc);
final JPanel panel3 = new JPanel();
panel3.setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(2, 2, 2, 2);
contentPane.add(panel3, gbc);
final JLabel label1 = new JLabel();
label1.setText("Email Address:");
label1.setDisplayedMnemonic('E');
label1.setDisplayedMnemonicIndex(0);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(0, 2, 0, 0);
panel3.add(label1, gbc);
mEmailAddressTextField = new JTextField();
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.HORIZONTAL;
panel3.add(mEmailAddressTextField, gbc);
final JLabel label2 = new JLabel();
label2.setText("Describe what went wrong:");
label2.setDisplayedMnemonic('D');
label2.setDisplayedMnemonicIndex(0);
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 1;
gbc.weightx = 1.0;
gbc.anchor = GridBagConstraints.WEST;
panel3.add(label2, gbc);
final JScrollPane scrollPane1 = new JScrollPane();
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 2;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
panel3.add(scrollPane1, gbc);
mProblemTextArea = new JTextArea();
mProblemTextArea.setColumns(28);
mProblemTextArea.setRows(10);
scrollPane1.setViewportView(mProblemTextArea);
label1.setLabelFor(mEmailAddressTextField);
label2.setLabelFor(mProblemTextArea);
}
/**
* @noinspection ALL
*/
public JComponent $$$getRootComponent$$$() { return contentPane; }
}