Package de.sciss.app

Class AbstractApplication

  • All Implemented Interfaces:
    Application
    Direct Known Subclasses:
    BasicApplication

    public abstract class AbstractApplication
    extends java.lang.Object
    implements Application
    A rudimentary implementation of the de.sciss.app.Application interface, which deals with component registration, quitting, preference, clipboard and resource bundle generation.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractApplication​(java.lang.Class mainClass, java.lang.String name)
      Creates a new instance of this class.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addComponent​(java.lang.Object key, java.lang.Object component)
      synchronization: this method is synchronized
      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)
      synchronization: this method is synchronized
      java.lang.String getName()
      Returns the application's name.
      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)
      synchronization: this method is synchronized
      void setName​(java.lang.String name)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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

      • setName

        public void setName​(java.lang.String name)
      • getName

        public java.lang.String getName()
        Description copied from interface: Application
        Returns the application's name.
        Specified by:
        getName in interface Application
        Returns:
        the application's name
      • 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)
        synchronization: this method is synchronized
        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
      • addComponent

        public final void addComponent​(java.lang.Object key,
                                       java.lang.Object component)
        synchronization: this method is synchronized
        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
      • removeComponent

        public final void removeComponent​(java.lang.Object key)
        synchronization: this method is synchronized
        Specified by:
        removeComponent in interface Application
        Parameters:
        key - agreed upon idenfier for the component to be removed, e.g. a string or class
      • 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 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.