Line 0
Link Here
|
|
|
1 |
/* |
2 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
3 |
* contributor license agreements. See the NOTICE file distributed with |
4 |
* this work for additional information regarding copyright ownership. |
5 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
6 |
* (the "License"); you may not use this file except in compliance with |
7 |
* the License. You may obtain a copy of the License at |
8 |
* |
9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
10 |
* |
11 |
* Unless required by applicable law or agreed to in writing, software |
12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 |
* See the License for the specific language governing permissions and |
15 |
* limitations under the License. |
16 |
* |
17 |
*/ |
18 |
|
19 |
package org.apache.jmeter.protocol.http.proxy.gui; |
20 |
|
21 |
import java.awt.BorderLayout; |
22 |
import java.awt.GridBagConstraints; |
23 |
import java.awt.GridBagLayout; |
24 |
import java.awt.event.ActionEvent; |
25 |
import java.awt.event.ItemEvent; |
26 |
import java.awt.event.ItemListener; |
27 |
import java.awt.event.KeyEvent; |
28 |
import java.awt.event.KeyListener; |
29 |
|
30 |
import javax.swing.AbstractAction; |
31 |
import javax.swing.Action; |
32 |
import javax.swing.ActionMap; |
33 |
import javax.swing.BorderFactory; |
34 |
import javax.swing.DefaultComboBoxModel; |
35 |
import javax.swing.InputMap; |
36 |
import javax.swing.JComboBox; |
37 |
import javax.swing.JComponent; |
38 |
import javax.swing.JDialog; |
39 |
import javax.swing.JFrame; |
40 |
import javax.swing.JLabel; |
41 |
import javax.swing.JOptionPane; |
42 |
import javax.swing.JPanel; |
43 |
import javax.swing.JRootPane; |
44 |
import javax.swing.JTextField; |
45 |
|
46 |
import org.apache.jmeter.gui.action.KeyStrokes; |
47 |
import org.apache.jmeter.util.JMeterUtils; |
48 |
|
49 |
/** |
50 |
* Dialog for Recorder |
51 |
*/ |
52 |
public class RecorderDialog extends JDialog implements ItemListener, KeyListener { // NOSONAR |
53 |
|
54 |
|
55 |
/** |
56 |
* |
57 |
*/ |
58 |
private static final long serialVersionUID = 931790497924069705L; |
59 |
|
60 |
/** |
61 |
* Add a prefix/transaction name to HTTP sample name recorded |
62 |
*/ |
63 |
private JTextField prefixHTTPSampleName; |
64 |
|
65 |
private JTextField proxyPauseHTTPSample; |
66 |
|
67 |
/** |
68 |
* To choose between a prefix or a transaction name |
69 |
*/ |
70 |
private JComboBox<String> httpSampleNamingMode; |
71 |
|
72 |
private ProxyControlGui recorderGui; |
73 |
|
74 |
public RecorderDialog(ProxyControlGui controlGui) { |
75 |
super((JFrame) null, JMeterUtils.getResString("proxy_recorder_dialog"), false); //$NON-NLS-1$ |
76 |
this.recorderGui = controlGui; |
77 |
this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); |
78 |
this.setResizable(false); |
79 |
init(); |
80 |
} |
81 |
|
82 |
@Override |
83 |
protected JRootPane createRootPane() { |
84 |
JRootPane rootPane = new JRootPane(); |
85 |
// Hide Window on ESC |
86 |
Action escapeAction = new AbstractAction("ESCAPE") { |
87 |
|
88 |
private static final long serialVersionUID = -6543764044868772971L; |
89 |
|
90 |
@Override |
91 |
public void actionPerformed(ActionEvent actionEvent) { |
92 |
setVisible(false); |
93 |
} |
94 |
}; |
95 |
|
96 |
ActionMap actionMap = rootPane.getActionMap(); |
97 |
actionMap.put(escapeAction.getValue(Action.NAME), escapeAction); |
98 |
InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); |
99 |
inputMap.put(KeyStrokes.ESC, escapeAction.getValue(Action.NAME)); |
100 |
|
101 |
return rootPane; |
102 |
} |
103 |
|
104 |
private void init() { // WARNING: called from ctor so must not be overridden (i.e. must be private or final) |
105 |
this.getContentPane().setLayout(new BorderLayout(10,10)); |
106 |
|
107 |
DefaultComboBoxModel<String> choice = new DefaultComboBoxModel<>(); |
108 |
choice.addElement(JMeterUtils.getResString("sample_name_prefix")); // $NON-NLS-1$ |
109 |
choice.addElement(JMeterUtils.getResString("sample_name_transaction")); // $NON-NLS-1$ |
110 |
httpSampleNamingMode = new JComboBox<>(choice); |
111 |
httpSampleNamingMode.setName(ProxyControlGui.HTTP_SAMPLER_NAMING_MODE); |
112 |
httpSampleNamingMode.addItemListener(this); |
113 |
|
114 |
prefixHTTPSampleName = new JTextField(20); |
115 |
prefixHTTPSampleName.addKeyListener(this); |
116 |
prefixHTTPSampleName.setName(ProxyControlGui.PREFIX_HTTP_SAMPLER_NAME); |
117 |
|
118 |
proxyPauseHTTPSample = new JTextField(10); |
119 |
proxyPauseHTTPSample.addKeyListener(this); |
120 |
proxyPauseHTTPSample.setName(ProxyControlGui.PROXY_PAUSE_HTTP_SAMPLER); |
121 |
|
122 |
proxyPauseHTTPSample.setActionCommand(ProxyControlGui.ENABLE_RESTART); |
123 |
JLabel labelProxyPause = new JLabel(JMeterUtils.getResString("proxy_pause_http_sampler")); // $NON-NLS-1$ |
124 |
labelProxyPause.setLabelFor(proxyPauseHTTPSample); |
125 |
|
126 |
GridBagLayout gridBagLayout = new GridBagLayout(); |
127 |
GridBagConstraints gbc = new GridBagConstraints(); |
128 |
gbc.anchor = GridBagConstraints.FIRST_LINE_START; |
129 |
gbc.fill = GridBagConstraints.NONE; |
130 |
gbc.gridheight = 1; |
131 |
gbc.gridwidth = 1; |
132 |
gbc.gridx = 0; |
133 |
gbc.gridy = 0; |
134 |
gbc.weightx = 1; |
135 |
gbc.weighty = 1; |
136 |
JPanel panel = new JPanel(gridBagLayout); |
137 |
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), |
138 |
JMeterUtils.getResString("proxy_sampler_settings"))); // $NON-NLS-1$ |
139 |
panel.add(httpSampleNamingMode, gbc.clone()); |
140 |
gbc.gridx++; |
141 |
gbc.weightx = 3; |
142 |
gbc.fill=GridBagConstraints.HORIZONTAL; |
143 |
panel.add(prefixHTTPSampleName, gbc.clone()); |
144 |
gbc.gridx = 0; |
145 |
gbc.gridy++; |
146 |
panel.add(labelProxyPause, gbc.clone()); |
147 |
gbc.gridx++; |
148 |
gbc.weightx = 3; |
149 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
150 |
panel.add(proxyPauseHTTPSample, gbc.clone()); |
151 |
|
152 |
this.getContentPane().add(panel, BorderLayout.NORTH); |
153 |
this.pack(); |
154 |
this.setLocation(5, 10); |
155 |
prefixHTTPSampleName.requestFocusInWindow(); |
156 |
} |
157 |
|
158 |
|
159 |
|
160 |
/* (non-Javadoc) |
161 |
* @see java.awt.Dialog#setVisible(boolean) |
162 |
*/ |
163 |
@Override |
164 |
public void setVisible(boolean b) { |
165 |
super.setVisible(b); |
166 |
prefixHTTPSampleName.requestFocusInWindow(); |
167 |
httpSampleNamingMode.setSelectedIndex(recorderGui.getRecorderModel().getHTTPSampleNamingMode()); |
168 |
proxyPauseHTTPSample.setText(recorderGui.getRecorderModel().getProxyPauseHTTPSample()); |
169 |
setAlwaysOnTop(b); |
170 |
} |
171 |
|
172 |
@Override |
173 |
public void itemStateChanged(ItemEvent e) { |
174 |
if (e.getSource() instanceof JComboBox) { |
175 |
JComboBox combo = (JComboBox) e.getSource(); |
176 |
if(ProxyControlGui.HTTP_SAMPLER_NAMING_MODE.equals(combo.getName())){ |
177 |
recorderGui.getRecorderModel().setHTTPSampleNamingMode(httpSampleNamingMode.getSelectedIndex()); |
178 |
} |
179 |
} |
180 |
else { |
181 |
recorderGui.enableRestart(); |
182 |
} |
183 |
} |
184 |
|
185 |
/** {@inheritDoc} */ |
186 |
@Override |
187 |
public void keyPressed(KeyEvent e) { |
188 |
// NOOP |
189 |
} |
190 |
|
191 |
/** {@inheritDoc} */ |
192 |
@Override |
193 |
public void keyTyped(KeyEvent e) { |
194 |
// NOOP |
195 |
} |
196 |
|
197 |
/** {@inheritDoc} */ |
198 |
@Override |
199 |
public void keyReleased(KeyEvent e) { |
200 |
String fieldName = e.getComponent().getName(); |
201 |
if(fieldName.equals(ProxyControlGui.PREFIX_HTTP_SAMPLER_NAME)) { |
202 |
recorderGui.getRecorderModel().setPrefixHTTPSampleName(prefixHTTPSampleName.getText()); |
203 |
} else if(fieldName.equals(ProxyControlGui.PROXY_PAUSE_HTTP_SAMPLER)) { |
204 |
try { |
205 |
Long.parseLong(proxyPauseHTTPSample.getText()); |
206 |
} catch (NumberFormatException nfe) { |
207 |
int length = proxyPauseHTTPSample.getText().length(); |
208 |
if (length > 0) { |
209 |
JOptionPane.showMessageDialog(this, JMeterUtils.getResString("proxy_settings_pause_error_digits"), // $NON-NLS-1$ |
210 |
JMeterUtils.getResString("proxy_settings_pause_error_invalid_data"), // $NON-NLS-1$ |
211 |
JOptionPane.WARNING_MESSAGE); |
212 |
// Drop the last character: |
213 |
proxyPauseHTTPSample.setText(proxyPauseHTTPSample.getText().substring(0, length - 1)); |
214 |
} |
215 |
} |
216 |
recorderGui.getRecorderModel().setProxyPauseHTTPSample(proxyPauseHTTPSample.getText()); |
217 |
recorderGui.enableRestart(); |
218 |
} |
219 |
} |
220 |
} |