diff options
Diffstat (limited to 'NET/worlds/scape/CheckboxEditorDialog.java')
| -rw-r--r-- | NET/worlds/scape/CheckboxEditorDialog.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/NET/worlds/scape/CheckboxEditorDialog.java b/NET/worlds/scape/CheckboxEditorDialog.java new file mode 100644 index 0000000..e8eb818 --- /dev/null +++ b/NET/worlds/scape/CheckboxEditorDialog.java @@ -0,0 +1,64 @@ +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); + } +} |