summaryrefslogtreecommitdiff
path: root/NET/worlds/console/MoreFriendsDialog.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/MoreFriendsDialog.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/console/MoreFriendsDialog.java')
-rw-r--r--NET/worlds/console/MoreFriendsDialog.java159
1 files changed, 159 insertions, 0 deletions
diff --git a/NET/worlds/console/MoreFriendsDialog.java b/NET/worlds/console/MoreFriendsDialog.java
new file mode 100644
index 0000000..29c7f01
--- /dev/null
+++ b/NET/worlds/console/MoreFriendsDialog.java
@@ -0,0 +1,159 @@
+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;
+import java.awt.Menu;
+import java.awt.MenuItem;
+import java.util.Vector;
+
+class MoreFriendsDialog extends PolledDialog {
+ private static final long serialVersionUID = -2543183536371825585L;
+ private List listbox = new List(10);
+ private Button cancelButton = new Button(Console.message("Close"));
+ private FriendsListPart friends;
+ private Menu menu;
+ private Vector<Button> buttons = new Vector<Button>();
+ private static Font font = new Font(Console.message("MenuFont"), 0, 12);
+ private static Font bfont = new Font(Console.message("ButtonFont"), 0, 12);
+ private Object listMutex = new Object();
+
+ MoreFriendsDialog(FriendsListPart friends, Menu menu, Vector<String> online) {
+ super(Console.getFrame(), friends, Console.message("Friends-Online"), false);
+ this.setAlignment(1);
+ this.friends = friends;
+ this.menu = menu;
+
+ for (int i = 0; i < online.size(); i++) {
+ this.listbox.add(online.elementAt(i));
+ }
+
+ this.ready();
+ }
+
+ @Override
+ protected void build() {
+ int buttonCount = this.menu.getItemCount();
+ 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 = buttonCount + 1;
+ 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;
+
+ for (int i = 0; i < buttonCount; i++) {
+ String item = this.menu.getItem(i).getLabel();
+ Button button = new Button(item);
+ button.setFont(bfont);
+ this.buttons.addElement(button);
+ this.add(gbag, button, c);
+ }
+
+ c.weighty = 1.0;
+ c.anchor = 15;
+ this.cancelButton.setFont(bfont);
+ this.add(gbag, this.cancelButton, c);
+ }
+
+ void addName(String name) {
+ synchronized (this.listMutex) {
+ this.listbox.add(name);
+ if (this.listbox.getItemCount() == 1) {
+ this.listbox.select(0);
+ this.select(true);
+ }
+ }
+ }
+
+ void removeName(int index) {
+ synchronized (this.listMutex) {
+ int selIndex = this.listbox.getSelectedIndex();
+ this.listbox.remove(index);
+ if (selIndex == 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();
+ }
+ }
+ }
+ }
+
+ private void select(boolean state) {
+ for (int i = 0; i < this.buttons.size(); i++) {
+ Button button = this.buttons.elementAt(i);
+ button.setEnabled(state);
+ }
+ }
+
+ @Override
+ public void show() {
+ super.show();
+ synchronized (this.listMutex) {
+ 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 {
+ int index = this.buttons.indexOf(target);
+ if (index != -1) {
+ MenuItem function = this.menu.getItem(index);
+ String selectedFriend;
+ synchronized (this.listMutex) {
+ selectedFriend = this.listbox.getSelectedItem();
+ }
+
+ if (selectedFriend != null) {
+ this.friends.moreFriendsAction(selectedFriend, function);
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+
+ @Override
+ public boolean keyDown(Event event, int key) {
+ return key != 27 && key != 10 ? super.keyDown(event, key) : this.done(false);
+ }
+}