KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > editor > suites > abbrevs > Utilities


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.test.editor.suites.abbrevs;
21
22 import org.netbeans.modules.editor.options.BaseOptions;
23 import java.util.ResourceBundle JavaDoc;
24 import org.openide.util.NbBundle;
25 import org.netbeans.modules.editor.options.BaseOptionsBeanInfo;
26 import java.awt.event.KeyEvent JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.Map JavaDoc;
31 //import org.netbeans.modules.editor.options.HTMLOptions; //SPLIT-TEMP
32
//import org.netbeans.modules.editor.options.JavaOptions; //SPLIT-TEMP
33
//import org.netbeans.modules.editor.options.PlainOptions; //SPLIT-TEMP
34
import org.openide.options.SystemOption;
35
36 /**
37  *
38  * @author Jan Lahoda
39  */

40 public class Utilities {
41     
42     
43     /** Creates a new instance of Utilities */
44     public Utilities() {
45     }
46     
47     public static ResourceBundle JavaDoc getEditorBundle() {
48         return NbBundle.getBundle(BaseOptionsBeanInfo.class);
49     }
50     
51     /**Saves abbreviations maps for all editor kits installed. You should not
52      * rely on the particular type returned (currently java.util.Map), but just save the
53      * returned Object and pass it unchanged to restoreAbbreviationsState();
54      */

55     public static Object JavaDoc saveAbbreviationsState() {
56         // SystemOption[] options = ((AllOptions) AllOptions.findObject(AllOptions.class, true)).getOptions(); -- //return null
57
SystemOption[] options = new SystemOption[]{};//SPLIT-TEMP
58
//{(JavaOptions)SystemOption.findObject(JavaOptions.class),
59
//(PlainOptions)SystemOption.findObject(PlainOptions.class),(HTMLOptions)SystemOption.findObject(HTMLOptions.class)};
60

61         Map JavaDoc result = new HashMap JavaDoc();
62         
63         for (int cntr = 0; cntr < options.length; cntr++) {
64             if (options[cntr] instanceof BaseOptions) {
65                 BaseOptions baseOptions = (BaseOptions) options[cntr];
66                 result.put(baseOptions.getClass(), baseOptions.getAbbrevMap());
67             }
68         }
69         return result;
70     }
71     
72     public static void restoreAbbreviationsState(Object JavaDoc state) throws ClassCastException JavaDoc {
73         Map JavaDoc abbreviations = (Map JavaDoc) state; //ClassCastException
74

75         /*Just check, no functionality:
76          */

77         {
78             Iterator JavaDoc it = abbreviations.values().iterator();
79             Map JavaDoc dummy;
80             
81             while (it.hasNext()) {
82                 dummy = (Map JavaDoc) it.next();
83             }
84         }
85         
86         /*The main functionality:
87          */

88         SystemOption[] options = new SystemOption[] {};//SPLIT-TEMP
89
//{(JavaOptions)SystemOption.findObject(JavaOptions.class),
90
//(PlainOptions)SystemOption.findObject(PlainOptions.class),(HTMLOptions)SystemOption.findObject(HTMLOptions.class)};
91

92         // SystemOption[] options = ((AllOptions) AllOptions.findObject(AllOptions.class)).getOptions(); --- //return null
93

94         for (int cntr = 0; cntr < options.length; cntr++) {
95             if (options[cntr] instanceof BaseOptions) {
96                 BaseOptions baseOptions = (BaseOptions) options[cntr];
97                 Map JavaDoc kitAbbreviations = (Map JavaDoc) abbreviations.get(baseOptions.getClass()); //ClassCastException
98

99                 if (kitAbbreviations != null) {
100                     baseOptions.setAbbrevMap(kitAbbreviations);
101                 }
102             }
103         }
104         
105     }
106     
107     public static void main(String JavaDoc[] argv) {
108         Utilities.saveAbbreviationsState();
109     }
110     
111 }
112
Popular Tags