show warning in less intrusive JFX notifications instead of Message boxes, suppress NPEs during painting.

This commit is contained in:
millmanorama 2018-04-30 14:53:08 +02:00
parent 3fbca05057
commit e134108767
2 changed files with 68 additions and 20 deletions

View File

@ -11,7 +11,7 @@
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,0,110,0,0,3,65"/> <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,0,-93,0,0,3,71"/>
</AuxValues> </AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
@ -49,9 +49,9 @@
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<EmptySpace max="32767" attributes="0"/> <EmptySpace pref="71" max="32767" attributes="0"/>
<Component id="jTextArea1" min="-2" pref="424" max="-2" attributes="0"/> <Component id="jTextArea1" min="-2" pref="424" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/> <EmptySpace pref="248" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -120,7 +120,7 @@
<Component id="zoomActualButton" min="-2" pref="33" max="-2" attributes="0"/> <Component id="zoomActualButton" min="-2" pref="33" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="fitZoomButton" min="-2" pref="32" max="-2" attributes="0"/> <Component id="fitZoomButton" min="-2" pref="32" max="-2" attributes="0"/>
<EmptySpace pref="12" max="32767" attributes="0"/> <EmptySpace max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -312,6 +312,17 @@
</Component> </Component>
</SubComponents> </SubComponents>
</Container> </Container>
<Container class="javafx.embed.swing.JFXPanel" name="notificationsJFXPanel">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="Last"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="true"/>
</Layout>
</Container>
</SubComponents> </SubComponents>
</Container> </Container>
</SubComponents> </SubComponents>

View File

