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

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.