diff options
| author | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
| commit | e1e781bb2135ef78592226f1a3eaba4925702f1f (patch) | |
| tree | 8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/console/PolledDialog.java | |
| download | worlds.jar-main.tar.xz worlds.jar-main.zip | |
Diffstat (limited to 'NET/worlds/console/PolledDialog.java')
| -rw-r--r-- | NET/worlds/console/PolledDialog.java | 402 |
1 files changed, 402 insertions, 0 deletions
diff --git a/NET/worlds/console/PolledDialog.java b/NET/worlds/console/PolledDialog.java new file mode 100644 index 0000000..6fe68bd --- /dev/null +++ b/NET/worlds/console/PolledDialog.java @@ -0,0 +1,402 @@ +/* */ package NET.worlds.console; +/* */ +/* */ import java.awt.Component; +/* */ import java.awt.Container; +/* */ import java.awt.Dialog; +/* */ import java.awt.Dimension; +/* */ import java.awt.Event; +/* */ import java.awt.Frame; +/* */ import java.awt.GridBagConstraints; +/* */ import java.awt.GridBagLayout; +/* */ import java.awt.Point; +/* */ import java.awt.Toolkit; +/* */ import java.io.PrintStream; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public abstract class PolledDialog +/* */ extends Dialog +/* */ implements MainCallback, DialogDisabled +/* */ { +/* */ private static final long serialVersionUID = -2608298148446880055L; +/* */ public static final int CENTER = 0; +/* */ public static final int BOTTOM = 1; +/* */ public static final int RIGHT = 2; +/* */ public static final int LEFT = 3; +/* */ private boolean active; +/* */ private boolean built; +/* */ private boolean restarting; +/* */ private boolean confirmed; +/* */ private boolean killed; +/* */ private boolean disableParent; +/* */ private boolean toBeDisposed; +/* */ private java.awt.Window parent; +/* */ private DialogReceiver receiver; +/* 89 */ private int alignment = 0; +/* 90 */ private Point initialOffset = new Point(0, 0); +/* */ +/* */ +/* */ private Object startupWaiter; +/* */ +/* */ private boolean started; +/* */ +/* */ +/* */ protected PolledDialog(java.awt.Window parent, DialogReceiver receiver, String title, boolean disableParent) +/* */ { +/* 100 */ super(findFrame(parent), title, false); +/* 101 */ this.parent = parent; +/* 102 */ this.receiver = receiver; +/* */ +/* */ +/* */ +/* */ +/* 107 */ if (disableParent) { +/* 108 */ disableParent(); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ protected void disableParent() +/* */ { +/* 116 */ this.disableParent = (this.parent instanceof DialogDisabled); +/* */ +/* 118 */ if (this.disableParent) { +/* 119 */ ((DialogDisabled)this.parent).dialogDisable(true); +/* */ } +/* */ } +/* */ +/* */ protected void ready() { +/* 124 */ this.killed = false; +/* 125 */ if ((this.built) && (!this.active)) +/* 126 */ this.restarting = true; +/* 127 */ Main.register(this); +/* 128 */ setResizable(true); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ protected void readySetGo() +/* */ { +/* 136 */ this.startupWaiter = new Object(); +/* 137 */ this.started = false; +/* 138 */ synchronized (this.startupWaiter) { +/* 139 */ ready(); +/* 140 */ while (!this.started) { +/* */ try { +/* 142 */ this.startupWaiter.wait(); +/* */ } +/* */ catch (InterruptedException localInterruptedException) {} +/* */ } +/* */ } +/* 147 */ this.startupWaiter = null; +/* 148 */ this.started = false; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ protected void setAlignment(int alignment) +/* */ { +/* 158 */ setAlignment(alignment, 0, 0); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ protected void setAlignment(int alignment, int offsetX, int offsetY) +/* */ { +/* 172 */ this.alignment = alignment; +/* 173 */ this.initialOffset.x = offsetX; +/* 174 */ this.initialOffset.y = offsetY; +/* */ } +/* */ +/* */ private static Frame findFrame(Container container) { +/* 178 */ while ((!(container instanceof Frame)) && (container != null)) +/* 179 */ container = container.getParent(); +/* 180 */ return (Frame)container; +/* */ } +/* */ +/* */ protected abstract void build(); +/* */ +/* */ public final synchronized void mainCallback() +/* */ { +/* 187 */ if (!this.killed) { +/* 188 */ if (!this.built) { +/* */ try { +/* 190 */ build(); +/* 191 */ pack(); +/* 192 */ restoreFrame(); +/* 193 */ position(); +/* 194 */ setVisible(true); +/* 195 */ this.built = true; +/* 196 */ this.active = true; +/* */ } catch (Exception e) { +/* 198 */ System.out.println("Caught exception building dialog " + +/* 199 */ toString() + " " + e.getMessage()); +/* */ } +/* 201 */ } else if (this.restarting) { +/* 202 */ restoreFrame(); +/* 203 */ setVisible(true); +/* 204 */ this.restarting = false; +/* 205 */ this.active = true; +/* */ } +/* */ } +/* */ +/* */ +/* 210 */ if ((this.killed) || (!this.active)) { +/* 211 */ if (this.toBeDisposed) +/* */ { +/* */ +/* 214 */ setVisible(false); +/* */ +/* */ +/* 217 */ this.parent.requestFocus(); +/* */ +/* */ +/* 220 */ if (!isDisplayable()) { +/* 221 */ dispose(); +/* */ } +/* 223 */ this.toBeDisposed = false; +/* */ } +/* 225 */ Main.unregister(this); +/* */ +/* */ +/* 228 */ if (this.receiver != null) +/* 229 */ this.receiver.dialogDone(this, this.confirmed); +/* */ } else { +/* 231 */ activeCallback(); +/* */ } +/* */ } +/* */ +/* */ protected void activeCallback() {} +/* */ +/* */ private void restoreFrame() +/* */ { +/* 239 */ int handle = Window.getFrameHandle(); +/* 240 */ if ((handle != 0) && (Window.getWindowState(handle) == 1)) { +/* 241 */ Window.setWindowState(handle, 0); +/* */ } +/* */ } +/* */ +/* */ +/* */ public void setVisible(boolean visible) +/* */ { +/* */ try +/* */ { +/* 250 */ super.setVisible(visible); +/* */ } catch (Exception e) { +/* 252 */ System.out.println("Caught exception in PolledDialog::setVisible: " + +/* 253 */ e.getMessage()); +/* */ } +/* */ +/* 256 */ if ((visible) && (this.startupWaiter != null)) { +/* 257 */ synchronized (this.startupWaiter) { +/* 258 */ this.started = true; +/* 259 */ this.startupWaiter.notify(); +/* */ } +/* */ } +/* */ } +/* */ +/* */ public void closeIt(boolean state) { +/* 265 */ done(state); +/* */ } +/* */ +/* */ protected synchronized boolean done(boolean confirmed) +/* */ { +/* 270 */ if ((!this.killed) && (this.disableParent)) { +/* 271 */ ((DialogDisabled)this.parent).dialogDisable(false); +/* */ } +/* 273 */ this.killed = true; +/* */ +/* */ +/* */ +/* */ +/* 278 */ this.toBeDisposed = true; +/* */ +/* 280 */ if (this.active) +/* */ { +/* 282 */ savePosAndSize(new PolledDialogSaver(this)); +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 291 */ this.active = false; +/* */ } +/* 293 */ this.confirmed = confirmed; +/* 294 */ return true; +/* */ } +/* */ +/* */ public boolean isActive() +/* */ { +/* 299 */ return this.active; +/* */ } +/* */ +/* */ protected void add(GridBagLayout gbag, Component comp, GridBagConstraints c) { +/* 303 */ if ((comp != null) && (c != null)) { +/* 304 */ gbag.setConstraints(comp, c); +/* 305 */ add(comp); +/* */ } +/* */ else { +/* 308 */ System.out.println("Bad parameter passed to PolledDialog::add, how bizarre."); +/* */ } +/* */ } +/* */ +/* */ +/* */ @Deprecated +/* */ public boolean handleEvent(Event event) +/* */ { +/* 316 */ if (event.id == 201) { +/* 317 */ return done(false); +/* */ } +/* */ +/* 320 */ if ((event.id == 401) || (event.id == 501)) +/* 321 */ Console.wake(); +/* 322 */ return super.handleEvent(event); +/* */ } +/* */ +/* */ public void dialogDisable(boolean disable) { +/* 326 */ setVisible(!disable); +/* */ } +/* */ +/* */ public boolean getConfirmed() +/* */ { +/* 331 */ return this.confirmed; +/* */ } +/* */ +/* */ protected void position() { +/* 335 */ Dimension mySize = getSize(); +/* 336 */ initialSize(mySize.width, mySize.height); +/* */ } +/* */ +/* */ +/* */ protected void initialSize(int width, int height) +/* */ { +/* 342 */ if (!PolledDialogSaver.restorePosAndSize(restorePosAndSize(), this)) { +/* 343 */ Point loc = this.parent.getLocation(); +/* 344 */ Dimension size = null; +/* 345 */ if ((this.parent instanceof Frame)) +/* */ { +/* 347 */ int hwnd = Window.getFrameHandle(); +/* 348 */ if (hwnd != 0) { +/* 349 */ size = new Dimension( +/* 350 */ Window.getWindowWidth(hwnd), +/* 351 */ Window.getWindowHeight(hwnd)); +/* */ } +/* */ } +/* 354 */ if (size == null) +/* 355 */ size = this.parent.getSize(); +/* */ int x; +/* */ int x; +/* 358 */ if (this.alignment == 2) { +/* 359 */ x = loc.x + this.initialOffset.x + size.width; } else { int x; +/* 360 */ if (this.alignment == 3) { +/* 361 */ x = loc.x + this.initialOffset.x - width; +/* */ } else +/* 363 */ x = loc.x + this.initialOffset.x + (size.width - width) / 2; } +/* */ int y; +/* */ int y; +/* 366 */ if (this.alignment == 1) { +/* 367 */ y = loc.y + this.initialOffset.y + size.height - height; +/* */ } +/* */ else { +/* 370 */ y = loc.y + this.initialOffset.y + (size.height - height) / 2; +/* */ } +/* 372 */ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); +/* 373 */ if (y + height > screenSize.height) +/* 374 */ y = screenSize.height - height; +/* 375 */ if (y < 0) +/* 376 */ y = 0; +/* 377 */ if (x + width > screenSize.width) +/* 378 */ x = screenSize.width - width; +/* 379 */ if (x < 0) { +/* 380 */ x = 0; +/* */ } +/* 382 */ setBounds(x, y, width, height); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ public void savePosAndSize(Object o) {} +/* */ +/* */ +/* */ +/* */ public Object restorePosAndSize() +/* */ { +/* 394 */ return null; +/* */ } +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\PolledDialog.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |