public TextEditElement setValidator(Predicate<String> validator) { field.setValidator(validator::test); return this; }
public TextFieldWidget setValidator(Predicate<String> validator) { this.textValidator = validator; if(isClientSide()) { this.textField.setValidator(validator::test); } return this; }
backgroundColor = new GuiTextField(8, fontRenderer, width / 4, 120 + textFieldOffset, 150, 16); backgroundColor.setText(OverlayConfig.toHex(new Color(OverlayConfig.bgcolor))); backgroundColor.setValidator(HEX_COLOR); gradientTop = new GuiTextField(9, fontRenderer, width / 4, 140 + textFieldOffset, 150, 16); gradientTop.setText(OverlayConfig.toHex(new Color(OverlayConfig.gradient1))); gradientTop.setValidator(HEX_COLOR); gradientBottom = new GuiTextField(9, fontRenderer, width / 4, 160 + textFieldOffset, 150, 16); gradientBottom.setText(OverlayConfig.toHex(new Color(OverlayConfig.gradient2))); gradientBottom.setValidator(HEX_COLOR); textColor = new GuiTextField(9, fontRenderer, width / 4, 180 + textFieldOffset, 150, 16); textColor.setText(OverlayConfig.toHex(new Color(OverlayConfig.fontcolor))); textColor.setValidator(HEX_COLOR);
@Override public void initGui() { Keyboard.enableRepeatEvents(true); this.buttonList.clear(); this.buttonList.add(new GuiButton(0, this.width / 2 - 155, this.height - 28, 150, 20, "Generate Image")); this.buttonList.add(new GuiButton(1, this.width / 2 + 5, this.height - 28, 150, 20, I18n.format("gui.cancel"))); this.btnBypassProvider = this.addButton(new GuiButton(2, this.width / 2 - 155, 151, 150, 20, "Bypass Biome Provider: NO")); this.btnBypassProvider.enabled = false; this.btnMapType = this.addButton(new GuiButton(3, this.width / 2 + 5, 151, 150, 20, I18n.format("selectWorld.mapType"))); this.worldNameField = new GuiTextField(4, this.fontRenderer, this.width / 2 - 100, 60, 200, 20); this.worldNameField.setFocused(true); this.worldNameField.setText(this.worldName); this.worldSeedField = new GuiTextField(5, this.fontRenderer, this.width / 2 - 100, 111, 200, 20); this.worldSeedField.setText(this.worldSeed); final int y = 173+this.fontRenderer.FONT_HEIGHT + ((this.height-28)-(173+this.fontRenderer.FONT_HEIGHT))/2-10; final int width = (150-this.fontRenderer.getStringWidth("X:")-this.fontRenderer.getStringWidth("Y:")-30)/2; this.radiusField = new GuiTextField(6, this.fontRenderer, this.width/2-155+this.fontRenderer.getStringWidth("Radius (chunks):")+10, y, 150-this.fontRenderer.getStringWidth("Radius (chunks):")-10, 20); this.radiusField.setValidator(Predicates.or(PredicateHelper.EMPTY_STRING, PredicateHelper.NONNEG_INT)); this.radiusField.setText(String.valueOf(this.radius)); this.xField = new GuiTextField(7, this.fontRenderer, this.width/2+5+this.fontRenderer.getStringWidth("X:")+10, y, width, 20); this.xField.setValidator(Predicates.or(PredicateHelper.EMPTY_STRING, PredicateHelper.INT)); this.xField.setText(String.valueOf(this.xCoord)); this.yField = new GuiTextField(8, this.fontRenderer, this.width/2+5+this.fontRenderer.getStringWidth("X:")+10+width+10+this.fontRenderer.getStringWidth("Y:")+10, y, width, 20); this.yField.setValidator(Predicates.or(PredicateHelper.EMPTY_STRING, PredicateHelper.INT)); this.yField.setText(String.valueOf(this.yCoord)); this.calcSaveDirName(); this.updateDisplayState(); }
public void initGui() { buttonList.clear(); Keyboard.enableRepeatEvents(true); textFields = new LinkedList(); defaultStrings = new String[4]; for(int i = 0; i < 4; i++) { GuiTextField field = new GuiTextField(i, fontRenderer, width / 2 + 4, 75 + i * 24, 120, 20); field.setValidator(this::validateText); field.setMaxStringLength(100); String text = sign.signText[i].getUnformattedText(); defaultStrings[i] = text; field.setText(text); textFields.add(field); } textFields.get(focusedField).setFocused(true); if(ImprovedSignEdit.enableCancel) { addButton(new GuiButton(4, width / 2 + 5, height / 4 + 120, 120, 20, I18n.format("gui.done"))); addButton(new GuiButton(5, width / 2 - 125, height / 4 + 120, 120, 20, I18n.format("gui.cancel"))); } else addButton(new GuiButton(4, width / 2 - 100, height / 4 + 120, I18n.format("gui.done"))); if(ImprovedSignEdit.enableShift) addButton(new GuiButton(6, width / 2 - 41, 147, 40, 20, I18n.format("quarkmisc.signShift"))); if(ImprovedSignEdit.enableClear) addButton(new GuiButton(7, width / 2 - 41, (ImprovedSignEdit.enableShift ? 123 : 147), 40, 20, I18n.format("quarkmisc.signClear"))); sign.setEditable(false); }