Autopsy  4.15.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;
20 
21 import javax.swing.DefaultListModel;
22 import javax.swing.JCheckBox;
23 import javax.swing.JLabel;
24 import javax.swing.JList;
27 
31 final class PastOccurrencesFilterPanel extends AbstractDiscoveryFilterPanel {
32 
33  private static final long serialVersionUID = 1L;
34 
38  PastOccurrencesFilterPanel() {
39  initComponents();
40  setUpFrequencyFilter();
41  }
42 
48  @SuppressWarnings("unchecked")
49  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
50  private void initComponents() {
51 
52  pastOccurrencesCheckbox = new javax.swing.JCheckBox();
53  crFrequencyScrollPane = new javax.swing.JScrollPane();
54  crFrequencyList = new javax.swing.JList<>();
55 
56  org.openide.awt.Mnemonics.setLocalizedText(pastOccurrencesCheckbox, org.openide.util.NbBundle.getMessage(PastOccurrencesFilterPanel.class, "PastOccurrencesFilterPanel.pastOccurrencesCheckbox.text")); // NOI18N
57  pastOccurrencesCheckbox.setMaximumSize(new java.awt.Dimension(150, 25));
58  pastOccurrencesCheckbox.setMinimumSize(new java.awt.Dimension(150, 25));
59  pastOccurrencesCheckbox.setPreferredSize(new java.awt.Dimension(150, 25));
60  pastOccurrencesCheckbox.addActionListener(new java.awt.event.ActionListener() {
61  public void actionPerformed(java.awt.event.ActionEvent evt) {
62  pastOccurrencesCheckboxActionPerformed(evt);
63  }
64  });
65 
66  setMinimumSize(new java.awt.Dimension(250, 30));
67  setPreferredSize(new java.awt.Dimension(250, 30));
68 
69  crFrequencyScrollPane.setPreferredSize(new java.awt.Dimension(27, 27));
70 
71  crFrequencyList.setModel(new DefaultListModel<Frequency>());
72  crFrequencyList.setEnabled(false);
73  crFrequencyList.setVisibleRowCount(5);
74  crFrequencyScrollPane.setViewportView(crFrequencyList);
75 
76  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
77  this.setLayout(layout);
78  layout.setHorizontalGroup(
79  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
80  .addComponent(crFrequencyScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
81  );
82  layout.setVerticalGroup(
83  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
84  .addGroup(layout.createSequentialGroup()
85  .addComponent(crFrequencyScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
86  .addGap(0, 0, 0))
87  );
88  }// </editor-fold>//GEN-END:initComponents
89 
90  private void pastOccurrencesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pastOccurrencesCheckboxActionPerformed
91  crFrequencyList.setEnabled(pastOccurrencesCheckbox.isSelected());
92  }//GEN-LAST:event_pastOccurrencesCheckboxActionPerformed
93 
97  private void setUpFrequencyFilter() {
98  int count = 0;
99  DefaultListModel<FileSearchData.Frequency> frequencyListModel = (DefaultListModel<FileSearchData.Frequency>) crFrequencyList.getModel();
100  frequencyListModel.removeAllElements();
101  if (!CentralRepository.isEnabled()) {
102  for (FileSearchData.Frequency freq : FileSearchData.Frequency.getOptionsForFilteringWithoutCr()) {
103  frequencyListModel.add(count, freq);
104  }
105  } else {
106  for (FileSearchData.Frequency freq : FileSearchData.Frequency.getOptionsForFilteringWithCr()) {
107  frequencyListModel.add(count, freq);
108  }
109  }
110  }
111 
112  // Variables declaration - do not modify//GEN-BEGIN:variables
113  private javax.swing.JList<Frequency> crFrequencyList;
114  private javax.swing.JScrollPane crFrequencyScrollPane;
115  private javax.swing.JCheckBox pastOccurrencesCheckbox;
116  // End of variables declaration//GEN-END:variables
117 
118  @Override
119  void configurePanel(boolean selected, int[] indicesSelected) {
120  pastOccurrencesCheckbox.setSelected(selected);
121  if (pastOccurrencesCheckbox.isEnabled() && pastOccurrencesCheckbox.isSelected()) {
122  crFrequencyScrollPane.setEnabled(true);
123  crFrequencyList.setEnabled(true);
124  if (indicesSelected != null) {
125  crFrequencyList.setSelectedIndices(indicesSelected);
126  }
127  } else {
128  crFrequencyScrollPane.setEnabled(false);
129  crFrequencyList.setEnabled(false);
130  }
131  }
132 
133  @Override
134  JCheckBox getCheckbox() {
135  return pastOccurrencesCheckbox;
136  }
137 
138  @Override
139  JLabel getAdditionalLabel() {
140  return null;
141  }
142 
143  @Override
144  String checkForError() {
145  if (pastOccurrencesCheckbox.isSelected() && crFrequencyList.getSelectedValuesList().isEmpty()) {
146  return "At least one value in the past occurrence filter must be selected";
147  }
148  return "";
149  }
150 
151  @Override
152  JList<?> getList() {
153  return crFrequencyList;
154  }
155 
156  @Override
157  FileSearchFiltering.FileFilter getFilter() {
158  if (pastOccurrencesCheckbox.isSelected()) {
159  return new FileSearchFiltering.FrequencyFilter(crFrequencyList.getSelectedValuesList());
160  }
161  return null;
162  }
163 }

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.