Autopsy  4.17.0
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 
22 import java.util.List;
23 import java.util.logging.Level;
24 import javax.swing.DefaultListModel;
25 import javax.swing.JCheckBox;
26 import javax.swing.JLabel;
27 import javax.swing.JList;
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  }
52 
56  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
57  private void setUpHashFilter() {
58  int count = 0;
59  try {
60  DefaultListModel<String> hashListModel = (DefaultListModel<String>) hashSetList.getModel();
61  hashListModel.removeAllElements();
62  List<String> setNames = DiscoveryUiUtils.getSetNames(BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT,
63  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME);
64  for (String name : setNames) {
65  hashListModel.add(count, name);
66  count++;
67  }
68  } catch (TskCoreException ex) {
69  logger.log(Level.SEVERE, "Error loading hash set names", ex);
70  hashSetCheckbox.setEnabled(false);
71  hashSetList.setEnabled(false);
72  }
73  }
74 
80  @SuppressWarnings("unchecked")
81  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
82  private void initComponents() {
83 
84  hashSetCheckbox = new javax.swing.JCheckBox();
85  hashSetScrollPane = new javax.swing.JScrollPane();
86  hashSetList = new javax.swing.JList<>();
87 
88  org.openide.awt.Mnemonics.setLocalizedText(hashSetCheckbox, org.openide.util.NbBundle.getMessage(HashSetFilterPanel.class, "HashSetFilterPanel.hashSetCheckbox.text")); // NOI18N
89  hashSetCheckbox.setMaximumSize(new java.awt.Dimension(150, 25));
90  hashSetCheckbox.setMinimumSize(new java.awt.Dimension(150, 25));
91  hashSetCheckbox.setPreferredSize(new java.awt.Dimension(150, 25));
92  hashSetCheckbox.addActionListener(new java.awt.event.ActionListener() {
93  public void actionPerformed(java.awt.event.ActionEvent evt) {
94  hashSetCheckboxActionPerformed(evt);
95  }
96  });
97 
98  setMinimumSize(new java.awt.Dimension(250, 30));
99  setPreferredSize(new java.awt.Dimension(250, 30));
100 
101  hashSetList.setModel(new DefaultListModel<String>());
102  hashSetList.setEnabled(false);
103  hashSetList.setVisibleRowCount(3);
104  hashSetScrollPane.setViewportView(hashSetList);
105 
106  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
107  this.setLayout(layout);
108  layout.setHorizontalGroup(
109  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
110  .addComponent(hashSetScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
111  );
112  layout.setVerticalGroup(
113  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
114  .addComponent(hashSetScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
115  );
116  }// </editor-fold>//GEN-END:initComponents
117 
118  private void hashSetCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hashSetCheckboxActionPerformed
119  hashSetList.setEnabled(hashSetCheckbox.isSelected());
120  }//GEN-LAST:event_hashSetCheckboxActionPerformed
121 
122 
123  // Variables declaration - do not modify//GEN-BEGIN:variables
124  private javax.swing.JCheckBox hashSetCheckbox;
125  private javax.swing.JList<String> hashSetList;
126  private javax.swing.JScrollPane hashSetScrollPane;
127  // End of variables declaration//GEN-END:variables
128 
129  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
130  @Override
131  void configurePanel(boolean selected, int[] indicesSelected) {
132  boolean hasHashSets = hashSetList.getModel().getSize() > 0;
133  hashSetCheckbox.setEnabled(hasHashSets);
134  hashSetCheckbox.setSelected(selected && hasHashSets);
135  if (hashSetCheckbox.isEnabled() && hashSetCheckbox.isSelected()) {
136  hashSetScrollPane.setEnabled(true);
137  hashSetList.setEnabled(true);
138  if (indicesSelected != null) {
139  hashSetList.setSelectedIndices(indicesSelected);
140  }
141  } else {
142  hashSetScrollPane.setEnabled(false);
143  hashSetList.setEnabled(false);
144  }
145  }
146 
147  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
148  @Override
149  JCheckBox getCheckbox() {
150  return hashSetCheckbox;
151  }
152 
153  @Override
154  JLabel getAdditionalLabel() {
155  return null;
156  }
157 
158  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
159  @NbBundle.Messages({"HashSetFilterPanel.error.text=At least one hash set name must be selected."})
160  @Override
161  String checkForError() {
162  if (hashSetCheckbox.isSelected() && hashSetList.getSelectedValuesList().isEmpty()) {
163  return Bundle.HashSetFilterPanel_error_text();
164  }
165  return "";
166  }
167 
168  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
169  @Override
170  JList<?> getList() {
171  return hashSetList;
172  }
173 
174  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
175  @Override
176  AbstractFilter getFilter() {
177  if (hashSetCheckbox.isSelected()) {
178  return new SearchFiltering.HashSetFilter(hashSetList.getSelectedValuesList());
179  }
180  return null;
181  }
182 }

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