Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ReportGenerationPanel.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2012-2018 Basis Technology Corp.
5 * Contact: carrier <at> sleuthkit <dot> org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19package org.sleuthkit.autopsy.report.infrastructure;
20
21import java.awt.*;
22import java.awt.event.ActionListener;
23import java.beans.PropertyChangeEvent;
24import javax.swing.Box;
25import javax.swing.JOptionPane;
26import javax.swing.SwingUtilities;
27import org.openide.util.NbBundle;
28import org.sleuthkit.autopsy.report.ReportProgressPanel.ReportStatus;
29import org.sleuthkit.autopsy.report.ReportProgressPanel;
30
35@SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
36final class ReportGenerationPanel extends javax.swing.JPanel {
37
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;
43
48 ReportGenerationPanel() {
49 initComponents();
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();
58 }
59
60 ReportProgressPanel getProgressPanel() {
61 return progressPanel;
62 }
63
71 void addReport(String reportName, String reportPath) {
72 /*
73 * Remove the "glue."
74 */
75 reportPanel.remove(glue);
76
77 progressPanel.setLabels(reportName, reportPath);
78 constraints.weighty = 0.0;
79 constraints.anchor = GridBagConstraints.NORTH;
80 reportPanel.add(progressPanel, constraints);
81 constraints.gridy++;
82
83 /*
84 * Add the "glue" back to the bottom of the panel.
85 */
86 constraints.weighty = 1.0;
87 constraints.anchor = GridBagConstraints.PAGE_END;
88 reportPanel.add(glue, constraints);
89
90 /*
91 * Use 80 pixels per progress panel. This is a leftover from when this
92 * panel used to show multiple report progress panels.
93 */
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);
102 });
103 }
104 });
105 }
106
110 void close() {
111 boolean closeable = true;
112 if (progressPanel.getStatus() != ReportStatus.CANCELED && progressPanel.getStatus() != ReportStatus.COMPLETE && progressPanel.getStatus() != ReportStatus.ERROR) {
113 closeable = false;
114 }
115 if (closeable) {
116 actionListener.actionPerformed(null);
117 } else {
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);
124 if (result == 0) {
125 progressPanel.cancel();
126 actionListener.actionPerformed(null);
127 }
128 }
129 }
130
136 void addCloseAction(ActionListener listener) {
137 this.actionListener = listener;
138 }
139
145 @SuppressWarnings("unchecked")
146 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
147 private void initComponents() {
148
149 closeButton = new javax.swing.JButton();
150 cancelButton = new javax.swing.JButton();
151 reportPanel = new javax.swing.JPanel();
152
153 setPreferredSize(new java.awt.Dimension(700, 400));
154
155 org.openide.awt.Mnemonics.setLocalizedText(closeButton, org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class, "ReportGenerationPanel.closeButton.text")); // NOI18N
156 closeButton.addActionListener(new java.awt.event.ActionListener() {
157 public void actionPerformed(java.awt.event.ActionEvent evt) {
158 closeButtonActionPerformed(evt);
159 }
160 });
161
162 org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class, "ReportGenerationPanel.cancelButton.text")); // NOI18N
163 cancelButton.setActionCommand(org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class, "ReportGenerationPanel.cancelButton.actionCommand")); // NOI18N
164 cancelButton.addActionListener(new java.awt.event.ActionListener() {
165 public void actionPerformed(java.awt.event.ActionEvent evt) {
166 cancelButtonActionPerformed(evt);
167 }
168 });
169
170 reportPanel.setPreferredSize(new java.awt.Dimension(600, 400));
171
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)
177 );
178 reportPanelLayout.setVerticalGroup(
179 reportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
180 .addGap(0, 344, Short.MAX_VALUE)
181 );
182
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()
188 .addContainerGap()
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))
196 .addContainerGap())
197 );
198 layout.setVerticalGroup(
199 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
200 .addGroup(layout.createSequentialGroup()
201 .addContainerGap()
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))
207 .addContainerGap())
208 );
209 }// </editor-fold>//GEN-END:initComponents
210
211 private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
212 close();
213 }//GEN-LAST:event_closeButtonActionPerformed
214
215 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
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);
222 if (result == 0) {
223 progressPanel.cancel();
224 }
225 }
226 }//GEN-LAST:event_cancelButtonActionPerformed
227
228 // Variables declaration - do not modify//GEN-BEGIN:variables
229 private javax.swing.JButton cancelButton;
230 private javax.swing.JButton closeButton;
231 private javax.swing.JPanel reportPanel;
232 // End of variables declaration//GEN-END:variables
233
234}
final void setLabels(String reportName, String reportPath)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.