Autopsy  4.19.3
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-2018 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 java.text.ParseException;
23 import java.util.Locale;
24 import javax.swing.JComboBox;
25 import org.openide.util.NbBundle;
26 import org.openide.util.NbBundle.Messages;
27 import org.python.icu.text.NumberFormat;
29 
33 class SizeSearchFilter extends AbstractFileSearchFilter<SizeSearchPanel> {
34 
38  SizeSearchFilter() {
39  this(new SizeSearchPanel());
40  }
41 
47  SizeSearchFilter(SizeSearchPanel component) {
48  super(component);
49  }
50 
51  @Override
52  public boolean isEnabled() {
53  return this.getComponent().getSizeCheckBox().isSelected();
54  }
55 
56  @Override
57  public String getPredicate() throws FilterValidationException {
58  int size = ((Number) this.getComponent().getSizeTextField().getValue()).intValue(); // note: already only allow number to the text field
59  String operator = compareComboBoxToOperator(this.getComponent().getSizeCompareComboBox());
60  int unit = this.getComponent().getSizeUnitComboBox().getSelectedIndex();
61  int divider = (int) Math.pow(2, (unit * 10));
62  size = size * divider;
63  return "size " + operator + " " + size; //NON-NLS
64  }
65 
74  private String compareComboBoxToOperator(JComboBox<String> compare) {
75  String compareSize = compare.getSelectedItem().toString();
76 
77  if (compareSize.equals(NbBundle.getMessage(this.getClass(), "SizeSearchPanel.sizeCompareComboBox.equalTo"))) {
78  return "=";
79  } else if (compareSize.equals(
80  NbBundle.getMessage(this.getClass(), "SizeSearchPanel.sizeCompareComboBox.greaterThan"))) {
81  return ">";
82  } else if (compareSize.equals(
83  NbBundle.getMessage(this.getClass(), "SizeSearchPanel.sizeCompareComboBox.lessThan"))) {
84  return "<";
85  } else {
86  throw new IllegalArgumentException();
87  }
88  }
89 
90  @Override
91  public void addActionListener(ActionListener l) {
92  getComponent().addActionListener(l);
93  }
94 
95  @Override
96  @Messages({
97  "SizeSearchFilter.errorMessage.nonNegativeNumber=Input size data is a negative number.",
98  "SizeSearchFilter.errorMessage.notANumber=Input size data is not a number."
99  })
100  public boolean isValid() {
101  String input = this.getComponent().getSizeTextField().getText();
102 
103  try {
104  int inputInt = NumberFormat.getNumberInstance(Locale.US).parse(input).intValue();
105  if (inputInt < 0) {
106  setLastError(Bundle.SizeSearchFilter_errorMessage_nonNegativeNumber());
107  return false;
108  }
109  } catch (ParseException ex) {
110  setLastError(Bundle.SizeSearchFilter_errorMessage_notANumber());
111  return false;
112  }
113  return true;
114  }
115 }

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