-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathExcludeTimeRangeAnalysisDialog.java
More file actions
365 lines (330 loc) · 10.9 KB
/
ExcludeTimeRangeAnalysisDialog.java
File metadata and controls
365 lines (330 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/*
* Copyright 2012 AT&T
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.att.aro.main.menu.view;
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.text.ParseException;
import java.util.ResourceBundle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.att.aro.commonui.MessageDialogFactory;
import com.att.aro.main.ApplicationResourceOptimizer;
import com.att.aro.main.ResourceBundleManager;
import com.att.aro.model.TimeRange;
import com.att.aro.model.TraceData;
/**
* Represents the Select Time Range Dialog Dialog (accessed through the View menu)
* that allows the user to set a time range that delineates a section of the
* trace data to be analyzed.
*/
public class ExcludeTimeRangeAnalysisDialog extends JDialog {
private static final long serialVersionUID = 1L;
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("0.00");
private static ResourceBundle rb = ResourceBundleManager.getDefaultBundle();
private static double endTimeResetValue = 0.0;
private JPanel timeRangeSelectionPanel;
private JPanel jDialogPanel;
private JButton startButton;
private JButton cancelButton;
private JButton resetButton;
private JTextField startTimeTextField;
private JTextField endTimeTextField;
private Double traceEndTime;
private double timeRangeStartTime;
private double timeRangeEndTime;
private ApplicationResourceOptimizer aro;
private TraceData.Analysis analysisData;
private JPanel jButtonPanel;
private JPanel jButtonGrid;
/**
* Initializes a new instance of the ExcludeTimeRangeAnalysisDialog class
* using the specified instance of the ApplicationResourceOptimizer as the
* owner.
*
* @param owner
* The ApplicationResourceOptimizer instance.
*
* @param analysisData
* An Analysis object containing the trace data.
*/
public ExcludeTimeRangeAnalysisDialog(ApplicationResourceOptimizer owner,
TraceData.Analysis analysisData) {
super(owner);
this.aro = owner;
if(endTimeResetValue == 0.0){
endTimeResetValue = analysisData.getTraceData().getTraceDuration();
}
this.traceEndTime = endTimeResetValue;
TimeRange timeRange = analysisData.getFilter().getTimeRange();
if(timeRange != null){
this.timeRangeStartTime = timeRange.getBeginTime();
this.timeRangeEndTime = timeRange.getEndTime();
}else{
this.timeRangeStartTime = 0.0;
this.timeRangeEndTime = traceEndTime;
}
this.analysisData = analysisData;
initialize();
}
/**
* Initializes the dialog.
*
* @return void
*/
private void initialize() {
this.setSize(400, 150);
this.setModal(true);
this.setTitle(rb.getString("excludetimerangeanalysis.title"));
this.setLocationRelativeTo(getOwner());
this.setContentPane(getJDialogPanel());
}
/**
* Initializes jDialogPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJDialogPanel() {
if (jDialogPanel == null) {
jDialogPanel = new JPanel();
jDialogPanel.setLayout(new BorderLayout());
jDialogPanel.add(getTimeRangeSelectionPanel(), BorderLayout.CENTER);
jDialogPanel.add(getJButtonPanel(), BorderLayout.SOUTH);
}
return jDialogPanel;
}
/**
* Initializes and returns the JPanel that holds the Ok and Cancel button.
*/
private JPanel getJButtonGrid() {
if (jButtonGrid == null) {
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(1);
gridLayout.setHgap(10);
jButtonGrid = new JPanel();
jButtonGrid.setBorder(BorderFactory.createEmptyBorder(10, 10, 10,
10));
jButtonGrid.setLayout(gridLayout);
jButtonGrid.add(getOKButton(), null);
jButtonGrid.add(getCancelButton(), null);
}
return jButtonGrid;
}
/**
* Initializes jButtonPanel
*/
private JPanel getJButtonPanel() {
if (jButtonPanel == null) {
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = -1;
gridBagConstraints.gridy = -1;
jButtonPanel = new JPanel();
jButtonPanel.setLayout(new BorderLayout());
jButtonPanel.add(getJButtonGrid(), BorderLayout.EAST);
}
return jButtonPanel;
}
/**
* Initializes and returns the timeRangeSelectionPanel
*
* @return javax.swing.JPanel
*/
private JPanel getTimeRangeSelectionPanel() {
if (timeRangeSelectionPanel == null) {
timeRangeSelectionPanel = new JPanel();
// timeRangeSelectionPanel.setPreferredSize(new Dimension(75, 75));
JLabel startTimeLabel = new JLabel(
rb.getString("timerangeanalysis.start"));
JLabel endTimeLabel = new JLabel(
rb.getString("timerangeanalysis.end"));
timeRangeSelectionPanel.add(startTimeLabel);
timeRangeSelectionPanel.add(getStartTimeTextField());
timeRangeSelectionPanel.add(endTimeLabel);
timeRangeSelectionPanel.add(getEndTimeTextField());
timeRangeSelectionPanel.add(getResetButton());
}
return timeRangeSelectionPanel;
}
/**
* Initializes and returns the start button
*/
private JButton getOKButton() {
if (startButton == null) {
startButton = new JButton();
startButton.setText(rb.getString("Button.ok"));
startButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
if (analysisData != null) {
double startTime;
double endTime;
try {
startTime = getTimeValue(startTimeTextField);
endTime = getTimeValue(endTimeTextField);
analysisData.getFilter().setTimeRange(new TimeRange(startTime, endTime));
} catch (NumberFormatException e) {
MessageDialogFactory.showErrorDialog(
ExcludeTimeRangeAnalysisDialog.this,
rb.getString("timerangeanalysis.numberError"));
return;
}
// Rounding traceEndTime as getEndTimeTextField() to
// handle time comparison
Double traceEndTimeRounded = new BigDecimal(traceEndTime).setScale(2, RoundingMode.HALF_UP).doubleValue();
if (startTime < endTime) {
if (((startTime >= 0.0) && (startTime <= traceEndTimeRounded))
&& ((endTime >= 0.0) && (endTime <= traceEndTimeRounded))) {
try {
aro.performExcludeTimeRangeAnalysis(
startTime, endTime);
ExcludeTimeRangeAnalysisDialog.this
.dispose();
} catch (IOException e) {
e.printStackTrace();
}
} else {
String strErrorMessage = MessageFormat.format(
rb.getString("timerangeanalysis.rangeError"),
0.00, DECIMAL_FORMAT
.format(traceEndTimeRounded));
MessageDialogFactory.showMessageDialog(
ExcludeTimeRangeAnalysisDialog.this,
strErrorMessage,
rb.getString("Error.title"),
JOptionPane.ERROR_MESSAGE);
}
} else {
String strErrorMessage = rb
.getString("timerangeanalysis.startTimeError");
MessageDialogFactory.showMessageDialog(
ExcludeTimeRangeAnalysisDialog.this,
strErrorMessage,
rb.getString("Error.title"),
JOptionPane.ERROR_MESSAGE);
}
} else {
MessageDialogFactory.showMessageDialog(
ExcludeTimeRangeAnalysisDialog.this,
rb.getString("Error.notrace"),
rb.getString("Error.title"),
JOptionPane.ERROR_MESSAGE);
}
}
});
}
return startButton;
}
/**
* Initializes and returns the cancel button.
*/
private JButton getResetButton() {
if (resetButton == null) {
resetButton = new JButton();
resetButton.setText(rb.getString("Button.reset"));
resetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
traceEndTime = endTimeResetValue;
startTimeTextField.setText(DECIMAL_FORMAT.format(0.0));
endTimeTextField.setText(DECIMAL_FORMAT.format(endTimeResetValue));
}
});
}
return resetButton;
}
/**
* Initializes and returns the cancel button.
*/
private JButton getCancelButton() {
if (cancelButton == null) {
cancelButton = new JButton();
cancelButton.setText(rb.getString("Button.cancel"));
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
ExcludeTimeRangeAnalysisDialog.this.dispose();
}
});
}
return cancelButton;
}
/**
* Initializes and returns the startTimeTextField
*/
private JTextField getStartTimeTextField() {
if (startTimeTextField == null) {
startTimeTextField = new JTextField(8);
String strStartTime = DECIMAL_FORMAT.format(timeRangeStartTime);
startTimeTextField.setText(strStartTime);
}
return startTimeTextField;
}
/**
* Returns the start time from the start time field
*/
private Double getTimeValue(JTextField field) throws NumberFormatException {
Number value= null;
try {
value = DECIMAL_FORMAT.parse(field.getText());
} catch (ParseException e) {
throw new NumberFormatException();
}
return value.doubleValue();
}
/**
* Initializes and returns the endTimeTextField
*/
private JTextField getEndTimeTextField() {
if (endTimeTextField == null) {
endTimeTextField = new JTextField(8);
String strEndTime = DECIMAL_FORMAT.format(timeRangeEndTime);
endTimeTextField.setText(strEndTime);
}
return endTimeTextField;
}
/**
* Sets a value that indicates the visibility of the TimeRangeAnalysis
* dialog box.
*
* @param b
* A boolean value that indicates whether the TimeRangeAnalysis
* dialog box is visible.
*
* @see java.awt.Dialog#setVisible(boolean)
*/
@Override
public void setVisible(boolean b) {
if (!isVisible() || !b) {
DecimalFormat decimalFormat = new DecimalFormat("0.00");
startTimeTextField
.setText(decimalFormat.format(timeRangeStartTime));
endTimeTextField.setText(decimalFormat.format(timeRangeEndTime));
}
super.setVisible(b);
}
}