de.sciss.app
Class AbstractApplication

java.lang.Object
  extended by net.roydesign.app.Application
      extended by de.sciss.app.AbstractApplication
All Implemented Interfaces:
Application
Direct Known Subclasses:
BasicApplication

public abstract class AbstractApplication
extends net.roydesign.app.Application
implements Application

A rudimentary implementation of the de.sciss.app.Application interface, which deals with component registration, quitting, preference, clipboard and resource bundle generation. It extends net.roydesign.app.Application in order to supply easy access to methods.

Version:
0.13, 15-Sep-05
Author:
Hanns Holger Rutz

Constructor Summary
protected AbstractApplication(java.lang.Class mainClass, java.lang.String name)
          Creates a new instance of this class.
 
Method Summary
 void addComponent(java.lang.Object key, java.lang.Object component)
          Adds a newly created component (e.g. a specific frame) to the application.
static Application getApplication()
          Returns the current runtime's application.
 java.awt.datatransfer.Clipboard getClipboard()
          Returns the system's clipboard, or a local clipboard if security permits to retrieve the system clipboard.
 java.lang.Object getComponent(java.lang.Object key)
          Retrieves a specific component (such as a GUI frame) of the application.
 net.roydesign.app.Application getMRJApplication()
          Returns this.
 java.lang.String getResourceString(java.lang.String key)
          Returns a localized string for a given key.
 java.lang.String getResourceString(java.lang.String key, java.lang.String defaultValue)
          Returns a localized string for a given key.
 java.util.prefs.Preferences getSystemPrefs()
          Returns the applications system wide preferences.
 java.util.prefs.Preferences getUserPrefs()
          Returns the applications user specific preferences.
 void quit()
          Flushes preferences and quits.
 void removeComponent(java.lang.Object key)
          Unregisters a component, for example when a frame has been disposed.
 
Methods inherited from class net.roydesign.app.Application
addOpenApplicationListener, addOpenDocumentListener, addPrintDocumentListener, addReopenApplicationListener, getAboutJMenuItem, getAboutMenuItem, getFramelessJMenuBar, getFramelessMenuBar, getInstance, getName, getPreferencesJMenuItem, getPreferencesMenuItem, getQuitJMenuItem, getQuitMenuItem, removeOpenApplicationListener, removeOpenDocumentListener, removePrintDocumentListener, removeReopenApplicationListener, setFramelessJMenuBar, setFramelessMenuBar, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.sciss.app.Application
getDocumentHandler, getGraphicsHandler, getMacOSCreator, getName, getVersion, getWindowHandler
 

Constructor Detail

AbstractApplication

protected AbstractApplication(java.lang.Class mainClass,
                              java.lang.String name)
Creates a new instance of this class. The mainClass will be used to determine the application's preference root node. This name will be used to set the application's name and to load a ResourceBundle with localized text strings. The resource bundle must be stored in a file "<name>Strings.properties", e.g. if name equals "FScape", the resources are retrieved from "FScapeStrings.properties"!

Only one instance of this class can be created, any further attempt will result in a RuntimeException. The one and only instance is available through the class method getApplication.

Parameters:
mainClass - the main class of the application whose package (e.g. de.sciss.fscape) is used to identify the preferences files.
name - application name, should not contain white spaces or special characters.
See Also:
getApplication()
Method Detail

getSystemPrefs

public final java.util.prefs.Preferences getSystemPrefs()
Description copied from interface: Application
Returns the applications system wide preferences.

Specified by:
getSystemPrefs in interface Application
Returns:
the root node of the application's global preferences
See Also:
Preferences.systemNodeForPackage( Class )

getUserPrefs

public final java.util.prefs.Preferences getUserPrefs()
Description copied from interface: Application
Returns the applications user specific preferences.

Specified by:
getUserPrefs in interface Application
Returns:
the root node of the application's preferences from the current user's local folder
See Also:
Preferences.userNodeForPackage( Class )

getClipboard

public final java.awt.datatransfer.Clipboard getClipboard()
Returns the system's clipboard, or a local clipboard if security permits to retrieve the system clipboard.

Specified by:
getClipboard in interface Application
Returns:
the clipboard used by the application
See Also:
Toolkit.getSystemClipboard()

getComponent

public final java.lang.Object getComponent(java.lang.Object key)
Description copied from interface: Application
Retrieves a specific component (such as a GUI frame) of the application.

Specified by:
getComponent in interface Application
Parameters:
key - agreed upon idenfier for the component, e.g. a string or class
Returns:
the requested component or null if absent or unknown
Synchronization:
this method is synchronized

addComponent

public final void addComponent(java.lang.Object key,
                               java.lang.Object component)
Description copied from interface: Application
Adds a newly created component (e.g. a specific frame) to the application. Adding means making it known to other components which can retrieve this object by calling the getComponent method.

Specified by:
addComponent in interface Application
Parameters:
key - agreed upon idenfier for the component, e.g. a string or class
component - the component to be registered
Synchronization:
this method is synchronized

removeComponent

public final void removeComponent(java.lang.Object key)
Description copied from interface: Application
Unregisters a component, for example when a frame has been disposed. This will reomve the component from the internal dictionary.

Specified by:
removeComponent in interface Application
Parameters:
key - agreed upon idenfier for the component to be removed, e.g. a string or class
Synchronization:
this method is synchronized

getMRJApplication

public final net.roydesign.app.Application getMRJApplication()
Returns this.

Specified by:
getMRJApplication in interface Application
Returns:
the Application class providing access to common menu items and system events registration

getResourceString

public final java.lang.String getResourceString(java.lang.String key)
Description copied from interface: Application
Returns a localized string for a given key. If the key is not found, returns a warning text and the key name.

Specified by:
getResourceString in interface Application
Parameters:
key - a key into the application's main string recource file
Returns:
the localized text
See Also:
ResourceBundle.getString( String )

getResourceString

public final java.lang.String getResourceString(java.lang.String key,
                                                java.lang.String defaultValue)
Description copied from interface: Application
Returns a localized string for a given key. If the key is not found, returns the given default string.

Specified by:
getResourceString in interface Application
Parameters:
key - a key into the application's main string recource file
defaultValue - the text to return if the key is not in the dictionary
Returns:
the localized text
See Also:
ResourceBundle.getString( String )

quit

public void quit()
Flushes preferences and quits.

Specified by:
quit in interface Application

getApplication

public static final Application getApplication()
Returns the current runtime's application. Since this is a class method, it can be used by static classes such IO or GUI utilities to retrieve the application and its preferences or resource bundle.

Returns:
the active Application or null if no application has been created.