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

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.