mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-13 00:16:16 +00:00
5187 have number formatters restore empty field when invalid input
This commit is contained in:
parent
008d8dc149
commit
003ab250a1
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package org.sleuthkit.autopsy.logicalimager.configuration;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import javax.swing.text.NumberFormatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number formatter which will reset to being a null value when an invalid value
|
||||||
|
* is entered
|
||||||
|
*/
|
||||||
|
final class DefaultToEmptyNumberFormatter extends NumberFormatter {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a DefaultToEmptyNumberFormatter
|
||||||
|
*
|
||||||
|
* @param format the format for the numbers
|
||||||
|
*/
|
||||||
|
DefaultToEmptyNumberFormatter(NumberFormat format) {
|
||||||
|
super(format);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object stringToValue(String string)
|
||||||
|
throws ParseException {
|
||||||
|
Object returnValue = null;
|
||||||
|
try {
|
||||||
|
returnValue = super.stringToValue(string);
|
||||||
|
} catch (ParseException ignored) {
|
||||||
|
//reset value to being empty since invalid value was entered
|
||||||
|
}
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
}
|
@ -222,24 +222,24 @@
|
|||||||
</Container>
|
</Container>
|
||||||
<Component class="javax.swing.JFormattedTextField" name="minSizeTextField">
|
<Component class="javax.swing.JFormattedTextField" name="minSizeTextField">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="formatterFactory" type="javax.swing.JFormattedTextField$AbstractFormatterFactory" editor="org.netbeans.modules.form.editors.AbstractFormatterFactoryEditor">
|
<Property name="formatterFactory" type="javax.swing.JFormattedTextField$AbstractFormatterFactory" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||||
<Format format="#,###; " subtype="-1" type="0"/>
|
<Connection code="new javax.swing.text.DefaultFormatterFactory(new DefaultToEmptyNumberFormatter(new java.text.DecimalFormat("#,###; ")))" type="code"/>
|
||||||
</Property>
|
</Property>
|
||||||
<Property name="enabled" type="boolean" value="false"/>
|
<Property name="enabled" type="boolean" value="false"/>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Component>
|
</Component>
|
||||||
<Component class="javax.swing.JFormattedTextField" name="maxSizeTextField">
|
<Component class="javax.swing.JFormattedTextField" name="maxSizeTextField">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="formatterFactory" type="javax.swing.JFormattedTextField$AbstractFormatterFactory" editor="org.netbeans.modules.form.editors.AbstractFormatterFactoryEditor">
|
<Property name="formatterFactory" type="javax.swing.JFormattedTextField$AbstractFormatterFactory" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||||
<Format format="#,###; " subtype="-1" type="0"/>
|
<Connection code="new javax.swing.text.DefaultFormatterFactory(new DefaultToEmptyNumberFormatter(new java.text.DecimalFormat("#,###; ")))" type="code"/>
|
||||||
</Property>
|
</Property>
|
||||||
<Property name="enabled" type="boolean" value="false"/>
|
<Property name="enabled" type="boolean" value="false"/>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Component>
|
</Component>
|
||||||
<Component class="javax.swing.JFormattedTextField" name="modifiedWithinTextField">
|
<Component class="javax.swing.JFormattedTextField" name="modifiedWithinTextField">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="formatterFactory" type="javax.swing.JFormattedTextField$AbstractFormatterFactory" editor="org.netbeans.modules.form.editors.AbstractFormatterFactoryEditor">
|
<Property name="formatterFactory" type="javax.swing.JFormattedTextField$AbstractFormatterFactory" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||||
<Format format="" subtype="-1" type="0"/>
|
<Connection code="new javax.swing.text.DefaultFormatterFactory(new DefaultToEmptyNumberFormatter(new java.text.DecimalFormat("#,###; ")))" type="code"/>
|
||||||
</Property>
|
</Property>
|
||||||
<Property name="enabled" type="boolean" value="false"/>
|
<Property name="enabled" type="boolean" value="false"/>
|
||||||
</Properties>
|
</Properties>
|
||||||
|
@ -362,13 +362,13 @@ final class EditNonFullPathsRulePanel extends javax.swing.JPanel {
|
|||||||
|
|
||||||
folderNamesScrollPane.setEnabled(false);
|
folderNamesScrollPane.setEnabled(false);
|
||||||
|
|
||||||
minSizeTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,###; "))));
|
minSizeTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new DefaultToEmptyNumberFormatter(new java.text.DecimalFormat("#,###; "))));
|
||||||
minSizeTextField.setEnabled(false);
|
minSizeTextField.setEnabled(false);
|
||||||
|
|
||||||
maxSizeTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,###; "))));
|
maxSizeTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new DefaultToEmptyNumberFormatter(new java.text.DecimalFormat("#,###; "))));
|
||||||
maxSizeTextField.setEnabled(false);
|
maxSizeTextField.setEnabled(false);
|
||||||
|
|
||||||
modifiedWithinTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat(""))));
|
modifiedWithinTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new DefaultToEmptyNumberFormatter(new java.text.DecimalFormat("#,###; "))));
|
||||||
modifiedWithinTextField.setEnabled(false);
|
modifiedWithinTextField.setEnabled(false);
|
||||||
|
|
||||||
userFolderNote.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/info-icon-16.png"))); // NOI18N
|
userFolderNote.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/info-icon-16.png"))); // NOI18N
|
||||||
@ -694,14 +694,30 @@ final class EditNonFullPathsRulePanel extends javax.swing.JPanel {
|
|||||||
return (extensionsCheckbox.isSelected() && !StringUtils.isBlank(extensionsTextField.getText()) && !validateExtensions(extensionsTextField).isEmpty())
|
return (extensionsCheckbox.isSelected() && !StringUtils.isBlank(extensionsTextField.getText()) && !validateExtensions(extensionsTextField).isEmpty())
|
||||||
|| (fileNamesCheckbox.isSelected() && !StringUtils.isBlank(fileNamesTextArea.getText()))
|
|| (fileNamesCheckbox.isSelected() && !StringUtils.isBlank(fileNamesTextArea.getText()))
|
||||||
|| (folderNamesCheckbox.isSelected() && !StringUtils.isBlank(folderNamesTextArea.getText()))
|
|| (folderNamesCheckbox.isSelected() && !StringUtils.isBlank(folderNamesTextArea.getText()))
|
||||||
|| (minSizeCheckbox.isSelected() && !StringUtils.isBlank(minSizeTextField.getText()) && !(Long.parseLong(minSizeTextField.getText()) == 0))
|
|| (minSizeCheckbox.isSelected() && !StringUtils.isBlank(minSizeTextField.getText()) && isNonZeroLong(minSizeTextField.getText()))
|
||||||
|| (maxSizeCheckbox.isSelected() && !StringUtils.isBlank(maxSizeTextField.getText()) && !(Long.parseLong(maxSizeTextField.getText()) == 0))
|
|| (maxSizeCheckbox.isSelected() && !StringUtils.isBlank(maxSizeTextField.getText()) && isNonZeroLong(maxSizeTextField.getText()))
|
||||||
|| (modifiedWithinCheckbox.isSelected() && !StringUtils.isBlank(modifiedWithinTextField.getText()));
|
|| (modifiedWithinCheckbox.isSelected() && !StringUtils.isBlank(modifiedWithinTextField.getText()));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.log(Level.WARNING, "Invalid contents of extensionsTextField", ex);
|
logger.log(Level.WARNING, "Invalid contents of extensionsTextField", ex);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that value could be a non zero long
|
||||||
|
*
|
||||||
|
* @param numberString the string to check
|
||||||
|
*
|
||||||
|
* @return true if the value is a non-zero long
|
||||||
|
*/
|
||||||
|
private boolean isNonZeroLong(String numberString) {
|
||||||
|
Long value = 0L;
|
||||||
|
try {
|
||||||
|
value = Long.parseLong(numberString);
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
//The string was not a number, this method will return false becaue the value is still 0L
|
||||||
|
}
|
||||||
|
return (value != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user