KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > text > syntax > XMLOptions


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 package org.netbeans.modules.xml.text.syntax;
20
21 import java.util.*;
22 import org.netbeans.editor.ext.ExtSettingsNames;
23 import org.netbeans.modules.editor.NbEditorUtilities;
24 import org.netbeans.modules.xml.text.indent.XMLIndentEngine;
25 import org.netbeans.modules.xml.text.api.XMLDefaultTokenContext;
26
27
28 /**
29  * Options for the xml editor kit
30  *
31  * @author Libor Kramolis
32  * @version 0.1
33  */

34 public class XMLOptions extends AbstractBaseOptions {
35     /** Serial Version UID */
36     private static final long serialVersionUID = 2347735706857337892L;
37
38     public static final String JavaDoc COMPLETION_AUTO_POPUP_PROP = "completionAutoPopup"; // NOI18N
39

40     public static final String JavaDoc COMPLETION_AUTO_POPUP_DELAY_PROP = "completionAutoPopupDelay"; // NOI18N
41

42     public static final String JavaDoc COMPLETION_INSTANT_SUBSTITUTION_PROP = "completionInstantSubstitution"; // NOI18N
43

44     static final String JavaDoc[] XML_PROP_NAMES = new String JavaDoc[] {
45                                                 COMPLETION_AUTO_POPUP_PROP,
46                                                 COMPLETION_AUTO_POPUP_DELAY_PROP,
47                                                 COMPLETION_INSTANT_SUBSTITUTION_PROP,
48                                             };
49     
50     //
51
// init
52
//
53

54     /** */
55     public XMLOptions () {
56         super (XMLKit.class, "xml"); // NOI18N
57
}
58
59     protected Class JavaDoc getDefaultIndentEngineClass () {
60         return XMLIndentEngine.class;
61     }
62     
63     public boolean getCompletionAutoPopup() {
64         return getSettingBoolean(ExtSettingsNames.COMPLETION_AUTO_POPUP);
65     }
66
67     public void setCompletionAutoPopup(boolean v) {
68         setSettingBoolean(ExtSettingsNames.COMPLETION_AUTO_POPUP, v, COMPLETION_AUTO_POPUP_PROP);
69     }
70
71     public int getCompletionAutoPopupDelay() {
72         return getSettingInteger(ExtSettingsNames.COMPLETION_AUTO_POPUP_DELAY);
73     }
74
75     public void setCompletionAutoPopupDelay(int delay) {
76         if (delay < 0) {
77             NbEditorUtilities.invalidArgument("MSG_NegativeValue"); // NOI18N
78
return;
79         }
80         setSettingInteger(ExtSettingsNames.COMPLETION_AUTO_POPUP_DELAY, delay,
81             COMPLETION_AUTO_POPUP_DELAY_PROP);
82     }
83
84     public boolean getCompletionInstantSubstitution() {
85         return getSettingBoolean(ExtSettingsNames.COMPLETION_INSTANT_SUBSTITUTION);
86     }
87     
88     public void setCompletionInstantSubstitution(boolean v) {
89         setSettingBoolean(ExtSettingsNames.COMPLETION_INSTANT_SUBSTITUTION, v,
90             COMPLETION_INSTANT_SUBSTITUTION_PROP);
91     }
92     
93     // remap old XMLTokenContext to new XMLDefaultTokenContext
94
// commented out match by name
95
private static final String JavaDoc[][] TRANSLATE_COLORS = {
96 // { "xml-comment", "xml-comment" },
97
// { "xml-ref", "xml-ref" },
98
{ "xml-string", "xml-value" },
99 // { "xml-attribute", "xml-attribute" },
100
{ "xml-symbol", "xml-operator" },
101 // { "xml-tag", "xml-tag" },
102
{ "xml-keyword", "xml-doctype" },
103         { "xml-plain", "xml-text"},
104     };
105     
106     /**
107      * Get coloring, possibly remap setting from previous versions
108      * to new one.
109      */

110     public Map getColoringMap() {
111         Map colors = super.getColoringMap();
112         
113         synchronized (this) {
114             // get old customized colors and map them to new token IDs
115
// the map will contain only such old colors that was customized AFAIK
116
// because current initializer does not create them
117

118             for (int i = 0; i<TRANSLATE_COLORS.length; i++) {
119                 String JavaDoc oldKey = TRANSLATE_COLORS[i][0];
120                 Object JavaDoc color = colors.get(oldKey);
121                 if (color != null) {
122                     colors.remove(oldKey);
123                     String JavaDoc newKey = TRANSLATE_COLORS[i][1];
124                     colors.put(newKey, color);
125                 }
126             }
127             
128             // do not save it explicitly if the user will do a customization
129
// it get saved automatically (i.e.old keys removal will apply)
130

131             return colors;
132         }
133     }
134 }
135
Popular Tags