001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.javahelp;
043:
044: import java.util.ConcurrentModificationException;
045: import java.util.HashSet;
046: import java.util.Iterator;
047: import java.util.Map;
048: import java.util.Set;
049: import java.util.logging.Logger;
050: import javax.swing.UIDefaults;
051: import javax.swing.UIManager;
052: import org.netbeans.api.javahelp.Help;
053: import org.openide.modules.ModuleInstall;
054:
055: public class Installer extends ModuleInstall {
056:
057: public static final Logger log = Logger
058: .getLogger("org.netbeans.modules.javahelp"); // NOI18N
059: public static final Logger UI = Logger
060: .getLogger("org.netbeans.ui.javahelp"); // NOI18N
061:
062: public void restored() {
063: log.fine("restored module");
064: // This ensures the static block will be called ASAP, hence that
065: // the AWT listener will actually be started quickly and there
066: // will already have been interesting mouse-entered events
067: // by the time F1 is first pressed. Otherwise only the second
068: // F1 actually gets anything other than the main window help.
069: HelpAction.WindowActivatedDetector.install();
070:
071: // XXX(-ttran) quick fix for #25470: Help viewer frozen on first open
072: // over modal dialogs. JavaHelp seems to try to be lazy with the
073: // installation of its Dialog detector (an AWTEventListener) but it
074: // doesn't work on Windows. Here we force JavaHelp instance to be
075: // created and thus its AWTEventListener be registered early enough.
076:
077: getDefaultHelp();
078: }
079:
080: public void uninstalled() {
081: log.fine("uninstalled module");
082: if (help != null) {
083: help.deactivate();
084: }
085: HelpAction.WindowActivatedDetector.uninstall();
086: // UIManager is too aggressive about caching, and we get CCE's,
087: // since JavaHelp's HelpUtilities sets up these defaults, and UIManager
088: // caches the actual classes (probably incorrectly). #4675772
089: cleanDefaults(UIManager.getDefaults());
090: cleanDefaults(UIManager.getLookAndFeelDefaults());
091: }
092:
093: private static void cleanDefaults(UIDefaults d) {
094: Set<Object> badKeys = new HashSet<Object>(10);
095: Iterator<Map.Entry<Object, Object>> it = d.entrySet()
096: .iterator();
097: ClassLoader aboutToDie = Installer.class.getClassLoader();
098: while (it.hasNext()) {
099: Map.Entry<Object, Object> e;
100: try {
101: e = it.next();
102: } catch (ConcurrentModificationException x) {
103: // Seems to be possible during shutdown. Just skip the hack in this case.
104: return;
105: }
106: Object k = e.getKey();
107: Object o = e.getValue();
108: if (o instanceof Class) {
109: Class c = (Class) o;
110: if (c.getClassLoader() == aboutToDie) {
111: badKeys.add(k);
112: }
113: } else if (k instanceof Class) {
114: Class c = (Class) k;
115: if (c.getClassLoader() == aboutToDie) {
116: badKeys.add(k);
117: }
118: }
119: }
120: if (!badKeys.isEmpty()) {
121: log
122: .fine("Cleaning up old UIDefaults keys (JRE bug #4675772): "
123: + badKeys);
124: for (Object o : badKeys) {
125: d.put(o, null);
126: }
127: }
128: }
129:
130: private static JavaHelp help = null;
131:
132: /** @deprecated only for use from the layer */
133: public static synchronized Help getDefaultHelp() {
134: // Does not work to use Lookup: help set processors called too early.
135: if (help == null) {
136: help = new JavaHelp();
137: }
138: return help;
139: }
140:
141: }
|