ChatboxTextInput: add ability to filter character inputs

This commit is contained in:
Ron Young
2019-10-05 20:35:46 -05:00
committed by Tomas Slusny
parent 3181ee896b
commit 021bb109d6

View File

@@ -129,6 +129,12 @@ public class ChatboxTextInput extends ChatboxInput implements KeyListener, Mouse
this.clientThread = clientThread;
}
public ChatboxTextInput addCharValidator(IntPredicate validator)
{
this.charValidator = this.charValidator.and(validator);
return this;
}
public ChatboxTextInput lines(int lines)
{
this.lines = lines;
@@ -151,7 +157,15 @@ public class ChatboxTextInput extends ChatboxInput implements KeyListener, Mouse
public ChatboxTextInput value(String value)
{
this.value = new StringBuffer(value);
StringBuffer sb = new StringBuffer();
for (char c : value.toCharArray())
{
if (charValidator.test(c))
{
sb.append(c);
}
}
this.value = sb;
cursorAt(this.value.length());
return this;
}