FileDocCategorySizeDatePackage
LazyActionMap.javaAPI DocJava SE 5 API4570Fri Aug 26 14:58:06 BST 2005javax.swing.plaf.basic

LazyActionMap

public class LazyActionMap extends ActionMapUIResource
An ActionMap that populates its contents as necessary. The contents are populated by invoking the loadActionMap method on the passed in Object.
version
1.5, 12/19/03
author
Scott Violet

Fields Summary
private transient Object
_loader
Object to invoke loadActionMap on. This may be a Class object.
Constructors Summary
private LazyActionMap(Class loader)

        _loader = loader;
    
Methods Summary
public java.lang.Object[]allKeys()

        loadIfNecessary();
        return super.allKeys();
    
public voidclear()

        loadIfNecessary();
        super.clear();
    
public javax.swing.Actionget(java.lang.Object key)

        loadIfNecessary();
        return super.get(key);
    
static javax.swing.ActionMapgetActionMap(java.lang.Class loaderClass, java.lang.String defaultsKey)
Returns an ActionMap that will be populated by invoking the loadActionMap method on the specified Class when necessary.

This should be used if the ActionMap can be shared.

param
c JComponent to install the ActionMap on.
param
loaderClass Class object that gets loadActionMap invoked on.
param
defaultsKey Key to use to defaults table to check for existing map and what resulting Map will be registered on.

        ActionMap map = (ActionMap)UIManager.get(defaultsKey);
        if (map == null) {
            map = new LazyActionMap(loaderClass);
            UIManager.getLookAndFeelDefaults().put(defaultsKey, map);
        }
        return map;
    
static voidinstallLazyActionMap(javax.swing.JComponent c, java.lang.Class loaderClass, java.lang.String defaultsKey)
Installs an ActionMap that will be populated by invoking the loadActionMap method on the specified Class when necessary.

This should be used if the ActionMap can be shared.

param
c JComponent to install the ActionMap on.
param
loaderClass Class object that gets loadActionMap invoked on.
param
defaultsKey Key to use to defaults table to check for existing map and what resulting Map will be registered on.

        ActionMap map = (ActionMap)UIManager.get(defaultsKey);
        if (map == null) {
            map = new LazyActionMap(loaderClass);
            UIManager.getLookAndFeelDefaults().put(defaultsKey, map);
        }
        SwingUtilities.replaceUIActionMap(c, map);
    
public java.lang.Object[]keys()

        loadIfNecessary();
        return super.keys();
    
private voidloadIfNecessary()

        if (_loader != null) {
            Object loader = _loader;

            _loader = null;
            Class klass = (Class)loader;
            try {
                Method method = klass.getDeclaredMethod("loadActionMap",
                                      new Class[] { LazyActionMap.class });
                method.invoke(klass, new Object[] { this });
            } catch (NoSuchMethodException nsme) {
                assert false : "LazyActionMap unable to load actions " +
                        klass;
            } catch (IllegalAccessException iae) {
                assert false : "LazyActionMap unable to load actions " +
                        iae;
            } catch (InvocationTargetException ite) {
                assert false : "LazyActionMap unable to load actions " +
                        ite;
            } catch (IllegalArgumentException iae) {
                assert false : "LazyActionMap unable to load actions " +
                        iae;
            }
        }
    
public voidput(javax.swing.Action action)

        put(action.getValue(Action.NAME), action);
    
public voidput(java.lang.Object key, javax.swing.Action action)

        loadIfNecessary();
        super.put(key, action);
    
public voidremove(java.lang.Object key)

        loadIfNecessary();
        super.remove(key);
    
public voidsetParent(javax.swing.ActionMap map)

        loadIfNecessary();
        super.setParent(map);
    
public intsize()

        loadIfNecessary();
        return super.size();