Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
SizeSearchFilter.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011 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.filesearch;
20 
21 import java.awt.event.ActionListener;
22 import javax.swing.JComboBox;
23 import org.openide.util.NbBundle;
25 
30 class SizeSearchFilter extends AbstractFileSearchFilter<SizeSearchPanel> {
31 
32  SizeSearchFilter() {
33  this(new SizeSearchPanel());
34  }
35 
36  SizeSearchFilter(SizeSearchPanel component) {
37  super(component);
38  }
39 
40  @Override
41  public boolean isEnabled() {
42  return this.getComponent().getSizeCheckBox().isSelected();
43  }
44 
45  @Override
46  public String getPredicate() throws FilterValidationException {
47  int size = ((Number) this.getComponent().getSizeTextField().getValue()).intValue(); // note: already only allow number to the text field
48  String operator = compareComboBoxToOperator(this.getComponent().getSizeCompareComboBox());
49  int unit = this.getComponent().getSizeUnitComboBox().getSelectedIndex();
50  int divider = (int) Math.pow(2, (unit * 10));
51  size = size * divider;
52  return "size " + operator + " " + size; //NON-NLS
53  }
54 
55  private String compareComboBoxToOperator(JComboBox<String> compare) {
56  String compareSize = compare.getSelectedItem().toString();
57 
58  if (compareSize.equals(NbBundle.getMessage(this.getClass(), "SizeSearchPanel.sizeCompareComboBox.equalTo"))) {
59  return "=";
60  } else if (compareSize.equals(
61  NbBundle.getMessage(this.getClass(), "SizeSearchPanel.sizeCompareComboBox.greaterThan"))) {
62  return ">";
63  } else if (compareSize.equals(
64  NbBundle.getMessage(this.getClass(), "SizeSearchPanel.sizeCompareComboBox.lessThan"))) {
65  return "<";
66  } else {
67  throw new IllegalArgumentException();
68  }
69  }
70 
71  @Override
72  public void addActionListener(ActionListener l) {
73  getComponent().addActionListener(l);
74  }
75 
76  @Override
77  public boolean isValid() {
78  return true;
79  }
80 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jan 2 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.