1 19 20 package org.netbeans.modules.javahelp; 21 22 import java.util.ConcurrentModificationException ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.Map ; 26 import java.util.Set ; 27 import java.util.logging.Logger ; 28 import javax.swing.UIDefaults ; 29 import javax.swing.UIManager ; 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 log = Logger.getLogger("org.netbeans.modules.javahelp"); 37 public void restored() { 38 log.fine("restored module"); 39 HelpAction.WindowActivatedDetector.install(); 45 46 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 cleanDefaults(UIManager.getDefaults()); 65 cleanDefaults(UIManager.getLookAndFeelDefaults()); 66 } 67 private static void cleanDefaults(UIDefaults d) { 68 Set <Object > badKeys = new HashSet <Object >(10); 69 Iterator <Map.Entry <Object , Object >> it = d.entrySet().iterator(); 70 ClassLoader aboutToDie = Installer.class.getClassLoader(); 71 while (it.hasNext()) { 72 Map.Entry <Object , Object > e; 73 try { 74 e = it.next(); 75 } catch (ConcurrentModificationException x) { 76 return; 78 } 79 Object k = e.getKey(); 80 Object o = e.getValue(); 81 if (o instanceof Class ) { 82 Class c = (Class )o; 83 if (c.getClassLoader() == aboutToDie) { 84 badKeys.add(k); 85 } 86 } else if (k instanceof Class ) { 87 Class c = (Class )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 o: badKeys) { 96 d.put(o, null); 97 } 98 } 99 } 100 101 private static JavaHelp help = null; 102 103 public static synchronized Help getDefaultHelp() { 104 if (help == null) { 106 help = new JavaHelp(); 107 } 108 return help; 109 } 110 111 } 112 | Popular Tags |