Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
ParentFolderFilterPanel.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 
22 import java.util.ArrayList;
23 import java.util.List;
24 import javax.swing.DefaultListModel;
25 import javax.swing.JCheckBox;
26 import javax.swing.JLabel;
27 import javax.swing.event.ListSelectionListener;
28 import org.openide.util.NbBundle;
32 
36 final class ParentFolderFilterPanel extends AbstractDiscoveryFilterPanel {
37 
38  private static final long serialVersionUID = 1L;
39  private DefaultListModel<SearchFiltering.ParentSearchTerm> parentListModel;
40  private static final String[] DEFAULT_IGNORED_PATHS = {"/Windows/", "/Program Files/"}; //NON-NLS
41 
45  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
46  ParentFolderFilterPanel() {
47  initComponents();
48  setUpParentPathFilter();
49  }
50 
54  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
55  private void setUpParentPathFilter() {
56  fullRadioButton.setSelected(true);
57  includeRadioButton.setSelected(true);
58  parentListModel = (DefaultListModel<SearchFiltering.ParentSearchTerm>) parentList.getModel();
59  for (String ignorePath : DEFAULT_IGNORED_PATHS) {
60  parentListModel.add(parentListModel.size(), new ParentSearchTerm(ignorePath, false, false));
61  }
62  }
63 
69  @SuppressWarnings("unchecked")
70  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
71  private void initComponents() {
72 
73  parentCheckbox = new javax.swing.JCheckBox();
74  parentLabel = new javax.swing.JLabel();
75  javax.swing.ButtonGroup includeButtonGroup = new javax.swing.ButtonGroup();
76  javax.swing.ButtonGroup pathTypeButtonGroup = new javax.swing.ButtonGroup();
77  parentScrollPane = new javax.swing.JScrollPane();
78  parentList = new javax.swing.JList<>();
79  fullRadioButton = new javax.swing.JRadioButton();
80  includeRadioButton = new javax.swing.JRadioButton();
81  substringRadioButton = new javax.swing.JRadioButton();
82  excludeRadioButton = new javax.swing.JRadioButton();
83  deleteButton = new javax.swing.JButton();
84  addButton = new javax.swing.JButton();
85  parentTextField = new javax.swing.JTextField();
86 
87  org.openide.awt.Mnemonics.setLocalizedText(parentCheckbox, org.openide.util.NbBundle.getMessage(ParentFolderFilterPanel.class, "ParentFolderFilterPanel.parentCheckbox.text_1")); // NOI18N
88  parentCheckbox.setMaximumSize(new java.awt.Dimension(150, 25));
89  parentCheckbox.setMinimumSize(new java.awt.Dimension(150, 25));
90  parentCheckbox.setPreferredSize(new java.awt.Dimension(150, 25));
91  parentCheckbox.addActionListener(new java.awt.event.ActionListener() {
92  public void actionPerformed(java.awt.event.ActionEvent evt) {
93  parentCheckboxActionPerformed(evt);
94  }
95  });
96 
97  org.openide.awt.Mnemonics.setLocalizedText(parentLabel, org.openide.util.NbBundle.getMessage(ParentFolderFilterPanel.class, "ParentFolderFilterPanel.parentLabel.text_1")); // NOI18N
98  parentLabel.setMaximumSize(new java.awt.Dimension(150, 25));
99  parentLabel.setMinimumSize(new java.awt.Dimension(150, 25));
100  parentLabel.setPreferredSize(new java.awt.Dimension(150, 25));
101 
102  setMinimumSize(new java.awt.Dimension(250, 120));
103  setPreferredSize(new java.awt.Dimension(250, 120));
104 
105  parentScrollPane.setPreferredSize(new java.awt.Dimension(27, 27));
106 
107  parentList.setModel(new DefaultListModel<ParentSearchTerm>());
108  parentList.setEnabled(false);
109  parentList.setVisibleRowCount(4);
110  parentList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
111  public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
112  parentListValueChanged(evt);
113  }
114  });
115  parentScrollPane.setViewportView(parentList);
116 
117  pathTypeButtonGroup.add(fullRadioButton);
118  fullRadioButton.setSelected(true);
119  org.openide.awt.Mnemonics.setLocalizedText(fullRadioButton, org.openide.util.NbBundle.getMessage(ParentFolderFilterPanel.class, "ParentFolderFilterPanel.fullRadioButton.text_1")); // NOI18N
120  fullRadioButton.setEnabled(false);
121 
122  includeButtonGroup.add(includeRadioButton);
123  includeRadioButton.setSelected(true);
124  org.openide.awt.Mnemonics.setLocalizedText(includeRadioButton, org.openide.util.NbBundle.getMessage(ParentFolderFilterPanel.class, "ParentFolderFilterPanel.includeRadioButton.text_1")); // NOI18N
125  includeRadioButton.setEnabled(false);
126 
127  pathTypeButtonGroup.add(substringRadioButton);
128  org.openide.awt.Mnemonics.setLocalizedText(substringRadioButton, org.openide.util.NbBundle.getMessage(ParentFolderFilterPanel.class, "ParentFolderFilterPanel.substringRadioButton.text_1")); // NOI18N
129  substringRadioButton.setEnabled(false);
130 
131  includeButtonGroup.add(excludeRadioButton);
132  org.openide.awt.Mnemonics.setLocalizedText(excludeRadioButton, org.openide.util.NbBundle.getMessage(ParentFolderFilterPanel.class, "ParentFolderFilterPanel.excludeRadioButton.text_1")); // NOI18N
133  excludeRadioButton.setEnabled(false);
134 
135  org.openide.awt.Mnemonics.setLocalizedText(deleteButton, org.openide.util.NbBundle.getMessage(ParentFolderFilterPanel.class, "ParentFolderFilterPanel.deleteButton.text_1")); // NOI18N
136  deleteButton.setEnabled(false);
137  deleteButton.setMaximumSize(new java.awt.Dimension(70, 23));
138  deleteButton.setMinimumSize(new java.awt.Dimension(70, 23));
139  deleteButton.setPreferredSize(new java.awt.Dimension(70, 23));
140  deleteButton.addActionListener(new java.awt.event.ActionListener() {
141  public void actionPerformed(java.awt.event.ActionEvent evt) {
142  deleteButtonActionPerformed(evt);
143  }
144  });
145 
146  org.openide.awt.Mnemonics.setLocalizedText(addButton, org.openide.util.NbBundle.getMessage(ParentFolderFilterPanel.class, "ParentFolderFilterPanel.addButton.text_1")); // NOI18N
147  addButton.setEnabled(false);
148  addButton.setMaximumSize(new java.awt.Dimension(70, 23));
149  addButton.setMinimumSize(new java.awt.Dimension(70, 23));
150  addButton.setPreferredSize(new java.awt.Dimension(70, 23));
151  addButton.addActionListener(new java.awt.event.ActionListener() {
152  public void actionPerformed(java.awt.event.ActionEvent evt) {
153  addButtonActionPerformed(evt);
154  }
155  });
156 
157  parentTextField.setEnabled(false);
158 
159  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
160  this.setLayout(layout);
161  layout.setHorizontalGroup(
162  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
163  .addGroup(layout.createSequentialGroup()
164  .addGap(8, 8, 8)
165  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
166  .addComponent(includeRadioButton)
167  .addComponent(fullRadioButton))
168  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
169  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
170  .addComponent(substringRadioButton)
171  .addComponent(excludeRadioButton)))
172  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
173  .addComponent(parentScrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
174  .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
175  .addComponent(parentTextField)
176  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
177  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
178  .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
179  .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
180  );
181  layout.setVerticalGroup(
182  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
183  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
184  .addComponent(parentScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
185  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
186  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
187  .addComponent(fullRadioButton)
188  .addComponent(substringRadioButton))
189  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
190  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
191  .addComponent(includeRadioButton)
192  .addComponent(excludeRadioButton)
193  .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
194  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
195  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
196  .addComponent(parentTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
197  .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
198  .addGap(0, 0, 0))
199  );
200  }// </editor-fold>//GEN-END:initComponents
201 
202  private void parentCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_parentCheckboxActionPerformed
203  configurePanel(parentCheckbox.isSelected(), null);
204  }//GEN-LAST:event_parentCheckboxActionPerformed
205 
206  private void parentListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_parentListValueChanged
207  if (parentList.getSelectedValuesList().isEmpty()) {
208  deleteButton.setEnabled(false);
209  } else {
210  deleteButton.setEnabled(true);
211  }
212  }//GEN-LAST:event_parentListValueChanged
213 
214  private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
215  int index = parentList.getSelectedIndex();
216  if (index >= 0) {
217  parentListModel.remove(index);
218  }
219  }//GEN-LAST:event_deleteButtonActionPerformed
220 
221  private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
222  if (!parentTextField.getText().isEmpty()) {
223  ParentSearchTerm searchTerm;
224  searchTerm = new ParentSearchTerm(parentTextField.getText(), fullRadioButton.isSelected(), includeRadioButton.isSelected());
225  parentListModel.add(parentListModel.size(), searchTerm);
226  parentTextField.setText("");
227  }
228  }//GEN-LAST:event_addButtonActionPerformed
229 
230 
231  // Variables declaration - do not modify//GEN-BEGIN:variables
232  private javax.swing.JButton addButton;
233  private javax.swing.JButton deleteButton;
234  private javax.swing.JRadioButton excludeRadioButton;
235  private javax.swing.JRadioButton fullRadioButton;
236  private javax.swing.JRadioButton includeRadioButton;
237  private javax.swing.JCheckBox parentCheckbox;
238  private javax.swing.JLabel parentLabel;
239  private javax.swing.JList<ParentSearchTerm> parentList;
240  private javax.swing.JScrollPane parentScrollPane;
241  private javax.swing.JTextField parentTextField;
242  private javax.swing.JRadioButton substringRadioButton;
243  // End of variables declaration//GEN-END:variables
244 
245  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
246  @Override
247  void configurePanel(boolean selected, List<?> selectedItems) {
248  parentCheckbox.setSelected(selected);
249  if (parentCheckbox.isEnabled() && parentCheckbox.isSelected()) {
250  parentScrollPane.setEnabled(true);
251  parentLabel.setEnabled(true);
252  includeRadioButton.setEnabled(true);
253  excludeRadioButton.setEnabled(true);
254  fullRadioButton.setEnabled(true);
255  substringRadioButton.setEnabled(true);
256  addButton.setEnabled(true);
257  deleteButton.setEnabled(!parentListModel.isEmpty());
258  parentList.setEnabled(true);
259  parentTextField.setEnabled(true);
260  } else {
261  parentScrollPane.setEnabled(false);
262  parentLabel.setEnabled(false);
263  parentList.setEnabled(false);
264  includeRadioButton.setEnabled(false);
265  excludeRadioButton.setEnabled(false);
266  fullRadioButton.setEnabled(false);
267  substringRadioButton.setEnabled(false);
268  addButton.setEnabled(false);
269  deleteButton.setEnabled(false);
270  parentTextField.setEnabled(false);
271  }
272  }
273 
274  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
275  @Override
276  JCheckBox getCheckbox() {
277  return parentCheckbox;
278  }
279 
280  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
281  @Override
282  JLabel getAdditionalLabel() {
283  return parentLabel;
284  }
285 
286  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
287  @NbBundle.Messages({"ParentFolderFilterPanel.error.text=At least one parent path must be entered."})
288  @Override
289  String checkForError() {
290  // Parent uses everything in the box
291  if (parentCheckbox.isSelected() && getParentPaths().isEmpty()) {
292  return Bundle.ParentFolderFilterPanel_error_text();
293  }
294  return "";
295  }
296 
297  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
303  private List<SearchFiltering.ParentSearchTerm> getParentPaths() {
304  List<SearchFiltering.ParentSearchTerm> results = new ArrayList<>();
305  for (int i = 0; i < parentListModel.getSize(); i++) {
306  results.add(parentListModel.get(i));
307  }
308  return results;
309  }
310 
311  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
312  @Override
313  AbstractFilter getFilter() {
314  if (parentCheckbox.isSelected()) {
315  return new SearchFiltering.ParentFilter(getParentPaths());
316  }
317  return null;
318  }
319 
320  @Override
321  void addListSelectionListener(ListSelectionListener listener) {
322  parentList.addListSelectionListener(listener);
323  }
324 
325  @Override
326  boolean isFilterSupported() {
327  return true;
328  }
329 
330 }
ParentSearchTerm(String searchStr, boolean isFullPath, boolean isIncluded)

Copyright © 2012-2022 Basis Technology. Generated on: Tue Oct 4 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.