org.bs.mdi
Class Application

java.lang.Object
  extended byorg.bs.mdi.Application
All Implemented Interfaces:
MessageProcessor

public abstract class Application
extends Object
implements MessageProcessor

The base class for all MDI applications.


Field Summary
protected static Application application
           
protected static ClipboardManager clipboardManager
           
protected static DocumentWindow currentWindow
           
protected static ArrayList documents
           
protected static FileIOManager fileIOManager
           
protected static MainWindow mainWindow
           
protected static MessageDispatcher messageDispatcher
           
protected static Preferences preferences
           
protected static RecentFiles recentFiles
           
protected static CompositeResources resources
           
protected static boolean running
           
 
Constructor Summary
Application()
          Creates a new Application.
 
Method Summary
 boolean close()
          Exits the application by closing its main window.
 void closeDocument()
          Tries to close the current document and all of its views and windows.
 void closeWindow()
          Tries to close the current window.
 void copy()
          Perform a copy operation on the current document.
static int countDocuments()
          Returns the number of currently opened documents.
protected abstract  ActionConverter[] createActionConverters()
          Creates and returns all available Action converters (see ActionConverter).
protected abstract  FileIOModule[] createFileIOModules()
          Creates and returns all available File I/O extension modules (see FileIOModule)..
protected abstract  MainWindow createMainWindow()
          Creates and return an application-specific main window (see MainWindow).
protected abstract  Resources createResources()
          Creates and returns the applications resources.
abstract  RootData createRootData()
          Creates and returns a new RootData instance.
abstract  RootView createRootView()
          Creates and returns a new RootView instance.
protected  void currentWindowChanged(DocumentWindow newWindow)
          Called when another document window is activated (receives the focus).
 void cut()
          Perform a cut operation on the current document.
 void delete()
          Perform a delete operation on the current document.
 void exit()
          Closes the application the brute-force way.
 void exportDocument(FileExporter exporter)
          Tries to export the current document.
static ClipboardManager getClipboardManager()
          Returns the ClipboardManager which provides clipboard access and data transfer/conversion functions.
static RootData getCurrentData()
          Returns the data which belongs to the current window.
static Document getCurrentDocument()
          Returns the document which belongs to the current window.
static RootView getCurrentView()
          Returns the view which belongs to the current window.
static DocumentWindow getCurrentWindow()
          Returns the currently active window.
static Document getDocument(int index)
          Gets the document at the specified index.
static Iterator getDocumentIterator()
          Gets an iterator for all currently opened documents.
static Document[] getDocuments()
          Returns an array of currently opened documents.
static FileIOManager getFileIOManager()
          Returns the FileIOManager which manages modules for performing file I/O (loading, saving, exporting).
static Application getInstance()
          Gets the current instance of the Application class.
static MainWindow getMainWindow()
          Returns the application's main window.
static MessageDispatcher getMessageDispatcher()
          Gets the MessageDispatcher object which is responsible for communication between various parts of the framework.
abstract  String getName()
          Get the name of the application.
static Preferences getPreferences()
          Gets the application's preferences.
static RecentFiles getRecentFiles()
          Gets the RecentFiles object which automatically maintains a list of recently opened filenames.
static Resources getResources()
          Returns the Resources object which handles internationalization and icon loading.
 boolean isCopyPossible()
          Returns true if information can be copied to the clipboard from the current document window.
 boolean isCutPossible()
          Returns true if information can be cutted to the clipboard from the current document window.
 boolean isDeletePossible()
          Returns true if information can be deleted from the current document window.
 boolean isPastePossible()
          Returns true if information can be pasted from the clipboard to the current document window.
 boolean isRedoPossible()
          Returns true if the last undo operation of the current document can be redone.
