From 47ca52f8da6e7b5029d24b231bf6fa2f625a3984 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Tue, 6 Aug 2019 15:04:01 -0400 Subject: [PATCH 1/6] Created ReportProgressPanel API and ReportProgressDialog --- .../autopsy/report/Bundle.properties | 8 +- .../autopsy/report/Bundle.properties-MERGED | 8 +- .../autopsy/report/Bundle_ja.properties | 8 +- .../autopsy/report/ReportGenerationPanel.java | 7 +- .../sleuthkit/autopsy/report/ReportKML.java | 34 +- ...ssPanel.form => ReportProgressDialog.form} | 8 +- .../autopsy/report/ReportProgressDialog.java | 373 ++++++++++++++++++ .../autopsy/report/ReportProgressPanel.java | 305 +------------- .../autopsy/report/TableReportGenerator.java | 4 +- .../report/caseuco/CaseUcoFormatExporter.java | 2 +- 10 files changed, 429 insertions(+), 328 deletions(-) rename Core/src/org/sleuthkit/autopsy/report/{ReportProgressPanel.form => ReportProgressDialog.form} (90%) create mode 100644 Core/src/org/sleuthkit/autopsy/report/ReportProgressDialog.java mode change 100644 => 100755 Core/src/org/sleuthkit/autopsy/report/ReportProgressPanel.java diff --git a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties index 45e66b1092..4c7e8868d7 100644 --- a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties @@ -12,10 +12,6 @@ ReportVisualPanel2.advancedButton.text=Data Types ArtifactSelectionDialog.deselectAllButton.text=Deselect All ArtifactSelectionDialog.selectAllButton.text=Select All ReportGenerationPanel.closeButton.text=Close -ReportProgressPanel.reportLabel.text=reportLabel -ReportProgressPanel.pathLabel.text=pathLabel -ReportProgressPanel.separationLabel.text=: -ReportProgressPanel.statusMessageLabel.text=processingLabel ReportGenerationPanel.titleLabel.text=Report Generation Progress ReportVisualPanel2.taggedResultsRadioButton.text=Tagged Results ReportVisualPanel2.allResultsRadioButton.text=All Results @@ -270,3 +266,7 @@ ReportFileTextConfigurationPanel.commaDelimitedButton.text=Comma delimited PortableCaseTagsListPanel.descLabel.text=Include the following tags: PortableCaseInterestingItemsListPanel.descLabel.text=Include Interesting Items from these sets: ReportWizardPortableCaseOptionsVisualPanel.compressCheckbox.toolTipText= +ReportProgressDialog.separationLabel.text=: +ReportProgressDialog.pathLabel.text=pathLabel +ReportProgressDialog.reportLabel.text=reportLabel +ReportProgressDialog.statusMessageLabel.text=processingLabel diff --git a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED index 53aa1acfbd..5e50acbea8 100755 --- a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED +++ b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED @@ -72,10 +72,6 @@ ReportVisualPanel2.advancedButton.text=Data Types ArtifactSelectionDialog.deselectAllButton.text=Deselect All ArtifactSelectionDialog.selectAllButton.text=Select All ReportGenerationPanel.closeButton.text=Close -ReportProgressPanel.reportLabel.text=reportLabel -ReportProgressPanel.pathLabel.text=pathLabel -ReportProgressPanel.separationLabel.text=: -ReportProgressPanel.statusMessageLabel.text=processingLabel ReportGenerationPanel.titleLabel.text=Report Generation Progress ReportVisualPanel2.taggedResultsRadioButton.text=Tagged Results ReportVisualPanel2.allResultsRadioButton.text=All Results @@ -330,5 +326,9 @@ ReportFileTextConfigurationPanel.commaDelimitedButton.text=Comma delimited PortableCaseTagsListPanel.descLabel.text=Include the following tags: PortableCaseInterestingItemsListPanel.descLabel.text=Include Interesting Items from these sets: ReportWizardPortableCaseOptionsVisualPanel.compressCheckbox.toolTipText= +ReportProgressDialog.separationLabel.text=: +ReportProgressDialog.pathLabel.text=pathLabel +ReportProgressDialog.reportLabel.text=reportLabel +ReportProgressDialog.statusMessageLabel.text=processingLabel ReportWizardPortableCaseOptionsVisualPanel.getName.title=Choose Portable Case settings TableReportGenerator.StatusColumn.Header=Review Status diff --git a/Core/src/org/sleuthkit/autopsy/report/Bundle_ja.properties b/Core/src/org/sleuthkit/autopsy/report/Bundle_ja.properties index b4c2844989..6c2db29da2 100644 --- a/Core/src/org/sleuthkit/autopsy/report/Bundle_ja.properties +++ b/Core/src/org/sleuthkit/autopsy/report/Bundle_ja.properties @@ -11,10 +11,6 @@ ReportVisualPanel2.advancedButton.text=\u30c7\u30fc\u30bf\u30bf\u30a4\u30d7 ArtifactSelectionDialog.deselectAllButton.text=\u5168\u3066\u9078\u629e\u89e3\u9664 ArtifactSelectionDialog.selectAllButton.text=\u5168\u3066\u9078\u629e ReportGenerationPanel.closeButton.text=\u9589\u3058\u308b -ReportProgressPanel.reportLabel.text=\u30ec\u30dd\u30fc\u30c8\u30e9\u30d9\u30eb -ReportProgressPanel.pathLabel.text=\u30d1\u30b9\u30e9\u30d9\u30eb -ReportProgressPanel.separationLabel.text=: -ReportProgressPanel.statusMessageLabel.text=\u30d7\u30ed\u30bb\u30b7\u30f3\u30b0\u30e9\u30d9\u30eb ReportGenerationPanel.titleLabel.text=\u30ec\u30dd\u30fc\u30c8\u751f\u6210\u30d7\u30ed\u30b0\u30ec\u30b9 ReportVisualPanel2.taggedResultsRadioButton.text=\u30bf\u30b0\u3055\u308c\u305f\u7d50\u679c ReportVisualPanel2.allResultsRadioButton.text=\u5168\u3066\u306e\u7d50\u679c @@ -244,3 +240,7 @@ ReportGenerationPanel.confDlg.cancelReport.msg=\u672c\u5f53\u306b\u30ec\u30dd\u3 ReportProgressPanel.complete.processLb2.text=\u5b8c\u4e86\u3057\u307e\u3057\u305f\u304c\u3001\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f ReportGenerationPanel.cancelButton.actionCommand=\u30ad\u30e3\u30f3\u30bb\u30eb ReportGenerationPanel.cancelButton.text=\u30ad\u30e3\u30f3\u30bb\u30eb +ReportProgressDialog.separationLabel.text=: +ReportProgressDialog.pathLabel.text=\u30d1\u30b9\u30e9\u30d9\u30eb +ReportProgressDialog.reportLabel.text=\u30ec\u30dd\u30fc\u30c8\u30e9\u30d9\u30eb +ReportProgressDialog.statusMessageLabel.text=\u30d7\u30ed\u30bb\u30b7\u30f3\u30b0\u30e9\u30d9\u30eb diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportGenerationPanel.java b/Core/src/org/sleuthkit/autopsy/report/ReportGenerationPanel.java index c9bf291314..53c17b3543 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportGenerationPanel.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportGenerationPanel.java @@ -24,7 +24,6 @@ import java.beans.PropertyChangeEvent; import javax.swing.Box; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; - import org.openide.util.NbBundle; import org.sleuthkit.autopsy.report.ReportProgressPanel.ReportStatus; @@ -39,7 +38,7 @@ class ReportGenerationPanel extends javax.swing.JPanel { private final GridBagConstraints constraints; private final Component glue; private ActionListener actionListener; - ReportProgressPanel progressPanel; + ReportProgressDialog progressPanel; /** * Constructs a panel that displays a panel used by a report generation @@ -65,13 +64,13 @@ class ReportGenerationPanel extends javax.swing.JPanel { * * @return The report generation progress panel. */ - ReportProgressPanel addReport(String reportName, String reportPath) { + ReportProgressDialog addReport(String reportName, String reportPath) { /* * Remove the "glue." */ reportPanel.remove(glue); - progressPanel = new ReportProgressPanel(reportName, reportPath); + progressPanel = new ReportProgressDialog(reportName, reportPath); constraints.weighty = 0.0; constraints.anchor = GridBagConstraints.NORTH; reportPanel.add(progressPanel, constraints); diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportKML.java b/Core/src/org/sleuthkit/autopsy/report/ReportKML.java index 3a092efc83..6f2f79a4f3 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportKML.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportKML.java @@ -184,7 +184,7 @@ class ReportKML implements GeneralReportModule { document.addContent(gpsSearchesFolder); document.addContent(gpsTrackpointsFolder); - ReportProgressPanel.ReportStatus result = ReportProgressPanel.ReportStatus.COMPLETE; + ReportProgressDialog.ReportStatus result = ReportProgressDialog.ReportStatus.COMPLETE; /** * In the following code, nulls are okay, and are handled when we go to @@ -233,12 +233,12 @@ class ReportKML implements GeneralReportModule { logger.log(Level.WARNING, String.format("Error reading file '%s' (id=%d).", fileName, fileId), ex); } catch (Exception ex) { logger.log(Level.SEVERE, "Could not extract photo information.", ex); //NON-NLS - result = ReportProgressPanel.ReportStatus.ERROR; + result = ReportProgressDialog.ReportStatus.ERROR; } } } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Could not extract photos with EXIF metadata.", ex); //NON-NLS - result = ReportProgressPanel.ReportStatus.ERROR; + result = ReportProgressDialog.ReportStatus.ERROR; } try { @@ -254,12 +254,12 @@ class ReportKML implements GeneralReportModule { gpsBookmarksFolder.addContent(makePlacemark(bookmarkName, FeatureColor.BLUE, desc, timestamp, point, formattedCoordinates)); } catch (Exception ex) { logger.log(Level.SEVERE, "Could not extract Bookmark information.", ex); //NON-NLS - result = ReportProgressPanel.ReportStatus.ERROR; + result = ReportProgressDialog.ReportStatus.ERROR; } } } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Could not get GPS Bookmarks from database.", ex); //NON-NLS - result = ReportProgressPanel.ReportStatus.ERROR; + result = ReportProgressDialog.ReportStatus.ERROR; } try { @@ -275,12 +275,12 @@ class ReportKML implements GeneralReportModule { gpsLastKnownLocationFolder.addContent(makePlacemark("Last Known Location", FeatureColor.PURPLE, desc, timestamp, point, formattedCoordinates)); //NON-NLS } catch (Exception ex) { logger.log(Level.SEVERE, "Could not extract Last Known Location information.", ex); //NON-NLS - result = ReportProgressPanel.ReportStatus.ERROR; + result = ReportProgressDialog.ReportStatus.ERROR; } } } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Could not get GPS Last Known Location from database.", ex); //NON-NLS - result = ReportProgressPanel.ReportStatus.ERROR; + result = ReportProgressDialog.ReportStatus.ERROR; } try { @@ -308,12 +308,12 @@ class ReportKML implements GeneralReportModule { gpsRouteFolder.addContent(makePlacemark("End", FeatureColor.GREEN, desc, timestamp, endingPoint, formattedCoordinates)); //NON-NLS } catch (Exception ex) { logger.log(Level.SEVERE, "Could not extract GPS Route information.", ex); //NON-NLS - result = ReportProgressPanel.ReportStatus.ERROR; + result = ReportProgressDialog.ReportStatus.ERROR; } } } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Could not get GPS Routes from database.", ex); //NON-NLS - result = ReportProgressPanel.ReportStatus.ERROR; + result = ReportProgressDialog.ReportStatus.ERROR; } try { @@ -336,7 +336,7 @@ class ReportKML implements GeneralReportModule { } } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Could not get GPS Searches from database.", ex); //NON-NLS - result = ReportProgressPanel.ReportStatus.ERROR; + result = ReportProgressDialog.ReportStatus.ERROR; } try { @@ -362,12 +362,12 @@ class ReportKML implements GeneralReportModule { gpsTrackpointsFolder.addContent(makePlacemark(trackName, FeatureColor.YELLOW, desc, timestamp, point, formattedCoordinates)); } catch (Exception ex) { logger.log(Level.SEVERE, "Could not extract Trackpoint information.", ex); //NON-NLS - result = ReportProgressPanel.ReportStatus.ERROR; + result = ReportProgressDialog.ReportStatus.ERROR; } } } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Could not get GPS Trackpoints from database.", ex); //NON-NLS - result = ReportProgressPanel.ReportStatus.ERROR; + result = ReportProgressDialog.ReportStatus.ERROR; } // Copy the style sheet @@ -377,14 +377,14 @@ class ReportKML implements GeneralReportModule { FileUtil.copy(input, output); } catch (IOException ex) { logger.log(Level.SEVERE, "Error placing KML stylesheet. The .KML file will not function properly.", ex); //NON-NLS - result = ReportProgressPanel.ReportStatus.ERROR; + result = ReportProgressDialog.ReportStatus.ERROR; } try (FileOutputStream writer = new FileOutputStream(kmlFileFullPath)) { XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(kmlDocument, writer); String prependedStatus = ""; - if (result == ReportProgressPanel.ReportStatus.ERROR) { + if (result == ReportProgressDialog.ReportStatus.ERROR) { prependedStatus = "Incomplete "; } Case.getCurrentCaseThrows().addReport(kmlFileFullPath, @@ -392,14 +392,14 @@ class ReportKML implements GeneralReportModule { prependedStatus + NbBundle.getMessage(this.getClass(), "ReportKML.genReport.reportName")); } catch (IOException ex) { logger.log(Level.SEVERE, "Could not write the KML file.", ex); //NON-NLS - progressPanel.complete(ReportProgressPanel.ReportStatus.ERROR); + progressPanel.complete(ReportProgressDialog.ReportStatus.ERROR); } catch (TskCoreException ex) { String errorMessage = String.format("Error adding %s to case as a report", kmlFileFullPath); //NON-NLS logger.log(Level.SEVERE, errorMessage, ex); - result = ReportProgressPanel.ReportStatus.ERROR; + result = ReportProgressDialog.ReportStatus.ERROR; } catch (NoCurrentCaseException ex) { logger.log(Level.SEVERE, "Exception while getting open case.", ex); - result = ReportProgressPanel.ReportStatus.ERROR; + result = ReportProgressDialog.ReportStatus.ERROR; } progressPanel.complete(result); diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportProgressPanel.form b/Core/src/org/sleuthkit/autopsy/report/ReportProgressDialog.form similarity index 90% rename from Core/src/org/sleuthkit/autopsy/report/ReportProgressPanel.form rename to Core/src/org/sleuthkit/autopsy/report/ReportProgressDialog.form index 597dd89df4..8979a5d188 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportProgressPanel.form +++ b/Core/src/org/sleuthkit/autopsy/report/ReportProgressDialog.form @@ -79,7 +79,7 @@ - + @@ -91,7 +91,7 @@ - + @@ -104,14 +104,14 @@ - + - + diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportProgressDialog.java b/Core/src/org/sleuthkit/autopsy/report/ReportProgressDialog.java new file mode 100644 index 0000000000..0b4064c69d --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/report/ReportProgressDialog.java @@ -0,0 +1,373 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2011-2019 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.report; + +import org.openide.util.NbBundle; +import java.awt.Color; +import java.awt.Cursor; +import java.awt.Desktop; +import java.awt.EventQueue; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.io.File; +import java.io.IOException; +import java.util.logging.Level; +import org.sleuthkit.autopsy.coreutils.Logger; + +/** + * A panel used by a report generation module to show progress. + */ +@SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives +public class ReportProgressDialog extends javax.swing.JPanel implements ReportProgressPanel { + + private static final long serialVersionUID = 1L; + private static final Logger logger = Logger.getLogger(ReportProgressDialog.class.getName()); + private static final Color GREEN = new Color(50, 205, 50); + private static final Color RED = new Color(178, 34, 34); + private volatile ReportProgressPanel.ReportStatus status; + + /** + * Constructs a panel used by report generation module to show progress. + * + * @param reportName The name of the report being generated. + * @param reportPath The path to the report file. + */ + ReportProgressDialog(String reportName, String reportPath) { + initComponents(); + reportProgressBar.setIndeterminate(true); + reportProgressBar.setMaximum(100); + reportLabel.setText(reportName); + statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.progress.queuing")); + status = ReportStatus.QUEUING; + if (null != reportPath) { + pathLabel.setText("" + shortenPath(reportPath) + ""); //NON-NLS + pathLabel.setToolTipText(reportPath); + String linkPath = reportPath; + pathLabel.addMouseListener(new MouseListener() { + + @Override + public void mouseClicked(MouseEvent mouseEvent) { + } + + @Override + public void mousePressed(MouseEvent mouseEvent) { + } + + @Override + public void mouseReleased(MouseEvent mouseEvent) { + File file = new File(linkPath); + try { + Desktop.getDesktop().open(file); + } catch (IOException ioex) { + logger.log(Level.SEVERE, "Error opening report file", ioex); + } catch (IllegalArgumentException iaEx) { + logger.log(Level.SEVERE, "Error opening report file", iaEx); + try { + Desktop.getDesktop().open(file.getParentFile()); + } catch (IOException ioEx2) { + logger.log(Level.SEVERE, "Error opening report file parent", ioEx2); + } + } + } + + @Override + public void mouseEntered(MouseEvent e3) { + pathLabel.setForeground(Color.DARK_GRAY); + setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + } + + @Override + public void mouseExited(MouseEvent e4) { + pathLabel.setForeground(Color.BLACK); + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + }); + } else { + pathLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.initPathLabel.noFile")); + } + } + + /** + * Gets the current status of the generation of the report. + * + * @return The report generation status as a ReportStatus enum. + */ + @Override + public ReportStatus getStatus() { + return status; + } + + /** + * Starts the progress bar component of this panel. + */ + @Override + public void start() { + EventQueue.invokeLater(() -> { + statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.start.progress.text")); + status = ReportStatus.RUNNING; + }); + } + + /** + * Sets the maximum value of the progress bar component of this panel. + * + * @param max The maximum value. + */ + @Override + public void setMaximumProgress(int max) { + EventQueue.invokeLater(() -> { + if (status != ReportStatus.CANCELED) { + reportProgressBar.setMaximum(max); + } + }); + } + + /** + * Increments the current value of the progress bar component of this panel + * by one unit. + */ + @Override + public void increment() { + EventQueue.invokeLater(() -> { + if (status != ReportStatus.CANCELED) { + reportProgressBar.setValue(reportProgressBar.getValue() + 1); + } + }); + } + + /** + * Sets the current value of the progress bar component of this panel. + * + * @param value The value to be set. + */ + @Override + public void setProgress(int value) { + EventQueue.invokeLater(() -> { + if (status != ReportStatus.CANCELED) { + reportProgressBar.setValue(value); + } + }); + } + + /** + * Changes the the progress bar component of this panel to be determinate or + * indeterminate. + * + * @param indeterminate True if the progress bar should be set to + * indeterminate. + */ + @Override + public void setIndeterminate(boolean indeterminate) { + EventQueue.invokeLater(() -> { + if (status != ReportStatus.CANCELED) { + reportProgressBar.setIndeterminate(indeterminate); + } + }); + } + + /** + * Changes the status message label component of this panel to show a given + * processing status message. For example, updateStatusLabel("Now processing + * files...") sets the label text to "Now processing files..." + * + * @param statusMessage String to use as label text. + */ + @Override + public void updateStatusLabel(String statusMessage) { + EventQueue.invokeLater(() -> { + if (status != ReportStatus.CANCELED) { + statusMessageLabel.setText(statusMessage); + } + }); + } + + /** + * Makes the components of this panel indicate the final status of + * generation of the report. + * + * @param reportStatus The final status, must be COMPLETE or ERROR. + */ + @Override + public void complete(ReportStatus reportStatus) { + EventQueue.invokeLater(() -> { + reportProgressBar.setIndeterminate(false); + if (status != ReportStatus.CANCELED) { + switch (reportStatus) { + case COMPLETE: { + ReportStatus oldValue = status; + status = ReportStatus.COMPLETE; + statusMessageLabel.setForeground(Color.BLACK); + statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLbl.text")); + reportProgressBar.setValue(reportProgressBar.getMaximum()); + reportProgressBar.setStringPainted(true); + reportProgressBar.setForeground(GREEN); + reportProgressBar.setString("Complete"); //NON-NLS + firePropertyChange(ReportStatus.COMPLETE.toString(), oldValue, status); + break; + } + case ERROR: { + ReportStatus oldValue = status; + status = ReportStatus.ERROR; + statusMessageLabel.setForeground(RED); + statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLb2.text")); + reportProgressBar.setValue(reportProgressBar.getMaximum()); + reportProgressBar.setStringPainted(true); + reportProgressBar.setForeground(RED); + reportProgressBar.setString("Error"); //NON-NLS + firePropertyChange(ReportStatus.COMPLETE.toString(), oldValue, status); + break; + } + default: { + break; + } + } + } + }); + } + + /** + * Makes the components of this panel indicate generation of the report was + * cancelled. + */ + void cancel() { + switch (status) { + case COMPLETE: + break; + case CANCELED: + break; + case ERROR: + break; + default: + ReportStatus oldValue = status; + status = ReportStatus.CANCELED; + reportProgressBar.setIndeterminate(false); + reportProgressBar.setValue(0); + reportProgressBar.setStringPainted(true); + reportProgressBar.setForeground(RED); // Red + reportProgressBar.setString("Cancelled"); //NON-NLS + firePropertyChange(ReportStatus.CANCELED.toString(), oldValue, status); + statusMessageLabel.setForeground(RED); + statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.cancel.procLbl.text")); + break; + } + } + + /** + * Gets a shortened version of a file path. + * + * @param path The path to shorten. + * + * @return The shortened path. + */ + private String shortenPath(String path) { + if (path.length() > 100) { + return path.substring(0, 10 + path.substring(10).indexOf(File.separator) + 1) + "..." + + path.substring((path.length() - 70) + path.substring(path.length() - 70).indexOf(File.separator)); + } else { + return path; + } + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + reportProgressBar = new javax.swing.JProgressBar(); + reportLabel = new javax.swing.JLabel(); + pathLabel = new javax.swing.JLabel(); + separationLabel = new javax.swing.JLabel(); + statusMessageLabel = new javax.swing.JLabel(); + + setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11)); + setMinimumSize(new java.awt.Dimension(486, 68)); + + reportProgressBar.setFont(reportProgressBar.getFont().deriveFont(reportProgressBar.getFont().getStyle() & ~java.awt.Font.BOLD, 11)); + + reportLabel.setFont(reportLabel.getFont().deriveFont(reportLabel.getFont().getStyle() | java.awt.Font.BOLD, 11)); + org.openide.awt.Mnemonics.setLocalizedText(reportLabel, org.openide.util.NbBundle.getMessage(ReportProgressDialog.class, "ReportProgressDialog.reportLabel.text")); // NOI18N + + pathLabel.setFont(pathLabel.getFont().deriveFont(pathLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11)); + org.openide.awt.Mnemonics.setLocalizedText(pathLabel, org.openide.util.NbBundle.getMessage(ReportProgressDialog.class, "ReportProgressDialog.pathLabel.text")); // NOI18N + pathLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP); + + separationLabel.setFont(separationLabel.getFont().deriveFont(separationLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11)); + org.openide.awt.Mnemonics.setLocalizedText(separationLabel, org.openide.util.NbBundle.getMessage(ReportProgressDialog.class, "ReportProgressDialog.separationLabel.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(statusMessageLabel, org.openide.util.NbBundle.getMessage(ReportProgressDialog.class, "ReportProgressDialog.statusMessageLabel.text")); // NOI18N + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(statusMessageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(reportProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addComponent(reportLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(separationLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(reportProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(reportLabel) + .addComponent(pathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(separationLabel)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(statusMessageLabel) + .addGap(13, 13, 13)) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel pathLabel; + private javax.swing.JLabel reportLabel; + private javax.swing.JProgressBar reportProgressBar; + private javax.swing.JLabel separationLabel; + private javax.swing.JLabel statusMessageLabel; + // End of variables declaration//GEN-END:variables + + /** + * Makes the components of this panel indicate the generation of the report + * is completed. + * + * @deprecated Use {@link #complete(ReportStatus)} + */ + @Deprecated + @Override + public void complete() { + complete(ReportStatus.COMPLETE); + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportProgressPanel.java b/Core/src/org/sleuthkit/autopsy/report/ReportProgressPanel.java old mode 100644 new mode 100755 index 9d3fd1bf41..4e985163f7 --- a/Core/src/org/sleuthkit/autopsy/report/ReportProgressPanel.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportProgressPanel.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011-2018 Basis Technology Corp. + * Copyright 2011-2019 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,31 +18,13 @@ */ package org.sleuthkit.autopsy.report; -import org.openide.util.NbBundle; -import java.awt.Color; -import java.awt.Cursor; -import java.awt.Desktop; -import java.awt.EventQueue; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.io.File; -import java.io.IOException; -import java.util.logging.Level; -import org.sleuthkit.autopsy.coreutils.Logger; - /** - * A panel used by a report generation module to show progress. + * This interface is necessary in order to not break backwards compatibility + * of GeneralReportModule interface. See JIRA-5354. */ -@SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives -public class ReportProgressPanel extends javax.swing.JPanel { - - private static final long serialVersionUID = 1L; - private static final Logger logger = Logger.getLogger(ReportProgressPanel.class.getName()); - private static final Color GREEN = new Color(50, 205, 50); - private static final Color RED = new Color(178, 34, 34); - private volatile ReportStatus status; - - /** +public interface ReportProgressPanel { + + /** * Used by a report generation module to communicate report generation * status to this panel and its listeners. */ @@ -53,125 +35,39 @@ public class ReportProgressPanel extends javax.swing.JPanel { COMPLETE, CANCELED, ERROR - } - - /** - * Constructs a panel used by report generation module to show progress. - * - * @param reportName The name of the report being generated. - * @param reportPath The path to the report file. - */ - public ReportProgressPanel(String reportName, String reportPath) { - initComponents(); - reportProgressBar.setIndeterminate(true); - reportProgressBar.setMaximum(100); - reportLabel.setText(reportName); - statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.progress.queuing")); - status = ReportStatus.QUEUING; - if (null != reportPath) { - pathLabel.setText("" + shortenPath(reportPath) + ""); //NON-NLS - pathLabel.setToolTipText(reportPath); - String linkPath = reportPath; - pathLabel.addMouseListener(new MouseListener() { - - @Override - public void mouseClicked(MouseEvent mouseEvent) { - } - - @Override - public void mousePressed(MouseEvent mouseEvent) { - } - - @Override - public void mouseReleased(MouseEvent mouseEvent) { - File file = new File(linkPath); - try { - Desktop.getDesktop().open(file); - } catch (IOException ioex) { - logger.log(Level.SEVERE, "Error opening report file", ioex); - } catch (IllegalArgumentException iaEx) { - logger.log(Level.SEVERE, "Error opening report file", iaEx); - try { - Desktop.getDesktop().open(file.getParentFile()); - } catch (IOException ioEx2) { - logger.log(Level.SEVERE, "Error opening report file parent", ioEx2); - } - } - } - - @Override - public void mouseEntered(MouseEvent e3) { - pathLabel.setForeground(Color.DARK_GRAY); - setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - } - - @Override - public void mouseExited(MouseEvent e4) { - pathLabel.setForeground(Color.BLACK); - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - }); - } else { - pathLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.initPathLabel.noFile")); - } - } - + } + /** * Gets the current status of the generation of the report. * * @return The report generation status as a ReportStatus enum. */ - public ReportStatus getStatus() { - return status; - } + public ReportStatus getStatus(); /** * Starts the progress bar component of this panel. */ - public void start() { - EventQueue.invokeLater(() -> { - statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.start.progress.text")); - status = ReportStatus.RUNNING; - }); - } + public void start(); /** * Sets the maximum value of the progress bar component of this panel. * * @param max The maximum value. */ - public void setMaximumProgress(int max) { - EventQueue.invokeLater(() -> { - if (status != ReportStatus.CANCELED) { - reportProgressBar.setMaximum(max); - } - }); - } + public void setMaximumProgress(int max); /** * Increments the current value of the progress bar component of this panel * by one unit. */ - public void increment() { - EventQueue.invokeLater(() -> { - if (status != ReportStatus.CANCELED) { - reportProgressBar.setValue(reportProgressBar.getValue() + 1); - } - }); - } + public void increment(); /** * Sets the current value of the progress bar component of this panel. * * @param value The value to be set. */ - public void setProgress(int value) { - EventQueue.invokeLater(() -> { - if (status != ReportStatus.CANCELED) { - reportProgressBar.setValue(value); - } - }); - } + public void setProgress(int value); /** * Changes the the progress bar component of this panel to be determinate or @@ -180,13 +76,7 @@ public class ReportProgressPanel extends javax.swing.JPanel { * @param indeterminate True if the progress bar should be set to * indeterminate. */ - public void setIndeterminate(boolean indeterminate) { - EventQueue.invokeLater(() -> { - if (status != ReportStatus.CANCELED) { - reportProgressBar.setIndeterminate(indeterminate); - } - }); - } + public void setIndeterminate(boolean indeterminate); /** * Changes the status message label component of this panel to show a given @@ -195,13 +85,7 @@ public class ReportProgressPanel extends javax.swing.JPanel { * * @param statusMessage String to use as label text. */ - public void updateStatusLabel(String statusMessage) { - EventQueue.invokeLater(() -> { - if (status != ReportStatus.CANCELED) { - statusMessageLabel.setText(statusMessage); - } - }); - } + public void updateStatusLabel(String statusMessage); /** * Makes the components of this panel indicate the final status of @@ -209,159 +93,7 @@ public class ReportProgressPanel extends javax.swing.JPanel { * * @param reportStatus The final status, must be COMPLETE or ERROR. */ - public void complete(ReportStatus reportStatus) { - EventQueue.invokeLater(() -> { - reportProgressBar.setIndeterminate(false); - if (status != ReportStatus.CANCELED) { - switch (reportStatus) { - case COMPLETE: { - ReportStatus oldValue = status; - status = ReportStatus.COMPLETE; - statusMessageLabel.setForeground(Color.BLACK); - statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLbl.text")); - reportProgressBar.setValue(reportProgressBar.getMaximum()); - reportProgressBar.setStringPainted(true); - reportProgressBar.setForeground(GREEN); - reportProgressBar.setString("Complete"); //NON-NLS - firePropertyChange(ReportStatus.COMPLETE.toString(), oldValue, status); - break; - } - case ERROR: { - ReportStatus oldValue = status; - status = ReportStatus.ERROR; - statusMessageLabel.setForeground(RED); - statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLb2.text")); - reportProgressBar.setValue(reportProgressBar.getMaximum()); - reportProgressBar.setStringPainted(true); - reportProgressBar.setForeground(RED); - reportProgressBar.setString("Error"); //NON-NLS - firePropertyChange(ReportStatus.COMPLETE.toString(), oldValue, status); - break; - } - default: { - break; - } - } - } - }); - } - - /** - * Makes the components of this panel indicate generation of the report was - * cancelled. - */ - void cancel() { - switch (status) { - case COMPLETE: - break; - case CANCELED: - break; - case ERROR: - break; - default: - ReportStatus oldValue = status; - status = ReportStatus.CANCELED; - reportProgressBar.setIndeterminate(false); - reportProgressBar.setValue(0); - reportProgressBar.setStringPainted(true); - reportProgressBar.setForeground(RED); // Red - reportProgressBar.setString("Cancelled"); //NON-NLS - firePropertyChange(ReportStatus.CANCELED.toString(), oldValue, status); - statusMessageLabel.setForeground(RED); - statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.cancel.procLbl.text")); - break; - } - } - - /** - * Gets a shortened version of a file path. - * - * @param path The path to shorten. - * - * @return The shortened path. - */ - private String shortenPath(String path) { - if (path.length() > 100) { - return path.substring(0, 10 + path.substring(10).indexOf(File.separator) + 1) + "..." - + path.substring((path.length() - 70) + path.substring(path.length() - 70).indexOf(File.separator)); - } else { - return path; - } - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - reportProgressBar = new javax.swing.JProgressBar(); - reportLabel = new javax.swing.JLabel(); - pathLabel = new javax.swing.JLabel(); - separationLabel = new javax.swing.JLabel(); - statusMessageLabel = new javax.swing.JLabel(); - - setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD, 11)); - setMinimumSize(new java.awt.Dimension(486, 68)); - - reportProgressBar.setFont(reportProgressBar.getFont().deriveFont(reportProgressBar.getFont().getStyle() & ~java.awt.Font.BOLD, 11)); - - reportLabel.setFont(reportLabel.getFont().deriveFont(reportLabel.getFont().getStyle() | java.awt.Font.BOLD, 11)); - org.openide.awt.Mnemonics.setLocalizedText(reportLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.reportLabel.text")); // NOI18N - - pathLabel.setFont(pathLabel.getFont().deriveFont(pathLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11)); - org.openide.awt.Mnemonics.setLocalizedText(pathLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.pathLabel.text")); // NOI18N - pathLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP); - - separationLabel.setFont(separationLabel.getFont().deriveFont(separationLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 11)); - org.openide.awt.Mnemonics.setLocalizedText(separationLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.separationLabel.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(statusMessageLabel, org.openide.util.NbBundle.getMessage(ReportProgressPanel.class, "ReportProgressPanel.statusMessageLabel.text")); // NOI18N - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(statusMessageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(reportProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createSequentialGroup() - .addComponent(reportLabel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(separationLabel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(reportProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(reportLabel) - .addComponent(pathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(separationLabel)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(statusMessageLabel) - .addGap(13, 13, 13)) - ); - }// //GEN-END:initComponents - - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JLabel pathLabel; - private javax.swing.JLabel reportLabel; - private javax.swing.JProgressBar reportProgressBar; - private javax.swing.JLabel separationLabel; - private javax.swing.JLabel statusMessageLabel; - // End of variables declaration//GEN-END:variables + public void complete(ReportStatus reportStatus); /** * Makes the components of this panel indicate the generation of the report @@ -370,8 +102,5 @@ public class ReportProgressPanel extends javax.swing.JPanel { * @deprecated Use {@link #complete(ReportStatus)} */ @Deprecated - public void complete() { - complete(ReportStatus.COMPLETE); - } - + public void complete(); } diff --git a/Core/src/org/sleuthkit/autopsy/report/TableReportGenerator.java b/Core/src/org/sleuthkit/autopsy/report/TableReportGenerator.java index 8e7ac04d05..d24dc190ec 100644 --- a/Core/src/org/sleuthkit/autopsy/report/TableReportGenerator.java +++ b/Core/src/org/sleuthkit/autopsy/report/TableReportGenerator.java @@ -726,7 +726,7 @@ class TableReportGenerator { String currentList = ""; while (resultSet.next()) { // Check to see if all the TableReportModules have been canceled - if (progressPanel.getStatus() == ReportProgressPanel.ReportStatus.CANCELED) { + if (progressPanel.getStatus() == ReportProgressDialog.ReportStatus.CANCELED) { break; } @@ -884,7 +884,7 @@ class TableReportGenerator { String currentSet = ""; while (resultSet.next()) { // Check to see if all the TableReportModules have been canceled - if (progressPanel.getStatus() == ReportProgressPanel.ReportStatus.CANCELED) { + if (progressPanel.getStatus() == ReportProgressDialog.ReportStatus.CANCELED) { break; } diff --git a/Core/src/org/sleuthkit/autopsy/report/caseuco/CaseUcoFormatExporter.java b/Core/src/org/sleuthkit/autopsy/report/caseuco/CaseUcoFormatExporter.java index 7c09ef3cb5..96f88a860c 100755 --- a/Core/src/org/sleuthkit/autopsy/report/caseuco/CaseUcoFormatExporter.java +++ b/Core/src/org/sleuthkit/autopsy/report/caseuco/CaseUcoFormatExporter.java @@ -58,7 +58,7 @@ public final class CaseUcoFormatExporter { * @param selectedDataSourceId Object ID of the data source * @param reportOutputPath Full path to directory where to save CASE-UCO * report file - * @param progressPanel ReportProgressPanel to update progress + * @param progressPanel ReportProgressDialog to update progress */ @NbBundle.Messages({ "ReportCaseUco.noCaseOpen=Unable to open currect case", From a2b436630f15c2ad0c262093054ac9af9a71c81c Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Tue, 6 Aug 2019 15:07:30 -0400 Subject: [PATCH 2/6] Created ReportProgressPanel API and ReportProgressDialog --- .../sleuthkit/autopsy/report/ReportKML.java | 34 +++++++++---------- .../autopsy/report/TableReportGenerator.java | 4 +-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportKML.java b/Core/src/org/sleuthkit/autopsy/report/ReportKML.java index 6f2f79a4f3..55f5809a7e 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportKML.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportKML.java @@ -184,7 +184,7 @@ class ReportKML implements GeneralReportModule { document.addContent(gpsSearchesFolder); document.addContent(gpsTrackpointsFolder); - ReportProgressDialog.ReportStatus result = ReportProgressDialog.ReportStatus.COMPLETE; + ReportProgressDialog.ReportStatus result = ReportProgressPanel.ReportStatus.COMPLETE; /** * In the following code, nulls are okay, and are handled when we go to @@ -233,12 +233,12 @@ class ReportKML implements GeneralReportModule { logger.log(Level.WARNING, String.format("Error reading file '%s' (id=%d).", fileName, fileId), ex); } catch (Exception ex) { logger.log(Level.SEVERE, "Could not extract photo information.", ex); //NON-NLS - result = ReportProgressDialog.ReportStatus.ERROR; + result = ReportProgressPanel.ReportStatus.ERROR; } } } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Could not extract photos with EXIF metadata.", ex); //NON-NLS - result = ReportProgressDialog.ReportStatus.ERROR; + result = ReportProgressPanel.ReportStatus.ERROR; } try { @@ -254,12 +254,12 @@ class ReportKML implements GeneralReportModule { gpsBookmarksFolder.addContent(makePlacemark(bookmarkName, FeatureColor.BLUE, desc, timestamp, point, formattedCoordinates)); } catch (Exception ex) { logger.log(Level.SEVERE, "Could not extract Bookmark information.", ex); //NON-NLS - result = ReportProgressDialog.ReportStatus.ERROR; + result = ReportProgressPanel.ReportStatus.ERROR; } } } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Could not get GPS Bookmarks from database.", ex); //NON-NLS - result = ReportProgressDialog.ReportStatus.ERROR; + result = ReportProgressPanel.ReportStatus.ERROR; } try { @@ -275,12 +275,12 @@ class ReportKML implements GeneralReportModule { gpsLastKnownLocationFolder.addContent(makePlacemark("Last Known Location", FeatureColor.PURPLE, desc, timestamp, point, formattedCoordinates)); //NON-NLS } catch (Exception ex) { logger.log(Level.SEVERE, "Could not extract Last Known Location information.", ex); //NON-NLS - result = ReportProgressDialog.ReportStatus.ERROR; + result = ReportProgressPanel.ReportStatus.ERROR; } } } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Could not get GPS Last Known Location from database.", ex); //NON-NLS - result = ReportProgressDialog.ReportStatus.ERROR; + result = ReportProgressPanel.ReportStatus.ERROR; } try { @@ -308,12 +308,12 @@ class ReportKML implements GeneralReportModule { gpsRouteFolder.addContent(makePlacemark("End", FeatureColor.GREEN, desc, timestamp, endingPoint, formattedCoordinates)); //NON-NLS } catch (Exception ex) { logger.log(Level.SEVERE, "Could not extract GPS Route information.", ex); //NON-NLS - result = ReportProgressDialog.ReportStatus.ERROR; + result = ReportProgressPanel.ReportStatus.ERROR; } } } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Could not get GPS Routes from database.", ex); //NON-NLS - result = ReportProgressDialog.ReportStatus.ERROR; + result = ReportProgressPanel.ReportStatus.ERROR; } try { @@ -336,7 +336,7 @@ class ReportKML implements GeneralReportModule { } } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Could not get GPS Searches from database.", ex); //NON-NLS - result = ReportProgressDialog.ReportStatus.ERROR; + result = ReportProgressPanel.ReportStatus.ERROR; } try { @@ -362,12 +362,12 @@ class ReportKML implements GeneralReportModule { gpsTrackpointsFolder.addContent(makePlacemark(trackName, FeatureColor.YELLOW, desc, timestamp, point, formattedCoordinates)); } catch (Exception ex) { logger.log(Level.SEVERE, "Could not extract Trackpoint information.", ex); //NON-NLS - result = ReportProgressDialog.ReportStatus.ERROR; + result = ReportProgressPanel.ReportStatus.ERROR; } } } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Could not get GPS Trackpoints from database.", ex); //NON-NLS - result = ReportProgressDialog.ReportStatus.ERROR; + result = ReportProgressPanel.ReportStatus.ERROR; } // Copy the style sheet @@ -377,14 +377,14 @@ class ReportKML implements GeneralReportModule { FileUtil.copy(input, output); } catch (IOException ex) { logger.log(Level.SEVERE, "Error placing KML stylesheet. The .KML file will not function properly.", ex); //NON-NLS - result = ReportProgressDialog.ReportStatus.ERROR; + result = ReportProgressPanel.ReportStatus.ERROR; } try (FileOutputStream writer = new FileOutputStream(kmlFileFullPath)) { XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(kmlDocument, writer); String prependedStatus = ""; - if (result == ReportProgressDialog.ReportStatus.ERROR) { + if (result == ReportProgressPanel.ReportStatus.ERROR) { prependedStatus = "Incomplete "; } Case.getCurrentCaseThrows().addReport(kmlFileFullPath, @@ -392,14 +392,14 @@ class ReportKML implements GeneralReportModule { prependedStatus + NbBundle.getMessage(this.getClass(), "ReportKML.genReport.reportName")); } catch (IOException ex) { logger.log(Level.SEVERE, "Could not write the KML file.", ex); //NON-NLS - progressPanel.complete(ReportProgressDialog.ReportStatus.ERROR); + progressPanel.complete(ReportProgressPanel.ReportStatus.ERROR); } catch (TskCoreException ex) { String errorMessage = String.format("Error adding %s to case as a report", kmlFileFullPath); //NON-NLS logger.log(Level.SEVERE, errorMessage, ex); - result = ReportProgressDialog.ReportStatus.ERROR; + result = ReportProgressPanel.ReportStatus.ERROR; } catch (NoCurrentCaseException ex) { logger.log(Level.SEVERE, "Exception while getting open case.", ex); - result = ReportProgressDialog.ReportStatus.ERROR; + result = ReportProgressPanel.ReportStatus.ERROR; } progressPanel.complete(result); diff --git a/Core/src/org/sleuthkit/autopsy/report/TableReportGenerator.java b/Core/src/org/sleuthkit/autopsy/report/TableReportGenerator.java index d24dc190ec..8e7ac04d05 100644 --- a/Core/src/org/sleuthkit/autopsy/report/TableReportGenerator.java +++ b/Core/src/org/sleuthkit/autopsy/report/TableReportGenerator.java @@ -726,7 +726,7 @@ class TableReportGenerator { String currentList = ""; while (resultSet.next()) { // Check to see if all the TableReportModules have been canceled - if (progressPanel.getStatus() == ReportProgressDialog.ReportStatus.CANCELED) { + if (progressPanel.getStatus() == ReportProgressPanel.ReportStatus.CANCELED) { break; } @@ -884,7 +884,7 @@ class TableReportGenerator { String currentSet = ""; while (resultSet.next()) { // Check to see if all the TableReportModules have been canceled - if (progressPanel.getStatus() == ReportProgressDialog.ReportStatus.CANCELED) { + if (progressPanel.getStatus() == ReportProgressPanel.ReportStatus.CANCELED) { break; } From deaaa106f760731774bac92fe8df8821a78b7447 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Tue, 6 Aug 2019 15:08:55 -0400 Subject: [PATCH 3/6] Created ReportProgressPanel API and ReportProgressDialog --- .../sleuthkit/autopsy/report/caseuco/CaseUcoFormatExporter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/report/caseuco/CaseUcoFormatExporter.java b/Core/src/org/sleuthkit/autopsy/report/caseuco/CaseUcoFormatExporter.java index 96f88a860c..7c09ef3cb5 100755 --- a/Core/src/org/sleuthkit/autopsy/report/caseuco/CaseUcoFormatExporter.java +++ b/Core/src/org/sleuthkit/autopsy/report/caseuco/CaseUcoFormatExporter.java @@ -58,7 +58,7 @@ public final class CaseUcoFormatExporter { * @param selectedDataSourceId Object ID of the data source * @param reportOutputPath Full path to directory where to save CASE-UCO * report file - * @param progressPanel ReportProgressDialog to update progress + * @param progressPanel ReportProgressPanel to update progress */ @NbBundle.Messages({ "ReportCaseUco.noCaseOpen=Unable to open currect case", From 43fa86626dfe77c2cb8bb1d750a1ca4d190f007b Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Tue, 6 Aug 2019 16:19:12 -0400 Subject: [PATCH 4/6] Created ReportProgressPanel API and ReportProgressDialog --- .../autopsy/report/Bundle.properties | 18 +- .../autopsy/report/Bundle.properties-MERGED | 18 +- .../autopsy/report/ReportProgressDialog.java | 12 +- .../autopsy/report/ReportProgressLogger.java | 157 ++++++++++++++++++ 4 files changed, 181 insertions(+), 24 deletions(-) create mode 100755 Core/src/org/sleuthkit/autopsy/report/ReportProgressLogger.java diff --git a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties index 4c7e8868d7..fd94e5fe55 100644 --- a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties @@ -196,15 +196,15 @@ ReportHTML.writeSum.modulesEnabledHeading=Enabled Modules: ReportHTML.writeSum.autopsyVersion=Autopsy Version: ReportHTML.writeSum.timezone=Timezone: ReportHTML.writeSum.path=Path: -ReportProgressPanel.progress.queuing=Queuing... -ReportProgressPanel.initPathLabel.noFile=No report file -ReportProgressPanel.start.cancelButton.text=Cancel -ReportProgressPanel.start.progress.text=Starting report... -ReportProgressPanel.complete.processLbl.text=Complete -ReportProgressPanel.complete.processLb2.text=Completed with error -ReportProgressPanel.complete.cancelButton.text=Complete -ReportProgressPanel.cancel.cancelButton.toolTipText=Canceled -ReportProgressPanel.cancel.procLbl.text=Canceled +ReportProgressDialog.progress.queuing=Queuing... +ReportProgressDialog.initPathLabel.noFile=No report file +ReportProgressDialog.start.cancelButton.text=Cancel +ReportProgressDialog.start.progress.text=Starting report... +ReportProgressDialog.complete.processLbl.text=Complete +ReportProgressDialog.complete.processLb2.text=Completed with error +ReportProgressDialog.complete.cancelButton.text=Complete +ReportProgressDialog.cancel.cancelButton.toolTipText=Canceled +ReportProgressDialog.cancel.procLbl.text=Canceled ReportVisualPanel1.getName.text=Select and Configure Report Modules ReportVisualPanel2.getName.text=Configure Artifact Reports ReportWizardAction.actionName.text=Generate Report diff --git a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED index 5e50acbea8..ea5d7670a5 100755 --- a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED +++ b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED @@ -256,15 +256,15 @@ ReportHTML.writeSum.modulesEnabledHeading=Enabled Modules: ReportHTML.writeSum.autopsyVersion=Autopsy Version: ReportHTML.writeSum.timezone=Timezone: ReportHTML.writeSum.path=Path: -ReportProgressPanel.progress.queuing=Queuing... -ReportProgressPanel.initPathLabel.noFile=No report file -ReportProgressPanel.start.cancelButton.text=Cancel -ReportProgressPanel.start.progress.text=Starting report... -ReportProgressPanel.complete.processLbl.text=Complete -ReportProgressPanel.complete.processLb2.text=Completed with error -ReportProgressPanel.complete.cancelButton.text=Complete -ReportProgressPanel.cancel.cancelButton.toolTipText=Canceled -ReportProgressPanel.cancel.procLbl.text=Canceled +ReportProgressDialog.progress.queuing=Queuing... +ReportProgressDialog.initPathLabel.noFile=No report file +ReportProgressDialog.start.cancelButton.text=Cancel +ReportProgressDialog.start.progress.text=Starting report... +ReportProgressDialog.complete.processLbl.text=Complete +ReportProgressDialog.complete.processLb2.text=Completed with error +ReportProgressDialog.complete.cancelButton.text=Complete +ReportProgressDialog.cancel.cancelButton.toolTipText=Canceled +ReportProgressDialog.cancel.procLbl.text=Canceled ReportVisualPanel1.getName.text=Select and Configure Report Modules ReportVisualPanel2.getName.text=Configure Artifact Reports ReportWizardAction.actionName.text=Generate Report diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportProgressDialog.java b/Core/src/org/sleuthkit/autopsy/report/ReportProgressDialog.java index 0b4064c69d..ddb32686e9 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportProgressDialog.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportProgressDialog.java @@ -53,7 +53,7 @@ public class ReportProgressDialog extends javax.swing.JPanel implements ReportPr reportProgressBar.setIndeterminate(true); reportProgressBar.setMaximum(100); reportLabel.setText(reportName); - statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.progress.queuing")); + statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressDialog.progress.queuing")); status = ReportStatus.QUEUING; if (null != reportPath) { pathLabel.setText("" + shortenPath(reportPath) + ""); //NON-NLS @@ -99,7 +99,7 @@ public class ReportProgressDialog extends javax.swing.JPanel implements ReportPr } }); } else { - pathLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.initPathLabel.noFile")); + pathLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressDialog.initPathLabel.noFile")); } } @@ -119,7 +119,7 @@ public class ReportProgressDialog extends javax.swing.JPanel implements ReportPr @Override public void start() { EventQueue.invokeLater(() -> { - statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.start.progress.text")); + statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressDialog.start.progress.text")); status = ReportStatus.RUNNING; }); } @@ -213,7 +213,7 @@ public class ReportProgressDialog extends javax.swing.JPanel implements ReportPr ReportStatus oldValue = status; status = ReportStatus.COMPLETE; statusMessageLabel.setForeground(Color.BLACK); - statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLbl.text")); + statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressDialog.complete.processLbl.text")); reportProgressBar.setValue(reportProgressBar.getMaximum()); reportProgressBar.setStringPainted(true); reportProgressBar.setForeground(GREEN); @@ -225,7 +225,7 @@ public class ReportProgressDialog extends javax.swing.JPanel implements ReportPr ReportStatus oldValue = status; status = ReportStatus.ERROR; statusMessageLabel.setForeground(RED); - statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.complete.processLb2.text")); + statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressDialog.complete.processLb2.text")); reportProgressBar.setValue(reportProgressBar.getMaximum()); reportProgressBar.setStringPainted(true); reportProgressBar.setForeground(RED); @@ -263,7 +263,7 @@ public class ReportProgressDialog extends javax.swing.JPanel implements ReportPr reportProgressBar.setString("Cancelled"); //NON-NLS firePropertyChange(ReportStatus.CANCELED.toString(), oldValue, status); statusMessageLabel.setForeground(RED); - statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressPanel.cancel.procLbl.text")); + statusMessageLabel.setText(NbBundle.getMessage(this.getClass(), "ReportProgressDialog.cancel.procLbl.text")); break; } } diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportProgressLogger.java b/Core/src/org/sleuthkit/autopsy/report/ReportProgressLogger.java new file mode 100755 index 0000000000..a6219d45c6 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/report/ReportProgressLogger.java @@ -0,0 +1,157 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2019 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.report; + +import java.util.logging.Level; +import org.sleuthkit.autopsy.coreutils.Logger; + +/** + * Writes progress and status messages to the application log. + */ +class ReportProgressLogger implements ReportProgressPanel { + + private static final Logger logger = Logger.getLogger(ReportProgressLogger.class.getName()); + private volatile ReportProgressPanel.ReportStatus status; + + ReportProgressLogger() { + status = ReportStatus.QUEUING; + } + + /** + * Gets the current status of the generation of the report. + * + * @return The report generation status as a ReportStatus enum. + */ + @Override + public ReportStatus getStatus() { + return status; + } + + /** + * Logs that the report has been started. + */ + @Override + public void start() { + status = ReportStatus.RUNNING; + logger.log(Level.INFO, "Report started"); + } + + /** + * NO-OP. + * + * @param max The maximum value. + */ + @Override + public void setMaximumProgress(int max) { + } + + /** + * NO-OP. + */ + @Override + public void increment() { + } + + /** + * NO-OP. + * + * @param value The value to be set. + */ + @Override + public void setProgress(int value) { + } + + /** + * NO-OP. + * + * @param indeterminate True if the progress bar should be set to + * indeterminate. + */ + @Override + public void setIndeterminate(boolean indeterminate) { + } + + /** + * Logs the status message. + * + * @param statusMessage String to use as label text. + */ + @Override + public void updateStatusLabel(String statusMessage) { + if (status != ReportStatus.CANCELED) { + logger.log(Level.INFO, "Report Progress Logger status update: {0}", statusMessage); + } + } + + /** + * Logs the final status of the report generation. + * + * @param reportStatus The final status, must be COMPLETE or ERROR. + */ + @Override + public void complete(ReportStatus reportStatus) { + if (status != ReportStatus.CANCELED) { + switch (reportStatus) { + case COMPLETE: { + status = ReportStatus.COMPLETE; + logger.log(Level.INFO, "Report completed"); + break; + } + case ERROR: { + status = ReportStatus.ERROR; + logger.log(Level.INFO, "Report completed with errors"); + break; + } + default: { + break; + } + } + } + } + + /** + * Logs that the generation of the report was cancelled. + */ + void cancel() { + switch (status) { + case COMPLETE: + break; + case CANCELED: + break; + case ERROR: + break; + default: + status = ReportStatus.CANCELED; + logger.log(Level.INFO, "Report cancelled"); + break; + } + } + + /** + * Logs the final status of the report generation. + * + * @deprecated Use {@link #complete(ReportStatus)} + */ + @Deprecated + @Override + public void complete() { + complete(ReportStatus.COMPLETE); + } + +} From b7945d3ecaec3c246f3a412772cb63025ea32269 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 7 Aug 2019 09:03:37 -0400 Subject: [PATCH 5/6] Code review --- Core/src/org/sleuthkit/autopsy/report/ReportProgressLogger.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportProgressLogger.java b/Core/src/org/sleuthkit/autopsy/report/ReportProgressLogger.java index a6219d45c6..d2ef9212b0 100755 --- a/Core/src/org/sleuthkit/autopsy/report/ReportProgressLogger.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportProgressLogger.java @@ -95,7 +95,7 @@ class ReportProgressLogger implements ReportProgressPanel { @Override public void updateStatusLabel(String statusMessage) { if (status != ReportStatus.CANCELED) { - logger.log(Level.INFO, "Report Progress Logger status update: {0}", statusMessage); + logger.log(Level.INFO, "Status update: {0}", statusMessage); } } From 0c505041056f5e8801f8d7568c2e362edaf1eeca Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 7 Aug 2019 13:41:22 -0400 Subject: [PATCH 6/6] Minor --- Core/src/org/sleuthkit/autopsy/report/ReportProgressLogger.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportProgressLogger.java b/Core/src/org/sleuthkit/autopsy/report/ReportProgressLogger.java index d2ef9212b0..210fdc2815 100755 --- a/Core/src/org/sleuthkit/autopsy/report/ReportProgressLogger.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportProgressLogger.java @@ -95,7 +95,7 @@ class ReportProgressLogger implements ReportProgressPanel { @Override public void updateStatusLabel(String statusMessage) { if (status != ReportStatus.CANCELED) { - logger.log(Level.INFO, "Status update: {0}", statusMessage); + logger.log(Level.INFO, statusMessage); } }