19 package org.sleuthkit.autopsy.report;
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;
28 import org.openide.util.NbBundle;
35 @SuppressWarnings(
"PMD.SingularField")
36 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 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();
68 ReportProgressPanel addReport(String reportName, String reportPath) {
72 reportPanel.remove(glue);
74 progressPanel =
new ReportProgressPanel(reportName, reportPath);
75 constraints.weighty = 0.0;
76 constraints.anchor = GridBagConstraints.NORTH;
77 reportPanel.add(progressPanel, constraints);
83 constraints.weighty = 1.0;
84 constraints.anchor = GridBagConstraints.PAGE_END;
85 reportPanel.add(glue, constraints);
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);
102 return progressPanel;
109 boolean closeable =
true;
110 if (progressPanel.getStatus() != ReportStatus.CANCELED && progressPanel.getStatus() != ReportStatus.COMPLETE && progressPanel.getStatus() != ReportStatus.ERROR) {
114 actionListener.actionPerformed(null);
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);
123 progressPanel.cancel();
124 actionListener.actionPerformed(null);
134 void addCloseAction(ActionListener listener) {
135 this.actionListener = listener;
143 @SuppressWarnings(
"unchecked")
145 private
void initComponents() {
147 closeButton =
new javax.swing.JButton();
148 cancelButton =
new javax.swing.JButton();
149 reportPanel =
new javax.swing.JPanel();
151 setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11));
152 setPreferredSize(
new java.awt.Dimension(700, 400));
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"));
156 closeButton.addActionListener(
new java.awt.event.ActionListener() {
157 public void actionPerformed(java.awt.event.ActionEvent evt) {
158 closeButtonActionPerformed(evt);
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"));
164 cancelButton.setActionCommand(
org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class,
"ReportGenerationPanel.cancelButton.actionCommand"));
165 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
166 public void actionPerformed(java.awt.event.ActionEvent evt) {
167 cancelButtonActionPerformed(evt);
171 reportPanel.setFont(reportPanel.getFont().deriveFont(reportPanel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
172 reportPanel.setPreferredSize(
new java.awt.Dimension(600, 400));
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)
180 reportPanelLayout.setVerticalGroup(
181 reportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
182 .addGap(0, 344, Short.MAX_VALUE)
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()
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))
200 layout.setVerticalGroup(
201 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
202 .addGroup(layout.createSequentialGroup()
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))
213 private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {
217 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
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);
225 progressPanel.cancel();
231 private javax.swing.JButton cancelButton;
232 private javax.swing.JButton closeButton;
233 private javax.swing.JPanel reportPanel;