static boolean isRunning()
          Returns the running status of this application.
 boolean isUndoPossible()
          Returns true if the last modification of the current document can be undone.
 Document newDocument()
          Creates a new document and makes its view (window) visible.
 Document openDocument()
          Displays a "Open File"-Dialog and tries to open the selected file.
 Document openDocument(String filename)
          Tries to open the given file.
 void paste()
          Perform a paste operation on the current document.
 void printDocument()
          Prints the current document.
 void processMessage(Object source, int type, Object argument)
          Called from the MessageDispatcher to indicate that an event has occurred which this object may be interested in.
 void redo()
          Perform a redo operation on the current document.
 void run(String[] args)
          Starts and runs the application.
 void saveDocument()
          Tries to save the current document.
 void saveDocumentAs()
          Displays a "Save File"-Dialog and tries to save the current document using the selected filename.
static void selectWindow(DocumentWindow window)
          Activates a window programmatically.
static void setBusy(boolean busy)
          Gives the user the indication that the application is busy now.
static boolean setCurrentDocumentLocked(boolean locked)
          Prevents other documents from becoming active.
static void setStatus(String status)
          Sets the text to be displayed in the application's status bar.
 void showPrintPreview()
          Shows a print preview dialog for the current document.
 void showPrintSetup()
          Shows a dialog allowing the user to setup printing options such as paper size and orientation.
static String tr(String key)
          Returns a localized string for the specified key.
 void undo()
          Perform an undo operation on the current document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

documents

protected static ArrayList documents

currentWindow

protected static DocumentWindow currentWindow

mainWindow

protected static MainWindow mainWindow

clipboardManager

protected static ClipboardManager clipboardManager

resources

protected static CompositeResources resources

fileIOManager

protected static FileIOManager fileIOManager

application

protected static Application application

preferences

protected static Preferences preferences

recentFiles

protected static RecentFiles recentFiles

messageDispatcher

protected static MessageDispatcher messageDispatcher

running

protected static boolean running
Constructor Detail

Application

public Application()
Creates a new Application. Due to static variable initialization in this constructor, there should be only one Application instance. Anyway, there is no reason for creating more than one Application instance. Don't try that, it will not work! You can always get the current Application instance by calling the static method getInstance().

Method Detail

getInstance

public static Application getInstance()
Gets the current instance of the Application class.

Returns:
the only valid instance of Application

getPreferences

public static Preferences getPreferences()
Gets the application's preferences. The Preferences object manages per-user preferences and settings for a particular application.

Returns:
the Preferences object

getRecentFiles

public static RecentFiles getRecentFiles()
Gets the RecentFiles object which automatically maintains a list of recently opened filenames.

Returns:
the RecentFiles object

getMessageDispatcher

public static MessageDispatcher getMessageDispatcher()
Gets the MessageDispatcher object which is responsible for communication between various parts of the framework.

Returns:
the framework's message dispatcher

getName

public abstract String getName()
Get the name of the application. Subclasses have to overwrite this method to set the own application name. Note that this application name is used by the Preferences object to create the user-specific settings filename, so your application name should be unique in order to avoid filename collisions.

Returns:
the name of the application

isRunning

public static boolean isRunning()
Returns the running status of this application.

Returns:
true if the application is currently running, false otherwise

tr

public static String tr(String key)
Returns a localized string for the specified key. This method searches the applications resources (as created by createResources()) for the specified key and returns its value. This is the preferred way of providing internationalization support for MDI applications.

Parameters:
key - the key which should be looked up in the resource bundle
Returns:
the localized string for the given key

newDocument

public Document newDocument()
Creates a new document and makes its view (window) visible.

Returns:
the created document

openDocument

public Document openDocument()
Displays a "Open File"-Dialog and tries to open the selected file. Displays an error message in case of an error.

Returns:
the opened document

openDocument

public Document openDocument(String filename)
Tries to open the given file. Displays an error message in case of an error.

Parameters:
filename - the file to be opened
Returns:
the opened document

saveDocument

public void saveDocument()
Tries to save the current document. Displays an error message in case of an error. If no valid filename was given to the document before, it displays a "Save File"-Dialog to choose one (i.e. it behaves like saveDocumentAs() in this case).


saveDocumentAs

public void saveDocumentAs()
Displays a "Save File"-Dialog and tries to save the current document using the selected filename. Displays an error message in case of an error.


exportDocument

public void exportDocument(FileExporter exporter)
Tries to export the current document. Displays an error message in case of an error.

