KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > example > PropertiesSettingsInitializer


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.example;
21
22 import java.awt.Font JavaDoc;
23 import java.awt.Color JavaDoc;
24 import java.awt.SystemColor JavaDoc;
25 import java.util.*;
26
27 import org.netbeans.editor.Settings;
28 import org.netbeans.editor.SettingsNames;
29 import org.netbeans.editor.SettingsUtil;
30 import org.netbeans.editor.Coloring;
31 import org.netbeans.editor.SettingsDefaults;
32 import org.netbeans.editor.Syntax;
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 import org.netbeans.modules.properties.syntax.*;
38
39
40 public class PropertiesSettingsInitializer extends Settings.AbstractInitializer {
41
42     /** Name assigned to initializer */
43     public static final String JavaDoc NAME = "properties-settings-initializer"; // NOI18N
44
private Class JavaDoc propertiesClass;
45
46     public PropertiesSettingsInitializer( Class JavaDoc propertiesClass ) {
47         super(NAME);
48         this.propertiesClass = propertiesClass;
49     }
50
51     public void updateSettingsMap (Class JavaDoc kitClass, Map settingsMap) {
52         
53         // Properties colorings
54
if (kitClass == BaseKit.class) {
55             new PropertiesTokenColoringInitializer().updateSettingsMap(kitClass, settingsMap);
56
57         }
58
59         if (kitClass == propertiesClass) {
60             settingsMap.put (org.netbeans.editor.SettingsNames.ABBREV_MAP, getPropertiesAbbrevMap());
61
62             SettingsUtil.updateListSetting(settingsMap, SettingsNames.TOKEN_CONTEXT_LIST,
63                 new TokenContext[] {
64                     PropertiesTokenContext.context
65                 }
66             );
67
68         }
69
70     }
71
72
73     Map getPropertiesAbbrevMap() {
74         Map propertiesAbbrevMap = new TreeMap ();
75         return propertiesAbbrevMap;
76     }
77
78     static class PropertiesTokenColoringInitializer
79     extends SettingsUtil.TokenColoringInitializer {
80
81         Font JavaDoc boldFont = SettingsDefaults.defaultFont.deriveFont(Font.BOLD);
82         Font JavaDoc italicFont = SettingsDefaults.defaultFont.deriveFont(Font.ITALIC);
83
84         Coloring emptyColoring = new Coloring(null, null, null);
85         Coloring commentColoring = new Coloring(italicFont, Coloring.FONT_MODE_APPLY_STYLE,
86                             Color.gray, null);
87
88         Coloring numbersColoring = new Coloring(null, Color.red, null);
89
90         public PropertiesTokenColoringInitializer() {
91             super(PropertiesTokenContext.context);
92         }
93
94         public Object JavaDoc getTokenColoring(TokenContextPath tokenContextPath,
95         TokenCategory tokenIDOrCategory, boolean printingSet) {
96
97             if (!printingSet) {
98                 switch (tokenIDOrCategory.getNumericID()) {
99                     case PropertiesTokenContext.KEY_ID:
100                         return new Coloring(boldFont, Coloring.FONT_MODE_APPLY_STYLE,
101                                 Color.blue, null);
102
103                     case PropertiesTokenContext.EQ_ID:
104                     case PropertiesTokenContext.TEXT_ID:
105                         return emptyColoring;
106
107                     case PropertiesTokenContext.LINE_COMMENT_ID:
108                         return new Coloring(italicFont, Coloring.FONT_MODE_APPLY_STYLE,
109                                 Color.gray, null);
110
111                     case PropertiesTokenContext.VALUE_ID:
112                         return new Coloring(null, Color.magenta, null);
113                 }
114
115
116
117             } else { // printing set
118
switch (tokenIDOrCategory.getNumericID()) {
119
120                     default:
121                          return SettingsUtil.defaultPrintColoringEvaluator;
122                 }
123
124             }
125
126             return null;
127
128         }
129
130     }
131
132 }
133
Popular Tags