From 1bec33604b401edffa5511c086ca0da6fe2ff77c Mon Sep 17 00:00:00 2001 From: millmanorama Date: Sat, 7 Apr 2018 16:19:14 +0200 Subject: [PATCH] fix codacy warnings --- .../communications/AbstractCVTAction.java | 5 +--- .../autopsy/communications/CVTEvents.java | 1 - .../communications/CommunicationsGraph.java | 23 ++++++++----------- .../communications/LockedVertexModel.java | 18 ++++++++------- .../communications/MessageBrowser.java | 1 - .../communications/PinAccountsAction.java | 8 +++++-- .../communications/PinnedAccountModel.java | 14 +++++++++++ .../ResetAndPinAccountsAction.java | 6 ++--- .../autopsy/communications/SelectionNode.java | 9 ++++---- .../communications/UnpinAccountsAction.java | 4 ++++ .../communications/VisualizationPanel.java | 11 ++++++++- 11 files changed, 62 insertions(+), 38 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/communications/AbstractCVTAction.java b/Core/src/org/sleuthkit/autopsy/communications/AbstractCVTAction.java index 82cbe5e0f8..ef751d262c 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/AbstractCVTAction.java +++ b/Core/src/org/sleuthkit/autopsy/communications/AbstractCVTAction.java @@ -26,7 +26,6 @@ import org.openide.util.Utilities; import org.openide.util.actions.Presenter; /** - * * Base class for actions that act on the selected AccountDeviceInstanceKeys. * getPopupPresenter() provides a JMenuItem that works (i.e., has an icon) in * custom context menus and also in the Netbeans Explorer views. @@ -39,8 +38,7 @@ abstract class AbstractCVTAction extends AbstractAction implements Presenter.Pop * @return The selected accounts */ Collection getSelectedAccounts() { - final Collection lookupAll = Utilities.actionsGlobalContext().lookupAll(AccountDeviceInstanceKey.class); - return lookupAll; + return Utilities.actionsGlobalContext().lookupAll(AccountDeviceInstanceKey.class); } @Override @@ -64,5 +62,4 @@ abstract class AbstractCVTAction extends AbstractAction implements Presenter.Pop * @return An ImageIcon used to represent this action. */ abstract ImageIcon getIcon(); - } diff --git a/Core/src/org/sleuthkit/autopsy/communications/CVTEvents.java b/Core/src/org/sleuthkit/autopsy/communications/CVTEvents.java index 54e5b8a1ef..6a6a60d3da 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/CVTEvents.java +++ b/Core/src/org/sleuthkit/autopsy/communications/CVTEvents.java @@ -21,7 +21,6 @@ package org.sleuthkit.autopsy.communications; import com.google.common.collect.ImmutableSet; import com.google.common.eventbus.EventBus; import java.util.Collection; -import java.util.Set; import org.sleuthkit.datamodel.CommunicationsFilter; /** diff --git a/Core/src/org/sleuthkit/autopsy/communications/CommunicationsGraph.java b/Core/src/org/sleuthkit/autopsy/communications/CommunicationsGraph.java index 98d9aa7d88..2cf04eacea 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/CommunicationsGraph.java +++ b/Core/src/org/sleuthkit/autopsy/communications/CommunicationsGraph.java @@ -25,7 +25,6 @@ import com.google.common.collect.MultimapBuilder; import com.mxgraph.model.mxCell; import com.mxgraph.model.mxICell; import com.mxgraph.util.mxConstants; -import com.mxgraph.view.mxCellState; import com.mxgraph.view.mxGraph; import com.mxgraph.view.mxStylesheet; import java.io.InputStream; @@ -38,7 +37,6 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; -import java.util.function.Consumer; import java.util.logging.Level; import javax.swing.SwingWorker; import org.sleuthkit.autopsy.coreutils.Logger; @@ -96,7 +94,7 @@ final class CommunicationsGraph extends mxGraph { CommunicationsGraph(PinnedAccountModel pinnedAccountModel, LockedVertexModel lockedVertexModel) { super(mxStylesheet); - this.pinnedAccountModel =pinnedAccountModel; + this.pinnedAccountModel = pinnedAccountModel; this.lockedVertexModel = lockedVertexModel; //set fixed properties of graph. setAutoSizeCells(true); @@ -243,20 +241,20 @@ final class CommunicationsGraph extends mxGraph { */ private class RebuildWorker extends SwingWorker { - private final ProgressIndicator progress; + private final ProgressIndicator progressIndicator; private final CommunicationsManager commsManager; private final CommunicationsFilter currentFilter; RebuildWorker(ProgressIndicator progress, CommunicationsManager commsManager, CommunicationsFilter currentFilter) { - this.progress = progress; + this.progressIndicator = progress; this.currentFilter = currentFilter; this.commsManager = commsManager; } @Override - protected Void doInBackground() throws Exception { - progress.start("Loading accounts"); + protected Void doInBackground() { + progressIndicator.start("Loading accounts"); int progressCounter = 0; try { /** @@ -278,7 +276,7 @@ final class CommunicationsGraph extends mxGraph { final AccountDeviceInstanceKey relatedADIKey = new AccountDeviceInstanceKey(relatedADI, currentFilter, adiRelationshipsCount); relatedAccounts.put(relatedADI, relatedADIKey); //store related accounts } - progress.progress(++progressCounter); + progressIndicator.progress(++progressCounter); } Set accounts = relatedAccounts.keySet(); @@ -286,9 +284,9 @@ final class CommunicationsGraph extends mxGraph { Map relationshipCounts = commsManager.getRelationshipCountsPairwise(accounts, currentFilter); int total = relationshipCounts.size(); - int k = 0; + int progress = 0; String progressText = ""; - progress.switchToDeterminate("", 0, total); + progressIndicator.switchToDeterminate("", 0, total); for (Map.Entry entry : relationshipCounts.entrySet()) { Long count = entry.getValue(); AccountPair relationshipKey = entry.getKey(); @@ -300,11 +298,10 @@ final class CommunicationsGraph extends mxGraph { mxCell addEdge = addOrUpdateEdge(count, account1, account2); progressText = addEdge.getId(); } - progress.progress(progressText, k++); + progressIndicator.progress(progressText, progress++); } } catch (TskCoreException tskCoreException) { logger.log(Level.SEVERE, "Error", tskCoreException); - } finally { } return null; @@ -320,7 +317,7 @@ final class CommunicationsGraph extends mxGraph { } catch (CancellationException ex) { logger.log(Level.INFO, "Graph visualization cancelled"); } finally { - progress.finish(); + progressIndicator.finish(); } } } diff --git a/Core/src/org/sleuthkit/autopsy/communications/LockedVertexModel.java b/Core/src/org/sleuthkit/autopsy/communications/LockedVertexModel.java index 873866f3f5..3ff5880b63 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/LockedVertexModel.java +++ b/Core/src/org/sleuthkit/autopsy/communications/LockedVertexModel.java @@ -32,14 +32,6 @@ import java.util.Set; */ final class LockedVertexModel { - void registerhandler(Object handler) { - eventBus.register(handler); - } - - void unregisterhandler(Object handler) { - eventBus.unregister(handler); - } - private final EventBus eventBus = new EventBus(); /** @@ -49,6 +41,16 @@ final class LockedVertexModel { */ private final Set lockedVertices = new HashSet<>(); + + void registerhandler(Object handler) { + eventBus.register(handler); + } + + void unregisterhandler(Object handler) { + eventBus.unregister(handler); + } + + /** * Lock the given vertices so that applying a layout algorithm doesn't move * them. The user can still manually position the vertices. diff --git a/Core/src/org/sleuthkit/autopsy/communications/MessageBrowser.java b/Core/src/org/sleuthkit/autopsy/communications/MessageBrowser.java index 7c0bf99c62..7b90357993 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/MessageBrowser.java +++ b/Core/src/org/sleuthkit/autopsy/communications/MessageBrowser.java @@ -35,7 +35,6 @@ import org.sleuthkit.autopsy.corecomponents.DataResultPanel; import org.sleuthkit.autopsy.corecomponents.DataResultViewerTable; import org.sleuthkit.autopsy.corecomponents.TableFilterNode; import org.sleuthkit.autopsy.directorytree.DataResultFilterNode; -import org.sleuthkit.datamodel.AccountDeviceInstance; /** * The right hand side of the CVT. Has a DataResultPanel to show a listing of diff --git a/Core/src/org/sleuthkit/autopsy/communications/PinAccountsAction.java b/Core/src/org/sleuthkit/autopsy/communications/PinAccountsAction.java index d820373284..52136d1b1a 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/PinAccountsAction.java +++ b/Core/src/org/sleuthkit/autopsy/communications/PinAccountsAction.java @@ -23,6 +23,10 @@ import javax.swing.ImageIcon; import org.openide.util.ImageUtilities; import org.openide.util.NbBundle; +/** + * Action that pins the AccountDevicesIntanceKeys in the ActionsGlobalContext to + * the visualizaion + */ @NbBundle.Messages({"PinAccountsAction.pluralText=Add Selected Accounts to Visualization", "PinAccountsAction.singularText=Add Selected Account to Visualization"}) final class PinAccountsAction extends AbstractCVTAction { @@ -31,7 +35,7 @@ final class PinAccountsAction extends AbstractCVTAction { "/org/sleuthkit/autopsy/communications/images/marker--plus.png", false); private static final String SINGULAR_TEXT = Bundle.PinAccountsAction_singularText(); private static final String PLURAL_TEXT = Bundle.PinAccountsAction_pluralText(); - + private static final PinAccountsAction instance = new PinAccountsAction(); static PinAccountsAction getInstance() { @@ -39,7 +43,7 @@ final class PinAccountsAction extends AbstractCVTAction { } @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(ActionEvent event) { CVTEvents.getCVTEventBus().post(new CVTEvents.PinAccountsEvent(getSelectedAccounts(), false)); } diff --git a/Core/src/org/sleuthkit/autopsy/communications/PinnedAccountModel.java b/Core/src/org/sleuthkit/autopsy/communications/PinnedAccountModel.java index beff35173d..f7fb7d1232 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/PinnedAccountModel.java +++ b/Core/src/org/sleuthkit/autopsy/communications/PinnedAccountModel.java @@ -19,9 +19,13 @@ package org.sleuthkit.autopsy.communications; import com.google.common.collect.ImmutableSet; +import com.google.common.eventbus.EventBus; import java.util.HashSet; import java.util.Set; +/** + * Model of what accounts are pinned to a visualization. + */ class PinnedAccountModel { /** @@ -32,6 +36,16 @@ class PinnedAccountModel { */ private final Set pinnedAccountDevices = new HashSet<>(); + private final EventBus eventBus = new EventBus(); + + void registerhandler(Object handler) { + eventBus.register(handler); + } + + void unregisterhandler(Object handler) { + eventBus.unregister(handler); + } + boolean isAccountPinned(AccountDeviceInstanceKey account) { return pinnedAccountDevices.contains(account); } diff --git a/Core/src/org/sleuthkit/autopsy/communications/ResetAndPinAccountsAction.java b/Core/src/org/sleuthkit/autopsy/communications/ResetAndPinAccountsAction.java index a42b2882ed..385ac3348b 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/ResetAndPinAccountsAction.java +++ b/Core/src/org/sleuthkit/autopsy/communications/ResetAndPinAccountsAction.java @@ -24,7 +24,8 @@ import org.openide.util.ImageUtilities; import org.openide.util.NbBundle; /** - * + * Action that clears any pinned accounts and pins the AcountDevicesInstanceKeys + * in the ActionsGlobalContext to the visualization. */ @NbBundle.Messages(value = {"ResetAndPinAccountsAction.singularText=Visualize Only Selected Account", "ResetAndPinAccountsAction.pluralText=Visualize Only Selected Accounts"}) @@ -42,7 +43,7 @@ final class ResetAndPinAccountsAction extends AbstractCVTAction { } @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(ActionEvent event) { CVTEvents.getCVTEventBus().post(new CVTEvents.PinAccountsEvent(getSelectedAccounts(), true)); } @@ -55,5 +56,4 @@ final class ResetAndPinAccountsAction extends AbstractCVTAction { ImageIcon getIcon() { return ICON; } - } diff --git a/Core/src/org/sleuthkit/autopsy/communications/SelectionNode.java b/Core/src/org/sleuthkit/autopsy/communications/SelectionNode.java index be564c01cc..1618bb9ecc 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/SelectionNode.java +++ b/Core/src/org/sleuthkit/autopsy/communications/SelectionNode.java @@ -20,7 +20,6 @@ package org.sleuthkit.autopsy.communications; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; @@ -48,7 +47,7 @@ import org.sleuthkit.datamodel.TskCoreException; */ final class SelectionNode extends AbstractNode { - SelectionNode(Children children, Lookup lookup) { + private SelectionNode(Children children, Lookup lookup) { super(children, lookup); } @@ -130,9 +129,9 @@ final class SelectionNode extends AbstractNode { } @Override - protected Node createNodeForKey(Content t) { - if (t instanceof BlackboardArtifact) { - return new RelationshipNode((BlackboardArtifact) t); + protected Node createNodeForKey(Content content) { + if (content instanceof BlackboardArtifact) { + return new RelationshipNode((BlackboardArtifact) content); } else { throw new UnsupportedOperationException("Cannot create a RelationshipNode for non BlackboardArtifact content."); } diff --git a/Core/src/org/sleuthkit/autopsy/communications/UnpinAccountsAction.java b/Core/src/org/sleuthkit/autopsy/communications/UnpinAccountsAction.java index 357f5a0451..ba0bbc545b 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/UnpinAccountsAction.java +++ b/Core/src/org/sleuthkit/autopsy/communications/UnpinAccountsAction.java @@ -23,6 +23,10 @@ import javax.swing.ImageIcon; import org.openide.util.ImageUtilities; import org.openide.util.NbBundle; +/** + * Action that unpins the AcccountDeviceInstanceKeys in the ActionsGlobalContext + * form the visualization. + */ @NbBundle.Messages({"UnpinAccountsAction.pluralText=Remove Selected Accounts", "UnpinAccountsAction.singularText=Remove Selected Account"}) final class UnpinAccountsAction extends AbstractCVTAction { diff --git a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java index e0fe563e81..9fca11992a 100644 --- a/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java +++ b/Core/src/org/sleuthkit/autopsy/communications/VisualizationPanel.java @@ -873,7 +873,10 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider } } - private class CancelationListener implements ActionListener { + /** + * Listener that closes a ModalDialogProgreessIndicator when invoked. + */ + final private class CancelationListener implements ActionListener { private Future cancellable; private ModalDialogProgressIndicator progress; @@ -891,6 +894,9 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider } } + /** + * Action that un-locks the selected vertices. + */ @NbBundle.Messages({ "VisualizationPanel.unlockAction.singularText=Unlock Selected Account", "VisualizationPanel.unlockAction.pluralText=Unlock Selected Accounts",}) @@ -911,6 +917,9 @@ final public class VisualizationPanel extends JPanel implements Lookup.Provider } } + /** + * Action that locks the selected vertices. + */ @NbBundle.Messages({ "VisualizationPanel.lockAction.singularText=Lock Selected Account", "VisualizationPanel.lockAction.pluralText=Lock Selected Accounts"})