2014-06-29 20:31:37 +10:00
|
|
|
package codechicken.nei.config;
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public class OptionIntegerField extends OptionTextField {
|
2019-12-30 20:19:16 -08:00
|
|
|
public final int min;
|
|
|
|
|
public final int max;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public OptionIntegerField(String name, int min, int max) {
|
|
|
|
|
super(name);
|
|
|
|
|
this.min = min;
|
|
|
|
|
this.max = max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OptionIntegerField(String name) {
|
|
|
|
|
this(name, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isValidInput(String s) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (s.length() == 0) return true;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Integer.parseInt(s);
|
|
|
|
|
return true;
|
2022-06-24 12:32:13 +01:00
|
|
|
} catch (NumberFormatException nfe) {
|
2014-06-29 20:31:37 +10:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isValidValue(String s) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (s.length() == 0 || !isValidInput(s)) return false;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
int i = Integer.parseInt(s);
|
|
|
|
|
return i >= min && i <= max;
|
|
|
|
|
}
|
|
|
|
|
}
|