1 | package de.ugoe.cs.eventbench.swing;
|
---|
2 |
|
---|
3 | import java.awt.BorderLayout;
|
---|
4 | import java.awt.FlowLayout;
|
---|
5 | import java.util.List;
|
---|
6 | import de.ugoe.cs.util.console.Console;
|
---|
7 | import de.ugoe.cs.eventbench.data.Event;
|
---|
8 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
9 |
|
---|
10 | import javax.swing.JButton;
|
---|
11 | import javax.swing.JDialog;
|
---|
12 | import javax.swing.JPanel;
|
---|
13 | import javax.swing.border.EmptyBorder;
|
---|
14 | import javax.swing.JComboBox;
|
---|
15 | import javax.swing.ComboBoxModel;
|
---|
16 | import javax.swing.JLabel;
|
---|
17 | import javax.swing.JTextField;
|
---|
18 | import javax.swing.DefaultComboBoxModel;
|
---|
19 | import javax.swing.JOptionPane;
|
---|
20 | import javax.swing.JFileChooser;
|
---|
21 | import java.awt.event.MouseAdapter;
|
---|
22 | import java.awt.event.MouseEvent;
|
---|
23 | import java.beans.PropertyChangeListener;
|
---|
24 | import java.beans.PropertyChangeEvent;
|
---|
25 | import java.io.File;
|
---|
26 | import java.awt.event.ActionListener;
|
---|
27 | import java.awt.event.ActionEvent;
|
---|
28 | import java.awt.event.KeyAdapter;
|
---|
29 | import java.awt.event.KeyEvent;
|
---|
30 | import javax.swing.JScrollPane;
|
---|
31 | import javax.swing.JList;
|
---|
32 |
|
---|
33 | public class DlgInsert extends JDialog {
|
---|
34 |
|
---|
35 | private final JPanel contentPanel = new JPanel();
|
---|
36 | private JTextField textFieldExpectedValue;
|
---|
37 | private JTextField textFieldTestFile;
|
---|
38 | private JTextField textFieldMatchingFile;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Launch the application.
|
---|
42 | */
|
---|
43 | public static void ShowDialog(List<Event<?>> sequences, int selectedIndex, final boolean insertBefore) {
|
---|
44 | try {
|
---|
45 | DlgInsert dialog = new DlgInsert(sequences, selectedIndex, insertBefore);
|
---|
46 | dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
---|
47 | dialog.setVisible(true);
|
---|
48 | } catch (Exception e) {
|
---|
49 | e.printStackTrace();
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Create the dialog.
|
---|
55 | */
|
---|
56 | public DlgInsert(final List<Event<?>> sequences, final int selectedIndex, final boolean insertBefore) {
|
---|
57 |
|
---|
58 | final javax.swing.DefaultListModel modelListTargets = new javax.swing.DefaultListModel();
|
---|
59 |
|
---|
60 | setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
---|
61 | setTitle("Insert testcase");
|
---|
62 |
|
---|
63 |
|
---|
64 | setModal(true);
|
---|
65 | setBounds(100, 100, 522, 482);
|
---|
66 | getContentPane().setLayout(new BorderLayout());
|
---|
67 | contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
---|
68 | getContentPane().add(contentPanel, BorderLayout.CENTER);
|
---|
69 | contentPanel.setLayout(null);
|
---|
70 | final JComboBox comboBoxTestcase = new JComboBox();
|
---|
71 | final JPanel panelTextEquals = new JPanel();
|
---|
72 | final JPanel panelFileEquals = new JPanel();
|
---|
73 |
|
---|
74 |
|
---|
75 | // JComboBox: comboBoxTestcase
|
---|
76 | comboBoxTestcase.addActionListener(new ActionListener() {
|
---|
77 | public void actionPerformed(ActionEvent arg0) {
|
---|
78 | if ("comboBoxChanged".equals(arg0.getActionCommand())) {
|
---|
79 |
|
---|
80 | //TextEquals
|
---|
81 | if(comboBoxTestcase.getSelectedIndex() == 0) {
|
---|
82 | panelTextEquals.setVisible(true);
|
---|
83 | panelFileEquals.setVisible(false);
|
---|
84 | }
|
---|
85 | //FileEquals
|
---|
86 | else if(comboBoxTestcase.getSelectedIndex() == 1) {
|
---|
87 | panelTextEquals.setVisible(false);
|
---|
88 | panelFileEquals.setVisible(true);
|
---|
89 | }
|
---|
90 | }
|
---|
91 | }
|
---|
92 | });
|
---|
93 | comboBoxTestcase.setModel(new DefaultComboBoxModel(new String[] {"TextEquals", "OutputFileEquals"}));
|
---|
94 | comboBoxTestcase.setSelectedIndex(0);
|
---|
95 | comboBoxTestcase.setBounds(128, 11, 178, 20);
|
---|
96 | contentPanel.add(comboBoxTestcase);
|
---|
97 | // ***
|
---|
98 |
|
---|
99 |
|
---|
100 | // JLabel
|
---|
101 | JLabel label = new JLabel("Testcase:");
|
---|
102 | label.setBounds(10, 14, 86, 14);
|
---|
103 | contentPanel.add(label);
|
---|
104 |
|
---|
105 | JLabel label_1 = new JLabel("Expected value:");
|
---|
106 | label_1.setBounds(10, 11, 83, 14);
|
---|
107 |
|
---|
108 | JLabel label_2 = new JLabel("Target:");
|
---|
109 | label_2.setBounds(10, 38, 86, 14);
|
---|
110 | // ***
|
---|
111 |
|
---|
112 |
|
---|
113 | // JTextField: textFieldExpectedValue
|
---|
114 | textFieldExpectedValue = new JTextField();
|
---|
115 | textFieldExpectedValue.setColumns(10);
|
---|
116 | textFieldExpectedValue.setBounds(116, 8, 368, 20);
|
---|
117 | // ***
|
---|
118 |
|
---|
119 |
|
---|
120 | // JPanel: panel
|
---|
121 | panelTextEquals.setLayout(null);
|
---|
122 | panelTextEquals.setBounds(10, 39, 494, 210);
|
---|
123 | contentPanel.add(panelTextEquals);
|
---|
124 | panelTextEquals.add(label_1);
|
---|
125 | panelTextEquals.add(label_2);
|
---|
126 | panelTextEquals.add(textFieldExpectedValue);
|
---|
127 |
|
---|
128 | JScrollPane scrollPane = new JScrollPane();
|
---|
129 | scrollPane.setBounds(116, 36, 368, 163);
|
---|
130 | panelTextEquals.add(scrollPane);
|
---|
131 |
|
---|
132 | JList listTargets = new JList(modelListTargets);
|
---|
133 | scrollPane.setViewportView(listTargets);
|
---|
134 |
|
---|
135 | for(int i=0; i<sequences.size(); i++) {
|
---|
136 | modelListTargets.addElement(sequences.get(i).getTarget());
|
---|
137 | }
|
---|
138 |
|
---|
139 |
|
---|
140 | panelFileEquals.setBounds(10, 260, 494, 140);
|
---|
141 | contentPanel.add(panelFileEquals);
|
---|
142 | panelFileEquals.setLayout(null);
|
---|
143 | panelFileEquals.setVisible(false);
|
---|
144 |
|
---|
145 | JLabel lblNewLabel = new JLabel("Testfile:");
|
---|
146 | lblNewLabel.setBounds(10, 11, 46, 14);
|
---|
147 | panelFileEquals.add(lblNewLabel);
|
---|
148 |
|
---|
149 | textFieldTestFile = new JTextField();
|
---|
150 | textFieldTestFile.setBounds(10, 36, 474, 20);
|
---|
151 | panelFileEquals.add(textFieldTestFile);
|
---|
152 | textFieldTestFile.setColumns(10);
|
---|
153 |
|
---|
154 | JButton btnNewButton = new JButton("Search file");
|
---|
155 | btnNewButton.addMouseListener(new MouseAdapter() {
|
---|
156 | public void mouseClicked(MouseEvent arg0) {
|
---|
157 | final JFileChooser fc = new JFileChooser();
|
---|
158 | if(fc.showOpenDialog(contentPanel) == 0) { textFieldMatchingFile.setText(fc.getSelectedFile().getAbsolutePath()); }
|
---|
159 | }
|
---|
160 | });
|
---|
161 | btnNewButton.setBounds(99, 80, 89, 23);
|
---|
162 | panelFileEquals.add(btnNewButton);
|
---|
163 |
|
---|
164 | JLabel lblNewLabel_1 = new JLabel("Matching file:");
|
---|
165 | lblNewLabel_1.setBounds(10, 84, 89, 14);
|
---|
166 | panelFileEquals.add(lblNewLabel_1);
|
---|
167 |
|
---|
168 | textFieldMatchingFile = new JTextField();
|
---|
169 | textFieldMatchingFile.setColumns(10);
|
---|
170 | textFieldMatchingFile.setBounds(10, 109, 474, 20);
|
---|
171 | panelFileEquals.add(textFieldMatchingFile);
|
---|
172 | {
|
---|
173 | JPanel buttonPane = new JPanel();
|
---|
174 | buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
---|
175 | getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
---|
176 | {
|
---|
177 | // JButton: okButton
|
---|
178 | JButton okButton = new JButton("Insert");
|
---|
179 | okButton.addMouseListener(new MouseAdapter() {
|
---|
180 | public void mouseClicked(MouseEvent arg0) {
|
---|
181 |
|
---|
182 | //FileEquals
|
---|
183 | if(panelFileEquals.isVisible()) {
|
---|
184 | if(! new File(textFieldTestFile.getText()).exists()) {
|
---|
185 | if(textFieldTestFile.getText().length() == 0) JOptionPane.showMessageDialog(null, "Please choose a test file.", "No test file chosen", JOptionPane.OK_OPTION);
|
---|
186 | else JOptionPane.showMessageDialog(null, "The test file \"" + textFieldTestFile.getText() + "\" does not exist.", "Test file does not exist", JOptionPane.OK_OPTION);
|
---|
187 | return;
|
---|
188 | }
|
---|
189 | else if(! new File(textFieldMatchingFile.getText()).exists()) {
|
---|
190 | if(textFieldMatchingFile.getText().length() == 0) JOptionPane.showMessageDialog(null, "Please choose a matching file.", "No matching file chosen", JOptionPane.OK_OPTION);
|
---|
191 | else JOptionPane.showMessageDialog(null, "The matching file \"" + textFieldTestFile.getText() + "\" does not exist.", "Matching file does not exist", JOptionPane.OK_OPTION);
|
---|
192 | return;
|
---|
193 | }
|
---|
194 | else {
|
---|
195 | Event<?> e = new Event("FileEquals");
|
---|
196 | e.setTarget(" ");
|
---|
197 | if(insertBefore) sequences.add(selectedIndex, e);
|
---|
198 | else sequences.add(selectedIndex+1, e);
|
---|
199 | }
|
---|
200 | }
|
---|
201 | //TextEquals
|
---|
202 | else {
|
---|
203 | if(textFieldExpectedValue.getText().length() == 0) {
|
---|
204 | JOptionPane.showMessageDialog(null, "\"Expected value\" is missing.", "Expected value", JOptionPane.OK_OPTION);
|
---|
205 | return;
|
---|
206 | }
|
---|
207 | else {
|
---|
208 | Event<?> e = new Event("TextEquals");
|
---|
209 | e.setTarget(" ");
|
---|
210 | if(insertBefore) sequences.add(selectedIndex, e);
|
---|
211 | else sequences.add(selectedIndex+1, e);
|
---|
212 | }
|
---|
213 | }
|
---|
214 |
|
---|
215 | dispose();
|
---|
216 | }
|
---|
217 | });
|
---|
218 | okButton.setActionCommand("OK");
|
---|
219 | buttonPane.add(okButton);
|
---|
220 | getRootPane().setDefaultButton(okButton);
|
---|
221 | // ***
|
---|
222 | }
|
---|
223 |
|
---|
224 | {
|
---|
225 | // JButton: cancelButton
|
---|
226 | JButton cancelButton = new JButton("Cancel");
|
---|
227 | cancelButton.addMouseListener(new MouseAdapter() {
|
---|
228 |
|
---|
229 | public void mouseClicked(MouseEvent arg0) { dispose(); }
|
---|
230 | });
|
---|
231 | cancelButton.setActionCommand("Cancel");
|
---|
232 | buttonPane.add(cancelButton);
|
---|
233 | // ***
|
---|
234 | }
|
---|
235 | }
|
---|
236 | // ***
|
---|
237 | }
|
---|
238 | }
|
---|