Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
PastOccurrencesFilterPanel.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;
23 import javax.swing.JCheckBox;
24 import javax.swing.JLabel;
25 import javax.swing.event.ListSelectionListener;
26 import org.openide.util.NbBundle;
33 
37 final class PastOccurrencesFilterPanel extends AbstractDiscoveryFilterPanel {
38 
39  private static final long serialVersionUID = 1L;
40  private final Type type;
41 
45  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
46  PastOccurrencesFilterPanel(Type type) {
47  initComponents();
48  this.type = type;
49  setUpFrequencyFilter();
50  add(crFrequencyList);
51  }
52 
58  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
59  private void initComponents() {
60 
61  pastOccurrencesCheckbox = new javax.swing.JCheckBox();
62  crFrequencyList = new org.sleuthkit.autopsy.guiutils.CheckBoxListPanel<>();
63 
64  org.openide.awt.Mnemonics.setLocalizedText(pastOccurrencesCheckbox, org.openide.util.NbBundle.getMessage(PastOccurrencesFilterPanel.class, "PastOccurrencesFilterPanel.pastOccurrencesCheckbox.text")); // NOI18N
65  pastOccurrencesCheckbox.setMaximumSize(new java.awt.Dimension(150, 25));
66  pastOccurrencesCheckbox.setMinimumSize(new java.awt.Dimension(150, 25));
67  pastOccurrencesCheckbox.setPreferredSize(new java.awt.Dimension(150, 25));
68  pastOccurrencesCheckbox.addActionListener(new java.awt.event.ActionListener() {
69  public void actionPerformed(java.awt.event.ActionEvent evt) {
70  pastOccurrencesCheckboxActionPerformed(evt);
71  }
72  });
73 
74  setMinimumSize(new java.awt.Dimension(250, 30));
75  setPreferredSize(new java.awt.Dimension(250, 30));
76  setLayout(new java.awt.BorderLayout());
77  add(crFrequencyList, java.awt.BorderLayout.CENTER);
78  }// </editor-fold>//GEN-END:initComponents
79 
80  private void pastOccurrencesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pastOccurrencesCheckboxActionPerformed
81  crFrequencyList.setEnabled(pastOccurrencesCheckbox.isSelected());
82  }//GEN-LAST:event_pastOccurrencesCheckboxActionPerformed
83 
87  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
88  private void setUpFrequencyFilter() {
89  crFrequencyList.clearList();
90  if (!CentralRepository.isEnabled()) {
91  if (type != Type.DOMAIN) {
92  for (SearchData.Frequency freq : SearchData.Frequency.getOptionsForFilteringWithoutCr()) {
93  crFrequencyList.addElement(freq.toString(), null, freq);
94  }
95  }
96  } else {
97  for (SearchData.Frequency freq : SearchData.Frequency.getOptionsForFilteringWithCr()) {
98  if (type != Type.DOMAIN || freq != SearchData.Frequency.KNOWN) {
99  crFrequencyList.addElement(freq.toString(), null, freq);
100  }
101  }
102  }
103  }
104 
105  // Variables declaration - do not modify//GEN-BEGIN:variables
106  private org.sleuthkit.autopsy.guiutils.CheckBoxListPanel<SearchData.Frequency> crFrequencyList;
107  private javax.swing.JCheckBox pastOccurrencesCheckbox;
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 canBeFilteredOn = type != Type.DOMAIN || CentralRepository.isEnabled();
114  pastOccurrencesCheckbox.setEnabled(canBeFilteredOn);
115  pastOccurrencesCheckbox.setSelected(selected && canBeFilteredOn);
116 
117  if (pastOccurrencesCheckbox.isEnabled() && pastOccurrencesCheckbox.isSelected()) {
118  crFrequencyList.setEnabled(true);
119  if (selectedItems != null) {
120  List<SearchData.Frequency> frequencyList = new ArrayList<>();
121  for (Object item : selectedItems) {
122  if (item instanceof SearchData.Frequency) {
123  frequencyList.add((SearchData.Frequency) item);
124  }
125  }
126  if (!frequencyList.isEmpty()) {
127  crFrequencyList.setSelectedElements(frequencyList);
128  }
129  }
130  } else {
131  crFrequencyList.setEnabled(false);
132  }
133  }
134 
135  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
136  @Override
137  JCheckBox getCheckbox() {
138  return pastOccurrencesCheckbox;
139  }
140 
141  @Override
142  JLabel getAdditionalLabel() {
143  return null;
144  }
145 
146  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
147  @NbBundle.Messages({"PastOccurrencesFilterPanel.error.text=At least one value in the past occurrence filter must be selected."})
148  @Override
149  String checkForError() {
150  if (pastOccurrencesCheckbox.isSelected() && crFrequencyList.getSelectedElements().isEmpty()) {
151  return Bundle.PastOccurrencesFilterPanel_error_text();
152  }
153  return "";
154  }
155 
156  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
157  @Override
158  AbstractFilter getFilter() {
159  if (pastOccurrencesCheckbox.isSelected()) {
160  List<SearchData.Frequency> frequencies = crFrequencyList.getSelectedElements();
161  return new SearchFiltering.FrequencyFilter(frequencies);
162  }
163  return null;
164  }
165 
166  @Override
167  void addListSelectionListener(ListSelectionListener listener) {
168  crFrequencyList.addListSelectionListener(listener);
169  }
170 
171  @Override
172  boolean isFilterSupported() {
173  return !crFrequencyList.isEmpty();
174  }
175 
176 }

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.