Autopsy  4.5.0
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;
24 import org.openide.util.NbBundle.Messages;
26 
31 class SizeSearchFilter extends AbstractFileSearchFilter<SizeSearchPanel> {
32 
33  SizeSearchFilter() {
34  this(new SizeSearchPanel());
35  }
36 
37  SizeSearchFilter(SizeSearchPanel component) {
38  super(component);
39  }
40 
41  @Override
42  public boolean isEnabled() {
43  return this.getComponent().getSizeCheckBox().isSelected();
44  }
45 
46  @Override
47  public String getPredicate() throws FilterValidationException {
48  int size = ((Number) this.getComponent().getSizeTextField().getValue()).intValue(); // note: already only allow number to the text field
49  String operator = compareComboBoxToOperator(this.getComponent().getSizeCompareComboBox());
50  int unit = this.getComponent().getSizeUnitComboBox().getSelectedIndex();
51  int divider = (int) Math.pow(2, (unit * 10));
52  size = size * divider;
53  return "size " + operator + " " + size; //NON-NLS
54  }
55 
56  private String compareComboBoxToOperator(JComboBox<String> compare) {
57  String compareSize = compare.getSelectedItem().toString();
58 
59  if (compareSize.equals(NbBundle.getMessage(this.getClass(), "SizeSearchPanel.sizeCompareComboBox.equalTo"))) {
60  return "=";
61  } else if (compareSize.equals(
62  NbBundle.getMessage(this.getClass(), "SizeSearchPanel.sizeCompareComboBox.greaterThan"))) {
63  return ">";
64  } else if (compareSize.equals(
65  NbBundle.getMessage(this.getClass(), "SizeSearchPanel.sizeCompareComboBox.lessThan"))) {
66  return "<";
67  } else {
68  throw new IllegalArgumentException();
69  }
70  }
71 
72  @Override
73  public void addActionListener(ActionListener l) {
74  getComponent().addActionListener(l);
75  }
76 
77  @Override
78  @Messages ({
79  "SizeSearchFilter.errorMessage.nonNegativeNumber=Input size data is a negative number.",
80  "SizeSearchFilter.errorMessage.notANumber=Input size data is not a number."
81  })
82  public boolean isValid() {
83  String input = this.getComponent().getSizeTextField().getText();
84 
85  try {
86  int inputInt = Integer.parseInt(input);
87  if (inputInt < 0) {
88  setLastError(Bundle.SizeSearchFilter_errorMessage_nonNegativeNumber());
89  return false;
90  }
91  } catch (NumberFormatException | NullPointerException e) {
92  setLastError(Bundle.SizeSearchFilter_errorMessage_notANumber());
93  return false;
94  }
95  return true;
96  }
97 }

Copyright © 2012-2016 Basis Technology. Generated on: Tue Feb 20 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.