19 package org.sleuthkit.autopsy.report.infrastructure;
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;
35 @SuppressWarnings(
"PMD.SingularField")
36 final class ReportGenerationPanel extends javax.swing.JPanel {
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;
48 ReportGenerationPanel() {
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();
60 ReportProgressPanel getProgressPanel() {
71 void addReport(String reportName, String reportPath) {
75 reportPanel.remove(glue);
77 progressPanel.setLabels(reportName, reportPath);
78 constraints.weighty = 0.0;
79 constraints.anchor = GridBagConstraints.NORTH;
80 reportPanel.add(progressPanel, constraints);
86 constraints.weighty = 1.0;
87 constraints.anchor = GridBagConstraints.PAGE_END;
88 reportPanel.add(glue, constraints);
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);
111 boolean closeable =
true;
112 if (progressPanel.getStatus() != ReportStatus.CANCELED && progressPanel.getStatus() != ReportStatus.COMPLETE && progressPanel.getStatus() != ReportStatus.ERROR) {
116 actionListener.actionPerformed(null);
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);
125 progressPanel.cancel();
126 actionListener.actionPerformed(null);
136 void addCloseAction(ActionListener listener) {
137 this.actionListener = listener;
145 @SuppressWarnings(
"unchecked")
147 private
void initComponents() {
149 closeButton =
new javax.swing.JButton();
150 cancelButton =
new javax.swing.JButton();
151 reportPanel =
new javax.swing.JPanel();
153 setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11));
154 setPreferredSize(
new java.awt.Dimension(700, 400));
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"));
158 closeButton.addActionListener(
new java.awt.event.ActionListener() {
159 public void actionPerformed(java.awt.event.ActionEvent evt) {
160 closeButtonActionPerformed(evt);
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"));
166 cancelButton.setActionCommand(
org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class,
"ReportGenerationPanel.cancelButton.actionCommand"));
167 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
168 public void actionPerformed(java.awt.event.ActionEvent evt) {
169 cancelButtonActionPerformed(evt);
173 reportPanel.setFont(reportPanel.getFont().deriveFont(reportPanel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
174 reportPanel.setPreferredSize(
new java.awt.Dimension(600, 400));
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)
182 reportPanelLayout.setVerticalGroup(
183 reportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
184 .addGap(0, 344, Short.MAX_VALUE)
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()
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))
202 layout.setVerticalGroup(
203 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204 .addGroup(layout.createSequentialGroup()
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))
215 private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {
219 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
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);
227 progressPanel.cancel();
233 private javax.swing.JButton cancelButton;
234 private javax.swing.JButton closeButton;
235 private javax.swing.JPanel reportPanel;