Autopsy  4.13.0
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  */
19 package org.sleuthkit.autopsy.report.infrastructure;
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 import org.openide.util.NbBundle;
30 
35 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
36 final 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  setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11));
154  setPreferredSize(new java.awt.Dimension(700, 400));
155 
156  closeButton.setFont(closeButton.getFont().deriveFont(closeButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
157  org.openide.awt.Mnemonics.setLocalizedText(closeButton, org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class, "ReportGenerationPanel.closeButton.text")); // NOI18N
158  closeButton.addActionListener(new java.awt.event.ActionListener() {
159  public void actionPerformed(java.awt.event.ActionEvent evt) {
160  closeButtonActionPerformed(evt);
161  }
162  });
163 
164  cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
165  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class, "ReportGenerationPanel.cancelButton.text")); // NOI18N
166  cancelButton.setActionCommand(org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class, "ReportGenerationPanel.cancelButton.actionCommand")); // NOI18N
167  cancelButton.addActionListener(new java.awt.event.ActionListener() {
168  public void actionPerformed(java.awt.event.ActionEvent evt) {
169  cancelButtonActionPerformed(evt);
170  }
171  });
172 
173  reportPanel.setFont(reportPanel.getFont().deriveFont(reportPanel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
174  reportPanel.setPreferredSize(new java.awt.Dimension(600, 400));
175 
176  javax.swing.GroupLayout reportPanelLayout = new javax.swing.GroupLayout(reportPanel);
177  reportPanel.setLayout(reportPanelLayout);
178  reportPanelLayout.setHorizontalGroup(
179  reportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
180  .addGap(0, 0, Short.MAX_VALUE)
181  );
182  reportPanelLayout.setVerticalGroup(
183  reportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
184  .addGap(0, 344, Short.MAX_VALUE)
185  );
186 
187  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
188  this.setLayout(layout);
189  layout.setHorizontalGroup(
190  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
191  .addGroup(layout.createSequentialGroup()
192  .addContainerGap()
193  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
194  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
195  .addGap(0, 546, Short.MAX_VALUE)
196  .addComponent(cancelButton)
197  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
198  .addComponent(closeButton))
199  .addComponent(reportPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 680, Short.MAX_VALUE))
200  .addContainerGap())
201  );
202  layout.setVerticalGroup(
203  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204  .addGroup(layout.createSequentialGroup()
205  .addContainerGap()
206  .addComponent(reportPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE)
207  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
208  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
209  .addComponent(closeButton)
210  .addComponent(cancelButton))
211  .addContainerGap())
212  );
213  }// </editor-fold>//GEN-END:initComponents
214 
215  private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
216  close();
217  }//GEN-LAST:event_closeButtonActionPerformed
218 
219  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
220  if (progressPanel.getStatus() == ReportStatus.QUEUING || progressPanel.getStatus() == ReportStatus.RUNNING) {
221  int result = JOptionPane.showConfirmDialog(this, NbBundle.getMessage(this.getClass(),
222  "ReportGenerationPanel.confDlg.cancelReport.msg"),
223  NbBundle.getMessage(this.getClass(),
224  "ReportGenerationPanel.cancelButton.text"),
225  JOptionPane.YES_NO_OPTION);
226  if (result == 0) {
227  progressPanel.cancel();
228  }
229  }
230  }//GEN-LAST:event_cancelButtonActionPerformed
231 
232  // Variables declaration - do not modify//GEN-BEGIN:variables
233  private javax.swing.JButton cancelButton;
234  private javax.swing.JButton closeButton;
235  private javax.swing.JPanel reportPanel;
236  // End of variables declaration//GEN-END:variables
237 
238 }

Copyright © 2012-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.