Autopsy  4.17.0
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 javax.swing.DefaultListModel;
22 import javax.swing.JCheckBox;
23 import javax.swing.JLabel;
24 import javax.swing.JList;
25 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  }
51 
57  @SuppressWarnings("unchecked")
58  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
59  private void initComponents() {
60 
61  pastOccurrencesCheckbox = new javax.swing.JCheckBox();
62  crFrequencyScrollPane = new javax.swing.JScrollPane();
63  crFrequencyList = new javax.swing.JList<>();
64 
65  org.openide.awt.Mnemonics.setLocalizedText(pastOccurrencesCheckbox, org.openide.util.NbBundle.getMessage(PastOccurrencesFilterPanel.class, "PastOccurrencesFilterPanel.pastOccurrencesCheckbox.text")); // NOI18N
66  pastOccurrencesCheckbox.setMaximumSize(new java.awt.Dimension(150, 25));
67  pastOccurrencesCheckbox.setMinimumSize(new java.awt.Dimension(150, 25));
68  pastOccurrencesCheckbox.setPreferredSize(new java.awt.Dimension(150, 25));
69  pastOccurrencesCheckbox.addActionListener(new java.awt.event.ActionListener() {
70  public void actionPerformed(java.awt.event.ActionEvent evt) {
71  pastOccurrencesCheckboxActionPerformed(evt);
72  }
73  });
74 
75  setMinimumSize(new java.awt.Dimension(250, 30));
76  setPreferredSize(new java.awt.Dimension(250, 30));
77 
78  crFrequencyScrollPane.setPreferredSize(new java.awt.Dimension(27, 27));
79 
80  crFrequencyList.setModel(new DefaultListModel<Frequency>());
81  crFrequencyList.setEnabled(false);
82  crFrequencyList.setVisibleRowCount(5);
83  crFrequencyScrollPane.setViewportView(crFrequencyList);
84 
85  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
86  this.setLayout(layout);
87  layout.setHorizontalGroup(
88  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
89  .addComponent(crFrequencyScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
90  );
91  layout.setVerticalGroup(
92  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
93  .addGroup(layout.createSequentialGroup()
94  .addComponent(crFrequencyScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
95  .addGap(0, 0, 0))
96  );
97  }// </editor-fold>//GEN-END:initComponents
98 
99  private void pastOccurrencesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pastOccurrencesCheckboxActionPerformed
100  crFrequencyList.setEnabled(pastOccurrencesCheckbox.isSelected());
101  }//GEN-LAST:event_pastOccurrencesCheckboxActionPerformed
102 
106  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
107  private void setUpFrequencyFilter() {
108  int count = 0;
109  DefaultListModel<SearchData.Frequency> frequencyListModel = (DefaultListModel<SearchData.Frequency>) crFrequencyList.getModel();
110  frequencyListModel.removeAllElements();
111  if (!CentralRepository.isEnabled()) {
112  if (type != Type.DOMAIN) {
113  for (SearchData.Frequency freq : SearchData.Frequency.getOptionsForFilteringWithoutCr()) {
114  frequencyListModel.add(count, freq);
115  }
116  }
117  } else {
118  for (SearchData.Frequency freq : SearchData.Frequency.getOptionsForFilteringWithCr()) {
119  if (type != Type.DOMAIN || freq != SearchData.Frequency.KNOWN) {
120  frequencyListModel.add(count, freq);
121  }
122  }
123  }
124  }
125 
126  // Variables declaration - do not modify//GEN-BEGIN:variables
127  private javax.swing.JList<Frequency> crFrequencyList;
128  private javax.swing.JScrollPane crFrequencyScrollPane;
129  private javax.swing.JCheckBox pastOccurrencesCheckbox;
130  // End of variables declaration//GEN-END:variables
131 
132  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
133  @Override
134  void configurePanel(boolean selected, int[] indicesSelected) {
135  boolean canBeFilteredOn = type != Type.DOMAIN || CentralRepository.isEnabled();
136  pastOccurrencesCheckbox.setEnabled(canBeFilteredOn);
137  pastOccurrencesCheckbox.setSelected(selected && canBeFilteredOn);
138 
139  if (pastOccurrencesCheckbox.isEnabled() && pastOccurrencesCheckbox.isSelected()) {
140  crFrequencyScrollPane.setEnabled(true);
141  crFrequencyList.setEnabled(true);
142  if (indicesSelected != null) {
143  crFrequencyList.setSelectedIndices(indicesSelected);
144  }
145  } else {
146  crFrequencyScrollPane.setEnabled(false);
147  crFrequencyList.setEnabled(false);
148  }
149  }
150 
151  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
152  @Override
153  JCheckBox getCheckbox() {
154  return pastOccurrencesCheckbox;
155  }
156 
157  @Override
158  JLabel getAdditionalLabel() {
159  return null;
160  }
161 
162  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
163  @NbBundle.Messages({"PastOccurrencesFilterPanel.error.text=At least one value in the past occurrence filter must be selected."})
164  @Override
165  String checkForError() {
166  if (pastOccurrencesCheckbox.isSelected() && crFrequencyList.getSelectedValuesList().isEmpty()) {
167  return Bundle.PastOccurrencesFilterPanel_error_text();
168  }
169  return "";
170  }
171 
172  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
173  @Override
174  JList<?> getList() {
175  return crFrequencyList;
176  }
177 
178  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
179  @Override
180  AbstractFilter getFilter() {
181  if (pastOccurrencesCheckbox.isSelected()) {
182  return new SearchFiltering.FrequencyFilter(crFrequencyList.getSelectedValuesList());
183  }
184  return null;
185  }
186 }

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.