2 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
27 import jsjavax.swing.Action;
28 import jsjavax.swing.ActionMap;
29 import jsjavax.swing.JComponent;
30 import jsjavax.swing.SwingUtilities;
31 import jsjavax.swing.UIManager;
32 import jsjavax.swing.plaf.ActionMapUIResource;
35 * An ActionMap that populates its contents as necessary. The
36 * contents are populated by invoking the <code>loadActionMap</code>
37 * method on the passed in Object.
39 * @author Scott Violet
41 class LazyActionMap extends ActionMapUIResource {
43 * Object to invoke <code>loadActionMap</code> on. This may be
46 private transient Object _loader;
49 * Installs an ActionMap that will be populated by invoking the
50 * <code>loadActionMap</code> method on the specified Class
53 * This should be used if the ActionMap can be shared.
55 * @param c JComponent to install the ActionMap on.
56 * @param loaderClass Class object that gets loadActionMap invoked
58 * @param defaultsKey Key to use to defaults table to check for
59 * existing map and what resulting Map will be registered on.
61 static void installLazyActionMap(JComponent c, Class loaderClass,
63 ActionMap map = (ActionMap)UIManager.get(defaultsKey);
65 map = new LazyActionMap(loaderClass);
66 // UIManager.getLookAndFeelDefaults().put(defaultsKey, map);
68 SwingUtilities.replaceUIActionMap(c, map);
72 * Returns an ActionMap that will be populated by invoking the
73 * <code>loadActionMap</code> method on the specified Class
76 * This should be used if the ActionMap can be shared.
78 * @param c JComponent to install the ActionMap on.
79 * @param loaderClass Class object that gets loadActionMap invoked
81 * @param defaultsKey Key to use to defaults table to check for
82 * existing map and what resulting Map will be registered on.
84 static ActionMap getActionMap(Class loaderClass,
86 ActionMap map = (ActionMap)UIManager.get(defaultsKey);
88 map = new LazyActionMap(loaderClass);
89 //SwingJS temp UIManager.getLookAndFeelDefaults().put(defaultsKey, map);
95 private LazyActionMap(Class loader) {
99 public void put(Action action) {
100 put(action.getValue(Action.NAME), action);
103 public void put(Object key, Action action) {
105 super.put(key, action);
108 public Action get(Object key) {
110 return super.get(key);
113 public void remove(Object key) {
118 public void clear() {
123 public Object[] keys() {
133 public Object[] allKeys() {
135 return super.allKeys();
138 public void setParent(ActionMap map) {
140 super.setParent(map);
143 private void loadIfNecessary() {
144 if (_loader != null) {
148 * this._loader.loadActionMap(this);
149 * this._loader = null;
152 // Object loader = _loader;
155 // Class klass = (Class)loader;
157 // Method method = klass.getDeclaredMethod("loadActionMap",
158 // new Class[] { LazyActionMap.class });
159 // method.invoke(klass, new Object[] { this });
160 // } catch (NoSuchMethodException nsme) {
161 // assert false : "LazyActionMap unable to load actions " +
163 // } catch (IllegalAccessException iae) {
164 // assert false : "LazyActionMap unable to load actions " +
166 // } catch (InvocationTargetException ite) {
167 // assert false : "LazyActionMap unable to load actions " +
169 // } catch (IllegalArgumentException iae) {
170 // assert false : "LazyActionMap unable to load actions " +