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

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