KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > sql > editor > SQLSettingsInitializer


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.db.sql.editor;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Font JavaDoc;
24 import java.util.Map JavaDoc;
25 import javax.swing.JEditorPane JavaDoc;
26 import javax.swing.JFrame JavaDoc;
27 import javax.swing.JScrollPane JavaDoc;
28 import org.netbeans.editor.Acceptor;
29 import org.netbeans.editor.AcceptorFactory;
30 import org.netbeans.editor.BaseKit;
31 import org.netbeans.editor.Coloring;
32 import org.netbeans.editor.Settings;
33 import org.netbeans.editor.SettingsDefaults;
34 import org.netbeans.editor.SettingsNames;
35 import org.netbeans.editor.SettingsUtil;
36 import org.netbeans.editor.TokenCategory;
37 import org.netbeans.editor.TokenContext;
38 import org.netbeans.editor.TokenContextPath;
39 import org.openide.util.NbBundle;
40
41 /**
42  * Initializes the SQL Settings
43  *
44  * @author Jesse Beaumont, Andrei Badea
45  */

46 public class SQLSettingsInitializer extends Settings.AbstractInitializer {
47
48     public static final String JavaDoc NAME = "sql-settings-initializer"; // NOI18N
49

50     /**
51      * Constructor
52      */

53     public SQLSettingsInitializer() {
54         super(NAME);
55     }
56
57    /**
58     * Update map filled with the settings.
59     * @param kitClass kit class for which the settings are being updated.
60     * It is always non-null value.
61     * @param settingsMap map holding [setting-name, setting-value] pairs.
62     * The map can be empty if this is the first initializer
63     * that updates it or if no previous initializers updated it.
64     */

65     public void updateSettingsMap(Class JavaDoc kitClass, Map JavaDoc settingsMap) {
66         if (kitClass == BaseKit.class) {
67             new SQLTokenColoringInitializer().updateSettingsMap(kitClass, settingsMap);
68         }
69
70         if (kitClass == SQLEditorKit.class) {
71             SettingsUtil.updateListSetting(
72                     settingsMap,
73                     SettingsNames.TOKEN_CONTEXT_LIST,
74                     new TokenContext[] { SQLTokenContext.context }
75             );
76         }
77     }
78     
79     /**
80      * Class for adding syntax coloring to the editor
81      */

82     static class SQLTokenColoringInitializer extends SettingsUtil.TokenColoringInitializer {
83
84         Font JavaDoc boldFont = SettingsDefaults.defaultFont.deriveFont(Font.BOLD);
85         Settings.Evaluator lightGraySubst =
86                 new SettingsUtil.ForeColorPrintColoringEvaluator(Color.lightGray);
87
88         /**
89          * Constructor
90          */

91         public SQLTokenColoringInitializer() {
92             super(SQLTokenContext.context);
93         }
94
95         /**
96          * Get colors for the SQL tokens
97          */

98         public Object JavaDoc getTokenColoring(
99                 TokenContextPath tokenContextPath,
100                 TokenCategory tokenIDOrCategory,
101                 boolean printingSet) {
102             // get the ones for non printing selecting some sensible defaults
103
if (!printingSet) {
104                 int id = tokenIDOrCategory.getNumericID();
105                 switch (id) {
106                     case SQLTokenContext.WHITESPACE_ID:
107                         return SettingsDefaults.emptyColoring;
108                     case SQLTokenContext.LINE_COMMENT_ID:
109                         return new Coloring(
110                                 null,
111                                 Color.gray,
112                                 null);
113                     case SQLTokenContext.BLOCK_COMMENT_ID:
114                         return new Coloring(
115                                 null,
116                                 Color.gray,
117                                 null);
118                     case SQLTokenContext.STRING_ID:
119                         return new Coloring(
120                                 null,
121                                 new Color JavaDoc(153, 0, 107),
122                                 null);
123                     case SQLTokenContext.IDENTIFIER_ID:
124                         return new Coloring(
125                                 null,
126                                 Color.blue,
127                                 null);
128                     case SQLTokenContext.OPERATOR_ID:
129                         return new Coloring(
130                                 null,
131                                 Color.black,
132                                 null);
133                     case SQLTokenContext.DOT_ID:
134                         return new Coloring(
135                                 null,
136                                 Color.black,
137                                 null);
138                     case SQLTokenContext.INT_LITERAL_ID:
139                     case SQLTokenContext.DOUBLE_LITERAL_ID:
140                         return new Coloring(
141                                 null,
142                                 new Color JavaDoc(120, 0, 0),
143                                 null);
144                     case SQLTokenContext.KEYWORD_ID:
145                         return new Coloring(
146                                 boldFont,
147                                 Coloring.FONT_MODE_APPLY_STYLE,
148                                 Color.blue.darker().darker(),
149                                 null);
150                     case SQLTokenContext.ERRORS_ID:
151                         return new Coloring(
152                                 null,
153                                 Color.black,
154                                 Color.pink);
155                 }
156
157             } else {
158                 // get the set for printing (no color)
159
switch (tokenIDOrCategory.getNumericID()) {
160                     case SQLTokenContext.BLOCK_COMMENT_ID:
161                     case SQLTokenContext.LINE_COMMENT_ID:
162                         return lightGraySubst;
163
164                     default:
165                          return SettingsUtil.defaultPrintColoringEvaluator;
166                 }
167             }
168             
169             return null;
170         }
171     }
172 }
173
Popular Tags