Parameters:
exporter - the FileExporter to use.

showPrintSetup

public void showPrintSetup()
Shows a dialog allowing the user to setup printing options such as paper size and orientation.


showPrintPreview

public void showPrintPreview()
Shows a print preview dialog for the current document. Does nothing if there's no current document.


printDocument

public void printDocument()
Prints the current document. The main window is responsible for showing a print dialog. Does nothing if there's no current document.


closeDocument

public void closeDocument()
Tries to close the current document and all of its views and windows. Note that the close operation may be aborted by the document (for example, the window may display a dialog to ask the user if he really wants to close the document).


closeWindow

public void closeWindow()
Tries to close the current window. Note that the close operation may be aborted by the document (for example, the window may display a dialog to ask the user if he really wants to close the document).


setStatus

public static void setStatus(String status)
Sets the text to be displayed in the application's status bar.

Parameters:
status - The status text to be displayed

setBusy

public static void setBusy(boolean busy)
Gives the user the indication that the application is busy now.

Parameters:
busy - true if the busy indication should be enabled, false otherwise

close

public boolean close()
Exits the application by closing its main window. This is the preferred way to exit the application. The user is asked to save modified documents and once all data is saved, the application terminates. However, this process may be interrupted by the user. Therefore this method can not guarantee a successful termination.

Returns:
true if the application was successfully terminated, false otherwise

exit

public void exit()
Closes the application the brute-force way. This closes the application by terminating the Java virtual machine. This does not remind the user of unsaved data; it's just quick and brutal. Consider using close() for a proper and safe method of closing the application.


undo

public void undo()
Perform an undo operation on the current document. Does nothing if there is no current document or an undo is not possible.


redo

public void redo()
Perform a redo operation on the current document. Does nothing if there is no current document or a redo is not possible.


cut

public void cut()
Perform a cut operation on the current document. Does nothing if there is no current document or a cut is not possible.


copy

public void copy()
Perform a copy operation on the current document. Does nothing if there is no current document or a copy is not possible.


paste

public void paste()
Perform a paste operation on the current document. Does nothing if there is no current document or a paste is not possible.


delete

public void delete()
Perform a delete operation on the current document. Does nothing if there is no current document or a delete is not possible.


isUndoPossible

public boolean isUndoPossible()
Returns true if the last modification of the current document can be undone.

Returns:
true if an undo operation is possible at the moment

isRedoPossible

public boolean isRedoPossible()
Returns true if the last undo operation of the current document can be redone.

Returns:
true if a redo operation is possible at the moment

isCutPossible

public boolean isCutPossible()
Returns true if information can be cutted to the clipboard from the current document window.

Returns:
true if a cut operation is possible at the moment

isCopyPossible

public boolean isCopyPossible()
Returns true if information can be copied to the clipboard from the current document window.

Returns:
true if a copy operation is possible at the moment

isPastePossible

public boolean isPastePossible()
Returns true if information can be pasted from the clipboard to the current document window.

Returns:
true if a paste operation is possible at the moment

isDeletePossible

public boolean isDeletePossible()
Returns true if information can be deleted from the current document window.

Returns:
true if a delete operation is possible at the moment

getResources

public static Resources getResources()
Returns the Resources object which handles internationalization and icon loading.

Returns:
the application's resources

getFileIOManager

public static FileIOManager getFileIOManager()
Returns the FileIOManager which manages modules for performing file I/O (loading, saving, exporting).

Returns:
the application's FileIOManager

getClipboardManager

public static ClipboardManager getClipboardManager()
Returns the ClipboardManager which provides clipboard access and data transfer/conversion functions.

Returns:
the application's ClipboardManager

getMainWindow

public static MainWindow getMainWindow()
Returns the application's main window.

Returns:
the application's main window

getDocuments

public static Document[] getDocuments()
Returns an array of currently opened documents. A document is considered open if it has at least one open window.

Returns:
an array of all currently opened Documents

countDocuments

public static int countDocuments()
Returns the number of currently opened documents.

Returns:
the number of currently opened documents

