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 class ReportGenerationPanel
extends javax.swing.JPanel {
37 private static final long serialVersionUID = 1L;
38 private final GridBagConstraints constraints;
39 private final Component glue;
40 private ActionListener actionListener;
41 ReportProgressPanel progressPanel;
47 ReportGenerationPanel() {
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();
67 ReportProgressPanel addReport(String reportName, String reportPath) {
71 reportPanel.remove(glue);
73 progressPanel =
new ReportProgressPanel(reportName, reportPath);
74 constraints.weighty = 0.0;
75 constraints.anchor = GridBagConstraints.NORTH;
76 reportPanel.add(progressPanel, constraints);
82 constraints.weighty = 1.0;
83 constraints.anchor = GridBagConstraints.PAGE_END;
84 reportPanel.add(glue, constraints);
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);
101 return progressPanel;
108 boolean closeable =
true;
109 if (progressPanel.getStatus() != ReportStatus.CANCELED && progressPanel.getStatus() != ReportStatus.COMPLETE && progressPanel.getStatus() != ReportStatus.ERROR) {
113 actionListener.actionPerformed(null);
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);
122 progressPanel.cancel();
123 actionListener.actionPerformed(null);
133 void addCloseAction(ActionListener listener) {
134 this.actionListener = listener;
142 @SuppressWarnings(
"unchecked")
144 private
void initComponents() {
146 closeButton =
new javax.swing.JButton();
147 cancelButton =
new javax.swing.JButton();
148 reportPanel =
new javax.swing.JPanel();
150 setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11));
151 setPreferredSize(
new java.awt.Dimension(700, 400));
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"));
155 closeButton.addActionListener(
new java.awt.event.ActionListener() {
156 public void actionPerformed(java.awt.event.ActionEvent evt) {
157 closeButtonActionPerformed(evt);
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"));
163 cancelButton.setActionCommand(
org.openide.util.NbBundle.getMessage(ReportGenerationPanel.class,
"ReportGenerationPanel.cancelButton.actionCommand"));
164 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
165 public void actionPerformed(java.awt.event.ActionEvent evt) {
166 cancelButtonActionPerformed(evt);
170 reportPanel.setFont(reportPanel.getFont().deriveFont(reportPanel.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
171 reportPanel.setPreferredSize(
new java.awt.Dimension(600, 400));
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)
179 reportPanelLayout.setVerticalGroup(
180 reportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
181 .addGap(0, 344, Short.MAX_VALUE)
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()
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))
199 layout.setVerticalGroup(
200 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
201 .addGroup(layout.createSequentialGroup()
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))
212 private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {
216 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
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);
224 progressPanel.cancel();
230 private javax.swing.JButton cancelButton;
231 private javax.swing.JButton closeButton;
232 private javax.swing.JPanel reportPanel;