19 package org.sleuthkit.autopsy.filesearch;
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;
33 class SizeSearchFilter
extends AbstractFileSearchFilter<SizeSearchPanel> {
39 this(
new SizeSearchPanel());
47 SizeSearchFilter(SizeSearchPanel component) {
52 public boolean isEnabled() {
53 return this.getComponent().getSizeCheckBox().isSelected();
57 public String getPredicate() throws FilterValidationException {
58 int size = ((Number) this.getComponent().getSizeTextField().getValue()).intValue();
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;
74 private String compareComboBoxToOperator(JComboBox<String> compare) {
75 String compareSize = compare.getSelectedItem().toString();
77 if (compareSize.equals(NbBundle.getMessage(
this.getClass(),
"SizeSearchPanel.sizeCompareComboBox.equalTo"))) {
79 }
else if (compareSize.equals(
80 NbBundle.getMessage(
this.getClass(),
"SizeSearchPanel.sizeCompareComboBox.greaterThan"))) {
82 }
else if (compareSize.equals(
83 NbBundle.getMessage(
this.getClass(),
"SizeSearchPanel.sizeCompareComboBox.lessThan"))) {
86 throw new IllegalArgumentException();
91 public void addActionListener(ActionListener l) {
92 getComponent().addActionListener(l);
97 "SizeSearchFilter.errorMessage.nonNegativeNumber=Input size data is a negative number.",
98 "SizeSearchFilter.errorMessage.notANumber=Input size data is not a number."
100 public boolean isValid() {
101 String input = this.getComponent().getSizeTextField().getText();
104 int inputInt = NumberFormat.getNumberInstance(Locale.US).parse(input).intValue();
106 setLastError(Bundle.SizeSearchFilter_errorMessage_nonNegativeNumber());
109 }
catch (ParseException ex) {
110 setLastError(Bundle.SizeSearchFilter_errorMessage_notANumber());