From ad3a196d12c20ca7b61d116cf52a296df2361e84 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Thu, 13 Sep 2018 12:17:56 -0400 Subject: [PATCH] 4167 clean up and add comments to CommonAttributePanel --- .../commonfilesearch/Bundle.properties | 2 +- .../CommonAttributePanel.form | 8 +- .../CommonAttributePanel.java | 171 +++++++++++++----- .../CommonAttributeSearchAction.java | 31 +++- 4 files changed, 152 insertions(+), 60 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/Bundle.properties b/Core/src/org/sleuthkit/autopsy/commonfilesearch/Bundle.properties index 035e165ae4..0915cc2769 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/Bundle.properties @@ -21,7 +21,6 @@ IntraCasePanel.documentsCheckbox.text=Documents IntraCasePanel.pictureVideoCheckbox.text=Pictures and Videos IntraCasePanel.selectedFileCategoriesButton.toolTipText=Select from the options below... CommonAttributePanel.percentageThresholdTextTwo.text_1=% of data sources in central repository. -CommonAttributePanel.percentageThresholdTextOne.text=20 CommonAttributePanel.percentageThresholdCheck.text_1_1=Hide files found in over CommonAttributePanel.intraCaseRadio.text=Between data sources in current case CommonAttributePanel.errorText.text=In order to search, you must select a file category. @@ -40,3 +39,4 @@ CommonAttributePanel.intraCasePanel.border.title=Current Case Options CommonAttributePanel.commonItemSearchDescription.text=Find items that exist in multipel data sources or cases CommonAttributePanel.scopeLabel.text=Scope of Search InterCasePanel.correlationComboBoxLabel.text=Select correlation type to search: +CommonAttributePanel.percentageThresholdInputBox.text=20 diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributePanel.form b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributePanel.form index 834b42a763..0f81ccb799 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributePanel.form +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributePanel.form @@ -66,7 +66,7 @@ - + @@ -115,7 +115,7 @@ - + @@ -205,11 +205,11 @@ - + - + diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributePanel.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributePanel.java index 56d5168664..aac27c914b 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributePanel.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributePanel.java @@ -97,12 +97,12 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer this.errorManager = new UserInputErrorManager(); - this.percentageThresholdTextOne.getDocument().addDocumentListener(new DocumentListener() { + this.percentageThresholdInputBox.getDocument().addDocumentListener(new DocumentListener() { - private Dimension preferredSize = CommonAttributePanel.this.percentageThresholdTextOne.getPreferredSize(); + private Dimension preferredSize = CommonAttributePanel.this.percentageThresholdInputBox.getPreferredSize(); private void maintainSize() { - CommonAttributePanel.this.percentageThresholdTextOne.setSize(preferredSize); + CommonAttributePanel.this.percentageThresholdInputBox.setSize(preferredSize); } @Override @@ -125,6 +125,13 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer }); } + /** + * Get whether or not the central repository will be enabled as a search + * option. + * + * @return true if the central repository exists and has at least 2 cases in + * and includes the current case, false otherwise. + */ static boolean isEamDbAvailableForIntercaseSearch() { try { return EamDb.isEnabled() @@ -144,7 +151,14 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer checkFileTypeCheckBoxState(); } - static boolean isEamDbAvailableForPercentageFrequencyCalculations() { + /** + * Get whether or not the central repository will be available for filtering + * results. + * + * @return true if the central repository exists and has at least 1 case in + * it, false otherwise. + */ + private static boolean isEamDbAvailableForPercentageFrequencyCalculations() { try { return EamDb.isEnabled() && EamDb.getInstance() != null @@ -155,11 +169,18 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer return false; } + /** + * Disable the option to search for common attributes in the central + * repository. + */ private void disableIntercaseSearch() { this.intraCaseRadio.setSelected(true); this.interCaseRadio.setEnabled(false); } + /** + * Perform the common attribute search. + */ @NbBundle.Messages({ "CommonAttributePanel.search.results.titleAll=Common Attributes (All Data Sources)", "CommonAttributePanel.search.results.titleSingle=Common Attributes (Match Within Data Source: %s)", @@ -179,10 +200,21 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer private String tabTitle; private ProgressHandle progress; + /** + * Set the title of the search results for searches using all data + * sources. + */ private void setTitleForAllDataSources() { this.tabTitle = Bundle.CommonAttributePanel_search_results_titleAll(); } + /** + * Set the title of the search results for searches using a single + * source. + * + * @param dataSourceId the datasource ID of the the source being + * used + */ private void setTitleForSingleSource(Long dataSourceId) { final String CommonAttributePanel_search_results_titleSingle = Bundle.CommonAttributePanel_search_results_titleSingle(); final Object[] dataSourceName = new Object[]{intraCasePanel.getDataSourceMap().get(dataSourceId)}; @@ -316,6 +348,10 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer new SwingWorker, Void>() { + /** + * Update the user interface of the panel to reflect the datasources + * available. + */ private void updateUi() { final Map dataSourceMap = CommonAttributePanel.this.intraCasePanel.getDataSourceMap(); @@ -333,12 +369,18 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer intraCasePanel.setVisible(false); interCasePanel.setVisible(true); } - CommonAttributePanel.this.updateErrorTextAndSearchBox(); + CommonAttributePanel.this.updateErrorTextAndSearchButton(); } } + /** + * Check if the case has multiple data sources + * + * @return true if the case has multiple data sources, false + * otherwise + */ private boolean caseHasMultipleSources() { - return CommonAttributePanel.this.intraCasePanel.getDataSourceMap().size() > 2; + return CommonAttributePanel.this.intraCasePanel.getDataSourceMap().size() > 2; //WJS-TODO should be > than 1? } @Override @@ -386,6 +428,10 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer new SwingWorker, Void>() { + /** + * Update the user interface of the panel to reflect the cases + * available. + */ private void updateUi() { final Map caseMap = CommonAttributePanel.this.interCasePanel.getCaseMap(); @@ -400,7 +446,16 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer } } - private Map mapDataSources(List cases) throws EamDbException { + /** + * Create a map of cases from a list of cases. + * + * @param cases + * + * @return a map of Cases + * + * @throws EamDbException + */ + private Map mapCases(List cases) throws EamDbException { Map casemap = new HashMap<>(); CorrelationCase currentCorCase = EamDb.getInstance().getCase(Case.getCurrentCase()); for (CorrelationCase correlationCase : cases) { @@ -408,7 +463,6 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer casemap.put(correlationCase.getID(), correlationCase.getDisplayName()); } } - return casemap; } @@ -416,7 +470,7 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer protected Map doInBackground() throws EamDbException { List dataSources = EamDb.getInstance().getCases(); - Map caseMap = mapDataSources(dataSources); + Map caseMap = mapCases(dataSources); return caseMap; } @@ -457,7 +511,7 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer intraCaseRadio = new javax.swing.JRadioButton(); interCaseRadio = new javax.swing.JRadioButton(); percentageThresholdCheck = new javax.swing.JCheckBox(); - percentageThresholdTextOne = new javax.swing.JTextField(); + percentageThresholdInputBox = new javax.swing.JTextField(); percentageThresholdTextTwo = new javax.swing.JLabel(); intraCasePanel = new org.sleuthkit.autopsy.commonfilesearch.IntraCasePanel(); interCasePanel = new org.sleuthkit.autopsy.commonfilesearch.InterCasePanel(); @@ -518,11 +572,11 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer } }); - percentageThresholdTextOne.setHorizontalAlignment(javax.swing.JTextField.TRAILING); - percentageThresholdTextOne.setText(org.openide.util.NbBundle.getMessage(CommonAttributePanel.class, "CommonAttributePanel.percentageThresholdTextOne.text")); // NOI18N - percentageThresholdTextOne.setMaximumSize(new java.awt.Dimension(40, 24)); - percentageThresholdTextOne.setMinimumSize(new java.awt.Dimension(40, 24)); - percentageThresholdTextOne.setPreferredSize(new java.awt.Dimension(40, 24)); + percentageThresholdInputBox.setHorizontalAlignment(javax.swing.JTextField.TRAILING); + percentageThresholdInputBox.setText(org.openide.util.NbBundle.getMessage(CommonAttributePanel.class, "CommonAttributePanel.percentageThresholdInputBox.text")); // NOI18N + percentageThresholdInputBox.setMaximumSize(new java.awt.Dimension(40, 24)); + percentageThresholdInputBox.setMinimumSize(new java.awt.Dimension(40, 24)); + percentageThresholdInputBox.setPreferredSize(new java.awt.Dimension(40, 24)); org.openide.awt.Mnemonics.setLocalizedText(percentageThresholdTextTwo, org.openide.util.NbBundle.getMessage(CommonAttributePanel.class, "CommonAttributePanel.percentageThresholdTextTwo.text_1")); // NOI18N @@ -541,37 +595,33 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addGap(0, 0, 0) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addComponent(errorText, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE) - .addGap(65, 65, 65) - .addComponent(searchButton) - .addContainerGap()) - .addGroup(jPanel1Layout.createSequentialGroup() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addComponent(commonItemSearchDescription, javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup() - .addGap(20, 20, 20) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(intraCaseRadio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(interCaseRadio, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)))) - .addGap(0, 0, Short.MAX_VALUE)))) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() + .addComponent(errorText, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE) + .addGap(65, 65, 65) + .addComponent(searchButton) + .addContainerGap()) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(percentageThresholdCheck) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(percentageThresholdTextOne, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(percentageThresholdInputBox, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(percentageThresholdTextTwo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(scopeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(37, 37, 37)) .addGroup(jPanel1Layout.createSequentialGroup() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addComponent(interCasePanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(intraCasePanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGap(0, 0, 0)))) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addComponent(commonItemSearchDescription, javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup() + .addGap(20, 20, 20) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(intraCaseRadio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(interCaseRadio, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)))) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addComponent(interCasePanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(intraCasePanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + .addGap(0, 0, Short.MAX_VALUE)))) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -591,7 +641,7 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(percentageThresholdCheck) - .addComponent(percentageThresholdTextOne, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(percentageThresholdInputBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(percentageThresholdTextTwo)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) @@ -609,9 +659,9 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer private void percentageThresholdCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_percentageThresholdCheckActionPerformed if (this.percentageThresholdCheck.isSelected()) { - this.percentageThresholdTextOne.setEnabled(true); + this.percentageThresholdInputBox.setEnabled(true); } else { - this.percentageThresholdTextOne.setEnabled(false); + this.percentageThresholdInputBox.setEnabled(false); } this.handleFrequencyPercentageState(); @@ -632,8 +682,12 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer SwingUtilities.windowForComponent(this).dispose(); }//GEN-LAST:event_searchButtonActionPerformed + /** + * Convert the text in the percentage threshold input box into an integer, + * -1 is used when the string can not be converted to an integer. + */ private void percentageThresholdChanged() { - String percentageString = this.percentageThresholdTextOne.getText(); + String percentageString = this.percentageThresholdInputBox.getText(); try { this.percentageThresholdValue = Integer.parseInt(percentageString); @@ -645,7 +699,11 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer this.handleFrequencyPercentageState(); } - private void updateErrorTextAndSearchBox() { + /** + * Update the error text and the enabled status of the search button to + * reflect the current validity of the search settings. + */ + private void updateErrorTextAndSearchButton() { if (this.errorManager.anyErrors()) { this.searchButton.setEnabled(false); //grab the first error error and show it @@ -657,20 +715,32 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer } } + /** + * Set the enabled status of the percentage threshold options + * + * @param enabled true to enable percentage threshold options, false to + * disable them + */ private void enablePercentageOptions(boolean enabled) { - this.percentageThresholdTextOne.setEnabled(enabled); + this.percentageThresholdInputBox.setEnabled(enabled); this.percentageThresholdCheck.setEnabled(enabled); this.percentageThresholdCheck.setSelected(enabled); this.percentageThresholdTextTwo.setEnabled(enabled); } + /** + * Check that the integer value of what is entered in the percentage + * threshold text box is a valid percentage and update the errorManager to + * reflect the validity. + */ private void handleFrequencyPercentageState() { if (this.percentageThresholdValue > 0 && this.percentageThresholdValue <= 100) { this.errorManager.setError(UserInputErrorManager.FREQUENCY_PERCENTAGE_OUT_OF_RANGE_KEY, false); } else { + this.errorManager.setError(UserInputErrorManager.FREQUENCY_PERCENTAGE_OUT_OF_RANGE_KEY, true); } - this.updateErrorTextAndSearchBox(); + this.updateErrorTextAndSearchButton(); } // Variables declaration - do not modify//GEN-BEGIN:variables @@ -683,17 +753,26 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer private javax.swing.JRadioButton intraCaseRadio; private javax.swing.JPanel jPanel1; private javax.swing.JCheckBox percentageThresholdCheck; - private javax.swing.JTextField percentageThresholdTextOne; + private javax.swing.JTextField percentageThresholdInputBox; private javax.swing.JLabel percentageThresholdTextTwo; private javax.swing.JLabel scopeLabel; private javax.swing.JButton searchButton; // End of variables declaration//GEN-END:variables + /** + * Add this panel as an observer of it's sub panels so that errors can be + * indicated accurately. + */ void observeSubPanels() { intraCasePanel.addObserver(this); interCasePanel.addObserver(this); } + /** + * Check that the sub panels have valid options selected regarding their + * file type filtering options, and update the errorManager with the + * validity. + */ private void checkFileTypeCheckBoxState() { boolean validCheckBoxState = true; if (CommonAttributePanel.this.interCaseRadio.isSelected()) { @@ -710,7 +789,7 @@ final class CommonAttributePanel extends javax.swing.JDialog implements Observer } else { this.errorManager.setError(UserInputErrorManager.NO_FILE_CATEGORIES_SELECTED_KEY, true); } - this.updateErrorTextAndSearchBox(); + this.updateErrorTextAndSearchButton(); } } diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributeSearchAction.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributeSearchAction.java index d5a7c9df80..0d5db72bc4 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributeSearchAction.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributeSearchAction.java @@ -37,7 +37,23 @@ final public class CommonAttributeSearchAction extends CallableSystemAction { private static CommonAttributeSearchAction instance = null; private static final long serialVersionUID = 1L; - CommonAttributeSearchAction() { + /** + * Get the default CommonAttributeSearchAction. + * + * @return the default instance of this action + */ + public static synchronized CommonAttributeSearchAction getDefault() { + if (instance == null) { + instance = new CommonAttributeSearchAction(); + } + return instance; + } + + /** + * Create a CommonAttributeSearchAction for opening the common attribute + * search dialog + */ + private CommonAttributeSearchAction() { super(); this.setEnabled(false); } @@ -54,15 +70,8 @@ final public class CommonAttributeSearchAction extends CallableSystemAction { } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Error getting data sources for action enabled check", ex); - } - return super.isEnabled() && shouldBeEnabled; - } - - public static synchronized CommonAttributeSearchAction getDefault() { - if (instance == null) { - instance = new CommonAttributeSearchAction(); } - return instance; + return super.isEnabled() && shouldBeEnabled; } @Override @@ -75,8 +84,12 @@ final public class CommonAttributeSearchAction extends CallableSystemAction { createAndShowPanel(); } + /** + * Create the commonAttributePanel and diplay it. + */ private void createAndShowPanel() { CommonAttributePanel commonAttributePanel = new CommonAttributePanel(); + //In order to update errors the CommonAttributePanel needs to observe its sub panels commonAttributePanel.observeSubPanels(); commonAttributePanel.setVisible(true); }