summaryrefslogtreecommitdiff
path: root/NET/worlds/console/AddNameDialog.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/AddNameDialog.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/console/AddNameDialog.java')
-rw-r--r--NET/worlds/console/AddNameDialog.java85
1 files changed, 85 insertions, 0 deletions
diff --git a/NET/worlds/console/AddNameDialog.java b/NET/worlds/console/AddNameDialog.java
new file mode 100644
index 0000000..79615e1
--- /dev/null
+++ b/NET/worlds/console/AddNameDialog.java
@@ -0,0 +1,85 @@
+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.Label;
+import java.awt.Panel;
+import java.awt.TextField;
+
+class AddNameDialog extends PolledDialog {
+ private static final long serialVersionUID = -6679739808485406091L;
+ private TextField nameField;
+ private Button okButton = new Button(Console.message("OK"));
+ private Button cancelButton = new Button(Console.message("Cancel"));
+ private String newName;
+ private static Font font = new Font(Console.message("ButtonFont"), 0, 12);
+
+ AddNameDialog(EditNamesDialog parent, String title) {
+ super(parent, parent, title, true);
+ this.ready();
+ }
+
+ @Override
+ protected void build() {
+ this.nameField = new TextField("", 40);
+ this.nameField.setFont(font);
+ GridBagLayout gbag = new GridBagLayout();
+ this.setLayout(gbag);
+ GridBagConstraints c = new GridBagConstraints();
+ c.fill = 0;
+ c.weightx = 1.0;
+ c.weighty = 1.0;
+ c.gridwidth = 2;
+ c.gridheight = 1;
+ this.add(gbag, new Label(Console.message("Name")), c);
+ c.gridwidth = 0;
+ c.fill = 2;
+ this.add(gbag, this.nameField, c);
+ Panel buttons = new Panel();
+ this.okButton.setFont(font);
+ this.cancelButton.setFont(font);
+ buttons.add(this.okButton);
+ buttons.add(this.cancelButton);
+ c.gridwidth = 0;
+ c.fill = 0;
+ this.add(gbag, buttons, c);
+ }
+
+ @Override
+ public boolean action(Event event, Object what) {
+ Object target = event.target;
+ if (target == this.okButton && this.mayConfirm()) {
+ return this.done(true);
+ } else {
+ return target == this.cancelButton ? this.done(false) : false;
+ }
+ }
+
+ @Override
+ public String getName() {
+ return this.newName;
+ }
+
+ private boolean mayConfirm() {
+ return FriendsListPart.isValidUserName(this.newName = this.nameField.getText().trim());
+ }
+
+ @Override
+ public boolean keyDown(Event event, int key) {
+ if (key == 27) {
+ return this.done(false);
+ } else {
+ return key == 10 && this.mayConfirm() ? this.done(true) : super.keyDown(event, key);
+ }
+ }
+
+ @Override
+ public void show() {
+ super.show();
+ this.nameField.requestFocus();
+ this.nameField.selectAll();
+ }
+}