diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/BookmarkListDialog.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/console/BookmarkListDialog.java')
| -rw-r--r-- | NET/worlds/console/BookmarkListDialog.java | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/NET/worlds/console/BookmarkListDialog.java b/NET/worlds/console/BookmarkListDialog.java new file mode 100644 index 0000000..e8586d5 --- /dev/null +++ b/NET/worlds/console/BookmarkListDialog.java @@ -0,0 +1,182 @@ +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 BookmarkListDialog extends PolledDialog implements DialogReceiver { + private static final long serialVersionUID = 2134767291802432777L; + private List listbox = new List(10); + private Button editButton = new Button(Console.message("Edit")); + private Button addButton = new Button(Console.message("Add")); + private Button copyButton = new Button(Console.message("Copy")); + private Button delButton = new Button(Console.message("Delete")); + private Button okButton = new Button(Console.message("Go-To")); + private Button cancelButton = new Button(Console.message("Done")); + private WorldsMarkPart bookmarks; + private static Font font = new Font(Console.message("MenuFont"), 0, 12); + private static Font bfont = new Font(Console.message("ButtonFont"), 0, 12); + + BookmarkListDialog(WorldsMarkPart bookmarks) { + super(Console.getFrame(), null, Console.message("Edit-WorldsMarkL"), true); + this.bookmarks = bookmarks; + this.ready(); + } + + @Override + protected void build() { + int count = WorldsMarkPart.getBookmarkCount(); + + for (int i = 0; i < count; i++) { + this.listbox.add(WorldsMarkPart.getBookmarkName(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 = 6; + this.listbox.setFont(font); + this.add(gbag, this.listbox, c); + c.weightx = 0.0; + c.weighty = 0.0; + c.gridwidth = 0; + c.gridheight = 1; + c.fill = 2; + this.editButton.setFont(bfont); + this.addButton.setFont(bfont); + this.delButton.setFont(bfont); + this.okButton.setFont(bfont); + this.cancelButton.setFont(bfont); + this.add(gbag, this.editButton, c); + this.add(gbag, this.addButton, c); + this.add(gbag, this.copyButton, c); + this.add(gbag, this.delButton, c); + c.weighty = 1.0; + c.anchor = 15; + this.add(gbag, this.okButton, c); + c.weighty = 0.0; + this.add(gbag, this.cancelButton, c); + } + + private void select(boolean state) { + this.editButton.setEnabled(state); + this.delButton.setEnabled(state); + this.copyButton.setEnabled(state); + this.okButton.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.okButton || target == this.listbox) { + WorldsMarkPart.gotoBookmark(this.listbox.getSelectedIndex()); + return this.done(true); + } else 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.bookmarks.removeBookmark(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.copyButton) { + int index = this.listbox.getSelectedIndex(); + if (index != -1) { + this.add(WorldsMarkPart.getBookmarkName(index), WorldsMarkPart.getBookmarkTarget(index)); + } + + return true; + } else if (target == this.addButton) { + new BookmarkAddDialog(this, this); + return true; + } else if (target == this.editButton) { + int index = this.listbox.getSelectedIndex(); + new BookmarkEditDialog(this, this, WorldsMarkPart.getBookmarkName(index), WorldsMarkPart.getBookmarkTarget(index), index); + return true; + } else { + return false; + } + } + + @Override + public boolean keyDown(Event event, int key) { + if (key == 27) { + return this.done(false); + } else if (key == 10) { + WorldsMarkPart.gotoBookmark(this.listbox.getSelectedIndex()); + return this.done(true); + } else { + return super.keyDown(event, key); + } + } + + private void add(String name, String target) { + this.bookmarks.addBookmark(name, target); + this.listbox.add(name); + this.listbox.makeVisible(this.listbox.getItemCount() - 1); + this.listbox.select(this.listbox.getItemCount() - 1); + this.select(true); + } + + @Override + public void dialogDone(Object who, boolean confirmed) { + if (confirmed) { + if (who instanceof BookmarkAddDialog) { + BookmarkAddDialog adder = (BookmarkAddDialog)who; + BookmarkEditDialog editor = adder.getEditor(); + this.add(editor.getName(), editor.getTarget()); + } else if (who instanceof BookmarkEditDialog) { + BookmarkEditDialog edit = (BookmarkEditDialog)who; + int index = edit.getIndex(); + String name = edit.getName(); + String target = edit.getTarget(); + this.bookmarks.changeBookmark(index, name, target); + this.listbox.replaceItem(name, index); + this.listbox.makeVisible(index); + this.listbox.select(index); + } + } + } +} |