package de.ugoe.cs.eventbench.swing; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.util.List; import de.ugoe.cs.util.console.Console; import de.ugoe.cs.eventbench.data.Event; import de.ugoe.cs.eventbench.data.GlobalDataContainer; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JComboBox; import javax.swing.ComboBoxModel; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.DefaultComboBoxModel; import javax.swing.JOptionPane; import javax.swing.JFileChooser; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import java.io.File; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.JScrollPane; import javax.swing.JList; public class DlgInsert extends JDialog { private final JPanel contentPanel = new JPanel(); private JTextField textFieldExpectedValue; private JTextField textFieldTestFile; private JTextField textFieldMatchingFile; /** * Launch the application. */ public static void ShowDialog(List> sequences, int selectedIndex, final boolean insertBefore) { try { DlgInsert dialog = new DlgInsert(sequences, selectedIndex, insertBefore); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } /** * Create the dialog. */ public DlgInsert(final List> sequences, final int selectedIndex, final boolean insertBefore) { final javax.swing.DefaultListModel modelListTargets = new javax.swing.DefaultListModel(); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setTitle("Insert testcase"); setModal(true); setBounds(100, 100, 522, 482); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(null); final JComboBox comboBoxTestcase = new JComboBox(); final JPanel panelTextEquals = new JPanel(); final JPanel panelFileEquals = new JPanel(); // JComboBox: comboBoxTestcase comboBoxTestcase.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if ("comboBoxChanged".equals(arg0.getActionCommand())) { //TextEquals if(comboBoxTestcase.getSelectedIndex() == 0) { panelTextEquals.setVisible(true); panelFileEquals.setVisible(false); } //FileEquals else if(comboBoxTestcase.getSelectedIndex() == 1) { panelTextEquals.setVisible(false); panelFileEquals.setVisible(true); } } } }); comboBoxTestcase.setModel(new DefaultComboBoxModel(new String[] {"TextEquals", "OutputFileEquals"})); comboBoxTestcase.setSelectedIndex(0); comboBoxTestcase.setBounds(128, 11, 178, 20); contentPanel.add(comboBoxTestcase); // *** // JLabel JLabel label = new JLabel("Testcase:"); label.setBounds(10, 14, 86, 14); contentPanel.add(label); JLabel label_1 = new JLabel("Expected value:"); label_1.setBounds(10, 11, 83, 14); JLabel label_2 = new JLabel("Target:"); label_2.setBounds(10, 38, 86, 14); // *** // JTextField: textFieldExpectedValue textFieldExpectedValue = new JTextField(); textFieldExpectedValue.setColumns(10); textFieldExpectedValue.setBounds(116, 8, 368, 20); // *** // JPanel: panel panelTextEquals.setLayout(null); panelTextEquals.setBounds(10, 39, 494, 210); contentPanel.add(panelTextEquals); panelTextEquals.add(label_1); panelTextEquals.add(label_2); panelTextEquals.add(textFieldExpectedValue); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(116, 36, 368, 163); panelTextEquals.add(scrollPane); JList listTargets = new JList(modelListTargets); scrollPane.setViewportView(listTargets); for(int i=0; i e = new Event("FileEquals"); e.setTarget(" "); if(insertBefore) sequences.add(selectedIndex, e); else sequences.add(selectedIndex+1, e); } } //TextEquals else { if(textFieldExpectedValue.getText().length() == 0) { JOptionPane.showMessageDialog(null, "\"Expected value\" is missing.", "Expected value", JOptionPane.OK_OPTION); return; } else { Event e = new Event("TextEquals"); e.setTarget(" "); if(insertBefore) sequences.add(selectedIndex, e); else sequences.add(selectedIndex+1, e); } } dispose(); } }); okButton.setActionCommand("OK"); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); // *** } { // JButton: cancelButton JButton cancelButton = new JButton("Cancel"); cancelButton.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent arg0) { dispose(); } }); cancelButton.setActionCommand("Cancel"); buttonPane.add(cancelButton); // *** } } // *** } }