19 package org.sleuthkit.autopsy.report.infrastructure;
22 import java.awt.event.ActionListener;
23 import java.beans.PropertyChangeEvent;
24 import javax.swing.Box;
25 import javax.swing.JOptionPane;
26 import javax.swing.SwingUtilities;
27 import org.openide.util.NbBundle;
35 @SuppressWarnings(
"PMD.SingularField")
36 final class ReportGenerationPanel extends javax.swing.JPanel {
38 private static final long serialVersionUID = 1L;
39 private final GridBagConstraints constraints;
40 private final Component glue;
41 private ActionListener actionListener;
42 private final ReportProgressPanel progressPanel;
48 ReportGenerationPanel() {
50 reportPanel.setLayout(
new GridBagLayout());
51 constraints =
new GridBagConstraints();
52 constraints.fill = GridBagConstraints.BOTH;
53 constraints.gridx = 0;
54 constraints.gridy = 0;
55 constraints.weightx = 1.0;
56 glue = Box.createVerticalGlue();
57 progressPanel =
new ReportProgressPanel();
60 ReportProgressPanel getProgressPanel() {
71 void addReport(String reportName, String reportPath) {
75 reportPanel.remove(glue);
77 progressPanel.setLabels(reportName, reportPath);
78 constraints.weighty = 0.0;
79 constraints.anchor = GridBagConstraints.NORTH;
80 reportPanel.add(progressPanel, constraints);
86 constraints.weighty = 1.0;
87 constraints.anchor = GridBagConstraints.PAGE_END;
88 reportPanel.add(glue, constraints);
94 reportPanel.setPreferredSize(
new Dimension(600, 1 * 80));
95 reportPanel.repaint();
96 progressPanel.addPropertyChangeListener((PropertyChangeEvent evt) -> {
97 String propName = evt.getPropertyName();
98 if (propName.equals(ReportProgressPanel.ReportStatus.COMPLETE.toString())
99 || propName.equals(ReportProgressPanel.ReportStatus.CANCELED.toString())) {
100 SwingUtilities.invokeLater(() -> {
101 cancelButton.setEnabled(
false);
111 boolean closeable =
true;
112 if (progressPanel.getStatus() != ReportStatus.CANCELED && progressPanel.getStatus() != ReportStatus.COMPLETE && progressPanel.getStatus() != ReportStatus.ERROR) {
116 actionListener.actionPerformed(null);
118 int result = JOptionPane.showConfirmDialog(
this,
119 NbBundle.getMessage(
this.getClass(),
120 "ReportGenerationPanel.confDlg.sureToClose.msg"),
121 NbBundle.getMessage(
this.getClass(),
122 "ReportGenerationPanel.confDlg.title.closing"),
123 JOptionPane.YES_NO_OPTION);
125 progressPanel.cancel();
126 actionListener.actionPerformed(null);
136 void addCloseAction(ActionListener listener) {
137 this.actionListener = listener;
145 @SuppressWarnings(
"unchecked")
147 private
void initComponents() {
149 closeButton =
new javax.swing.JButton();
150 cancelButton =
new javax.swing.JButton();
151 reportPanel =
new javax.swing.JPanel();
153 setPreferredSize(
new java.awt.Dimension(700, 400));
155 org.openide.awt.Mnemonics.setLocalizedText(closeButton,
org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class,
"ReportGenerationPanel.closeButton.text"));
156 closeButton.addActionListener(
new java.awt.event.ActionListener() {
157 public void actionPerformed(java.awt.event.ActionEvent evt) {
158 closeButtonActionPerformed(evt);
162 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class,
"ReportGenerationPanel.cancelButton.text"));
163 cancelButton.setActionCommand(
org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class,
"ReportGenerationPanel.cancelButton.actionCommand"));
164 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
165 public void actionPerformed(java.awt.event.ActionEvent evt) {
166 cancelButtonActionPerformed(evt);
170 reportPanel.setPreferredSize(
new java.awt.Dimension(600, 400));
172 javax.swing.GroupLayout reportPanelLayout =
new javax.swing.GroupLayout(reportPanel);
173 reportPanel.setLayout(reportPanelLayout);
174 reportPanelLayout.setHorizontalGroup(
175 reportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
176 .addGap(0, 0, Short.MAX_VALUE)
178 reportPanelLayout.setVerticalGroup(
179 reportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
180 .addGap(0, 344, Short.MAX_VALUE)
183 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
184 this.setLayout(layout);
185 layout.setHorizontalGroup(
186 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
187 .addGroup(layout.createSequentialGroup()
189 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
190 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
191 .addGap(0, 546, Short.MAX_VALUE)
192 .addComponent(cancelButton)
193 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
194 .addComponent(closeButton))
195 .addComponent(reportPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 680, Short.MAX_VALUE))
198 layout.setVerticalGroup(
199 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
200 .addGroup(layout.createSequentialGroup()
202 .addComponent(reportPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE)
203 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
204 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
205 .addComponent(closeButton)
206 .addComponent(cancelButton))
211 private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {
215 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
216 if (progressPanel.getStatus() == ReportStatus.QUEUING || progressPanel.getStatus() == ReportStatus.RUNNING) {
217 int result = JOptionPane.showConfirmDialog(
this, NbBundle.getMessage(
this.getClass(),
218 "ReportGenerationPanel.confDlg.cancelReport.msg"),
219 NbBundle.getMessage(
this.getClass(),
220 "ReportGenerationPanel.cancelButton.text"),
221 JOptionPane.YES_NO_OPTION);
223 progressPanel.cancel();
229 private javax.swing.JButton cancelButton;
230 private javax.swing.JButton closeButton;
231 private javax.swing.JPanel reportPanel;