Autopsy  4.15.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;
20 
21 import java.awt.Component;
22 import java.awt.GridBagConstraints;
23 import java.awt.GridBagLayout;
24 import java.awt.Insets;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.util.ArrayList;
28 import java.util.List;
29 import javax.swing.JPanel;
30 import javax.swing.JSplitPane;
31 import javax.swing.event.ListSelectionEvent;
32 import javax.swing.event.ListSelectionListener;
33 import org.apache.commons.lang3.StringUtils;
34 
39 abstract class AbstractFiltersPanel extends JPanel implements ActionListener, ListSelectionListener {
40 
41  private boolean isInitialized = false;
42  private static final double LABEL_WEIGHT = 0;
43  private static final double PANEL_WEIGHT = .1;
44  private static final int LABEL_WIDTH = 1;
45  private static final int PANEL_WIDTH = 2;
46  private static final int LABEL_HEIGHT = 1;
47  private static final int PANEL_HEIGHT = 2;
48  private static final long serialVersionUID = 1L;
49  private final GridBagConstraints constraints = new GridBagConstraints();
50  private final List<AbstractDiscoveryFilterPanel> filters = new ArrayList<>();
51  private final JPanel firstColumnPanel = new JPanel();
52  private final JPanel secondColumnPanel = new JPanel();
53  private int firstColumnY = 0;
54  private int secondColumnY = 0;
55 
59  AbstractFiltersPanel() {
60  firstColumnPanel.setLayout(new GridBagLayout());
61  secondColumnPanel.setLayout(new GridBagLayout());
62  }
63 
69  abstract FileSearchData.FileType getFileType();
70 
82  final synchronized void addFilter(AbstractDiscoveryFilterPanel filterPanel, boolean isSelected, int[] indicesSelected, int column) {
83  if (!isInitialized) {
84  constraints.gridy = 0;
85  constraints.anchor = GridBagConstraints.FIRST_LINE_START;
86  constraints.insets = new Insets(8, 8, 8, 8);
87  isInitialized = true;
88  }
89  if (column == 0) {
90  constraints.gridy = firstColumnY;
91  } else {
92  constraints.gridy = secondColumnY;
93  }
94  constraints.gridx = 0;
95  filterPanel.configurePanel(isSelected, indicesSelected);
96  filterPanel.addListeners(this, this);
97  filters.add(filterPanel);
98  constraints.fill = GridBagConstraints.VERTICAL;
99  constraints.gridheight = LABEL_HEIGHT;
100  constraints.gridwidth = LABEL_WIDTH;
101  constraints.weightx = LABEL_WEIGHT;
102  constraints.weighty = LABEL_WEIGHT;
103  constraints.gridwidth = LABEL_WIDTH;
104  addToGridBagLayout(filterPanel.getCheckbox(), filterPanel.getAdditionalLabel(), column);
105  if (filterPanel.hasPanel()) {
106  constraints.gridx += constraints.gridwidth;
107  constraints.fill = GridBagConstraints.BOTH;
108  constraints.gridheight = PANEL_HEIGHT;
109  constraints.weightx = PANEL_WEIGHT;
110  constraints.weighty = PANEL_WEIGHT;
111  constraints.gridwidth = PANEL_WIDTH;
112  addToGridBagLayout(filterPanel, null, column);
113  }
114  if (column == 0) {
115  firstColumnY += constraints.gridheight;
116  } else {
117  secondColumnY += constraints.gridheight;
118  }
119  }
120 
126  final void addPanelsToScrollPane(JSplitPane splitPane) {
127  splitPane.setLeftComponent(firstColumnPanel);
128  splitPane.setRightComponent(secondColumnPanel);
129  validate();
130  repaint();
131  }
132 
136  final synchronized void clearFilters() {
137  for (AbstractDiscoveryFilterPanel filterPanel : filters) {
138  filterPanel.removeListeners();
139  }
140  filters.clear();
141  }
142 
153  private void addToGridBagLayout(Component componentToAdd, Component additionalComponentToAdd, int columnIndex) {
154  addToColumn(componentToAdd, columnIndex);
155  if (additionalComponentToAdd != null) {
156  constraints.gridy += constraints.gridheight;
157  addToColumn(additionalComponentToAdd, columnIndex);
158  constraints.gridy -= constraints.gridheight;
159  }
160  }
161 
168  private void addToColumn(Component component, int columnNumber) {
169  if (columnNumber == 0) {
170  firstColumnPanel.add(component, constraints);
171  } else {
172  secondColumnPanel.add(component, constraints);
173  }
174  }
175 
180  synchronized void validateFields() {
181  String errorString = null;
182  for (AbstractDiscoveryFilterPanel filterPanel : filters) {
183  errorString = filterPanel.checkForError();
184  if (!StringUtils.isBlank(errorString)) {
185  break;
186  }
187  }
188  firePropertyChange("FilterError", null, errorString);
189  }
190 
191  @Override
192  public void actionPerformed(ActionEvent e) {
193  validateFields();
194  validate();
195  repaint();
196  }
197 
203  boolean isObjectsFilterSupported() {
204  for (AbstractDiscoveryFilterPanel filter : filters) {
205  if (filter instanceof ObjectDetectedFilterPanel) {
206  return filter.getList().getModel().getSize() > 0;
207  }
208  }
209  return false;
210  }
211 
217  boolean isHashSetFilterSupported() {
218  for (AbstractDiscoveryFilterPanel filter : filters) {
219  if (filter instanceof HashSetFilterPanel) {
220  return filter.getList().getModel().getSize() > 0;
221  }
222  }
223  return false;
224  }
225 
231  boolean isInterestingItemsFilterSupported() {
232  for (AbstractDiscoveryFilterPanel filter : filters) {
233  if (filter instanceof InterestingItemsFilterPanel) {
234  return filter.getList().getModel().getSize() > 0;
235  }
236  }
237  return false;
238  }
239 
245  synchronized List<FileSearchFiltering.FileFilter> getFilters() {
246  List<FileSearchFiltering.FileFilter> filtersToUse = new ArrayList<>();
247  filtersToUse.add(new FileSearchFiltering.FileTypeFilter(getFileType()));
248  for (AbstractDiscoveryFilterPanel filterPanel : filters) {
249  if (filterPanel.getCheckbox().isSelected()) {
250  FileSearchFiltering.FileFilter filter = filterPanel.getFilter();
251  if (filter != null) {
252  filtersToUse.add(filter);
253  }
254  }
255  }
256  return filtersToUse;
257  }
258 
259  @Override
260  public void valueChanged(ListSelectionEvent evt) {
261  if (!evt.getValueIsAdjusting()) {
262  validateFields();
263  validate();
264  repaint();
265  }
266  }
267 
268 }

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.