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

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.