Class ApplicationContext


  • public class ApplicationContext
    extends AbstractBean
    A singleton that manages shared objects, like actions, resources, and tasks, for Applications.

    Applications use the ApplicationContext singleton to find global values and services. The majority of the Swing Application Framework API can be accessed through ApplicationContext. The static getInstance method returns the singleton Typically it's only called after the application has been launched, however it is always safe to call getInstance.

    See Also:
    Application
    • Constructor Detail

      • ApplicationContext

        protected ApplicationContext()
    • Method Detail

      • getApplicationClass

        public final java.lang.Class getApplicationClass()
        Returns the application's class or null if the application hasn't been launched and this property hasn't been set. Once the application has been launched, the value returned by this method is the same as getApplication().getClass().
        Returns:
        the application's class or null
        See Also:
        setApplicationClass(java.lang.Class), getApplication()
      • setApplicationClass

        public final void setApplicationClass​(java.lang.Class applicationClass)
        Called by Application.launch() to record the application's class.

        This method is only intended for testing, or design time configuration. Normal applications shouldn't need to call it directly.

        See Also:
        getApplicationClass()
      • getResourceManager

        public final ResourceManager getResourceManager()
        The application's ResourceManager provides read-only cached access to resources in ResourceBundles via the ResourceMap class.
        Returns:
        this application's ResourceManager.
        See Also:
        getResourceMap(Class, Class)
      • setResourceManager

        protected void setResourceManager​(ResourceManager resourceManager)
        Change this application's ResourceManager. An ApplicationContext subclass that wanted to fundamentally change the way ResourceMaps were created and cached could replace this property in its constructor.

        Throws an IllegalArgumentException if resourceManager is null.

        Parameters:
        resourceManager - the new value of the resourceManager property.
        See Also:
        getResourceMap(Class, Class), getResourceManager()
      • getResourceMap

        public final ResourceMap getResourceMap​(java.lang.Class cls)
        Returns a chain of two or more ResourceMaps. The first encapsulates the ResourceBundles defined for the specified class, and its parent encapsulates the ResourceBundles defined for the entire application.

        This is just a convenience method that calls ResourceManager.getResourceMap(). It's defined as:

         return getResourceManager().getResourceMap(cls, cls);
         
        Parameters:
        cls - the class that defines the location of ResourceBundles
        Returns:
        a ResourceMap that contains resources loaded from ResourceBundles found in the resources subpackage of the specified class's package.
        See Also:
        ResourceManager.getResourceMap(Class)
      • getResourceMap

        public final ResourceMap getResourceMap​(java.lang.Class startClass,
                                                java.lang.Class stopClass)
        Returns a chain of two or more ResourceMaps. The first encapsulates the ResourceBundles defined for the all of the classes between startClass and stopClass inclusive. It's parent encapsulates the ResourceBundles defined for the entire application.

        This is just a convenience method that calls ResourceManager.getResourceMap(). It's defined as:

         return getResourceManager().getResourceMap(startClass, stopClass);
         
        Parameters:
        startClass - the first class whose ResourceBundles will be included
        stopClass - the last class whose ResourceBundles will be included
        Returns:
        a ResourceMap that contains resources loaded from ResourceBundles found in the resources subpackage of the specified class's package.
        See Also:
        ResourceManager.getResourceMap(Class, Class)
      • setActionManager

        protected void setActionManager​(ActionManager actionManager)
        Change this application's ActionManager. An ApplicationContext subclass that wanted to fundamentally change the way ActionManagers were created and cached could replace this property in its constructor.

        Throws an IllegalArgumentException if actionManager is null.

        Parameters:
        actionManager - the new value of the actionManager property.
        See Also:
        getActionManager(), getActionMap(Object)
      • getActionMap

        public final ApplicationActionMap getActionMap​(java.lang.Object actionsObject)
        Defined as getActionMap(actionsObject.getClass(), actionsObject).
        Returns:
        the ActionMap for the specified object
        See Also:
        getActionMap(Class, Object)
      • getClipboard

        public java.awt.datatransfer.Clipboard getClipboard()
        A shared Clipboard.
      • getFocusOwner

        public javax.swing.JComponent getFocusOwner()
        The application's focus owner.
      • addTaskService

        public void addTaskService​(TaskService taskService)
      • removeTaskService

        public void removeTaskService​(TaskService taskService)
      • getTaskService

        public TaskService getTaskService​(java.lang.String name)
      • getTaskService

        public final TaskService getTaskService()
        Returns the default TaskService, i.e. the one named "default": return getTaskService("default"). The ApplicationAction actionPerformed method executes background Tasks on the default TaskService. Application's can launch Tasks in the same way, e.g.
         ApplicationContext.getInstance().getTaskService().execute(myTask);
         
        Returns:
        the default TaskService.
        See Also:
        getTaskService(String)
      • getTaskMonitor

        public final TaskMonitor getTaskMonitor()
        Returns a shared TaskMonitor object. Most applications only need one TaskMonitor for the sake of status bars and other status indicators.
        Returns:
        the shared TaskMonitor object.