@ -44,6 +44,7 @@ import java.awt.Cursor;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.Frame; import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
@ -57,14 +58,18 @@ import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.Map;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; 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.AbstractAction;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton; import javax.swing.JButton;
@ -78,6 +83,7 @@ import javax.swing.JToolBar;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
import org.controlsfx.control.Notifications;
import org.jdesktop.layout.GroupLayout; import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle; import org.jdesktop.layout.LayoutStyle;
import org.openide.explorer.ExplorerManager; 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.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined;
import org.sleuthkit.autopsy.progress.ModalDialogProgressIndicator; import org.sleuthkit.autopsy.progress.ModalDialogProgressIndicator;
import org.sleuthkit.datamodel.CommunicationsFilter; import org.sleuthkit.datamodel.CommunicationsFilter;
@ -142,12 +147,38 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider
private final Map<NamedGraphLayout, JButton> layoutButtons = new HashMap<>(); private final Map<NamedGraphLayout, JButton> layoutButtons = new HashMap<>();
private NamedGraphLayout currentLayout; private NamedGraphLayout currentLayout;
@NbBundle.Messages("VisalizationPanel.paintingError=Problem painting visualization.")
public VisualizationPanel() { public VisualizationPanel() {
initComponents(); initComponents();
//initialize invisible JFXPanel that is used to show JFXNotifications over this window.
notificationsJFXPanel.setScene(new Scene(new Pane()));
graph = new CommunicationsGraph(pinnedAccountModel, lockedVertexModel); 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.setAutoExtend(true);
graphComponent.setAutoScroll(true); graphComponent.setAutoScroll(true);
graphComponent.setAutoscrolls(true); graphComponent.setAutoscrolls(true);
@ -355,6 +386,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider
zoomLabel = new JLabel(); zoomLabel = new JLabel();
clearVizButton = new JButton(); clearVizButton = new JButton();
jSeparator2 = new JToolBar.Separator(); jSeparator2 = new JToolBar.Separator();
notificationsJFXPanel = new JFXPanel();
setLayout(new BorderLayout()); setLayout(new BorderLayout());
@ -373,9 +405,9 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider
placeHolderPanel.setLayout(placeHolderPanelLayout); placeHolderPanel.setLayout(placeHolderPanelLayout);
placeHolderPanelLayout.setHorizontalGroup(placeHolderPanelLayout.createParallelGroup(GroupLayout.LEADING) placeHolderPanelLayout.setHorizontalGroup(placeHolderPanelLayout.createParallelGroup(GroupLayout.LEADING)
.add(placeHolderPanelLayout.createSequentialGroup() .add(placeHolderPanelLayout.createSequentialGroup()
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap(71, Short.MAX_VALUE)
.add(jTextArea1, GroupLayout.PREFERRED_SIZE, 424, GroupLayout.PREFERRED_SIZE) .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) placeHolderPanelLayout.setVerticalGroup(placeHolderPanelLayout.createParallelGroup(GroupLayout.LEADING)
.add(placeHolderPanelLayout.createSequentialGroup() .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) .add(zoomActualButton, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.RELATED) .addPreferredGap(LayoutStyle.RELATED)
.add(fitZoomButton, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE) .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) toolbarLayout.setVerticalGroup(toolbarLayout.createParallelGroup(GroupLayout.LEADING)
.add(toolbarLayout.createSequentialGroup() .add(toolbarLayout.createSequentialGroup()
@ -528,6 +560,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider
); );
borderLayoutPanel.add(toolbar, BorderLayout.PAGE_START); borderLayoutPanel.add(toolbar, BorderLayout.PAGE_START);
borderLayoutPanel.add(notificationsJFXPanel, BorderLayout.PAGE_END);
splitPane.setLeftComponent(borderLayoutPanel); splitPane.setLeftComponent(borderLayoutPanel);
@ -589,12 +622,15 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider
get(); get();
} catch (InterruptedException | ExecutionException ex) { } catch (InterruptedException | ExecutionException ex) {
logger.log(Level.WARNING, "CVT graph layout failed.", ex); logger.log(Level.WARNING, "CVT graph layout failed.", ex);
if (lockedVertexModel.isEmpty()) { String message = (lockedVertexModel.isEmpty())
MessageNotifyUtil.Message.error(Bundle.VisualizationPanel_layoutFail_text(layout.getDisplayName())); ? Bundle.VisualizationPanel_layoutFail_text(layout.getDisplayName())
} else { : Bundle.VisualizationPanel_layoutFailWithLockedVertices_text(layout.getDisplayName());
MessageNotifyUtil.Message.error(Bundle.VisualizationPanel_layoutFailWithLockedVertices_text(layout.getDisplayName()));
} Platform.runLater(()
undoManager.undo(); -> Notifications.create().owner(notificationsJFXPanel.getScene().getWindow())
.text(message)
.showWarning()
);
} }
} }
}.execute(); }.execute();
@ -651,6 +687,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider
private JToolBar.Separator jSeparator1; private JToolBar.Separator jSeparator1;
private JToolBar.Separator jSeparator2; private JToolBar.Separator jSeparator2;
private JTextArea jTextArea1; private JTextArea jTextArea1;
private JFXPanel notificationsJFXPanel;
private JButton organicLayoutButton; private JButton organicLayoutButton;
private JPanel placeHolderPanel; private JPanel placeHolderPanel;
private JSplitPane splitPane; private JSplitPane splitPane;
@ -729,7 +766,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider
@Override @Override
public boolean isVertexIgnored(Object vertex) { public boolean isVertexIgnored(Object vertex) {
return super.isVertexIgnored(vertex) return super.isVertexIgnored(vertex)
|| lockedVertexModel.isVertexLocked((mxCell) vertex); || lockedVertexModel.isVertexLocked((mxCell) vertex);
} }
@Override @Override
@ -760,7 +797,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider
@Override @Override
public boolean isVertexIgnored(Object vertex) { public boolean isVertexIgnored(Object vertex) {
return super.isVertexIgnored(vertex) return super.isVertexIgnored(vertex)
|| lockedVertexModel.isVertexLocked((mxCell) vertex); || lockedVertexModel.isVertexLocked((mxCell) vertex);
} }
@Override @Override
@ -791,7 +828,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider
@Override @Override
public boolean isVertexIgnored(Object vertex) { public boolean isVertexIgnored(Object vertex) {
return super.isVertexIgnored(vertex) return super.isVertexIgnored(vertex)
|| lockedVertexModel.isVertexLocked((mxCell) vertex); || lockedVertexModel.isVertexLocked((mxCell) vertex);
} }
@Override @Override
@ -821,7 +858,7 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider
@Override @Override
public boolean isVertexIgnored(Object vertex) { public boolean isVertexIgnored(Object vertex) {
return super.isVertexIgnored(vertex) return super.isVertexIgnored(vertex)
|| lockedVertexModel.isVertexLocked((mxCell) vertex); || lockedVertexModel.isVertexLocked((mxCell) vertex);
} }
@Override @Override