gov.sns.application
Class Application

java.lang.Object
  |
  +--gov.sns.application.Application
All Implemented Interfaces:
XalDocumentListener
Direct Known Subclasses:
AcceleratorApplication

public class Application
extends java.lang.Object
implements XalDocumentListener

The Application class handles defines the core of an application. It is often the first handler of application wide events and typically forwards those events to the custom application adaptor for further processing. Every application has exactly one instance of this class. The static method getApp() provides access to that instance. Every application has one custom application adaptor. The adaptor acts as a delegate for handling events specific to the custom application. The Application, however, handles events common to all multi-document applications.


Field Summary
static int NO_OPTION
           
static int YES_OPTION
           
 
Constructor Summary
Application(ApplicationAdaptor adaptor)
          Application constructor.
Application(ApplicationAdaptor adaptor, java.net.URL[] urls)
          Application constructor.
 
Method Summary
 void addApplicationListener(ApplicationListener listener)
          Add the listener as a listener of Application events.
protected  void cascadeWindowsAbout(XalDocument targetDocument)
          Handle the "Cascade Windows" action by cascading all document windows about the target document.
protected  void closeAllDocuments()
          Handle the "Close All" action by closing all open documents and opening a new empty document.
protected  void closeDocument(XalDocument document)
          Handle the "Close" action by closing the specified document.
static void displayApplicationError(java.lang.String title, java.lang.String prefix, java.lang.Exception exception)
          Display an error dialog box with information about the exception.
static int displayConfirmDialog(java.lang.String title, java.lang.String message)
          Display a confirmation dialog with a title and message
static void displayError(java.lang.Exception exception)
          Display an error dialog box with information about the exception.
static void displayError(java.lang.String title, java.lang.String message)
          Display an error dialog box.
static void displayError(java.lang.String title, java.lang.String prefix, java.lang.Exception exception)
          Display an error dialog box with information about the exception.
static void displayWarning(java.lang.Exception exception)
          Display a warning dialog box with information about the exception.
static void displayWarning(java.lang.String title, java.lang.String message)
          Display a warning dialog box.
static void displayWarning(java.lang.String title, java.lang.String prefix, java.lang.Exception exception)
          Display a warning dialog box with information about the exception.
 void documentHasClosed(XalDocument document)
          Implement XalDocumentListener.
 void documentWillClose(XalDocument document)
          Implement XalDocumentListener.
static java.awt.Window getActiveWindow()
          Get the active window which is in focus for this application.
static ApplicationAdaptor getAdaptor()
          Convenience method for getting the custom application adaptor.
static Application getApp()
          Get the application instance.
 ApplicationAdaptor getApplicationAdaptor()
          Get the custom application adaptor.
 Commander getCommander()
          Get the application commander that manages commands for the entire application.
 java.util.List getDocuments()
          Get the list of all open documents.
 javax.swing.JFileChooser getOpenFileChooser()
          Get the file chooser with which the user interacts when opening a document.
 javax.swing.JFileChooser getSaveFileChooser()
          Get the file chooser with which the user interacts when saving a document.
 void hasChangesChanged(XalDocument document, boolean newHasChangesStatus)
          Implement XalDocumentListener.
protected  void hideAllWindows()
          Handle the "Hide All" action by hiding all main windows corresponding to the open documents.
static void launch(ApplicationAdaptor adaptor)
          Handle the launching of the application by creating the application instance and performing application initialization.
static void launch(ApplicationAdaptor adaptor, java.net.URL[] urls)
          Handle the launching of the application by creating the application instance and performing application initialization.
protected  Commander makeCommander()
          Make an application commander
protected  void makeFileChoosers()
          Create a file chooser for opening and saving documents.
protected  void newDocument()
          Handle the "New" action by creating a new document.
protected  void openDocument()
          Handle the "Open" action by opening a new document.
 void openDocument(java.net.URL url)
          Support method for opening a document with the specified URL.
protected  void openFile(java.io.File file)
          Support method for opening a new document given a file.
protected  void openFiles(java.io.File[] files)
          Support method for opening an array of files.
