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