Autopsy  4.9.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 2011-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  */
19 package org.sleuthkit.autopsy.report;
20 
21 import java.awt.*;
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 
28 import org.openide.util.NbBundle;
30 
35 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
36 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  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  }
58 
68  ReportProgressPanel addReport(String reportName, String reportPath) {
69  /*
70  * Remove the "glue."
71  */
72  reportPanel.remove(glue);
73 
74  progressPanel = new ReportProgressPanel(reportName, reportPath);
75  constraints.weighty = 0.0;
76  constraints.anchor = GridBagConstraints.NORTH;
77  reportPanel.add(progressPanel, constraints);
78  constraints.gridy++;
79 
80  /*
81  * Add the "glue" back to the bottom of the panel.
82  */
83  constraints.weighty = 1.0;
84  constraints.anchor = GridBagConstraints.PAGE_END;
85  reportPanel.add(glue, constraints);
86 
87  /*
88  * Use 80 pixels per progress panel. This is a leftover from when this
89  * panel used to show multiple report progress panels.
90  */
91  reportPanel.setPreferredSize(new Dimension(600, 1 * 80));
92  reportPanel.repaint();
93  progressPanel.addPropertyChangeListener((PropertyChangeEvent evt) -> {
94  String propName = evt.getPropertyName();
95  if (propName.equals(ReportProgressPanel.ReportStatus.COMPLETE.toString())
96  || propName.equals(ReportProgressPanel.ReportStatus.CANCELED.toString())) {
97  SwingUtilities.invokeLater(() -> {
98  cancelButton.setEnabled(false);
99  });
100  }
101  });
102  return progressPanel;
103  }
104 
108  void close() {
109  boolean closeable = true;
110  if (progressPanel.getStatus() != ReportStatus.CANCELED && progressPanel.getStatus() != ReportStatus.COMPLETE && progressPanel.getStatus() != ReportStatus.ERROR) {
111  closeable = false;
112  }
113  if (closeable) {
114  actionListener.actionPerformed(null);
115  } else {
116  int result = JOptionPane.showConfirmDialog(this,
117  NbBundle.getMessage(this.getClass(),
118  "ReportGenerationPanel.confDlg.sureToClose.msg"),
119  NbBundle.getMessage(this.getClass(),
120  "ReportGenerationPanel.confDlg.title.closing"),
121  JOptionPane.YES_NO_OPTION);
122  if (result == 0) {
123  progressPanel.cancel();
124  actionListener.actionPerformed(null);
125  }
126  }
127  }
128 
134  void addCloseAction(ActionListener listener) {
135  this.actionListener = listener;
136  }
137 
143  @SuppressWarnings("unchecked")
144  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
145  private void initComponents() {
146 
147  closeButton = new javax.swing.JButton();
148  cancelButton = new javax.swing.JButton();
149  reportPanel = new javax.swing.JPanel();
150 
151  setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11));
152  setPreferredSize(new java.awt.Dimension(700, 400));
153 
154  closeButton.setFont(closeButton.getFont().deriveFont(closeButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
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  cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
163  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class, "ReportGenerationPanel.cancelButton.text")); // NOI18N
164  cancelButton.setActionCommand(org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class, "ReportGenerationPanel.cancelButton.actionCommand")); // NOI18N
165  cancelButton.addActionListener(new java.awt.event.ActionListener() {
166  public void actionPerformed(java.awt.event.ActionEvent evt) {
167  cancelButtonActionPerformed(evt);
168  }
169  });
170 
171  reportPanel.setFont(reportPanel.getFont().deriveFont(reportPanel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
172  reportPanel.setPreferredSize(new java.awt.Dimension(600, 400));
173 
174  javax.swing.GroupLayout reportPanelLayout = new javax.swing.GroupLayout(reportPanel);
175  reportPanel.setLayout(reportPanelLayout);
176  reportPanelLayout.setHorizontalGroup(
177  reportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
178  .addGap(0, 0, Short.MAX_VALUE)
179  );
180  reportPanelLayout.setVerticalGroup(
181  reportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
182  .addGap(0, 344, Short.MAX_VALUE)
183  );
184 
185  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
186  this.setLayout(layout);
187  layout.setHorizontalGroup(
188  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
189  .addGroup(layout.createSequentialGroup()
190  .addContainerGap()
191  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
192  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
193  .addGap(0, 546, Short.MAX_VALUE)
194  .addComponent(cancelButton)
195  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
196  .addComponent(closeButton))
197  .addComponent(reportPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 680, Short.MAX_VALUE))
198  .addContainerGap())
199  );
200  layout.setVerticalGroup(
201  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
202  .addGroup(layout.createSequentialGroup()
203  .addContainerGap()
204  .addComponent(reportPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE)
205  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
206  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
207  .addComponent(closeButton)
208  .addComponent(cancelButton))
209  .addContainerGap())
210  );
211  }// </editor-fold>//GEN-END:initComponents
212 
213  private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
214  close();
215  }//GEN-LAST:event_closeButtonActionPerformed
216 
217  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
218  if (progressPanel.getStatus() == ReportStatus.QUEUING || progressPanel.getStatus() == ReportStatus.RUNNING) {
219  int result = JOptionPane.showConfirmDialog(this, NbBundle.getMessage(this.getClass(),
220  "ReportGenerationPanel.confDlg.cancelReport.msg"),
221  NbBundle.getMessage(this.getClass(),
222  "ReportGenerationPanel.cancelButton.text"),
223  JOptionPane.YES_NO_OPTION);
224  if (result == 0) {
225  progressPanel.cancel();
226  }
227  }
228  }//GEN-LAST:event_cancelButtonActionPerformed
229 
230  // Variables declaration - do not modify//GEN-BEGIN:variables
231  private javax.swing.JButton cancelButton;
232  private javax.swing.JButton closeButton;
233  private javax.swing.JPanel reportPanel;
234  // End of variables declaration//GEN-END:variables
235 
236 }

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.