Autopsy  4.19.3
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.SwingUtilities;
33 import javax.swing.event.ListSelectionEvent;
34 import javax.swing.event.ListSelectionListener;
35 import org.apache.commons.lang3.StringUtils;
42 
47 abstract class AbstractFiltersPanel extends JPanel implements ActionListener, ListSelectionListener {
48 
49  private boolean isInitialized = false;
50  private static final double LABEL_WEIGHT = 0;
51  private static final double PANEL_WEIGHT = .1;
52  private static final int LABEL_WIDTH = 1;
53  private static final int PANEL_WIDTH = 2;
54  private static final int LABEL_HEIGHT = 1;
55  private static final int PANEL_HEIGHT = 2;
56  private static final long serialVersionUID = 1L;
57  private final GridBagConstraints constraints = new GridBagConstraints();
58  private final List<AbstractDiscoveryFilterPanel> filters = new ArrayList<>();
59  private final JPanel firstColumnPanel = new JPanel();
60  private final JPanel secondColumnPanel = new JPanel();
61  private int firstColumnY = 0;
62  private int secondColumnY = 0;
63  private SortingMethod lastSortingMethod = SortingMethod.BY_FILE_NAME;
64  private GroupingAttributeType lastGroupingAttributeType = GroupingAttributeType.PARENT_PATH;
65  private Group.GroupSortingAlgorithm lastGroupSortingAlg = Group.GroupSortingAlgorithm.BY_GROUP_SIZE;
66 
70  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
71  AbstractFiltersPanel() {
72  firstColumnPanel.setLayout(new GridBagLayout());
73  secondColumnPanel.setLayout(new GridBagLayout());
74  }
75 
81  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
82  abstract SearchData.Type getType();
83 
95  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
96  final void addFilter(AbstractDiscoveryFilterPanel filterPanel, boolean isSelected, List<?> selectedItems, int column) {
97  if (!isInitialized) {
98  constraints.gridy = 0;
99  constraints.anchor = GridBagConstraints.FIRST_LINE_START;
100  constraints.insets = new Insets(8, 8, 8, 8);
101  isInitialized = true;
102  }
103  if (column == 0) {
104  constraints.gridy = firstColumnY;
105  } else {
106  constraints.gridy = secondColumnY;
107  }
108  constraints.gridx = 0;
109  filterPanel.configurePanel(isSelected, selectedItems);
110  filterPanel.addListeners(this, this);
111  filters.add(filterPanel);
112  constraints.fill = GridBagConstraints.VERTICAL;
113  constraints.gridheight = LABEL_HEIGHT;
114  constraints.gridwidth = LABEL_WIDTH;
115  constraints.weightx = LABEL_WEIGHT;
116  constraints.weighty = LABEL_WEIGHT;
117  constraints.gridwidth = LABEL_WIDTH;
118  if (filterPanel.hasPanel()) {
119  addToGridBagLayout(filterPanel.getCheckbox(), filterPanel.getAdditionalLabel(), column);
120  constraints.gridx += constraints.gridwidth;
121  constraints.fill = GridBagConstraints.BOTH;
122  constraints.gridheight = PANEL_HEIGHT;
123  constraints.weightx = PANEL_WEIGHT;
124  constraints.weighty = PANEL_WEIGHT;
125  constraints.gridwidth = PANEL_WIDTH;
126  addToGridBagLayout(filterPanel, null, column);
127  } else {
128  constraints.weightx = PANEL_WEIGHT;
129  constraints.fill = GridBagConstraints.BOTH;
130  constraints.gridwidth = PANEL_WIDTH + LABEL_WIDTH;
131  addToGridBagLayout(filterPanel.getCheckbox(), filterPanel.getAdditionalLabel(), column);
132  }
133  if (column == 0) {
134  firstColumnY += constraints.gridheight;
135  } else {
136  secondColumnY += constraints.gridheight;
137  }
138  }
139 
145  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
146  final void addPanelsToScrollPane(JSplitPane splitPane) {
147  splitPane.setLeftComponent(firstColumnPanel);
148  splitPane.setRightComponent(secondColumnPanel);
149  validate();
150  repaint();
151  }
152 
163  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
164  private void addToGridBagLayout(Component componentToAdd, Component additionalComponentToAdd, int columnIndex) {
165  addToColumn(componentToAdd, columnIndex);
166  if (additionalComponentToAdd != null) {
167  constraints.gridy += constraints.gridheight;
168  addToColumn(additionalComponentToAdd, columnIndex);
169  constraints.gridy -= constraints.gridheight;
170  }
171  }
172 
179  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
180  private void addToColumn(Component component, int columnNumber) {
181  if (columnNumber == 0) {
182  firstColumnPanel.add(component, constraints);
183  } else {
184  secondColumnPanel.add(component, constraints);
185  }
186  }
187 
192  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
193  void validateFields() {
194  String errorString = null;
195  for (AbstractDiscoveryFilterPanel filterPanel : filters) {
196  errorString = filterPanel.checkForError();
197  if (!StringUtils.isBlank(errorString)) {
198  break;
199  }
200  }
201  firePropertyChange("FilterError", null, errorString);
202  }
203 
204  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
205  @Override
206  public void actionPerformed(ActionEvent e) {
207  //invoke it after all the currently queued gui actions are performed
208  SwingUtilities.invokeLater(new Runnable() {
209  @Override
210  public void run() {
211  validateFields();
212  validate();
213  repaint();
214  }
215  });
216  }
217 
223  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
224  boolean isObjectsFilterSupported() {
225  for (AbstractDiscoveryFilterPanel filter : filters) {
226  if (filter instanceof ObjectDetectedFilterPanel) {
227  return filter.isFilterSupported();
228  }
229  }
230  return false;
231  }
232 
238  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
239  boolean isHashSetFilterSupported() {
240  for (AbstractDiscoveryFilterPanel filter : filters) {
241  if (filter instanceof HashSetFilterPanel) {
242  return filter.isFilterSupported();
243  }
244  }
245  return false;
246  }
247 
253  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
254  boolean isInterestingItemsFilterSupported() {
255  for (AbstractDiscoveryFilterPanel filter : filters) {
256  if (filter instanceof InterestingItemsFilterPanel) {
257  return filter.isFilterSupported();
258  }
259  }
260  return false;
261  }
262 
268  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
269  List<AbstractFilter> getFilters() {
270  List<AbstractFilter> filtersToUse = new ArrayList<>();
271  if (getType() != SearchData.Type.DOMAIN) { //Domain type does not have a file type
272  filtersToUse.add(new SearchFiltering.FileTypeFilter(getType()));
273  }
274  for (AbstractDiscoveryFilterPanel filterPanel : filters) {
275  if (filterPanel.getCheckbox().isSelected()) {
276  AbstractFilter filter = filterPanel.getFilter();
277  if (filter != null) {
278  filtersToUse.add(filter);
279  }
280  }
281  }
282  return filtersToUse;
283  }
284 
285  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
286  @Override
287  public void valueChanged(ListSelectionEvent evt) {
288  if (!evt.getValueIsAdjusting()) {
289  //invoke it after all the currently queued gui actions are performed
290  SwingUtilities.invokeLater(new Runnable() {
291  @Override
292  public void run() {
293  validateFields();
294  validate();
295  repaint();
296  }
297  });
298  }
299  }
300 
306  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
307  SortingMethod getLastSortingMethod() {
308  return lastSortingMethod;
309  }
310 
316  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
317  final void setLastSortingMethod(SortingMethod lastSortingMethod) {
318  this.lastSortingMethod = lastSortingMethod;
319  }
320 
326  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
327  GroupingAttributeType getLastGroupingAttributeType() {
328  return lastGroupingAttributeType;
329  }
330 
337  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
338  final void setLastGroupingAttributeType(GroupingAttributeType lastGroupingAttributeType) {
339  this.lastGroupingAttributeType = lastGroupingAttributeType;
340  }
341 
347  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
348  Group.GroupSortingAlgorithm getLastGroupSortingAlg() {
349  return lastGroupSortingAlg;
350  }
351 
358  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
359  final void setLastGroupSortingAlg(Group.GroupSortingAlgorithm lastGroupSortingAlg) {
360  this.lastGroupSortingAlg = lastGroupSortingAlg;
361  }
362 
363 }

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