protected  void openURL(java.lang.String urlSpec)
          Support method for opening a new document with the URL specification
 void produceDocument(XalDocument document)
          Add a new document to this application and show it
 void produceDocument(XalDocument document, boolean makeVisible)
          Add a new document to this application and if makeVisible is true, show it
 void quit()
          Handle the "Quit" action by quitting the application.
protected  void registerApplicationStatusService()
          Register the application status service so clients on the network can query the status of this application instance.
protected  void registerEvents()
          Register the instance as a provider for ApplictionListener events.
 void removeApplicationListener(ApplicationListener listener)
          Remove the listener from listening to Application events.
protected  void revertToSaved(XalDocument document)
          Handle the "Revert To Saved" action by reverting the specified document to that of its source file.
protected  void saveAllDocuments()
          Handle the "Save All" action by saving all open documents.
protected  void saveAsDocument(XalDocument document)
          Handle the "Save As" action by saving the specified document to the location chosen by the user.
protected  void saveDocument(XalDocument document)
          Handle the "Save" action by saving the specified document.
protected  void saveDocumentToFile(XalDocument document, java.io.File file)
          Support method for saving a document to a file.
 void setOpenFileChooser(javax.swing.JFileChooser fileChooser)
          Set the file chooser with which the user will interact when opening a document.
 void setSaveFileChooser(javax.swing.JFileChooser fileChooser)
          Set the file chooser with which the user will interact when saving a document.
protected  void setupConsole()
          Setup the console to capture standard output and standard error
protected  void showAllWindows()
          Handle the "Show All" action by showing all main windows corresponding to the open documents.
 void titleChanged(XalDocument document, java.lang.String newTitle)
          Implement XalDocumentListener.
protected  void updateFileChooserFolder()
          Update the current directories of the open and save file choosers.
protected  void updateFileChooserFolder(javax.swing.JFileChooser fileChooser)
          Update the current directory of the specified file chooser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

YES_OPTION

public static final int YES_OPTION
See Also:
Constant Field Values

NO_OPTION

public static final int NO_OPTION
See Also:
Constant Field Values
Constructor Detail

Application

public Application(ApplicationAdaptor adaptor)
Application constructor.

Parameters:
adaptor - The application adaptor used for customization.

Application

public Application(ApplicationAdaptor adaptor,
                   java.net.URL[] urls)
Application constructor.

Parameters:
adaptor - The application adaptor used for customization.
urls - An array of document URLs to open upon startup.
Method Detail

getCommander

public Commander getCommander()
Get the application commander that manages commands for the entire application.

Returns:
the application commander

makeCommander

protected Commander makeCommander()
Make an application commander

Returns:
the commander that loads default and custom actions.

registerApplicationStatusService

protected final void registerApplicationStatusService()
Register the application status service so clients on the network can query the status of this application instance.


setupConsole

protected void setupConsole()
Setup the console to capture standard output and standard error


getSaveFileChooser

public javax.swing.JFileChooser getSaveFileChooser()
Get the file chooser with which the user interacts when saving a document.

Returns:
The file chooser with which the user interacts when saving a document.

setSaveFileChooser

public void setSaveFileChooser(javax.swing.JFileChooser fileChooser)
Set the file chooser with which the user will interact when saving a document.

Parameters:
fileChooser - The file chooser with which the user will interact when saving a document.

getOpenFileChooser

public javax.swing.JFileChooser getOpenFileChooser()
Get the file chooser with which the user interacts when opening a document.

Returns:
The file chooser with which the user interacts when opening a document.

setOpenFileChooser

public void setOpenFileChooser(javax.swing.JFileChooser fileChooser)
Set the file chooser with which the user will interact when opening a document.

Parameters:
fileChooser - The file chooser with which the user will interact when opening a document.

makeFileChoosers

protected void makeFileChoosers()
Create a file chooser for opening and saving documents.


updateFileChooserFolder

protected void updateFileChooserFolder()
Update the current directories of the open and save file choosers.


updateFileChooserFolder

protected void updateFileChooserFolder(javax.swing.JFileChooser fileChooser)
Update the current directory of the specified file chooser.

