2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
|
|
|
|
public class ItemQuantityField extends TextField
|
|
|
|
|
{
|
2014-06-29 20:31:37 +10:00
|
|
|
public ItemQuantityField(String ident) {
|
2014-04-29 10:54:20 +10:00
|
|
|
super(ident);
|
|
|
|
|
centered = true;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public boolean isValid(String string) {
|
|
|
|
|
if (string.equals(""))
|
2014-04-29 10:54:20 +10:00
|
|
|
return true;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
try {
|
2014-04-29 10:54:20 +10:00
|
|
|
return Integer.parseInt(string) >= 0;
|
2014-06-29 20:31:37 +10:00
|
|
|
} catch (NumberFormatException nfe) {
|
2014-04-29 10:54:20 +10:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public int intValue() {
|
2014-04-29 10:54:20 +10:00
|
|
|
return intValue(text());
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public int intValue(String s) {
|
|
|
|
|
try {
|
2014-04-29 10:54:20 +10:00
|
|
|
return Integer.parseInt(s);
|
2014-06-29 20:31:37 +10:00
|
|
|
} catch (NumberFormatException nfe) {
|
2014-04-29 10:54:20 +10:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public void loseFocus() {
|
2014-04-29 10:54:20 +10:00
|
|
|
setText(Integer.toString(NEIClientConfig.getItemQuantity()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public void onTextChange(String oldText) {
|
|
|
|
|
if (intValue(oldText) != intValue())//hacky recursion stopper
|
2014-04-29 10:54:20 +10:00
|
|
|
NEIClientUtils.setItemQuantity(intValue());
|
|
|
|
|
}
|
|
|
|
|
}
|