Class ApplicationContext
- java.lang.Object
-
- org.jdesktop.application.AbstractBean
-
- org.jdesktop.application.ApplicationContext
-
public class ApplicationContext extends AbstractBean
A singleton that manages shared objects, like actions, resources, and tasks, forApplications
.Applications
useApplicationContext
, viaApplication.getContext()
, to access global values and services. The majority of the Swing Application Framework API can be accessed throughApplicationContext
.- Author:
- Hans Muller (Hans.Muller@Sun.COM)
- See Also:
Application
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ApplicationContext()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTaskService(TaskService taskService)
Register a new TaskService with the application.ActionManager
getActionManager()
Return this application's ActionManager.ApplicationActionMap
getActionMap()
Returns the sharedActionMap
chain for the entireApplication
.ApplicationActionMap
getActionMap(java.lang.Class actionsClass, java.lang.Object actionsObject)
Returns theApplicationActionMap
chain for the specified actions class and target object.ApplicationActionMap
getActionMap(java.lang.Object actionsObject)
Defined asgetActionMap(actionsObject.getClass(), actionsObject)
.Application
getApplication()
TheApplication
singleton, or null iflaunch
hasn't been called yet.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.java.awt.datatransfer.Clipboard
getClipboard()
Return a sharedClipboard
.javax.swing.JComponent
getFocusOwner()
Returns the application's focus owner.LocalStorage
getLocalStorage()
The sharedLocalStorage
object.ResourceManager
getResourceManager()
The application'sResourceManager
provides read-only cached access to resources in ResourceBundles via theResourceMap
class.ResourceMap
getResourceMap()
Returns thechain
of ResourceMaps that's shared by the entire application, beginning with the one defined for the Application class, i.e.ResourceMap
getResourceMap(java.lang.Class cls)
Returns achain
of two or more ResourceMaps.ResourceMap
getResourceMap(java.lang.Class startClass, java.lang.Class stopClass)
Returns achain
of two or more ResourceMaps.SessionStorage
getSessionStorage()
The sharedSessionStorage
object.TaskMonitor
getTaskMonitor()
Returns a shared TaskMonitor object.TaskService
getTaskService()
Returns the default TaskService, i.e.TaskService
getTaskService(java.lang.String name)
Look up a task service by name.java.util.List<TaskService>
getTaskServices()
Returns a read-only view of the complete list of TaskServices.void
removeTaskService(TaskService taskService)
Unregister a previously registered TaskService.protected void
setActionManager(ActionManager actionManager)
Change this application'sActionManager
.void
setApplicationClass(java.lang.Class applicationClass)
Called byApplication.launch()
to record the application's class.protected void
setLocalStorage(LocalStorage localStorage)
The sharedLocalStorage
object.protected void
setResourceManager(ResourceManager resourceManager)
Change this application'sResourceManager
.protected void
setSessionStorage(SessionStorage sessionStorage)
The sharedSessionStorage
object.-
Methods inherited from class org.jdesktop.application.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
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 asgetApplication().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 byApplication.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.
- Parameters:
applicationClass
-- See Also:
getApplicationClass()
-
getApplication
public final Application getApplication()
TheApplication
singleton, or null iflaunch
hasn't been called yet.- Returns:
- the launched Application singleton.
- See Also:
Application.launch(java.lang.Class<T>, java.lang.String[])
-
getResourceManager
public final ResourceManager getResourceManager()
The application'sResourceManager
provides read-only cached access to resources in ResourceBundles via theResourceMap
class.- Returns:
- this application's ResourceManager.
- See Also:
getResourceMap(Class, Class)
-
setResourceManager
protected void setResourceManager(ResourceManager resourceManager)
Change this application'sResourceManager
. AnApplicationContext
subclass that wanted to fundamentally change the wayResourceMaps
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 achain
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 fromResourceBundles
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 achain
of two or more ResourceMaps. The first encapsulates the ResourceBundles defined for the all of the classes betweenstartClass
andstopClass
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 includedstopClass
- the last class whose ResourceBundles will be included- Returns:
- a
ResourceMap
that contains resources loaded fromResourceBundles
found in the resources subpackage of the specified class's package. - See Also:
ResourceManager.getResourceMap(Class, Class)
-
getResourceMap
public final ResourceMap getResourceMap()
Returns thechain
of ResourceMaps that's shared by the entire application, beginning with the one defined for the Application class, i.e. the value of theapplicationClass
property.This is just a convenience method that calls
ResourceManager.getResourceMap()
. It's defined as:return getResourceManager().getResourceMap();
- Returns:
- the Application's ResourceMap
- See Also:
ResourceManager.getResourceMap()
,getApplicationClass()
-
getActionManager
public final ActionManager getActionManager()
Return this application's ActionManager.- Returns:
- this application's ActionManager.
- See Also:
getActionMap(Object)
-
setActionManager
protected void setActionManager(ActionManager actionManager)
Change this application'sActionManager
. AnApplicationContext
subclass that wanted to fundamentally change the wayActionManagers
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()
Returns the sharedActionMap
chain for the entireApplication
.This is just a convenience method that calls
ActionManager.getActionMap()
. It's defined as:return getActionManager().getActionMap()
- Returns:
- the
ActionMap
chain for the entireApplication
. - See Also:
ActionManager.getActionMap()
-
getActionMap
public final ApplicationActionMap getActionMap(java.lang.Class actionsClass, java.lang.Object actionsObject)
Returns theApplicationActionMap
chain for the specified actions class and target object.This is just a convenience method that calls
ActionManager.getActionMap(Class, Object)
. It's defined as:return getActionManager().getActionMap(actionsClass, actionsObject)
- Parameters:
actionsClass
-actionsObject
-- Returns:
- the
ActionMap
chain for the entireApplication
. - See Also:
ActionManager.getActionMap(Class, Object)
-
getActionMap
public final ApplicationActionMap getActionMap(java.lang.Object actionsObject)
Defined asgetActionMap(actionsObject.getClass(), actionsObject)
.- Parameters:
actionsObject
-- Returns:
- the
ActionMap
for the specified object - See Also:
getActionMap(Class, Object)
-
getLocalStorage
public final LocalStorage getLocalStorage()
The sharedLocalStorage
object.- Returns:
- the shared
LocalStorage
object.
-
setLocalStorage
protected void setLocalStorage(LocalStorage localStorage)
The sharedLocalStorage
object.- Parameters:
localStorage
- the sharedLocalStorage
object.
-
getSessionStorage
public final SessionStorage getSessionStorage()
The sharedSessionStorage
object.- Returns:
- the shared
SessionStorage
object.
-
setSessionStorage
protected void setSessionStorage(SessionStorage sessionStorage)
The sharedSessionStorage
object.- Parameters:
sessionStorage
- the sharedSessionStorage
object.
-
getClipboard
public java.awt.datatransfer.Clipboard getClipboard()
Return a sharedClipboard
.- Returns:
- A shared
Clipboard
.
-
getFocusOwner
public javax.swing.JComponent getFocusOwner()
Returns the application's focus owner.- Returns:
- The application's focus owner.
-
addTaskService
public void addTaskService(TaskService taskService)
Register a new TaskService with the application. The task service then be retrieved by name viagetTaskService(String)
.- Parameters:
taskService
- Task service to register
-
removeTaskService
public void removeTaskService(TaskService taskService)
Unregister a previously registered TaskService. The task service is not shut down.- Parameters:
taskService
- TaskService to unregister
-
getTaskService
public TaskService getTaskService(java.lang.String name)
Look up a task service by name.- Parameters:
name
- Name of the task service to retrieve.- Returns:
- Task service found, or null if no service of that name found
-
getTaskService
public final TaskService getTaskService()
Returns the default TaskService, i.e. the one named "default":return getTaskService("default")
. TheApplicationAction actionPerformed
method executes backgroundTasks
on the default TaskService. Application's can launch Tasks in the same way, e.g.Application.getInstance().getContext().getTaskService().execute(myTask);
- Returns:
- the default TaskService.
- See Also:
getTaskService(String)
-
getTaskServices
public java.util.List<TaskService> getTaskServices()
Returns a read-only view of the complete list of TaskServices.- Returns:
- a list of all of the TaskServices.
- See Also:
addTaskService(org.jdesktop.application.TaskService)
,removeTaskService(org.jdesktop.application.TaskService)
-
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.
-
-