Parameters:
fileChooser - The file chooser for which to update the current directory.

registerEvents

protected void registerEvents()
Register the instance as a provider for ApplictionListener events. Register the application adaptor as an ApplicationListener.


addApplicationListener

public void addApplicationListener(ApplicationListener listener)
Add the listener as a listener of Application events.

Parameters:
listener - Object to register as a listener of application events.

removeApplicationListener

public void removeApplicationListener(ApplicationListener listener)
Remove the listener from listening to Application events.

Parameters:
listener - Object to un-register as a listener of application events.

getDocuments

public java.util.List getDocuments()
Get the list of all open documents.

Returns:
An immutable list of the open documents.

getApplicationAdaptor

public ApplicationAdaptor getApplicationAdaptor()
Get the custom application adaptor.

Returns:
The custom application adaptor.
See Also:
getAdaptor()

newDocument

protected void newDocument()
Handle the "New" action by creating a new document.


openDocument

protected void openDocument()
Handle the "Open" action by opening a new document.


openURL

protected void openURL(java.lang.String urlSpec)
Support method for opening a new document with the URL specification

Parameters:
urlSpec - The URL specification of the file to open.

openFile

protected void openFile(java.io.File file)
Support method for opening a new document given a file.

Parameters:
file - The file to open.
See Also:
openFiles(java.io.File[])

openFiles

protected void openFiles(java.io.File[] files)
Support method for opening an array of files.

Parameters:
files - The files to open.
See Also:
openDocument()

openDocument

public void openDocument(java.net.URL url)
Support method for opening a document with the specified URL.

Parameters:
url - The URL of the file to open.
See Also:
openURL(java.lang.String), openFile(java.io.File)

closeDocument

protected void closeDocument(XalDocument document)
Handle the "Close" action by closing the specified document.

Parameters:
document - The document to close.

closeAllDocuments

protected void closeAllDocuments()
Handle the "Close All" action by closing all open documents and opening a new empty document.


saveDocument

protected void saveDocument(XalDocument document)
Handle the "Save" action by saving the specified document. If the document has a an existing file source, the document is saved to that source. Otherwise, the user is shown a dialog box to select a file location to which the document will be saved.

Parameters:
document - The document to save.

saveAsDocument

protected void saveAsDocument(XalDocument document)
Handle the "Save As" action by saving the specified document to the location chosen by the user. Displays a dialog box to allow the user to select a location.

Parameters:
document - The document to save.

saveAllDocuments

protected void saveAllDocuments()
Handle the "Save All" action by saving all open documents.


saveDocumentToFile

protected void saveDocumentToFile(XalDocument document,
                                  java.io.File file)
Support method for saving a document to a file.

Parameters:
document - The document to save.
file - The file to which the document will be saved.

revertToSaved

protected void revertToSaved(XalDocument document)
Handle the "Revert To Saved" action by reverting the specified document to that of its source file.

Parameters:
document - The document to revert.

quit

public void quit()
Handle the "Quit" action by quitting the application.


cascadeWindowsAbout

protected void cascadeWindowsAbout(XalDocument targetDocument)
Handle the "Cascade Windows" action by cascading all document windows about the target document.

Parameters:
targetDocument - The document about whose window all document windows should cascade

showAllWindows

protected void showAllWindows()
Handle the "Show All" action by showing all main windows corresponding to the open documents. The windows are brought to the front and un-collapsed as necessary.


hideAllWindows

protected void hideAllWindows()
Handle the "Hide All" action by hiding all main windows corresponding to the open documents.


titleChanged

public void titleChanged(XalDocument document,
                         java.lang.String newTitle)
Implement XalDocumentListener. Empty implementation.

Specified by:
titleChanged in interface XalDocumentListener
Parameters:
document - The document whose title changed.
newTitle - The new document title.

hasChangesChanged

public void hasChangesChanged(XalDocument document,
                              boolean newHasChangesStatus)
Implement XalDocumentListener. Empty implementation.

Specified by:
hasChangesChanged in interface XalDocumentListener
Parameters:
document - The document whose change status changed
newHasChangesStatus - The new "hasChanges" status of the document.

