Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ArtifactTypeFilterPanel.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;
22 import java.util.List;
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 
37 class ArtifactTypeFilterPanel extends AbstractDiscoveryFilterPanel {
38 
39  private static final long serialVersionUID = 1L;
40 
44  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
45  ArtifactTypeFilterPanel() {
46  initComponents();
47  setUpArtifactTypeFilter();
48 
49  }
50 
54  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
55  private void setUpArtifactTypeFilter() {
56  int count = 0;
57  DefaultListModel<ArtifactTypeItem> artifactTypeModel = (DefaultListModel<ArtifactTypeItem>) artifactList.getModel();
58  artifactTypeModel.removeAllElements();
59  for (BlackboardArtifact.ARTIFACT_TYPE artifactType : SearchData.Type.DOMAIN.getArtifactTypes()) {
60  artifactTypeModel.add(count, new ArtifactTypeItem(artifactType));
61  count++;
62  }
63  }
64 
70  @SuppressWarnings("unchecked")
71  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
72  private void initComponents() {
73 
74  artifactTypeCheckbox = new javax.swing.JCheckBox();
75  artifactTypeScrollPane = new javax.swing.JScrollPane();
76  artifactList = new javax.swing.JList<>();
77 
78  org.openide.awt.Mnemonics.setLocalizedText(artifactTypeCheckbox, org.openide.util.NbBundle.getMessage(ArtifactTypeFilterPanel.class, "ArtifactTypeFilterPanel.artifactTypeCheckbox.text")); // NOI18N
79  artifactTypeCheckbox.addActionListener(new java.awt.event.ActionListener() {
80  public void actionPerformed(java.awt.event.ActionEvent evt) {
81  artifactTypeCheckboxActionPerformed(evt);
82  }
83  });
84 
85  setPreferredSize(new java.awt.Dimension(27, 27));
86 
87  artifactTypeScrollPane.setPreferredSize(new java.awt.Dimension(27, 27));
88 
89  artifactList.setModel(new DefaultListModel<ArtifactTypeItem>());
90  artifactList.setEnabled(false);
91  artifactTypeScrollPane.setViewportView(artifactList);
92 
93  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
94  this.setLayout(layout);
95  layout.setHorizontalGroup(
96  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
97  .addComponent(artifactTypeScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
98  );
99  layout.setVerticalGroup(
100  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
101  .addComponent(artifactTypeScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
102  );
103  }// </editor-fold>//GEN-END:initComponents
104 
105  private void artifactTypeCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_artifactTypeCheckboxActionPerformed
106  artifactTypeScrollPane.setEnabled(artifactTypeCheckbox.isSelected());
107  artifactList.setEnabled(artifactTypeCheckbox.isSelected());
108  }//GEN-LAST:event_artifactTypeCheckboxActionPerformed
109 
110  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
111  @Override
112  void configurePanel(boolean selected, int[] indicesSelected) {
113  artifactTypeCheckbox.setSelected(selected);
114  if (artifactTypeCheckbox.isEnabled() && artifactTypeCheckbox.isSelected()) {
115  artifactTypeScrollPane.setEnabled(true);
116  artifactList.setEnabled(true);
117  if (indicesSelected != null) {
118  artifactList.setSelectedIndices(indicesSelected);
119  }
120  } else {
121  artifactTypeScrollPane.setEnabled(false);
122  artifactList.setEnabled(false);
123  }
124  }
125 
126  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
127  @Override
128  JCheckBox getCheckbox() {
129  return artifactTypeCheckbox;
130  }
131 
132  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
133  @Override
134  JList<?> getList() {
135  return artifactList;
136  }
137 
138  @Override
139  JLabel getAdditionalLabel() {
140  return null;
141  }
142 
143  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
144  @NbBundle.Messages({"ArtifactTypeFilterPanel.selectionNeeded.text=At least one Result type must be selected."})
145  @Override
146  String checkForError() {
147  if (artifactTypeCheckbox.isSelected() && artifactList.getSelectedValuesList().isEmpty()) {
148  return Bundle.ArtifactTypeFilterPanel_selectionNeeded_text();
149  }
150  return "";
151  }
152 
153  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
154  @Override
155  AbstractFilter getFilter() {
156  if (artifactTypeCheckbox.isSelected() && !artifactList.getSelectedValuesList().isEmpty()) {
157  List<BlackboardArtifact.ARTIFACT_TYPE> artifactTypeList = new ArrayList<>();
158  for (ArtifactTypeItem item : artifactList.getSelectedValuesList()) {
159  artifactTypeList.add(item.getArtifactType());
160  }
161  return new ArtifactTypeFilter(artifactTypeList);
162  }
163  return null;
164  }
165 
170  private class ArtifactTypeItem {
171 
172  private final BlackboardArtifact.ARTIFACT_TYPE artifactType;
173 
179  ArtifactTypeItem(BlackboardArtifact.ARTIFACT_TYPE artifactType) {
180  this.artifactType = artifactType;
181  }
182 
188  BlackboardArtifact.ARTIFACT_TYPE getArtifactType() {
189  return artifactType;
190  }
191 
192  @Override
193  public String toString() {
194  return artifactType.getDisplayName();
195  }
196  }
197 
198  // Variables declaration - do not modify//GEN-BEGIN:variables
199  private javax.swing.JList<ArtifactTypeItem> artifactList;
200  private javax.swing.JCheckBox artifactTypeCheckbox;
201  private javax.swing.JScrollPane artifactTypeScrollPane;
202  // End of variables declaration//GEN-END:variables
203 }

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.