KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > properties > syntax > 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
21 package org.netbeans.modules.properties.syntax;
22
23
24 import java.awt.Font JavaDoc;
25 import java.awt.Color JavaDoc;
26 import java.awt.SystemColor JavaDoc;
27 import java.util.*;
28
29 import org.netbeans.editor.AcceptorFactory;
30 import org.netbeans.editor.Settings;
31 import org.netbeans.editor.SettingsNames;
32 import org.netbeans.editor.SettingsUtil;
33 import org.netbeans.editor.Coloring;
34 import org.netbeans.editor.SettingsDefaults;
35 import org.netbeans.editor.BaseKit;
36 import org.netbeans.editor.TokenContext;
37 import org.netbeans.editor.TokenContextPath;
38 import org.netbeans.editor.TokenCategory;
39
40
41 /**
42  * Initializes properties editor kit settings.
43  *
44  * @author Mila Metelka
45  */

46 public class PropertiesSettingsInitializer extends Settings.AbstractInitializer {
47
48     /** Name assigned to initializer */
49     public static final String JavaDoc NAME = "properties-settings-initializer";
50
51
52     /** Construct <code>PropertiesSettingsInitializer</code>. */
53     public PropertiesSettingsInitializer() {
54         super(NAME);
55     }
56
57
58     /** Updates settings map for editor kit class. */
59     public void updateSettingsMap(Class JavaDoc kitClass, Map settingsMap) {
60         
61         // Properties colorings
62
if(kitClass == BaseKit.class) {
63             new PropertiesTokenColoringInitializer().updateSettingsMap(kitClass, settingsMap);
64         } else if(kitClass == PropertiesKit.class) {
65             // initialize color for shadowing cells in table view
66
settingsMap.put(PropertiesOptions.SHADOW_TABLE_CELL_PROP, new Color JavaDoc(SystemColor.controlHighlight.getRGB()));
67
68             settingsMap.put(SettingsNames.ABBREV_MAP, new TreeMap());
69             
70             settingsMap.put(SettingsNames.IDENTIFIER_ACCEPTOR, AcceptorFactory.JAVA_IDENTIFIER);
71
72             SettingsUtil.updateListSetting(settingsMap, SettingsNames.TOKEN_CONTEXT_LIST,
73                 new TokenContext[] {
74                     PropertiesTokenContext.context
75                 }
76             );
77         }
78     }
79
80
81     /** Properties token coloring initializer. */
82     private static class PropertiesTokenColoringInitializer extends SettingsUtil.TokenColoringInitializer {
83
84         /** Bold font. */
85         private static final Font JavaDoc boldFont = SettingsDefaults.defaultFont.deriveFont(Font.BOLD);
86         /** Italic font. */
87         private static final Font JavaDoc italicFont = SettingsDefaults.defaultFont.deriveFont(Font.ITALIC);
88
89         /** Key coloring. */
90         private static final Coloring keyColoring = new Coloring(boldFont, Coloring.FONT_MODE_APPLY_STYLE, Color.blue, null);
91         /** Value coloring. */
92         private static final Coloring valueColoring = new Coloring(null, Color.magenta, null);
93         /** Comment coloring. */
94         // #48502 - changed comment coloring to use non-italic font style
95
private static final Coloring commentColoring = new Coloring(null, Color.gray, null);
96         /** Empty coloring. */
97         private static final Coloring emptyColoring = new Coloring(null, null, null);
98
99         
100         /** Constructs <code>PropertiesTokenColoringInitializer</code>. */
101         public PropertiesTokenColoringInitializer() {
102             super(PropertiesTokenContext.context);
103         }
104
105
106         /** Gets token coloring. */
107         public Object JavaDoc getTokenColoring(TokenContextPath tokenContextPath,
108             TokenCategory tokenIDOrCategory, boolean printingSet) {
109
110             if(!printingSet) {
111                 int tokenID = tokenIDOrCategory.getNumericID();
112                 
113                 if(tokenID == PropertiesTokenContext.KEY_ID) {
114                     return keyColoring;
115                 } else if(tokenID == PropertiesTokenContext.VALUE_ID) {
116                     return valueColoring;
117                 } else if(tokenID == PropertiesTokenContext.LINE_COMMENT_ID) {
118                     return commentColoring;
119                 } else if(tokenID == PropertiesTokenContext.EQ_ID
120                             || tokenID == PropertiesTokenContext.TEXT_ID) {
121                     return emptyColoring;
122                 }
123             } else { // printing set
124
return SettingsUtil.defaultPrintColoringEvaluator;
125             }
126
127             return null;
128         }
129         
130     } // End of class PropertiesTokenColoringInitializer.
131

132 }
133
Popular Tags