2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
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 {
|
2021-08-22 11:15:23 -06:00
|
|
|
return Math.max(0, 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
|
|
|
|
2021-08-22 11:15:23 -06:00
|
|
|
@Override
|
|
|
|
|
public void gainFocus() {
|
|
|
|
|
if (text().equals("0")) {
|
|
|
|
|
setText("");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2021-08-22 11:15:23 -06:00
|
|
|
NEIClientUtils.setItemQuantity(intValue());
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
}
|