KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > gsf > browser > ModuleInstaller


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.gsf.browser;
21
22 import javax.swing.event.ChangeEvent JavaDoc;
23 import javax.swing.event.ChangeListener JavaDoc;
24 import javax.swing.text.JTextComponent JavaDoc;
25 import org.netbeans.editor.Registry;
26 import org.openide.modules.ModuleInstall;
27
28 /**
29  * (From the stripwhitespace module's ModuleInstaller)
30  * @author Andrei Badea
31  */

32 public class ModuleInstaller extends ModuleInstall {
33
34     // prevent the listener from begin GCd (Registry holds the listeners weakly)
35
private static ChangeListener JavaDoc listener;
36
37     public void restored() {
38         assert listener == null;
39         listener = new ChangeListener JavaDoc() {
40             public void stateChanged(ChangeEvent JavaDoc e) {
41                 HighlightSections.getDefault().install(Registry.getMostActiveComponent());
42             }
43         };
44         Registry.addChangeListener(listener);
45
46         // we need to install the highlighting in the active component when the module
47
// is installed/enabled through Module Manager/Update Center
48
JTextComponent JavaDoc component = Registry.getMostActiveComponent();
49         if (component != null) {
50             HighlightSections.getDefault().install(component);
51         }
52     }
53
54     public void uninstalled() {
55         Registry.removeChangeListener(listener);
56         listener = null;
57         HighlightSections.getDefault().uninstall();
58     }
59 }
60
Popular Tags