documentWillClose

public void documentWillClose(XalDocument document)
Implement XalDocumentListener. Empty implementation.

Specified by:
documentWillClose in interface XalDocumentListener
Parameters:
document - The document that will close.

documentHasClosed

public void documentHasClosed(XalDocument document)
Implement XalDocumentListener. When a document has closed, the application receives this event and removes the document from its open documents list. If there are no documents remaining, the application quits.

Specified by:
documentHasClosed in interface XalDocumentListener
Parameters:
document - The document that has closed.

launch

public static void launch(ApplicationAdaptor adaptor)
Handle the launching of the application by creating the application instance and performing application initialization.

Parameters:
adaptor - The custom application adaptor.

launch

public static void launch(ApplicationAdaptor adaptor,
                          java.net.URL[] urls)
Handle the launching of the application by creating the application instance and performing application initialization.

Parameters:
adaptor - The custom application adaptor.
urls - The URLs of documents to open upon launching the application

getAdaptor

public static ApplicationAdaptor getAdaptor()
Convenience method for getting the custom application adaptor. There is only one such adaptor for the entire application.

Returns:
The custom application adaptor.
See Also:
getApplicationAdaptor()

getApp

public static Application getApp()
Get the application instance. There is only one application instance per application.

Returns:
The application instance.

getActiveWindow

public static java.awt.Window getActiveWindow()
Get the active window which is in focus for this application. It is a good window relative to which you can place application warning dialog boxes.

Returns:
The active window

produceDocument

public void produceDocument(XalDocument document)
Add a new document to this application and show it

Parameters:
document - the document to produce

produceDocument

public void produceDocument(XalDocument document,
                            boolean makeVisible)
Add a new document to this application and if makeVisible is true, show it

Parameters:
document - the document to produce
makeVisible - make the document visible

displayConfirmDialog

public static int displayConfirmDialog(java.lang.String title,
                                       java.lang.String message)
Display a confirmation dialog with a title and message

Parameters:
title - The title of the dialog
message - The message to display
Returns:
YES_OPTION or NO_OPTION

displayWarning

public static void displayWarning(java.lang.Exception exception)
Display a warning dialog box with information about the exception.

Parameters:
exception - The exception about which the warning dialog is displayed.

displayWarning

public static void displayWarning(java.lang.String title,
                                  java.lang.String message)
Display a warning dialog box.

Parameters:
title - Title of the warning dialog box.
message - The warning message to appear in the warning dialog box.

displayWarning

public static void displayWarning(java.lang.String title,
                                  java.lang.String prefix,
                                  java.lang.Exception exception)
Display a warning dialog box with information about the exception. This method allows clarification about the consequences of the exception (e.g. "Save Failed:").

Parameters:
title - Title of the warning dialog box.
prefix - Text that should appear in the dialog box before the exception messasge.
exception - The exception about which the warning dialog is displayed.

displayError

public static void displayError(java.lang.String title,
                                java.lang.String message)
Display an error dialog box.

Parameters:
title - Title of the warning dialog box.
message - The warning message to appear in the warning dialog box.

displayError

public static void displayError(java.lang.Exception exception)
Display an error dialog box with information about the exception.

Parameters:
exception - The exception about which the warning dialog is displayed.

displayError

public static void displayError(java.lang.String title,
                                java.lang.String prefix,
                                java.lang.Exception exception)
Display an error dialog box with information about the exception. This method allows clarification about the consequences of the exception (e.g. "Save Failed:").

Parameters:
title - Title of the warning dialog box.
prefix - Text that should appear in the dialog box before the exception messasge.
exception - The exception about which the warning dialog is displayed.

displayApplicationError

public static void displayApplicationError(java.lang.String title,
                                           java.lang.String prefix,
                                           java.lang.Exception exception)
Display an error dialog box with information about the exception. This method allows clarification about the consequences of the exception (e.g. "Save Failed:").

Parameters:
title - Title of the warning dialog box.
prefix - Text that should appear in the dialog box before the exception messasge.
exception - The exception about which the warning dialog is displayed.