Autopsy  4.16.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;
40 
45 abstract class AbstractFiltersPanel extends JPanel implements ActionListener, ListSelectionListener {
46 
47  private boolean isInitialized = false;
48  private static final double LABEL_WEIGHT = 0;
49  private static final double PANEL_WEIGHT = .1;
50  private static final int LABEL_WIDTH = 1;
51  private static final int PANEL_WIDTH = 2;
52  private static final int LABEL_HEIGHT = 1;
53  private static final int PANEL_HEIGHT = 2;
54  private static final long serialVersionUID = 1L;
55  private final GridBagConstraints constraints = new GridBagConstraints();
56  private final List<AbstractDiscoveryFilterPanel> filters = new ArrayList<>();
57  private final JPanel firstColumnPanel = new JPanel();
58  private final JPanel secondColumnPanel = new JPanel();
59  private int firstColumnY = 0;
60  private int secondColumnY = 0;
61  private SortingMethod lastSortingMethod = SortingMethod.BY_FILE_NAME;
62  private GroupingAttributeType lastGroupingAttributeType = GroupingAttributeType.PARENT_PATH;
63  private Group.GroupSortingAlgorithm lastGroupSortingAlg = Group.GroupSortingAlgorithm.BY_GROUP_SIZE;
64 
68  AbstractFiltersPanel() {
69  firstColumnPanel.setLayout(new GridBagLayout());
70  secondColumnPanel.setLayout(new GridBagLayout());
71  }
72 
78  abstract SearchData.Type getType();
79 
91  final synchronized void addFilter(AbstractDiscoveryFilterPanel filterPanel, boolean isSelected, int[] indicesSelected, int column) {
92  if (!isInitialized) {
93  constraints.gridy = 0;
94  constraints.anchor = GridBagConstraints.FIRST_LINE_START;
95  constraints.insets = new Insets(8, 8, 8, 8);
96  isInitialized = true;
97  }
98  if (column == 0) {
99  constraints.gridy = firstColumnY;
100  } else {
101  constraints.gridy = secondColumnY;
102  }
103  constraints.gridx = 0;
104  filterPanel.configurePanel(isSelected, indicesSelected);
105  filterPanel.addListeners(this, this);
106  filters.add(filterPanel);
107  constraints.fill = GridBagConstraints.VERTICAL;
108  constraints.gridheight = LABEL_HEIGHT;
109  constraints.gridwidth = LABEL_WIDTH;
110  constraints.weightx = LABEL_WEIGHT;
111  constraints.weighty = LABEL_WEIGHT;
112  constraints.gridwidth = LABEL_WIDTH;
113  addToGridBagLayout(filterPanel.getCheckbox(), filterPanel.getAdditionalLabel(), column);
114  if (filterPanel.hasPanel()) {
115  constraints.gridx += constraints.gridwidth;
116  constraints.fill = GridBagConstraints.BOTH;
117  constraints.gridheight = PANEL_HEIGHT;
118  constraints.weightx = PANEL_WEIGHT;
119  constraints.weighty = PANEL_WEIGHT;
120  constraints.gridwidth = PANEL_WIDTH;
121  addToGridBagLayout(filterPanel, null, column);
122  }
123  if (column == 0) {
124  firstColumnY += constraints.gridheight;
125  } else {
126  secondColumnY += constraints.gridheight;
127  }
128  }
129 
135  final void addPanelsToScrollPane(JSplitPane splitPane) {
136  splitPane.setLeftComponent(firstColumnPanel);
137  splitPane.setRightComponent(secondColumnPanel);
138  validate();
139  repaint();
140  }
141 
145  final synchronized void clearFilters() {
146  for (AbstractDiscoveryFilterPanel filterPanel : filters) {
147  filterPanel.removeListeners();
148  }
149  filters.clear();
150  }
151 
162  private void addToGridBagLayout(Component componentToAdd, Component additionalComponentToAdd, int columnIndex) {
163  addToColumn(componentToAdd, columnIndex);
164  if (additionalComponentToAdd != null) {
165  constraints.gridy += constraints.gridheight;
166  addToColumn(additionalComponentToAdd, columnIndex);
167  constraints.gridy -= constraints.gridheight;
168  }
169  }
170 
177  private void addToColumn(Component component, int columnNumber) {
178  if (columnNumber == 0) {
179  firstColumnPanel.add(component, constraints);
180  } else {
181  secondColumnPanel.add(component, constraints);
182  }
183  }
184 
189  synchronized void validateFields() {
190  String errorString = null;
191  for (AbstractDiscoveryFilterPanel filterPanel : filters) {
192  errorString = filterPanel.checkForError();
193  if (!StringUtils.isBlank(errorString)) {
194  break;
195  }
196  }
197  firePropertyChange("FilterError", null, errorString);
198  }
199 
200  @Override
201  public void actionPerformed(ActionEvent e) {
202  validateFields();
203  validate();
204  repaint();
205  }
206 
212  boolean isObjectsFilterSupported() {
213  for (AbstractDiscoveryFilterPanel filter : filters) {
214  if (filter instanceof ObjectDetectedFilterPanel) {
215  return filter.getList().getModel().getSize() > 0;
216  }
217  }
218  return false;
219  }
220 
226  boolean isHashSetFilterSupported() {
227  for (AbstractDiscoveryFilterPanel filter : filters) {
228  if (filter instanceof HashSetFilterPanel) {
229  return filter.getList().getModel().getSize() > 0;
230  }
231  }
232  return false;
233  }
234 
240  boolean isInterestingItemsFilterSupported() {
241  for (AbstractDiscoveryFilterPanel filter : filters) {
242  if (filter instanceof InterestingItemsFilterPanel) {
243  return filter.getList().getModel().getSize() > 0;
244  }
245  }
246  return false;
247  }
248 
254  synchronized List<AbstractFilter> getFilters() {
255 
256  List<AbstractFilter> filtersToUse = new ArrayList<>();
257  if (getType() != SearchData.Type.DOMAIN) { //Domain type does not have a file type
258  filtersToUse.add(new SearchFiltering.FileTypeFilter(getType()));
259  }
260  for (AbstractDiscoveryFilterPanel filterPanel : filters) {
261  if (filterPanel.getCheckbox().isSelected()) {
262  AbstractFilter filter = filterPanel.getFilter();
263  if (filter != null) {
264  filtersToUse.add(filter);
265  }
266  }
267  }
268  return filtersToUse;
269  }
270 
271  @Override
272  public void valueChanged(ListSelectionEvent evt) {
273  if (!evt.getValueIsAdjusting()) {
274  validateFields();
275  validate();
276  repaint();
277  }
278  }
279 
285  SortingMethod getLastSortingMethod() {
286  return lastSortingMethod;
287  }
288 
294  final void setLastSortingMethod(SortingMethod lastSortingMethod) {
295  this.lastSortingMethod = lastSortingMethod;
296  }
297 
303  GroupingAttributeType getLastGroupingAttributeType() {
304  return lastGroupingAttributeType;
305  }
306 
313  final void setLastGroupingAttributeType(GroupingAttributeType lastGroupingAttributeType) {
314  this.lastGroupingAttributeType = lastGroupingAttributeType;
315  }
316 
322  Group.GroupSortingAlgorithm getLastGroupSortingAlg() {
323  return lastGroupSortingAlg;
324  }
325 
332  final void setLastGroupSortingAlg(Group.GroupSortingAlgorithm lastGroupSortingAlg) {
333  this.lastGroupSortingAlg = lastGroupSortingAlg;
334  }
335 
336 }

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.