gumbo.app
Class MainWindow

java.lang.Object
  |
  +--gumbo.util.AbstractDisposable
        |
        +--gumbo.app.MainWindow
All Implemented Interfaces:
Disposable
Direct Known Subclasses:
NetWindow, RootWindow, TestViewWindow

public class MainWindow
extends AbstractDisposable

A proxy for a Swing top-level window (JFrame, JDialog) that provides a standard GUI consisting of a window with a title bar, menubar, tool bar, status bar, and main content area. Typically used as the "main" window for an application but can also be used as a child window of some owner (subwindow).

The default close operation is to dispose the window, which is generally fine for subwindows, such as dialogs and child windows. Use setDefaultCloseOperation() on this object (not the window graphic) to change the operation (such as WindowConstants.EXIT_ON_CLOSE for the root window of an application).

Version:
$Revision: 1.11 $
Author:
Jon Barrilleaux (jonb@jmbaai.com) of JMB and Associates Inc.

Constructor Summary
MainWindow(java.lang.String name)
          Creates an instance.
MainWindow(java.awt.Window window, java.lang.String name)
          Creates an instance.
 
Method Summary
 java.awt.Container getContentPane()
          Gets the window's content pane.
 javax.swing.JMenuBar getMenuBar()
          Gets the menu bar.
 javax.swing.JLabel getStatusBar()
          Gets the status bar.
 java.lang.String getStatusText()
          Gets the text in the window status bar.
 java.lang.String getTitleText()
          Gets the text in the window title bar, without the pre-pended app name.
 javax.swing.JToolBar getToolBar()
          Gets the tool bar.
 java.awt.Window getWindowGraphic()
          Gets the native graphic implementing the window functionality of this main window.
 java.lang.String getWindowName()
          Gets the window name used in the title text.
protected  void implDispose()
          Disposes the window graph, then disposes self.
protected  void initWindowGraphic(java.awt.Window graphic)
          Initializes the native graphic implementing the window functionality of this main window.
 void pack()
          Packs the delegate window content into a tight layout making it ready for display, but does not make the window visible.
 void setDefaultCloseOperation(int operation)
          Sets the default close action of the delegate window.
 void setMainArea(java.awt.Component main)
          Sets the window main area contents.
 void setStatusText(java.lang.String text)
          Sets the window status bar text.
 void setTitleText(java.lang.String text)
          Sets the text in the window title.
 void setVisible(boolean visible)
          Shows the delegate window, after first packing it if not already displayable, and performs any post-realization processing.
 void setWindowName(java.lang.String name)
          Sets the window name used in the title bar and error messages, and updates the title bar accordingly.
static java.lang.String showProblemMessage(java.lang.String name, java.awt.Component parent, java.lang.String msg, java.lang.Throwable th)
          Shows a dialog as a result of a throw, with the dialog style determined by the throwable type.
 java.lang.String showProblemMessage(java.lang.String msg, java.lang.Throwable th)
          Shows a dialog as a result of a throw, with the dialog style determined by the throwable type.
 
Methods inherited from class gumbo.util.AbstractDisposable
dispose, isDisposed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MainWindow

public MainWindow(java.lang.String name)
Creates an instance. Must call initWindowGraphic() before using this object.

Parameters:
name - The window name used in the title bar and error messages. None if null.

MainWindow

public MainWindow(java.awt.Window window,
                  java.lang.String name)
Creates an instance.

Parameters:
window - The window graphic. Never null.
name - The application name used in the title bar and error messages. None if null.
Method Detail

setDefaultCloseOperation

public void setDefaultCloseOperation(int operation)
Sets the default close action of the delegate window. The initial action is to just hide the window. If the action is dispose or exit on close, this object will also be disposed. As such, clients should use this method, not that of the window graphic.

Parameters:
operation - The operation (WindowConstants.???_ON_CLOSE).

pack

public void pack()
Packs the delegate window content into a tight layout making it ready for display, but does not make the window visible.


setVisible

public void setVisible(boolean visible)
Shows the delegate window, after first packing it if not already displayable, and performs any post-realization processing.


initWindowGraphic

protected void initWindowGraphic(java.awt.Window graphic)
Initializes the native graphic implementing the window functionality of this main window. Throws an exception if null or already initialized.

Parameters:
graphic - The window graphic (JFrame or JDialog). Never null.

getWindowGraphic

public java.awt.Window getWindowGraphic()
Gets the native graphic implementing the window functionality of this main window.

Returns:
The window graphic (JFrame or JDialog). Never null.

getContentPane

public java.awt.Container getContentPane()
Gets the window's content pane.

Returns:
The content pane. Never null.

setWindowName

public void setWindowName(java.lang.String name)
Sets the window name used in the title bar and error messages, and updates the title bar accordingly.

Parameters:
name - The window name. None if null.

getWindowName

public java.lang.String getWindowName()
Gets the window name used in the title text. Possibly empty, never null.


setTitleText

public void setTitleText(java.lang.String text)
Sets the text in the window title. If this window's app name is null then the title will be just the text; otherwise, the title format will be ": ".

Parameters:
text - The text. If null, empty string.

getTitleText

public java.lang.String getTitleText()
Gets the text in the window title bar, without the pre-pended app name.

Returns:
The title bar text. Never null. Empty if the delegate window is a JWindow (no title bar).

setStatusText

public void setStatusText(java.lang.String text)
Sets the window status bar text.


getStatusText

public java.lang.String getStatusText()
Gets the text in the window status bar.

Returns:
The title bar text. Never null. Empty if the delegate window is a JWindow (no status bar).

setMainArea

public void setMainArea(java.awt.Component main)
Sets the window main area contents.


getMenuBar

public javax.swing.JMenuBar getMenuBar()
Gets the menu bar. Only null if the window is a JWindow, which does not support a menu bar.


getToolBar

public javax.swing.JToolBar getToolBar()
Gets the tool bar. Never null.


getStatusBar

public javax.swing.JLabel getStatusBar()
Gets the status bar. Never null.


showProblemMessage

public java.lang.String showProblemMessage(java.lang.String msg,
                                           java.lang.Throwable th)
Shows a dialog as a result of a throw, with the dialog style determined by the throwable type. The dialog will contain an optional client message, the throwable message and stack trace, and options for the user to continue or exit.

Parameters:
msg - The client error message. A newline will be automatically appended. Null if none.
th - The error object. Null if none.
Returns:
The entire message displayed in the dialog (unless the user chooses to exit).

implDispose

protected void implDispose()
Disposes the window graph, then disposes self.

Specified by:
implDispose in class AbstractDisposable

showProblemMessage

public static java.lang.String showProblemMessage(java.lang.String name,
                                                  java.awt.Component parent,
                                                  java.lang.String msg,
                                                  java.lang.Throwable th)
Shows a dialog as a result of a throw, with the dialog style determined by the throwable type. The dialog will contain an optional client message, the throwable message and stack trace, and options for the user to continue or exit. The dialog message is also printed to System.err.

Parameters:
name - Application name that will appear in the title bar. Null if none.
parent - Dialog parent component. Null if none.
msg - The client error message. A newline will be automatically appended. Null if none.
th - The error object. Null if none.
Returns:
The entire message displayed in the dialog (unless the user chooses to exit).