ch.aplu.util
Class QuitPane

java.lang.Object
  extended by ch.aplu.util.QuitPane

public class QuitPane
extends java.lang.Object

Modeless dialog containing a "Quit" button only. Mainly used to hold the thread in a endless loop. in simple realtime applications or to simulate a modeless application window for testing or demonstration purposes.

Only one QuitPane may be used.
If no exist listener is registered, clicking the title bar's close button calls System.exit(0), otherwise its notifyExit() method is called.

All Swing methods are invoked in the EDT.


Constructor Summary
QuitPane()
          Same as QuitPane(true).
QuitPane(boolean visible)
          Construct a QuitPane with given visibility.
 
Method Summary
static void addExitListener(ExitListener listener)
          Create a QuitPane dialog, if it's not yet done.
 void addQuitNotifier(Cleanable notifier)
          Register a Cleanble whose clean method will be called when the Quit or Close button is hit.
static void close()
          Hide the dialog.
static void dispose()
          Hide the dialog and release the resources.
static javax.swing.JDialog getDialog()
          Return the dialog.
static void halt()
          Create a QuitPane dialog, if it's not yet done.
static void halt(boolean exit)
          Same as halt(), but if exit = false clicking the title bar's close button acts the same as clicking the Quit button (System.exit(0) will not be called anymore).
static void init()
          Same as init(true).
static void init(boolean visible)
          Create a QuitPane dialog, if it's not yet done with the given visibility.
static boolean quit()
          Create a QuitPane dialog, if it's not yet done.
static boolean quit(boolean exit)
          Same as quit(), but if exit = false clicking the title bar's close button acts the same as clicking the Quit button (System.exit(0) will not be called anymore).
static void setVisible(boolean visible)
          Show/hide the dialog.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QuitPane

public QuitPane()
Same as QuitPane(true).


QuitPane

public QuitPane(boolean visible)
Construct a QuitPane with given visibility. Runs in Event Dispatch Thread. (Only one instance is allowed)

Method Detail

addExitListener

public static void addExitListener(ExitListener listener)
Create a QuitPane dialog, if it's not yet done. Register a class with a method notifyExit() that is called when the title bar's close button is hit.


quit

public static boolean quit(boolean exit)
Same as quit(), but if exit = false clicking the title bar's close button acts the same as clicking the Quit button (System.exit(0) will not be called anymore). Useful if you need to proceed in any case. To remove the dialog, call QuitPane.dispose().


quit

public static boolean quit()
Create a QuitPane dialog, if it's not yet done. Return true, if the Quit button has been hit previously.
Thread.currentThread().sleep(1) is called to improve time response when quit() is called in a tight loop like
while (!QuitPane.quit()) {}

If the title bar's close button is hit, System.exit(0) is called.


halt

public static void halt()
Create a QuitPane dialog, if it's not yet done. Block the current thread until the Quit button is hit. If no cleanable is registered, clicking the title bar's close button will call System.exit(0), if a cleanable is registered, its clean() method will be called.

After halt() returns, the internal state is resetted, so that quit() returns false.


halt

public static void halt(boolean exit)
Same as halt(), but if exit = false clicking the title bar's close button acts the same as clicking the Quit button (System.exit(0) will not be called anymore). Useful if you need to proceed in any case. To remove the dialog, call QuitPane.dispose().


init

public static void init(boolean visible)
Create a QuitPane dialog, if it's not yet done with the given visibility. Reset the internal state, so that quit() returns false.


init

public static void init()
Same as init(true).


close

public static void close()
Hide the dialog. May be shown again by calling init().


dispose

public static void dispose()
Hide the dialog and release the resources.


getDialog

public static javax.swing.JDialog getDialog()
Return the dialog.


setVisible

public static void setVisible(boolean visible)
Show/hide the dialog.

Parameters:
visible - if true, the dialog is shown, otherwise hidden.

addQuitNotifier

public void addQuitNotifier(Cleanable notifier)
Register a Cleanble whose clean method will be called when the Quit or Close button is hit.