Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AbstractFiltersPanel.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.awt.Component;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import java.awt.Insets;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.util.ArrayList;
29 import java.util.List;
30 import javax.swing.JPanel;
31 import javax.swing.JSplitPane;
32 import javax.swing.event.ListSelectionEvent;
33 import javax.swing.event.ListSelectionListener;
34 import org.apache.commons.lang3.StringUtils;
41 
46 abstract class AbstractFiltersPanel extends JPanel implements ActionListener, ListSelectionListener {
47 
48  private boolean isInitialized = false;
49  private static final double LABEL_WEIGHT = 0;
50  private static final double PANEL_WEIGHT = .1;
51  private static final int LABEL_WIDTH = 1;
52  private static final int PANEL_WIDTH = 2;
53  private static final int LABEL_HEIGHT = 1;
54  private static final int PANEL_HEIGHT = 2;
55  private static final long serialVersionUID = 1L;
56  private final GridBagConstraints constraints = new GridBagConstraints();
57  private final List<AbstractDiscoveryFilterPanel> filters = new ArrayList<>();
58  private final JPanel firstColumnPanel = new JPanel();
59  private final JPanel secondColumnPanel = new JPanel();
60  private int firstColumnY = 0;
61  private int secondColumnY = 0;
62  private SortingMethod lastSortingMethod = SortingMethod.BY_FILE_NAME;
63  private GroupingAttributeType lastGroupingAttributeType = GroupingAttributeType.PARENT_PATH;
64  private Group.GroupSortingAlgorithm lastGroupSortingAlg = Group.GroupSortingAlgorithm.BY_GROUP_SIZE;
65 
69  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
70  AbstractFiltersPanel() {
71  firstColumnPanel.setLayout(new GridBagLayout());
72  secondColumnPanel.setLayout(new GridBagLayout());
73  }
74 
80  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
81  abstract SearchData.Type getType();
82 
94  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
95  final void addFilter(AbstractDiscoveryFilterPanel filterPanel, boolean isSelected, int[] indicesSelected, int column) {
96  if (!isInitialized) {
97  constraints.gridy = 0;
98  constraints.anchor = GridBagConstraints.FIRST_LINE_START;
99  constraints.insets = new Insets(8, 8, 8, 8);
100  isInitialized = true;
101  }
102  if (column == 0) {
103  constraints.gridy = firstColumnY;
104  } else {
105  constraints.gridy = secondColumnY;
106  }
107  constraints.gridx = 0;
108  filterPanel.configurePanel(isSelected, indicesSelected);
109  filterPanel.addListeners(this, this);
110  filters.add(filterPanel);
111  constraints.fill = GridBagConstraints.VERTICAL;
112  constraints.gridheight = LABEL_HEIGHT;
113  constraints.gridwidth = LABEL_WIDTH;
114  constraints.weightx = LABEL_WEIGHT;
115  constraints.weighty = LABEL_WEIGHT;
116  constraints.gridwidth = LABEL_WIDTH;
117  if (filterPanel.hasPanel()) {
118  addToGridBagLayout(filterPanel.getCheckbox(), filterPanel.getAdditionalLabel(), column);
119  constraints.gridx += constraints.gridwidth;
120  constraints.fill = GridBagConstraints.BOTH;
121  constraints.gridheight = PANEL_HEIGHT;
122  constraints.weightx = PANEL_WEIGHT;
123  constraints.weighty = PANEL_WEIGHT;
124  constraints.gridwidth = PANEL_WIDTH;
125  addToGridBagLayout(filterPanel, null, column);
126  } else {
127  constraints.weightx = PANEL_WEIGHT;
128  constraints.fill = GridBagConstraints.BOTH;
129  constraints.gridwidth = PANEL_WIDTH + LABEL_WIDTH;
130  addToGridBagLayout(filterPanel.getCheckbox(), filterPanel.getAdditionalLabel(), column);
131  }
132  if (column == 0) {
133  firstColumnY += constraints.gridheight;
134  } else {
135  secondColumnY += constraints.gridheight;
136  }
137  }
138 
144  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
145  final void addPanelsToScrollPane(JSplitPane splitPane) {
146  splitPane.setLeftComponent(firstColumnPanel);
147  splitPane.setRightComponent(secondColumnPanel);
148  validate();
149  repaint();
150  }
151 
155  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
156  final void clearFilters() {
157  for (AbstractDiscoveryFilterPanel filterPanel : filters) {
158  filterPanel.removeListeners();
159  }
160  filters.clear();
161  }
162 
173  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
174  private void addToGridBagLayout(Component componentToAdd, Component additionalComponentToAdd, int columnIndex) {
175  addToColumn(componentToAdd, columnIndex);
176  if (additionalComponentToAdd != null) {
177  constraints.gridy += constraints.gridheight;
178  addToColumn(additionalComponentToAdd, columnIndex);
179  constraints.gridy -= constraints.gridheight;
180  }
181  }
182 
189  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
190  private void addToColumn(Component component, int columnNumber) {
191  if (columnNumber == 0) {
192  firstColumnPanel.add(component, constraints);
193  } else {
194  secondColumnPanel.add(component, constraints);
195  }
196  }
197 
202  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
203  void validateFields() {
204  String errorString = null;
205  for (AbstractDiscoveryFilterPanel filterPanel : filters) {
206  errorString = filterPanel.checkForError();
207  if (!StringUtils.isBlank(errorString)) {
208  break;
209  }
210  }
211  firePropertyChange("FilterError", null, errorString);
212  }
213 
214  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
215  @Override
216  public void actionPerformed(ActionEvent e) {
217  validateFields();
218  validate();
219  repaint();
220  }
221 
227  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
228  boolean isObjectsFilterSupported() {
229  for (AbstractDiscoveryFilterPanel filter : filters) {
230  if (filter instanceof ObjectDetectedFilterPanel) {
231  return filter.getList().getModel().getSize() > 0;
232  }
233  }
234  return false;
235  }
236 
242  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
243  boolean isHashSetFilterSupported() {
244  for (AbstractDiscoveryFilterPanel filter : filters) {
245  if (filter instanceof HashSetFilterPanel) {
246  return filter.getList().getModel().getSize() > 0;
247  }
248  }
249  return false;
250  }
251 
257  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
258  boolean isInterestingItemsFilterSupported() {
259  for (AbstractDiscoveryFilterPanel filter : filters) {
260  if (filter instanceof InterestingItemsFilterPanel) {
261  return filter.getList().getModel().getSize() > 0;
262  }
263  }
264  return false;
265  }
266 
272  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
273  List<AbstractFilter> getFilters() {
274  List<AbstractFilter> filtersToUse = new ArrayList<>();
275  if (getType() != SearchData.Type.DOMAIN) { //Domain type does not have a file type
276  filtersToUse.add(new SearchFiltering.FileTypeFilter(getType()));
277  }
278  for (AbstractDiscoveryFilterPanel filterPanel : filters) {
279  if (filterPanel.getCheckbox().isSelected()) {
280  AbstractFilter filter = filterPanel.getFilter();
281  if (filter != null) {
282  filtersToUse.add(filter);
283  }
284  }
285  }
286  return filtersToUse;
287  }
288 
289  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
290  @Override
291  public void valueChanged(ListSelectionEvent evt) {
292  if (!evt.getValueIsAdjusting()) {
293  validateFields();
294  validate();
295  repaint();
296  }
297  }
298 
304  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
305  SortingMethod getLastSortingMethod() {
306  return lastSortingMethod;
307  }
308 
314  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
315  final void setLastSortingMethod(SortingMethod lastSortingMethod) {
316  this.lastSortingMethod = lastSortingMethod;
317  }
318 
324  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
325  GroupingAttributeType getLastGroupingAttributeType() {
326  return lastGroupingAttributeType;
327  }
328 
335  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
336  final void setLastGroupingAttributeType(GroupingAttributeType lastGroupingAttributeType) {
337  this.lastGroupingAttributeType = lastGroupingAttributeType;
338  }
339 
345  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
346  Group.GroupSortingAlgorithm getLastGroupSortingAlg() {
347  return lastGroupSortingAlg;
348  }
349 
356  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
357  final void setLastGroupSortingAlg(Group.GroupSortingAlgorithm lastGroupSortingAlg) {
358  this.lastGroupSortingAlg = lastGroupSortingAlg;
359  }
360 
361 }

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.