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

Copyright © 2012-2020 Basis Technology. Generated on: Mon Jul 6 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.