KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > properties > syntax > RestoreColoring


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.properties.syntax;
21
22 import java.util.MissingResourceException JavaDoc;
23
24 import org.netbeans.editor.LocaleSupport;
25 import org.netbeans.editor.Settings;
26
27 import org.openide.modules.ModuleInstall;
28 import org.openide.text.PrintSettings;
29 import org.openide.util.NbBundle;
30 import org.openide.util.SharedClassObject;
31
32 /**
33  * Instalation class of module properties syntax.
34  *
35  * @author Petr Jiricka, Libor Kramolis, Jesse Glick
36  */

37 public class RestoreColoring extends ModuleInstall {
38
39     /** <code>Localizer</code> passed to editor. */
40     private static LocaleSupport.Localizer localizer;
41
42     /** Registers properties editor, installs options and copies settings. Overrides superclass method. */
43     public void restored() {
44         addInitializer();
45         installOptions();
46     }
47
48     /** Uninstalls properties options. And cleans up editor settings copy. Overrides superclass method. */
49     public void uninstalled() {
50         uninstallOptions();
51     }
52
53     /** Adds initializer and registers editor kit. */
54     public void addInitializer() {
55         Settings.addInitializer(new PropertiesSettingsInitializer());
56     }
57
58     /** Installs properties editor and print options. */
59     public void installOptions() {
60         PrintSettings printSettings = (PrintSettings)SharedClassObject.findObject(PrintSettings.class, true);
61         printSettings.addOption((PropertiesPrintOptions)SharedClassObject.findObject(PropertiesPrintOptions.class, true));
62         
63         
64         // Adds localizer.
65
LocaleSupport.addLocalizer(localizer = new LocaleSupport.Localizer() {
66             public String JavaDoc getString(String JavaDoc key) {
67                 try {
68                     return NbBundle.getBundle(RestoreColoring.class).getString(key);
69                 } catch(MissingResourceException JavaDoc mre) {
70                     return null;
71                 }
72             }
73         });
74     }
75
76     /** Uninstalls properties editor and print options. */
77     public void uninstallOptions() {
78         PropertiesPrintOptions propertiesPrintOptions = (PropertiesPrintOptions)SharedClassObject.findObject(PropertiesPrintOptions.class, false);
79         if(propertiesPrintOptions != null) {
80             PrintSettings printSettings = (PrintSettings)SharedClassObject.findObject(PrintSettings.class, true);
81             printSettings.removeOption(propertiesPrintOptions);
82         }
83         
84         // remove localizer
85
LocaleSupport.removeLocalizer(localizer);
86     }
87     
88 }
89
Popular Tags