From e134108767def261d82dfbaf71d06f50047d2986 Mon Sep 17 00:00:00 2001 From: millmanorama Date: Mon, 30 Apr 2018 14:53:08 +0200 Subject: [PATCH 1/6] show warning in less intrusive JFX notifications instead of Message boxes, suppress NPEs during painting. --- .../communications/VisualizationPanel.form | 19 +++-- .../communications/VisualizationPanel.java | 69 ++++++++++++++----- 2 files changed, 68 insertions(+), 20 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.form b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.form index a847f700c7..49b86ae014 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.form +++ b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.form @@ -11,7 +11,7 @@ - + @@ -49,9 +49,9 @@ - + - + @@ -120,7 +120,7 @@ - + @@ -312,6 +312,17 @@ + + + + + + + + + + + diff --git a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java index 4f6b53ae39..83b30e9a01 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java +++ b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java @@ -44,6 +44,7 @@ import java.awt.Cursor; import java.awt.Dimension; import java.awt.Font; import java.awt.Frame; +import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; @@ -57,14 +58,18 @@ import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutionException; -import java.util.Map; import java.util.concurrent.Future; import java.util.function.BiConsumer; import java.util.logging.Level; import java.util.stream.Collectors; import java.util.stream.Stream; +import javafx.application.Platform; +import javafx.embed.swing.JFXPanel; +import javafx.scene.Scene; +import javafx.scene.layout.Pane; import javax.swing.AbstractAction; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -78,6 +83,7 @@ import javax.swing.JToolBar; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; +import org.controlsfx.control.Notifications; import org.jdesktop.layout.GroupLayout; import org.jdesktop.layout.LayoutStyle; import org.openide.explorer.ExplorerManager; @@ -89,7 +95,6 @@ import org.openide.util.lookup.ProxyLookup; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.progress.ModalDialogProgressIndicator; import org.sleuthkit.datamodel.CommunicationsFilter; @@ -142,12 +147,38 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider private final Map layoutButtons = new HashMap<>(); private NamedGraphLayout currentLayout; + @NbBundle.Messages("VisalizationPanel.paintingError=Problem painting visualization.") public VisualizationPanel() { initComponents(); + //initialize invisible JFXPanel that is used to show JFXNotifications over this window. + notificationsJFXPanel.setScene(new Scene(new Pane())); graph = new CommunicationsGraph(pinnedAccountModel, lockedVertexModel); - graphComponent = new mxGraphComponent(graph); + /* + * custom implementation of mxGraphComponent that uses... a custom + * implmementation of mxGraphControl ... that overrides paint so we can + * catch the NPEs we are getting and deal with them. For now that means + * just ignoring them. + */ + graphComponent = new mxGraphComponent(graph) { + @Override + protected mxGraphComponent.mxGraphControl createGraphControl() { + + return new mxGraphControl() { + + @Override + public void paint(Graphics graphics) { + try { + super.paint(graphics); + } catch (NullPointerException ex) { + logger.log(Level.WARNING, "There was a NPE while painging the VisualizaitonPanel.", ex); + } + } + + }; + } + }; graphComponent.setAutoExtend(true); graphComponent.setAutoScroll(true); graphComponent.setAutoscrolls(true); @@ -355,6 +386,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider zoomLabel = new JLabel(); clearVizButton = new JButton(); jSeparator2 = new JToolBar.Separator(); + notificationsJFXPanel = new JFXPanel(); setLayout(new BorderLayout()); @@ -373,9 +405,9 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider placeHolderPanel.setLayout(placeHolderPanelLayout); placeHolderPanelLayout.setHorizontalGroup(placeHolderPanelLayout.createParallelGroup(GroupLayout.LEADING) .add(placeHolderPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap(71, Short.MAX_VALUE) .add(jTextArea1, GroupLayout.PREFERRED_SIZE, 424, GroupLayout.PREFERRED_SIZE) - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap(248, Short.MAX_VALUE)) ); placeHolderPanelLayout.setVerticalGroup(placeHolderPanelLayout.createParallelGroup(GroupLayout.LEADING) .add(placeHolderPanelLayout.createSequentialGroup() @@ -504,7 +536,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider .add(zoomActualButton, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.RELATED) .add(fitZoomButton, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE) - .addContainerGap(12, Short.MAX_VALUE)) + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); toolbarLayout.setVerticalGroup(toolbarLayout.createParallelGroup(GroupLayout.LEADING) .add(toolbarLayout.createSequentialGroup() @@ -528,6 +560,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider ); borderLayoutPanel.add(toolbar, BorderLayout.PAGE_START); + borderLayoutPanel.add(notificationsJFXPanel, BorderLayout.PAGE_END); splitPane.setLeftComponent(borderLayoutPanel); @@ -589,12 +622,15 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider get(); } catch (InterruptedException | ExecutionException ex) { logger.log(Level.WARNING, "CVT graph layout failed.", ex); - if (lockedVertexModel.isEmpty()) { - MessageNotifyUtil.Message.error(Bundle.VisualizationPanel_layoutFail_text(layout.getDisplayName())); - } else { - MessageNotifyUtil.Message.error(Bundle.VisualizationPanel_layoutFailWithLockedVertices_text(layout.getDisplayName())); - } - undoManager.undo(); + String message = (lockedVertexModel.isEmpty()) + ? Bundle.VisualizationPanel_layoutFail_text(layout.getDisplayName()) + : Bundle.VisualizationPanel_layoutFailWithLockedVertices_text(layout.getDisplayName()); + + Platform.runLater(() + -> Notifications.create().owner(notificationsJFXPanel.getScene().getWindow()) + .text(message) + .showWarning() + ); } } }.execute(); @@ -651,6 +687,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider private JToolBar.Separator jSeparator1; private JToolBar.Separator jSeparator2; private JTextArea jTextArea1; + private JFXPanel notificationsJFXPanel; private JButton organicLayoutButton; private JPanel placeHolderPanel; private JSplitPane splitPane; @@ -729,7 +766,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider @Override public boolean isVertexIgnored(Object vertex) { return super.isVertexIgnored(vertex) - || lockedVertexModel.isVertexLocked((mxCell) vertex); + || lockedVertexModel.isVertexLocked((mxCell) vertex); } @Override @@ -760,7 +797,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider @Override public boolean isVertexIgnored(Object vertex) { return super.isVertexIgnored(vertex) - || lockedVertexModel.isVertexLocked((mxCell) vertex); + || lockedVertexModel.isVertexLocked((mxCell) vertex); } @Override @@ -791,7 +828,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider @Override public boolean isVertexIgnored(Object vertex) { return super.isVertexIgnored(vertex) - || lockedVertexModel.isVertexLocked((mxCell) vertex); + || lockedVertexModel.isVertexLocked((mxCell) vertex); } @Override @@ -821,7 +858,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider @Override public boolean isVertexIgnored(Object vertex) { return super.isVertexIgnored(vertex) - || lockedVertexModel.isVertexLocked((mxCell) vertex); + || lockedVertexModel.isVertexLocked((mxCell) vertex); } @Override From b6f33bf798805d2ed153e4da8107e837c05a4c1c Mon Sep 17 00:00:00 2001 From: millmanorama Date: Mon, 30 Apr 2018 15:07:24 +0200 Subject: [PATCH 2/6] disable PMD/codacy warning about catching NPE --- .../sleuthkit/autopsy/communications/VisualizationPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java index 83b30e9a01..e0ac3c9220 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java +++ b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java @@ -171,7 +171,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider public void paint(Graphics graphics) { try { super.paint(graphics); - } catch (NullPointerException ex) { + } catch (NullPointerException ex) { //NOPMD We can't find the underlying cause in jgraphx logger.log(Level.WARNING, "There was a NPE while painging the VisualizaitonPanel.", ex); } } From f36a7b5a6e1afb4e2ee4bb965c77948dd70ddf5b Mon Sep 17 00:00:00 2001 From: millmanorama Date: Mon, 30 Apr 2018 15:08:09 +0200 Subject: [PATCH 3/6] fix typo in log message --- .../sleuthkit/autopsy/communications/VisualizationPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java index e0ac3c9220..e7ec7cec82 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java +++ b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java @@ -172,7 +172,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider try { super.paint(graphics); } catch (NullPointerException ex) { //NOPMD We can't find the underlying cause in jgraphx - logger.log(Level.WARNING, "There was a NPE while painging the VisualizaitonPanel.", ex); + logger.log(Level.WARNING, "There was a NPE while painting the VisualizaitonPanel.", ex); } } From 7195a146a6b634462c754a7e61b558e37332b3cd Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Wed, 9 May 2018 18:16:15 -0400 Subject: [PATCH 4/6] Fix spelling errors in VisualizationPanel.java --- .../sleuthkit/autopsy/communications/VisualizationPanel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java index e7ec7cec82..42d360db64 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java +++ b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java @@ -157,7 +157,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider /* * custom implementation of mxGraphComponent that uses... a custom - * implmementation of mxGraphControl ... that overrides paint so we can + * implementation of mxGraphControl ... that overrides paint so we can * catch the NPEs we are getting and deal with them. For now that means * just ignoring them. */ @@ -172,7 +172,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider try { super.paint(graphics); } catch (NullPointerException ex) { //NOPMD We can't find the underlying cause in jgraphx - logger.log(Level.WARNING, "There was a NPE while painting the VisualizaitonPanel.", ex); + logger.log(Level.WARNING, "There was a NPE while painting the VisualizationPanel", ex); } } From 5e7dddc8d87bf959b2edb3d37e3b17809c394360 Mon Sep 17 00:00:00 2001 From: millmanorama Date: Thu, 10 May 2018 16:28:41 +0200 Subject: [PATCH 5/6] improve comment --- .../autopsy/communications/VisualizationPanel.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java index 42d360db64..918eb017da 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java +++ b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java @@ -171,7 +171,12 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider public void paint(Graphics graphics) { try { super.paint(graphics); - } catch (NullPointerException ex) { //NOPMD We can't find the underlying cause in jgraphx + } catch (NullPointerException ex) { //NOPMD + /* We can't find the underlying cause of the NPE in + * jgraphx, but it doesn't seem to cause any + * noticeable problems, so we are just logging it + * and moving on. + */ logger.log(Level.WARNING, "There was a NPE while painting the VisualizationPanel", ex); } } From d4d157765de6c239bf714f288566471d267678e7 Mon Sep 17 00:00:00 2001 From: "U-BASIS\\dgrove" Date: Mon, 14 May 2018 14:00:29 -0400 Subject: [PATCH 6/6] Fixed scrollbar on options panel. --- .../KeywordSearchGlobalLanguageSettingsPanel.form | 4 ++-- .../KeywordSearchGlobalLanguageSettingsPanel.java | 11 ++++++++--- .../autopsy/keywordsearch/KeywordSearchSettings.java | 8 +++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchGlobalLanguageSettingsPanel.form b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchGlobalLanguageSettingsPanel.form index c6f133161b..02b5d3cede 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchGlobalLanguageSettingsPanel.form +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchGlobalLanguageSettingsPanel.form @@ -48,14 +48,14 @@ - + - + diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchGlobalLanguageSettingsPanel.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchGlobalLanguageSettingsPanel.java index 513b26ea30..8342587833 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchGlobalLanguageSettingsPanel.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchGlobalLanguageSettingsPanel.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2012-2014 Basis Technology Corp. + * Copyright 2012-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,6 +28,7 @@ import java.util.Map; import javax.swing.JCheckBox; import org.netbeans.spi.options.OptionsPanelController; import org.sleuthkit.autopsy.corecomponents.OptionsPanel; +import org.sleuthkit.autopsy.coreutils.PlatformUtil; import org.sleuthkit.autopsy.coreutils.StringExtract; import org.sleuthkit.autopsy.coreutils.StringExtract.StringExtractUnicodeTable.SCRIPT; import org.sleuthkit.autopsy.ingest.IngestManager; @@ -61,6 +62,10 @@ class KeywordSearchGlobalLanguageSettingsPanel extends javax.swing.JPanel implem } } }; + + if (!PlatformUtil.isWindowsOS()) { + enableOcrCheckbox.setVisible(false); + } initScriptsCheckBoxes(); reloadScriptsCheckBoxes(); @@ -234,14 +239,14 @@ class KeywordSearchGlobalLanguageSettingsPanel extends javax.swing.JPanel implem .addComponent(ingestSettingsLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(enableOcrCheckbox) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(enableUTF16Checkbox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(enableUTF8Checkbox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(languagesLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(langPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(langPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE) .addContainerGap()) ); }// //GEN-END:initComponents diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSettings.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSettings.java index 096c6a255a..4350ce3085 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSettings.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSettings.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2012-2014 Basis Technology Corp. + * Copyright 2012-2018 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -132,7 +132,8 @@ class KeywordSearchSettings { /** * Save OCR setting to permanent storage - * @param enabled + * + * @param enabled Is OCR enabled? */ static void setOcrOption(boolean enabled) { ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, OCR_ENABLED, (enabled ? "true" : "false")); //NON-NLS @@ -140,7 +141,8 @@ class KeywordSearchSettings { /** * Get OCR setting from permanent storage - * @return + * + * @return Is OCR enabled? */ static boolean getOcrOption() { if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, OCR_ENABLED)) {