summaryrefslogtreecommitdiff
path: root/NET/worlds/console/YesNoCancelDialog.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/YesNoCancelDialog.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/console/YesNoCancelDialog.java')
-rw-r--r--NET/worlds/console/YesNoCancelDialog.java89
1 files changed, 89 insertions, 0 deletions
diff --git a/NET/worlds/console/YesNoCancelDialog.java b/NET/worlds/console/YesNoCancelDialog.java
new file mode 100644
index 0000000..a057214
--- /dev/null
+++ b/NET/worlds/console/YesNoCancelDialog.java
@@ -0,0 +1,89 @@
+package NET.worlds.console;
+
+import java.awt.Button;
+import java.awt.Event;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+
+public class YesNoCancelDialog extends PolledDialog {
+ private static final long serialVersionUID = 4497394464783317237L;
+ private Button yesButton = new Button(Console.message("Yes"));
+ private Button noButton = new Button(Console.message("No"));
+ private Button cancelButton = new Button(Console.message("Cancel"));
+ private GridBagLayout gbag = new GridBagLayout();
+ private String prompt;
+ private int choice = -2;
+ public static final int UNDECIDED = -2;
+ public static final int CANCEL = -1;
+ public static final int NO = 0;
+ public static final int YES = 1;
+
+ public YesNoCancelDialog(java.awt.Window parent, DialogReceiver receiver, String title, String prompt) {
+ super(parent, receiver, title, true);
+ this.prompt = prompt;
+ this.setLayout(this.gbag);
+ this.ready();
+ }
+
+ public int getChoice() {
+ return this.choice;
+ }
+
+ @Override
+ protected void build() {
+ GridBagConstraints c = new GridBagConstraints();
+ c.weightx = 1.0;
+ c.weighty = 1.0;
+ c.gridwidth = 0;
+ this.add(this.gbag, new MultiLineLabel(this.prompt, 5, 5), c);
+ c.gridwidth = 3;
+ c.weightx = 1.0;
+ c.weighty = 0.0;
+ this.add(this.gbag, this.yesButton, c);
+ this.add(this.gbag, this.noButton, c);
+ this.add(this.gbag, this.cancelButton, c);
+ }
+
+ @Override
+ public void show() {
+ super.show();
+ this.yesButton.requestFocus();
+ }
+
+ private boolean yes() {
+ this.choice = 1;
+ return this.done(true);
+ }
+
+ private boolean no() {
+ this.choice = 0;
+ return this.done(false);
+ }
+
+ private boolean cancel() {
+ this.choice = -1;
+ return this.done(false);
+ }
+
+ @Override
+ public boolean handleEvent(Event event) {
+ return event.id == 201 ? this.cancel() : super.handleEvent(event);
+ }
+
+ @Override
+ public boolean action(Event event, Object what) {
+ Object target = event.target;
+ if (target == this.yesButton) {
+ return this.yes();
+ } else if (target == this.noButton) {
+ return this.no();
+ } else {
+ return target == this.cancelButton ? this.cancel() : false;
+ }
+ }
+
+ @Override
+ public boolean keyDown(Event event, int key) {
+ return key == 27 ? this.cancel() : super.keyDown(event, key);
+ }
+}