KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javahelp > Installer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.javahelp;
21
22 import java.util.ConcurrentModificationException JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Set JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28 import javax.swing.UIDefaults JavaDoc;
29 import javax.swing.UIManager JavaDoc;
30 import org.netbeans.api.javahelp.Help;
31 import org.openide.modules.ModuleInstall;
32
33 public class Installer extends ModuleInstall {
34
35     public static final Logger JavaDoc log = Logger.getLogger("org.netbeans.modules.javahelp"); // NOI18N
36

37     public void restored() {
38         log.fine("restored module");
39         // This ensures the static block will be called ASAP, hence that
40
// the AWT listener will actually be started quickly and there
41
// will already have been interesting mouse-entered events
42
// by the time F1 is first pressed. Otherwise only the second
43
// F1 actually gets anything other than the main window help.
44
HelpAction.WindowActivatedDetector.install();
45
46         // XXX(-ttran) quick fix for #25470: Help viewer frozen on first open
47
// over modal dialogs. JavaHelp seems to try to be lazy with the
48
// installation of its Dialog detector (an AWTEventListener) but it
49
// doesn't work on Windows. Here we force JavaHelp instance to be
50
// created and thus its AWTEventListener be registered early enough.
51

52         getDefaultHelp();
53     }
54     
55     public void uninstalled() {
56         log.fine("uninstalled module");
57         if (help != null) {
58             help.deactivate();
59         }
60         HelpAction.WindowActivatedDetector.uninstall();
61         // UIManager is too aggressive about caching, and we get CCE's,
62
// since JavaHelp's HelpUtilities sets up these defaults, and UIManager
63
// caches the actual classes (probably incorrectly). #4675772
64
cleanDefaults(UIManager.getDefaults());
65         cleanDefaults(UIManager.getLookAndFeelDefaults());
66     }
67     private static void cleanDefaults(UIDefaults JavaDoc d) {
68         Set JavaDoc<Object JavaDoc> badKeys = new HashSet JavaDoc<Object JavaDoc>(10);
69         Iterator JavaDoc<Map.Entry JavaDoc<Object JavaDoc, Object JavaDoc>> it = d.entrySet().iterator();
70         ClassLoader JavaDoc aboutToDie = Installer.class.getClassLoader();
71         while (it.hasNext()) {
72             Map.Entry JavaDoc<Object JavaDoc, Object JavaDoc> e;
73             try {
74                 e = it.next();
75             } catch (ConcurrentModificationException JavaDoc x) {
76                 // Seems to be possible during shutdown. Just skip the hack in this case.
77
return;
78             }
79             Object JavaDoc k = e.getKey();
80             Object JavaDoc o = e.getValue();
81             if (o instanceof Class JavaDoc) {
82                 Class JavaDoc c = (Class JavaDoc)o;
83                 if (c.getClassLoader() == aboutToDie) {
84                     badKeys.add(k);
85                 }
86             } else if (k instanceof Class JavaDoc) {
87                 Class JavaDoc c = (Class JavaDoc)k;
88                 if (c.getClassLoader() == aboutToDie) {
89                     badKeys.add(k);
90                 }
91             }
92         }
93         if (!badKeys.isEmpty()) {
94             log.fine("Cleaning up old UIDefaults keys (JRE bug #4675772): " + badKeys);
95             for (Object JavaDoc o: badKeys) {
96                 d.put(o, null);
97             }
98         }
99     }
100     
101     private static JavaHelp help = null;
102     /** @deprecated only for use from the layer */
103     public static synchronized Help getDefaultHelp() {
104         // Does not work to use Lookup: help set processors called too early.
105
if (help == null) {
106             help = new JavaHelp();
107         }
108         return help;
109     }
110
111 }
112
Popular Tags