From c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 12 Feb 2026 22:33:32 -0800 Subject: Initial commit --- NET/worlds/console/EditNamesDialog.java | 143 ++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 NET/worlds/console/EditNamesDialog.java (limited to 'NET/worlds/console/EditNamesDialog.java') diff --git a/NET/worlds/console/EditNamesDialog.java b/NET/worlds/console/EditNamesDialog.java new file mode 100644 index 0000000..6134ae5 --- /dev/null +++ b/NET/worlds/console/EditNamesDialog.java @@ -0,0 +1,143 @@ +package NET.worlds.console; + +import java.awt.Button; +import java.awt.Event; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.List; + +class EditNamesDialog extends PolledDialog implements DialogReceiver { + private static final long serialVersionUID = -3309806087387084117L; + private List listbox = new List(10); + private Button addButton = new Button(Console.message("Add")); + private Button delButton = new Button(Console.message("Delete")); + private Button cancelButton = new Button(Console.message("Done")); + private NameListOwner owner; + private String addTitle; + private static Font font = new Font(Console.message("ButtonFont"), 0, 12); + + EditNamesDialog(NameListOwner owner, String title, String addTitle) { + super(Console.getFrame(), null, title, true); + this.owner = owner; + this.addTitle = addTitle; + this.ready(); + } + + @Override + protected void build() { + int count = this.owner.getNameListCount(); + + for (int i = 0; i < count; i++) { + this.listbox.add(this.owner.getNameListName(i)); + } + + GridBagLayout gbag = new GridBagLayout(); + this.setLayout(gbag); + GridBagConstraints c = new GridBagConstraints(); + c.fill = 1; + c.weightx = 1.0; + c.weighty = 1.0; + c.gridwidth = 2; + c.gridheight = 3; + this.add(gbag, this.listbox, c); + c.weightx = 0.0; + c.weighty = 0.0; + c.gridwidth = 0; + c.gridheight = 1; + c.fill = 2; + this.addButton.setFont(font); + this.delButton.setFont(font); + this.cancelButton.setFont(font); + this.add(gbag, this.addButton, c); + this.add(gbag, this.delButton, c); + c.weighty = 1.0; + c.anchor = 15; + this.add(gbag, this.cancelButton, c); + } + + private void select(boolean state) { + this.delButton.setEnabled(state); + } + + @Override + public void show() { + super.show(); + if (this.listbox.getItemCount() != 0) { + this.listbox.select(0); + this.select(true); + } else { + this.select(false); + } + + this.listbox.requestFocus(); + } + + @Override + public boolean handleEvent(Event event) { + if (event.id == 701) { + this.select(true); + } else if (event.id == 702) { + this.select(false); + } + + return super.handleEvent(event); + } + + @Override + public boolean action(Event event, Object what) { + Object target = event.target; + if (target == this.cancelButton) { + return this.done(false); + } else if (target == this.delButton) { + int index = this.listbox.getSelectedIndex(); + if (index != -1) { + this.listbox.remove(index); + this.owner.removeNameListName(index); + int count = this.listbox.getItemCount(); + if (index < count - 1) { + this.listbox.select(index); + } else if (count > 0) { + this.listbox.select(count - 1); + } else { + this.select(false); + this.listbox.requestFocus(); + } + } + + return true; + } else if (target == this.addButton) { + if (this.owner.mayAddNameListName(this)) { + new AddNameDialog(this, this.addTitle); + } + + return true; + } else { + return false; + } + } + + @Override + public boolean keyDown(Event event, int key) { + return key != 27 && key != 10 ? super.keyDown(event, key) : this.done(false); + } + + @Override + public void dialogDone(Object who, boolean confirmed) { + if (confirmed) { + String name = Console.parseUnicode(((AddNameDialog)who).getName()); + int pos = this.owner.addNameListName(name); + if (pos == -1) { + return; + } + + if (pos == this.listbox.getItemCount()) { + this.listbox.add(name); + } + + this.listbox.makeVisible(pos); + this.listbox.select(pos); + this.select(true); + } + } +} -- cgit v1.2.3