Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  
  /*
   * Copyright (C) 2006 Sun Microsystems, Inc. All rights reserved. Use is
   * subject to license terms.
   */ 
  
  package org.jdesktop.application;
  
 import java.util.List;
 import java.util.Map;
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.

Author(s):
Hans Muller (Hans.Muller@Sun.COM)
See also:
Application
 
 public class ApplicationContext extends AbstractBean {
     private static final Logger logger = Logger.getLogger(ApplicationContext.class.getName());
     private final List<TaskServicetaskServices;
     private final List<TaskServicetaskServicesReadOnly;
     private ResourceManager resourceManager;
     private ActionManager actionManager;
     private LocalStorage localStorage;
     private SessionStorage sessionStorage;
     private Application application = null;
     private Class applicationClass = null;
     private JComponent focusOwner = null;   
     private Clipboard clipboard = null;     
     private Throwable uncaughtException = null;
     private TaskMonitor taskMonitor = null;
     
 
     protected ApplicationContext() { 
 	 = new ActionManager(this);
 	 = new LocalStorage(this);
 	 = new SessionStorage(this);
 	.add(new TaskService("default"));
     }

    
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()
 
     public final synchronized Class getApplicationClass() {
 	return ;
     }

    
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.

 
     public final synchronized void setApplicationClass(Class applicationClass) {
         if (this. != null) {
	    throw new IllegalStateException("application has been launched");
	}
	this. = applicationClass;
    }

    
The Application singleton, or null if launch hasn't been called yet.

Returns:
the launched Application singleton.
See also:
Application.launch(java.lang.Class,java.lang.String[])
    public final synchronized Application getApplication() {
	return ;
    }
    /* Called by Application.launch().
     */
    synchronized void setApplication(Application application) {
	if (this. != null) {
	    throw new IllegalStateException("application has already been launched");
	}
	this. = application;
    }

    
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(java.lang.Class,java.lang.Class)
    public final ResourceManager getResourceManager() {
    }

    
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(java.lang.Class,java.lang.Class)
getResourceManager()
    protected void setResourceManager(ResourceManager resourceManager) {
	if (resourceManager == null) {
	    throw new IllegalArgumentException("null resourceManager");
	}
	Object oldValue = this.;
	this. = resourceManager;
	firePropertyChange("resourceManager"oldValuethis.);
    }

    
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(java.lang.Class)
    public final ResourceMap getResourceMap(Class cls) {
        return getResourceManager().getResourceMap(clscls);
    }

    
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(java.lang.Class,java.lang.Class)
    public final ResourceMap getResourceMap(Class startClassClass stopClass) {
        return getResourceManager().getResourceMap(startClassstopClass);
    }

    
Returns the chain of ResourceMaps that's shared by the entire application, beginning with the one defined for the Application class, i.e. the value of the applicationClass 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()
    public final ResourceMap getResourceMap() {
        return getResourceManager().getResourceMap();
    }

    

Returns:
this application's ActionManager.
See also:
getActionMap(java.lang.Object)
    public final ActionManager getActionManager() {
    }

    
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(java.lang.Object)
    protected void setActionManager(ActionManager actionManager) {
	if (actionManager == null) {
	    throw new IllegalArgumentException("null actionManager");
	}
	Object oldValue = this.;
	this. = actionManager;
	firePropertyChange("actionManager"oldValuethis.);
    }


    
Returns the shared ActionMap chain for the entire Application.

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

 return getActionManager().getActionMap()
 

Returns:
the ActionMap chain for the entire Application.
See also:
ActionManager.getActionMap()
    public final ApplicationActionMap getActionMap() {
    }

    
Returns the ApplicationActionMap 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)
 

Returns:
the ActionMap chain for the entire Application.
See also:
ActionManager.getActionMap(java.lang.Class,java.lang.Object)
    public final ApplicationActionMap getActionMap(Class actionsClassObject actionsObject) {
	return getActionManager().getActionMap(actionsClassactionsObject);
    }

    
Defined as getActionMap(actionsObject.getClass(), actionsObject).

Returns:
the ActionMap for the specified object
See also:
getActionMap(java.lang.Class,java.lang.Object)
    public final ApplicationActionMap getActionMap(Object actionsObject) {
	if (actionsObject == null) {
	    throw new IllegalArgumentException("null actionsObject");
	}
	return getActionManager().getActionMap(actionsObject.getClass(), actionsObject);
    }

    
The shared LocalStorage object.

Returns:
the shared LocalStorage object.
    public final LocalStorage getLocalStorage() {
	return ;
    }

    
The shared LocalStorage object.

Parameters:
localStorage the shared LocalStorage object.
    protected void setLocalStorage(LocalStorage localStorage) {
	if (localStorage == null) {
	    throw new IllegalArgumentException("null localStorage");
	}
	Object oldValue = this.;
	this. = localStorage;
	firePropertyChange("localStorage"oldValuethis.);
    }


    
The shared SessionStorage object.

Returns:
the shared SessionStorage object.
    public final SessionStorage getSessionStorage() {
    }

    
The shared SessionStorage object.

Parameters:
sessionStorage the shared SessionStorage object.
    protected void setSessionStorage(SessionStorage sessionStorage) {
	if (sessionStorage == null) {
	    throw new IllegalArgumentException("null sessionStorage");
	}
	Object oldValue = this.;
	this. = sessionStorage;
	firePropertyChange("sessionStorage"oldValuethis.);
    }

    
A shared Clipboard.
    public Clipboard getClipboard() {
	if ( == null) {
	    try {
	    } 
	    catch (SecurityException e) {
		 = new Clipboard("sandbox");
	    }
	}
	return ;
    }

    
The application's focus owner.
    public JComponent getFocusOwner() { return ; }
    void setFocusOwner(JComponent focusOwner) {
	Object oldValue = this.;
	this. = focusOwner
	firePropertyChange("focusOwner"oldValuethis.);
    }
    private List<TaskServicecopyTaskServices() {
    }
    public void addTaskService(TaskService taskService) {
	if (taskService == null) {
	    throw new IllegalArgumentException("null taskService");
	}
	List<TaskServiceoldValue = nullnewValue = null;
	boolean changed = false;
	synchronized() {
	    if (!.contains(taskService)) {
		oldValue = copyTaskServices();
		.add(taskService);
		newValue = copyTaskServices();
		changed = true;
	    }
	}
	if (changed) {
	    firePropertyChange("taskServices"oldValuenewValue);
	}
    }
    public void removeTaskService(TaskService taskService) {
	if (taskService == null) {
	    throw new IllegalArgumentException("null taskService");
	}
	List<TaskServiceoldValue = nullnewValue = null;
	boolean changed = false;
	synchronized() {
	    if (.contains(taskService)) {
		oldValue = copyTaskServices();
		.remove(taskService);
		newValue = copyTaskServices();
		changed = true;
	    }
	}
	if (changed) {
	    firePropertyChange("taskServices"oldValuenewValue);
	}
    }
    public TaskService getTaskService(String name) {
	if (name == null) {
	    throw new IllegalArgumentException("null name");
	}
	for(TaskService taskService : ) {
	    if (name.equals(taskService.getName())) {
		return taskService;
	    }
	}
	return null;
    }

    
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(java.lang.String)
    public final TaskService getTaskService() {
	return getTaskService("default");
    }

    
Returns a read-only view of the complete list of TaskServices.

    public List<TaskServicegetTaskServices() {
    }

    
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.
    public final TaskMonitor getTaskMonitor() {
	if ( == null) {
	     = new TaskMonitor(this);
	}
	return ;
    }
New to GrepCode? Check out our FAQ X