ch.aplu.util
Class ModelessOptionPane

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

public class ModelessOptionPane
extends java.lang.Object

Modeless message dialog using Swing JOptionPane. Useful to show text and/or images while the application continues to run.

When the close button of the MessagePane window title bar is hit, System.exit(0) is executed that terminates the JVM, but you can modifiy this behavior by registering your own implementation of the ExitListener interface or by using the key ModelessOptionPaneClosingMode in aplu_util.properties. For more details consult aplu_util.properties file found in the distribution.

All Swing methods are invoked in the EDT.


Field Summary
static java.net.URL ICON_EXCLAMATION
          URL to display the exclamation icon.
 
Constructor Summary
ModelessOptionPane(java.awt.Frame owner, int ulx, int uly, java.awt.Dimension size, boolean isDecorated)
          Same as general constructor, but with no text, no icon and no button, given dimension and selectable decoration.
ModelessOptionPane(int ulx, int uly, java.lang.String text)
          Same as general constructor, but with no icon and no button.
ModelessOptionPane(int ulx, int uly, java.lang.String text, java.net.URL iconUrl)
          Same as ModelessOptionPane(ulx, uly, text, iconUrl, buttonText), but with no button.
ModelessOptionPane(int ulx, int uly, java.lang.String text, java.net.URL iconUrl, java.lang.String buttonText)
          General constructor that show a modeless message dialog at given position (upper left corner) containing given text and given icon image (gif or jpg). iconUrl is the URL for the icon resource.
ModelessOptionPane(java.lang.String text)
          Same as general constructor, but with no icon and no button and dialog centered in middle of screen.
ModelessOptionPane(java.lang.String text, java.net.URL iconUrl)
          Same as general constructor, but with no button and dialog centered in middle of the screen.
ModelessOptionPane(java.lang.String text, java.net.URL iconUrl, java.lang.String buttonText)
          Same as general constructor, but dialog centered in middle of the screen.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener listener)
          Register a ActionListener to get a notification when the button is hit.
 void addCleanable(Cleanable cl)
          Register a class that implements Cleanable.clean() that will be called when the title bar's close button is hit.
 void addExitListener(ExitListener listener)
          Register a class that implements ExitListener.notifyExit() that will be called when the title bar's close button is hit.
 void dispose()
          Dispose the dialog.
 javax.swing.JDialog getDialog()
          Return the dialog.
 boolean isDisposed()
          Return true, if in aplu_util.properties the ModelessOptionPaneClosingMode key is set to DisposeOnClose and the close button is clicked or after dispose() is called.
 boolean isVisible()
          Return true, if dialog is visible; otherwise false.
 void requestFocus()
          Request the focus.
 void setButtonEnabled(boolean enable)
          Enable/disable the button (if any).
 void setText(java.lang.String text)
          Display the given text.
 void setText(java.lang.String text, boolean adjust)
          Same as setText() but select whether to adjust size of dialog.
 void setTitle(java.lang.String title)
          Same as showTitle().
 void setVisible(boolean visible)
          Show/hide the dialog.
 void showTitle(java.lang.String title)
          Show the given title in the title bar.
 void toFront()
          Bring the dialog to the front.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ICON_EXCLAMATION

public static final java.net.URL ICON_EXCLAMATION
URL to display the exclamation icon.

Constructor Detail

ModelessOptionPane

public ModelessOptionPane(int ulx,
                          int uly,
                          java.lang.String text,
                          java.net.URL iconUrl,
                          java.lang.String buttonText)
General constructor that show a modeless message dialog at given position (upper left corner) containing given text and given icon image (gif or jpg). iconUrl is the URL for the icon resource. The iconUrl is normally retrieved by calling

ClassLoader loader = getClass().getClassLoader();
URL iconUrl = loader.getResource(iconResource);


where iconResource is a '/'-separated path name that identifies the resource. If the resource is not found or iconUrl is set to ICON_EXCLAMATION, the exclamation icon is displayed.

If buttonText is not null and not empty a single button is displayed with the given text. To get a click event, register an ActionListener.
Example:
   mop.addActionListener(
   new ActionListener()
   {
   public void actionPerformed(ActionEvent evt)
   {
   // Code to execute when the button is hit
   }
   });

All methods run in the Event Dispatch Thread (EDT).


ModelessOptionPane

public ModelessOptionPane(int ulx,
                          int uly,
                          java.lang.String text,
                          java.net.URL iconUrl)
Same as ModelessOptionPane(ulx, uly, text, iconUrl, buttonText), but with no button.


ModelessOptionPane

public ModelessOptionPane(int ulx,
                          int uly,
                          java.lang.String text)
Same as general constructor, but with no icon and no button.


ModelessOptionPane

public ModelessOptionPane(java.awt.Frame owner,
                          int ulx,
                          int uly,
                          java.awt.Dimension size,
                          boolean isDecorated)
Same as general constructor, but with no text, no icon and no button, given dimension and selectable decoration. Useful for undecorated status bars. If an owner is given, the owner window is brought to front when the status bar is clicked and vice versa. (The z-order position of the pane is the same as the owner.)


ModelessOptionPane

public ModelessOptionPane(java.lang.String text,
                          java.net.URL iconUrl)
Same as general constructor, but with no button and dialog centered in middle of the screen.


ModelessOptionPane

public ModelessOptionPane(java.lang.String text,
                          java.net.URL iconUrl,
                          java.lang.String buttonText)
Same as general constructor, but dialog centered in middle of the screen.


ModelessOptionPane

public ModelessOptionPane(java.lang.String text)
Same as general constructor, but with no icon and no button and dialog centered in middle of screen.

Method Detail

addActionListener

public void addActionListener(java.awt.event.ActionListener listener)
Register a ActionListener to get a notification when the button is hit.


setText

public void setText(java.lang.String text)
Display the given text. Adjust size of dialog to length of text, unless the size is given in constructor.


setText

public void setText(java.lang.String text,
                    boolean adjust)
Same as setText() but select whether to adjust size of dialog.


showTitle

public void showTitle(java.lang.String title)
Show the given title in the title bar.


setTitle

public void setTitle(java.lang.String title)
Same as showTitle().


setButtonEnabled

public void setButtonEnabled(boolean enable)
Enable/disable the button (if any).


addCleanable

public void addCleanable(Cleanable cl)
Register a class that implements Cleanable.clean() that will be called when the title bar's close button is hit. (Deprecated, use addExitListener())


addExitListener

public void addExitListener(ExitListener listener)
Register a class that implements ExitListener.notifyExit() that will be called when the title bar's close button is hit. Replacement of addCleanable().


dispose

public void dispose()
Dispose the dialog.


getDialog

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


setVisible

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


isVisible

public boolean isVisible()
Return true, if dialog is visible; otherwise false.


toFront

public void toFront()
Bring the dialog to the front.


requestFocus

public void requestFocus()
Request the focus.


isDisposed

public boolean isDisposed()
Return true, if in aplu_util.properties the ModelessOptionPaneClosingMode key is set to DisposeOnClose and the close button is clicked or after dispose() is called.