package NET.worlds.scape; import NET.worlds.console.Console; import NET.worlds.console.OkCancelDialog; import java.awt.Checkbox; import java.awt.CheckboxGroup; import java.awt.Dimension; import java.awt.GridBagConstraints; public abstract class CheckboxEditorDialog extends OkCancelDialog { private CheckboxGroup group = new CheckboxGroup(); private Checkbox[] choices; private String[] labels; protected EditTile parent; protected CheckboxEditorDialog(EditTile parent, String title, String[] labels) { super(Console.getFrame(), parent, title); this.labels = labels; this.parent = parent; } @Override protected void build() { this.choices = new Checkbox[this.labels.length]; GridBagConstraints c = new GridBagConstraints(); c.weightx = 1.0; c.weighty = 1.0; c.gridwidth = 0; for (int i = 0; i < this.labels.length; i++) { this.add(this.gbag, this.choices[i] = new Checkbox(this.labels[i], this.group, false), c); } super.build(); } protected abstract int getValue(); protected abstract void setValue(int var1); @Override protected boolean setValue() { Checkbox selected = this.group.getCurrent(); for (int i = 0; i < this.choices.length; i++) { if (this.choices[i] == selected) { this.setValue(i); return true; } } return false; } @Override public void show() { Dimension mySize = this.size(); this.initialSize(mySize.width < 160 ? 160 : mySize.width, mySize.height < 120 ? 120 : mySize.height); super.show(); int choice = this.getValue(); this.choices[choice].requestFocus(); this.choices[choice].setState(true); } }