Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
HashSetFilterPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.discovery.ui;
20 
21 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.logging.Level;
25 import javax.swing.JCheckBox;
26 import javax.swing.JLabel;
27 import javax.swing.event.ListSelectionListener;
28 import org.openide.util.NbBundle;
32 import org.sleuthkit.datamodel.BlackboardArtifact;
33 import org.sleuthkit.datamodel.BlackboardAttribute;
34 import org.sleuthkit.datamodel.TskCoreException;
35 
39 final class HashSetFilterPanel extends AbstractDiscoveryFilterPanel {
40 
41  private static final long serialVersionUID = 1L;
42  private final static Logger logger = Logger.getLogger(HashSetFilterPanel.class.getName());
43 
47  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
48  HashSetFilterPanel() {
49  initComponents();
50  setUpHashFilter();
51  add(hashSetList);
52  }
53 
57  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
58  private void setUpHashFilter() {
59  try {
60  hashSetList.clearList();
61  List<String> setNames = DiscoveryUiUtils.getSetNames(BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT,
62  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME);
63  for (String name : setNames) {
64  hashSetList.addElement(name, null, name);
65  }
66  } catch (TskCoreException ex) {
67  logger.log(Level.SEVERE, "Error loading hash set names", ex);
68  hashSetCheckbox.setEnabled(false);
69  hashSetList.setEnabled(false);
70  }
71  }
72 
78  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
79  private void initComponents() {
80 
81  hashSetCheckbox = new javax.swing.JCheckBox();
82  hashSetList = new org.sleuthkit.autopsy.guiutils.CheckBoxListPanel<>();
83 
84  org.openide.awt.Mnemonics.setLocalizedText(hashSetCheckbox, org.openide.util.NbBundle.getMessage(HashSetFilterPanel.class, "HashSetFilterPanel.hashSetCheckbox.text")); // NOI18N
85  hashSetCheckbox.setMaximumSize(new java.awt.Dimension(150, 25));
86  hashSetCheckbox.setMinimumSize(new java.awt.Dimension(150, 25));
87  hashSetCheckbox.setPreferredSize(new java.awt.Dimension(150, 25));
88  hashSetCheckbox.addActionListener(new java.awt.event.ActionListener() {
89  public void actionPerformed(java.awt.event.ActionEvent evt) {
90  hashSetCheckboxActionPerformed(evt);
91  }
92  });
93 
94  setMinimumSize(new java.awt.Dimension(250, 30));
95  setPreferredSize(new java.awt.Dimension(250, 30));
96  setLayout(new java.awt.BorderLayout());
97  add(hashSetList, java.awt.BorderLayout.CENTER);
98  }// </editor-fold>//GEN-END:initComponents
99 
100  private void hashSetCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hashSetCheckboxActionPerformed
101  hashSetList.setEnabled(hashSetCheckbox.isSelected());
102  }//GEN-LAST:event_hashSetCheckboxActionPerformed
103 
104 
105  // Variables declaration - do not modify//GEN-BEGIN:variables
106  private javax.swing.JCheckBox hashSetCheckbox;
107  private org.sleuthkit.autopsy.guiutils.CheckBoxListPanel<String> hashSetList;
108  // End of variables declaration//GEN-END:variables
109 
110  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
111  @Override
112  void configurePanel(boolean selected, List<?> selectedItems) {
113  boolean hasHashSets = isFilterSupported();
114  hashSetCheckbox.setEnabled(hasHashSets);
115  hashSetCheckbox.setSelected(selected && hasHashSets);
116  if (hashSetCheckbox.isEnabled() && hashSetCheckbox.isSelected()) {
117  hashSetList.setEnabled(true);
118  if (selectedItems != null) {
119  List<String> setList = new ArrayList<>();
120  for (Object item : selectedItems) {
121  if (item instanceof String) {
122  setList.add((String) item);
123  }
124  }
125  if (!setList.isEmpty()) {
126  hashSetList.setSelectedElements(setList);
127  }
128  }
129  } else {
130  hashSetList.setEnabled(false);
131  }
132  }
133 
134  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
135  @Override
136  JCheckBox getCheckbox() {
137  return hashSetCheckbox;
138  }
139 
140  @Override
141  JLabel getAdditionalLabel() {
142  return null;
143  }
144 
145  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
146  @NbBundle.Messages({"HashSetFilterPanel.error.text=At least one hash set name must be selected."})
147  @Override
148  String checkForError() {
149  if (hashSetCheckbox.isSelected() && hashSetList.getSelectedElements().isEmpty()) {
150  return Bundle.HashSetFilterPanel_error_text();
151  }
152  return "";
153  }
154 
155  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
156  @Override
157  AbstractFilter getFilter() {
158  if (hashSetCheckbox.isSelected()) {
159  List<String> setList = hashSetList.getSelectedElements();
160  return new SearchFiltering.InterestingFileSetFilter(setList);
161  }
162  return null;
163  }
164 
165  @Override
166  void addListSelectionListener(ListSelectionListener listener) {
167  hashSetList.addListSelectionListener(listener);
168  }
169 
170  @Override
171  boolean isFilterSupported() {
172  return !hashSetList.isEmpty();
173  }
174 
175 }

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.