KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > ext > html > HTMLSettingsInitializer


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.editor.ext.html;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Font JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import org.netbeans.editor.Acceptor;
27 import org.netbeans.editor.AcceptorFactory;
28 import org.netbeans.editor.Coloring;
29 import org.netbeans.editor.Settings;
30 import org.netbeans.editor.SettingsNames;
31 import org.netbeans.editor.SettingsDefaults;
32 import org.netbeans.editor.SettingsUtil;
33 import org.netbeans.editor.BaseKit;
34 import org.netbeans.editor.TokenContext;
35 import org.netbeans.editor.TokenContextPath;
36 import org.netbeans.editor.TokenCategory;
37
38 /**
39 * Extended settings provide the settings for the extended editor features
40 * supported by the various classes of this package.
41 *
42 * @author Miloslav Metelka
43 * @version 1.00
44 */

45
46 public class HTMLSettingsInitializer extends Settings.AbstractInitializer {
47
48     private final Class JavaDoc htmlKitClass;
49
50     /** Name assigned to initializer */
51     public static final String JavaDoc NAME = "html-settings-initializer"; // NOI18N
52

53     public static final Acceptor HTML_IDENTIFIER_ACCEPTOR =
54         new Acceptor() {
55             public final boolean accept(char ch) {
56                 return (ch == ':') || AcceptorFactory.JAVA_IDENTIFIER.accept(ch);
57             }
58         };
59
60
61     /** Construct HTML Settings initializer
62     * @param htmlKitClass the real kit class for which the settings are created.
63     * It's unknown here so it must be passed to this constructor.
64     */

65     public HTMLSettingsInitializer(Class JavaDoc htmlKitClass) {
66         super(NAME);
67         this.htmlKitClass = htmlKitClass;
68     }
69
70     /** Update map filled with the settings.
71     * @param kitClass kit class for which the settings are being updated.
72     * It is always non-null value.
73     * @param settingsMap map holding [setting-name, setting-value] pairs.
74     * The map can be empty if this is the first initializer
75     * that updates it or if no previous initializers updated it.
76     */

77     public void updateSettingsMap(Class JavaDoc kitClass, Map JavaDoc settingsMap) {
78
79         if (kitClass == BaseKit.class) {
80
81             new HTMLTokenColoringInitializer().updateSettingsMap(kitClass, settingsMap);
82
83         }
84
85         if (kitClass == htmlKitClass) {
86
87             SettingsUtil.updateListSetting(settingsMap, SettingsNames.TOKEN_CONTEXT_LIST,
88                 new TokenContext[] {
89                     HTMLTokenContext.context
90                 }
91             );
92             
93             settingsMap.put(SettingsNames.IDENTIFIER_ACCEPTOR,
94                             HTML_IDENTIFIER_ACCEPTOR);
95
96             settingsMap.put(HTMLSettingsNames.COMPLETION_LOWER_CASE,
97                             HTMLSettingsDefaults.defaultCompletionLowerCase);
98             
99         }
100
101     }
102
103     static class HTMLTokenColoringInitializer
104     extends SettingsUtil.TokenColoringInitializer {
105
106         Font JavaDoc boldFont = SettingsDefaults.defaultFont.deriveFont(Font.BOLD);
107         Font JavaDoc italicFont = SettingsDefaults.defaultFont.deriveFont(Font.ITALIC);
108         Settings.Evaluator boldSubst = new SettingsUtil.FontStylePrintColoringEvaluator(Font.BOLD);
109         Settings.Evaluator italicSubst = new SettingsUtil.FontStylePrintColoringEvaluator(Font.ITALIC);
110         Settings.Evaluator lightGraySubst = new SettingsUtil.ForeColorPrintColoringEvaluator(Color.lightGray);
111
112         public HTMLTokenColoringInitializer() {
113             super(HTMLTokenContext.context);
114         }
115
116         public Object JavaDoc getTokenColoring(TokenContextPath tokenContextPath,
117         TokenCategory tokenIDOrCategory, boolean printingSet) {
118             if (!printingSet) {
119                 switch (tokenIDOrCategory.getNumericID()) {
120                     case HTMLTokenContext.TEXT_ID:
121                     case HTMLTokenContext.WS_ID:
122                         return SettingsDefaults.emptyColoring;
123
124                     case HTMLTokenContext.ERROR_ID:
125                         return new Coloring(null, Color.white, Color.red);
126
127                     case HTMLTokenContext.TAG_CATEGORY_ID:
128                         return new Coloring(null, Color.blue, null);
129
130                     case HTMLTokenContext.ARGUMENT_ID:
131                         return new Coloring(null, Color.green.darker().darker(), null);
132
133                     case HTMLTokenContext.OPERATOR_ID:
134                         return new Coloring(null, Color.green.darker().darker(), null);
135
136                     case HTMLTokenContext.VALUE_ID:
137                         return new Coloring(null, new Color JavaDoc(153, 0, 107), null);
138
139                     case HTMLTokenContext.BLOCK_COMMENT_ID:
140                         // #48502 - comment changed to non-italic font style
141
return new Coloring(null, Color.gray, null);
142
143                     case HTMLTokenContext.SGML_COMMENT_ID:
144                         return new Coloring( null, Color.gray, null );
145
146                     case HTMLTokenContext.DECLARATION_ID:
147                         return new Coloring(null, new Color JavaDoc(191, 146, 33), null);
148
149                     case HTMLTokenContext.CHARACTER_ID:
150                         return new Coloring(null, Color.red.darker(), null);
151                         
152                 }
153
154             } else { // printing set
155
switch (tokenIDOrCategory.getNumericID()) {
156                     case HTMLTokenContext.BLOCK_COMMENT_ID:
157                     case HTMLTokenContext.SGML_COMMENT_ID:
158                         return lightGraySubst;
159
160                     default:
161                          return SettingsUtil.defaultPrintColoringEvaluator;
162                 }
163
164             }
165
166             return null;
167
168         }
169
170     }
171      
172 }
173
Popular Tags