getDocument

public static Document getDocument(int index)
Gets the document at the specified index.

Parameters:
index -
Returns:
the document at the specified position

getDocumentIterator

public static Iterator getDocumentIterator()
Gets an iterator for all currently opened documents.

Returns:
an iterator

getCurrentWindow

public static DocumentWindow getCurrentWindow()
Returns the currently active window.

Returns:
the currently active Window, or null if there is no active window

getCurrentDocument

public static Document getCurrentDocument()
Returns the document which belongs to the current window. Calling this method is equivalent for calling getCurrentWindow().getDocument() (except for NullPointerException handling).

Returns:
the currently active document, or null if there is no active document

getCurrentView

public static RootView getCurrentView()
Returns the view which belongs to the current window. Calling this method is equivalent for calling getCurrentWindow().getView() (except for NullPointerException handling).

Returns:
the currently active view, or null if there is no active view

getCurrentData

public static RootData getCurrentData()
Returns the data which belongs to the current window. Calling this method is equivalent for calling getCurrentWindow().getDocument().getData() (except for NullPointerException handling).

Returns:
the currently active data, or null if there is no active data object

selectWindow

public static void selectWindow(DocumentWindow window)
Activates a window programmatically.

Parameters:
window - the window to be activated

setCurrentDocumentLocked

public static boolean setCurrentDocumentLocked(boolean locked)
Prevents other documents from becoming active. Using this method, you can ensure that only the currently selected document stays active. The user will be unable to activate other document windows than the current one. This is done by calling setEnabled on every document window which does not belong to the currently selected document. Note that this method does not necessarily have to succeed. If the return value is false, this method failed and had no effect.

Parameters:
locked - true to activate the document lock, false to deactivate
Returns:
true on success, false on error

processMessage

public void processMessage(Object source,
                           int type,
                           Object argument)
Description copied from interface: MessageProcessor
Called from the MessageDispatcher to indicate that an event has occurred which this object may be interested in.

Specified by:
processMessage in interface MessageProcessor
Parameters:
source - the source where this message originated from
type - the message type
argument - an optional argument

run

public void run(String[] args)
Starts and runs the application. This method is designed to be called by the main method of the actual application. It brings up the main window and loads the documents specified by the filenames given as command line arguments.

Parameters:
args - the command line arguments passed to the application

currentWindowChanged

protected void currentWindowChanged(DocumentWindow newWindow)
Called when another document window is activated (receives the focus).

Parameters:
newWindow - the DocumentWindow that is now active

createFileIOModules

protected abstract FileIOModule[] createFileIOModules()
Creates and returns all available File I/O extension modules (see FileIOModule).. FileIOModules are required for opening, saving and exporting documents. The framework is responsible for making these modules available to the FileIOManager. This is a factory method which is to be implemented by subclasses of Application.

Returns:
an array of all available FileIOModules

createActionConverters

protected abstract ActionConverter[] createActionConverters()
Creates and returns all available Action converters (see ActionConverter). ActionConverters are required for clipboard functionality (cut, copy, paste). The framework is responsible for making these converters available to the ClipboardManager. This is a factory method which is to be implemented by subclasses of Application.

Returns:
an array of all available ActionConverters

createMainWindow

protected abstract MainWindow createMainWindow()
Creates and return an application-specific main window (see MainWindow). This is a factory method which is to be implemented by subclasses of Application.

Returns:
the main window

createResources

protected abstract Resources createResources()
Creates and returns the applications resources. Resources provide internationalization functionality to MDI applications. Since the MDI framework itself relies on this functionality, is is necessary to create and return a proper Resources object here. The framework is responsible for making the resource available to the CompositeResources. This is a factory method which is to be implemented by subclasses of Application.

Returns:
the applications resources

createRootData

public abstract RootData createRootData()
Creates and returns a new RootData instance. This is a factory method which is to be implemented by subclasses of Application.

Returns:
a new RootData object

createRootView

public abstract RootView createRootView()
Creates and returns a new RootView instance. This is a factory method which is to be implemented by subclasses of Application.

Returns:
a new RootView object