protected void createInstances() { labelTitle = new GenericLabel(title); textText = new GenericTextField(); textText.setWidth(200); textText.setText(text); buttonCancel = new GenericButton("Cancel"); buttonDone = new GenericButton("Done"); getScreen().attachWidgets("Spoutcraft", labelTitle, textText, buttonCancel, buttonDone); }
protected void layoutWidgets() { final int totalHeight = 11 + 5 + 20 + 5 + 20; int top = height / 2 - totalHeight / 2; labelTitle.setWidth(200).setHeight(11).setX(width / 2 - 100).setY(top); top += 16; textText.setWidth(200).setHeight(20).setX(width / 2 - 100).setY(top); top += 25; buttonCancel.setWidth(95).setHeight(20).setX(width / 2 - 100).setY(top); buttonDone.setWidth(100).setHeight(20).setX(width / 2).setY(top); }
@Override public Control setFocus(boolean focus) { super.setFocus(focus); if (!focus) { try { int width = Integer.parseInt(getText()); if (width < 1) throw new RuntimeException("Must be at least 1"); Configuration.setResizedScreenshotWidth(width); Configuration.write(); setText(""); setPlaceholder("" + width); } catch (Exception e) { setText(""); setPlaceholder("Error"); } } return this; }
@Override public void onTick() { setEnabled(Configuration.isResizeScreenshots()); super.onTick(); }
public String getText() { text = textText.getText(); return text; }
public void setText(String text) { this.text = text; if (textText != null) { textText.setText(text); // Redundant text is redundant } }