summaryrefslogtreecommitdiff
path: root/NET/worlds/console/UpdateableDialog.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/UpdateableDialog.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/console/UpdateableDialog.java')
-rw-r--r--NET/worlds/console/UpdateableDialog.java170
1 files changed, 170 insertions, 0 deletions
diff --git a/NET/worlds/console/UpdateableDialog.java b/NET/worlds/console/UpdateableDialog.java
new file mode 100644
index 0000000..9ba965e
--- /dev/null
+++ b/NET/worlds/console/UpdateableDialog.java
@@ -0,0 +1,170 @@
+package NET.worlds.console;
+
+import java.awt.Button;
+import java.awt.Event;
+import java.awt.Font;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+
+public class UpdateableDialog extends PolledDialog {
+ private static final long serialVersionUID = 8859312510212567551L;
+ protected Button okButton = new Button(Console.message("OK"));
+ protected Button cancelButton = new Button(Console.message("Cancel"));
+ protected GridBagLayout gbag = new GridBagLayout();
+ private String prompt;
+ private MultiLineLabel promptLabel;
+ private static Font font = new Font(Console.message("MenuFont"), 0, 12);
+ private static Font bfont = new Font(Console.message("ButtonFont"), 0, 12);
+ protected int cancelKey = 27;
+ protected int confirmKey = 10;
+
+ protected UpdateableDialog(java.awt.Window parent, String title) {
+ this(parent, (DialogReceiver)parent, title);
+ }
+
+ protected UpdateableDialog(java.awt.Window parent, String title, String cancel, String ok) {
+ this(parent, (DialogReceiver)parent, title, cancel, ok);
+ }
+
+ protected UpdateableDialog(java.awt.Window parent, DialogReceiver target, String title) {
+ this(parent, target, title, true);
+ }
+
+ protected UpdateableDialog(java.awt.Window parent, DialogReceiver target, String title, boolean modal) {
+ super(parent, target, title, modal);
+ this.setLayout(this.gbag);
+ }
+
+ protected UpdateableDialog(java.awt.Window parent, DialogReceiver target, String title, String cancel, String ok) {
+ this(parent, target, title, cancel, ok, true);
+ }
+
+ protected UpdateableDialog(java.awt.Window parent, DialogReceiver target, String title, String cancel, String ok, boolean modal) {
+ this(parent, target, title, modal);
+ if (ok != null) {
+ this.okButton.setLabel(ok);
+ } else {
+ this.okButton = null;
+ }
+
+ if (cancel != null) {
+ this.cancelButton.setLabel(cancel);
+ } else {
+ this.cancelButton = null;
+ }
+ }
+
+ public UpdateableDialog(java.awt.Window parent, DialogReceiver target, String title, String cancel, String ok, String prompt) {
+ this(parent, target, title, cancel, ok, prompt, true);
+ }
+
+ public UpdateableDialog(java.awt.Window parent, DialogReceiver target, String title, String cancel, String ok, String prompt, boolean modal) {
+ this(parent, target, title, cancel, ok, modal);
+ this.setFont(font);
+ this.prompt = prompt;
+ this.ready();
+ }
+
+ public UpdateableDialog(java.awt.Window parent, DialogReceiver target, String title, String cancel, String ok, String prompt, boolean modal, int alignment) {
+ this(parent, target, title, cancel, ok, modal);
+ this.prompt = prompt;
+ this.setAlignment(alignment);
+ this.ready();
+ }
+
+ @Override
+ protected void build() {
+ GridBagConstraints c = new GridBagConstraints();
+ if (this.prompt != null) {
+ c.weightx = 1.0;
+ c.weighty = 1.0;
+ c.gridwidth = 0;
+ this.promptLabel = new MultiLineLabel(this.prompt, 5, 5);
+ this.promptLabel.setFont(font);
+ this.add(this.gbag, this.promptLabel, c);
+ }
+
+ int count = 0;
+ if (this.okButton != null) {
+ count++;
+ }
+
+ if (this.cancelButton != null) {
+ count++;
+ }
+
+ c.gridwidth = count;
+ c.weightx = 1.0;
+ c.weighty = 0.0;
+ if (this.okButton != null) {
+ this.okButton.setFont(bfont);
+ this.add(this.gbag, this.okButton, c);
+ }
+
+ if (this.cancelButton != null) {
+ this.cancelButton.setFont(bfont);
+ this.add(this.gbag, this.cancelButton, c);
+ }
+ }
+
+ @Override
+ public boolean action(Event event, Object what) {
+ Object target = event.target;
+ if (target == this.okButton && this.setValue()) {
+ return this.done(true);
+ } else {
+ return target == this.cancelButton ? this.done(false) : false;
+ }
+ }
+
+ protected boolean setValue() {
+ return true;
+ }
+
+ public void setCancelKey(int key) {
+ this.cancelKey = key;
+ }
+
+ public void setConfirmKey(int key) {
+ this.confirmKey = key;
+ }
+
+ @Override
+ public boolean keyDown(Event event, int key) {
+ if (key == this.cancelKey) {
+ return this.done(false);
+ } else {
+ if (key == this.confirmKey) {
+ if (this.okButton == null) {
+ return this.done(false);
+ }
+
+ if (this.setValue()) {
+ return this.done(true);
+ }
+ }
+
+ return super.keyDown(event, key);
+ }
+ }
+
+ public void setPrompt(String text) {
+ GridBagConstraints c = new GridBagConstraints();
+ this.prompt = text;
+ if (this.promptLabel != null) {
+ this.gbag.removeLayoutComponent(this.promptLabel);
+ }
+
+ c.weightx = 1.0;
+ c.weighty = 1.0;
+ c.gridwidth = 0;
+ this.promptLabel = new MultiLineLabel(this.prompt, 5, 5);
+ this.add(this.gbag, this.promptLabel, c);
+ this.show();
+ }
+
+ @Override
+ public void closeIt(boolean state) {
+ this.done(state);
+ }
+}