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 an modeless application window for testing or demonstration purposes.

Only one QuitPane may be used.
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.

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 addCleanable(Cleanable cl)
          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()
          Dispose the dialog
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() will not be called anymore).
static void halt(Cleanable cl)
          Same as halt(), but registers a cleanable, so its clean() method will be called when the title bar's close button is clicked.
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 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

addCleanable

public static void addCleanable(Cleanable cl)
Create a QuitPane dialog, if it's not yet done. Register a class with a method clean() that will be called when the title bar's close button is hit.


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()) {}


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() will not be called anymore). Useful if you need to proceed in any case.


halt

public static void halt(Cleanable cl)
Same as halt(), but registers a cleanable, so its clean() method will be called when the title bar's close button is clicked. The method remains blocked until clean() returns.


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 reshown by calling init().


dispose

public static void dispose()
Dispose the dialog


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.