Autopsy  3.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 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 javax.swing.Box;
24 import javax.swing.JOptionPane;
25 
26 import org.openide.util.NbBundle;
28 
29  class ReportGenerationPanel extends javax.swing.JPanel {
30  private GridBagConstraints c;
31  ReportProgressPanel progressPanel;
32  private Component glue;
33  private ActionListener actionListener;
34 
38  public ReportGenerationPanel() {
39  initComponents();
40  customInit();
41  }
42 
43  private void customInit() {
44  reportPanel.setLayout(new GridBagLayout());
45  c = new GridBagConstraints();
46  c.fill = GridBagConstraints.BOTH;
47  c.gridx = 0;
48  c.gridy = 0;
49  c.weightx = 1.0;
50  glue = Box.createVerticalGlue();
51  }
52 
60  public ReportProgressPanel addReport(String reportName, String reportPath) {
61  // Remove the glue
62  reportPanel.remove(glue);
63 
64  progressPanel = new ReportProgressPanel(reportName, reportPath);
65  c.weighty = 0.0;
66  c.anchor = GridBagConstraints.NORTH;
67  reportPanel.add(progressPanel, c);
68  c.gridy++;
69 
70  // Add the glue back to the bottom
71  c.weighty = 1.0;
72  c.anchor = GridBagConstraints.PAGE_END;
73  reportPanel.add(glue, c);
74 
75  // 80 px per progressPanel.
76  reportPanel.setPreferredSize(new Dimension(600, 1 * 80));
77  reportPanel.repaint();
78  return progressPanel;
79  }
80 
84  void close() {
85  boolean closeable = true;
86  if (progressPanel.getStatus() != ReportStatus.CANCELED && progressPanel.getStatus() != ReportStatus.COMPLETE && progressPanel.getStatus() != ReportStatus.ERROR) {
87  closeable = false;
88  }
89  if (closeable) {
90  actionListener.actionPerformed(null);
91  } else {
92  int result = JOptionPane.showConfirmDialog(null,
93  NbBundle.getMessage(this.getClass(),
94  "ReportGenerationPanel.confDlg.sureToClose.msg"),
95  NbBundle.getMessage(this.getClass(),
96  "ReportGenerationPanel.confDlg.title.closing"),
97  JOptionPane.YES_NO_OPTION);
98  if (result == 0) {
99  progressPanel.cancel();
100  actionListener.actionPerformed(null);
101  }
102  }
103  }
104 
105 
111  @SuppressWarnings("unchecked")
112  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
113  private void initComponents() {
114 
115  closeButton = new javax.swing.JButton();
116  cancelButton = new javax.swing.JButton();
117  reportScrollPane = new javax.swing.JScrollPane();
118  reportPanel = new javax.swing.JPanel();
119  titleLabel = new javax.swing.JLabel();
120  titleSeparator = new javax.swing.JSeparator();
121  optionSeparator = new javax.swing.JSeparator();
122 
123  setPreferredSize(new java.awt.Dimension(700, 400));
124 
125  org.openide.awt.Mnemonics.setLocalizedText(closeButton, org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class, "ReportGenerationPanel.closeButton.text")); // NOI18N
126  closeButton.addActionListener(new java.awt.event.ActionListener() {
127  public void actionPerformed(java.awt.event.ActionEvent evt) {
128  closeButtonActionPerformed(evt);
129  }
130  });
131 
132  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class, "ReportGenerationPanel.cancelButton.text")); // NOI18N
133  cancelButton.setActionCommand(org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class, "ReportGenerationPanel.cancelButton.actionCommand")); // NOI18N
134  cancelButton.addActionListener(new java.awt.event.ActionListener() {
135  public void actionPerformed(java.awt.event.ActionEvent evt) {
136  cancelButtonActionPerformed(evt);
137  }
138  });
139 
140  reportScrollPane.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.SystemColor.activeCaptionBorder));
141  reportScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
142 
143  reportPanel.setPreferredSize(new java.awt.Dimension(600, 400));
144 
145  javax.swing.GroupLayout reportPanelLayout = new javax.swing.GroupLayout(reportPanel);
146  reportPanel.setLayout(reportPanelLayout);
147  reportPanelLayout.setHorizontalGroup(
148  reportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
149  .addGap(0, 661, Short.MAX_VALUE)
150  );
151  reportPanelLayout.setVerticalGroup(
152  reportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
153  .addGap(0, 400, Short.MAX_VALUE)
154  );
155 
156  reportScrollPane.setViewportView(reportPanel);
157 
158  titleLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
159  org.openide.awt.Mnemonics.setLocalizedText(titleLabel, org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class, "ReportGenerationPanel.titleLabel.text")); // NOI18N
160 
161  titleSeparator.setForeground(new java.awt.Color(0, 0, 0));
162 
163  optionSeparator.setForeground(new java.awt.Color(0, 0, 0));
164 
165  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
166  this.setLayout(layout);
167  layout.setHorizontalGroup(
168  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
169  .addComponent(optionSeparator)
170  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
171  .addContainerGap()
172  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
173  .addComponent(reportScrollPane)
174  .addComponent(titleSeparator, javax.swing.GroupLayout.Alignment.LEADING)
175  .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
176  .addComponent(titleLabel)
177  .addGap(0, 522, Short.MAX_VALUE))
178  .addGroup(layout.createSequentialGroup()
179  .addGap(0, 546, Short.MAX_VALUE)
180  .addComponent(cancelButton)
181  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
182  .addComponent(closeButton)))
183  .addContainerGap())
184  );
185  layout.setVerticalGroup(
186  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
187  .addGroup(layout.createSequentialGroup()
188  .addContainerGap()
189  .addComponent(titleLabel)
190  .addGap(0, 0, 0)
191  .addComponent(titleSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
192  .addGap(18, 18, 18)
193  .addComponent(reportScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)
194  .addGap(18, 18, 18)
195  .addComponent(optionSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
196  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
197  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
198  .addComponent(closeButton)
199  .addComponent(cancelButton))
200  .addContainerGap())
201  );
202  }// </editor-fold>//GEN-END:initComponents
203 
204  private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
205  close();
206  }//GEN-LAST:event_closeButtonActionPerformed
207 
208  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
209  if(progressPanel.getStatus() == ReportStatus.QUEUING || progressPanel.getStatus() == ReportStatus.RUNNING) {
210  int result = JOptionPane.showConfirmDialog(null, NbBundle.getMessage(this.getClass(),
211  "ReportGenerationPanel.confDlg.cancelReport.msg"),
212  NbBundle.getMessage(this.getClass(),
213  "ReportGenerationPanel.cancelButton.text"),
214  JOptionPane.YES_NO_OPTION);
215  if (result == 0) {
216  progressPanel.cancel();
217  }
218  }
219  }//GEN-LAST:event_cancelButtonActionPerformed
220 
221  void addCloseAction(ActionListener l) {
222  this.actionListener = l;
223  }
224 
225  // Variables declaration - do not modify//GEN-BEGIN:variables
226  private javax.swing.JButton cancelButton;
227  private javax.swing.JButton closeButton;
228  private javax.swing.JSeparator optionSeparator;
229  private javax.swing.JPanel reportPanel;
230  private javax.swing.JScrollPane reportScrollPane;
231  private javax.swing.JLabel titleLabel;
232  private javax.swing.JSeparator titleSeparator;
233  // End of variables declaration//GEN-END:variables
234 }

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.