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;
The application's ActionManager provides read-only cached access to ActionMaps that contain one entry for each method marked with the @Action annotation in a class.

 public class ActionManager extends AbstractBean {
     private static final Logger logger = Logger.getLogger(ActionManager.class.getName());
     private final ApplicationContext context;
     private ApplicationActionMap globalActionMap = null;
     protected ActionManager(ApplicationContext context) {
         if (context == null) {
             throw new IllegalArgumentException("null context");
         this. = context;
     protected final ApplicationContext getContext() {
         return ;
             Class startClassClass stopClassObject actionsObjectResourceMap resourceMap) {
         // All of the classes from stopClass to startClass, inclusive. 
     	List<Classclasses = new ArrayList<Class>();
 	for(Class c = startClass;  ; c = c.getSuperclass()) {
             if (c.equals(stopClass)) { break; }
         // Create the ActionMap chain, one per class
         ApplicationContext ctx = getContext();
         ApplicationActionMap parent = null;
         for(Class cls : classes) {
             ApplicationActionMap appAM = new ApplicationActionMap(ctxclsactionsObjectresourceMap);
             parent = appAM;
         return parent;

The ActionMap chain for the entire Application.

Returns an ActionMap with the @Actions defined in the application's Application subclass, i.e. the the value of:

The remainder of the chain contains one ActionMap for each superclass, up to Application.class. The ActionMap.get() method searches the entire chain, so logically, the ActionMap that this method returns contains all of the application-global actions.

The value returned by this method is cached.

     public ApplicationActionMap getActionMap() {
 	if ( == null) {
 	    ApplicationContext ctx = getContext();
 	    Object appObject = ctx.getApplication();
 	    Class appClass = ctx.getApplicationClass();
            ResourceMap resourceMap = ctx.getResourceMap();
	     = createActionMapChain(appClassApplication.classappObjectresourceMap);
	    initProxyActionSupport();  // lazy initialization
    private void initProxyActionSupport() {
        KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();

Returns the ApplicationActionMap chain for the specified actions class and target object.

The specified class can contain methods marked with the @Action annotation. Each one will be turned into an ApplicationAction object and all of them will be added to a single ApplicationActionMap. All of the ApplicationActions invoke their actionPerformed method on the specified actionsObject. The parent of the returned ActionMap is the global ActionMap that contains the @Actions defined in this application's Application subclass.

To bind an @Action to a Swing component, one specifies the @Action's name in an expression like this:

 ApplicationContext ctx = Application.getInstance(MyApplication.class).getContext();
 MyActions myActions = new MyActions();

The value returned by this method is cached. The lifetime of the cached entry will be the same as the lifetime of the actionsObject and the ApplicationActionMap and ApplicationActions that refer to it. In other words, if you drop all references to the actionsObject, including its ApplicationActions and their ApplicationActionMaps, then the cached ActionMap entry will be cleared.

    public ApplicationActionMap getActionMap(Class actionsClassObject actionsObject) {
	if (actionsClass == null) {
	    throw new IllegalArgumentException("null actionsClass");
	if (actionsObject == null) {
	    throw new IllegalArgumentException("null actionsObject");
        if (!actionsClass.isAssignableFrom(actionsObject.getClass())) {  
	    throw new IllegalArgumentException("actionsObject not instanceof actionsClass");
	synchronized() {
	    WeakReference<ApplicationActionMapref = .get(actionsObject);
	    ApplicationActionMap classActionMap = (ref != null) ? ref.get() : null;
	    if ((classActionMap == null) || (classActionMap.getActionsClass() != actionsClass)) {
                ApplicationContext ctx = getContext();
                Class actionsObjectClass = actionsObject.getClass();
                ResourceMap resourceMap = ctx.getResourceMap(actionsObjectClassactionsClass);
                classActionMap = createActionMapChain(actionsObjectClassactionsClassactionsObjectresourceMap);
                ActionMap lastActionMap = classActionMap
                while(lastActionMap.getParent() != null) {
                    lastActionMap = lastActionMap.getParent();
		.put(actionsObjectnew WeakReference(classActionMap));
	    return classActionMap;
    private final class KeyboardFocusPCL implements PropertyChangeListener {
	private final TextActions textActions;
	     = new TextActions(getContext());
	    if (e.getPropertyName() == "permanentFocusOwner") {
		Object newValue = e.getNewValue();
		JComponent newOwner = (newValue instanceof JComponent) ? (JComponent)newValue : null;
    /* For each proxyAction in each ApplicationActionMap, if
     * the newFocusOwner's ActionMap includes an Action with the same
     * name then bind the proxyAction to it, otherwise set the proxyAction's 
     * proxyBinding to null.  [TBD: synchronize access to actionMaps]
    private void updateAllProxyActions(JComponent oldFocusOwnerJComponent newFocusOwner) {
	if (newFocusOwner != null) {
	    ActionMap ownerActionMap = newFocusOwner.getActionMap();
	    if (ownerActionMap != null) {
		updateProxyActions(getActionMap(), ownerActionMapnewFocusOwner);
		    ApplicationActionMap appAM = appAMRef.get();
		    if (appAM == null) {
    /* For each proxyAction in appAM: if there's an action with the same
     * name in the focusOwner's ActionMap, then set the proxyAction's proxy
     * to the matching Action.  In other words: calls to the proxyAction
     * (actionPerformed) will delegate to the matching Action.
    private void updateProxyActions(ApplicationActionMap appAMActionMap ownerActionMapJComponent focusOwner) {
	for(ApplicationAction proxyAction : appAM.getProxyActions()) {
	    String proxyActionName = proxyAction.getName();
	    javax.swing.Action proxy = ownerActionMap.get(proxyActionName);
	    if (proxy != null) {
	    else {
New to GrepCode? Check out our FAQ X