Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
3abe9331 | 2 | * Copyright (c) 2000-2015 Ericsson Telecom AB |
970ed795 EL |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | ******************************************************************************/ | |
8 | package org.eclipse.titan.executorapi.demo; | |
9 | ||
10 | import java.awt.Dimension; | |
11 | import java.awt.GridBagConstraints; | |
12 | import java.awt.GridBagLayout; | |
13 | import java.awt.Insets; | |
14 | import java.awt.Toolkit; | |
15 | import java.awt.event.ActionEvent; | |
16 | import java.awt.event.ActionListener; | |
17 | ||
18 | import javax.swing.JButton; | |
19 | import javax.swing.JDialog; | |
20 | import javax.swing.JFrame; | |
21 | import javax.swing.JLabel; | |
22 | import javax.swing.JOptionPane; | |
23 | import javax.swing.JTextField; | |
24 | ||
25 | import org.eclipse.titan.executorapi.JniExecutor; | |
26 | import org.eclipse.titan.executorapi.exception.JniExecutorWrongStateException; | |
27 | ||
28 | public class ExecuteCfgDialog extends JDialog { | |
29 | ||
30 | /** Generated serial version ID to avoid warning */ | |
31 | private static final long serialVersionUID = -2926485859174706529L; | |
32 | ||
33 | private JTextField mTextFieldIndex = new JTextField(); | |
34 | private JButton mButtonExecute = new JButton("Execute"); | |
35 | ||
36 | public ExecuteCfgDialog( final DemoFrame aParent ) { | |
37 | super( aParent, "Execute config file", true ); | |
38 | ||
39 | // init ui elements | |
40 | // default values | |
41 | mTextFieldIndex.setText("0"); | |
42 | ||
43 | mButtonExecute.addActionListener(new ActionListener() { | |
44 | @Override | |
45 | public void actionPerformed(ActionEvent e) { | |
46 | final JniExecutor je = JniExecutor.getInstance(); | |
47 | try { | |
48 | je.executeCfg(Integer.parseInt(mTextFieldIndex.getText())); | |
49 | ExecuteCfgDialog.this.setVisible(false); | |
50 | ExecuteCfgDialog.this.dispose(); | |
51 | } catch (Exception e1) { | |
52 | JOptionPane.showMessageDialog(ExecuteCfgDialog.this, e1.toString(), "Error", JOptionPane.ERROR_MESSAGE); | |
53 | } | |
54 | } | |
55 | }); | |
56 | ||
57 | // add ui elements to layout | |
58 | setLayout( new GridBagLayout() ); | |
59 | GridBagConstraints c = new GridBagConstraints(); | |
60 | c.fill = GridBagConstraints.BOTH; | |
61 | c.insets = new Insets(10, 10, 10, 10); | |
62 | ||
63 | c.gridx = 0; | |
64 | c.gridy = 0; | |
65 | add( new JLabel("Number of testcases:"), c); | |
66 | c.gridy++; | |
67 | add( new JLabel("Testcase index:"), c); | |
68 | ||
69 | c.weightx = 1.0; | |
70 | c.weighty = 0.0; | |
71 | c.gridx = 1; | |
72 | c.gridy = 0; | |
73 | int numTestcases = 0; | |
74 | try { | |
75 | numTestcases = JniExecutor.getInstance().getExecuteCfgLen(); | |
76 | } catch (JniExecutorWrongStateException e1) { | |
77 | JOptionPane.showMessageDialog(ExecuteCfgDialog.this, e1.toString(), "Error", JOptionPane.ERROR_MESSAGE); | |
78 | } | |
79 | add( new JLabel( "" + numTestcases ), c ); | |
80 | c.gridy++; | |
81 | add( mTextFieldIndex, c); | |
82 | ||
83 | c.gridx = 0; | |
84 | c.gridy++; | |
85 | c.gridwidth = 2; | |
86 | c.fill = GridBagConstraints.NONE; | |
87 | add(mButtonExecute, c); | |
88 | ||
89 | setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); | |
90 | setSize( 600, 200 ); | |
91 | // place to the middle of the screen | |
92 | Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); | |
93 | setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2); | |
94 | } | |
95 | } |