KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > css > text > syntax > CSSEditorSettings


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.css.text.syntax;
20
21 import java.awt.Font JavaDoc;
22 import java.awt.Color JavaDoc;
23 import java.util.Map JavaDoc;
24 import java.util.TreeMap JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Arrays JavaDoc;
28
29 import org.openide.actions.ToolsAction;
30 import org.openide.windows.TopComponent;
31
32 import org.netbeans.editor.*;
33 import org.netbeans.editor.ext.ExtSettingsNames;
34
35 import org.netbeans.modules.css.actions.*;
36 import org.netbeans.modules.css.text.syntax.CSSTokenContext;
37
38 /**
39  * Settings.Initializer for CSSEditor
40  *
41  * @author Petr Kuzel
42  * @version 1.0
43  */

44 public class CSSEditorSettings extends Settings.AbstractInitializer {
45
46     /** Name assigned to initializer */
47     public static final String JavaDoc NAME = "css-settings-initializer"; // NOI18N
48

49     static final Font JavaDoc boldFont = SettingsDefaults.defaultFont.deriveFont(Font.BOLD);
50     static final Font JavaDoc italicFont = SettingsDefaults.defaultFont.deriveFont(Font.ITALIC);
51
52     /** Creates new CSSEditorSettings */
53     public CSSEditorSettings() {
54         super(NAME);
55     }
56
57     /** Update map filled with the settings from the previous initializer
58      * @param kitClass kit class for which the settings are being updated.
59      * It is always non-null value.
60      * @param settingsMap map with settings to update. It can be null if all
61      * the previous initializers didn't need to create any settings
62      * for the given kit class.
63      * @return map containing the desired settings or null if no settings
64      * are defined for the given kit
65      */

66     public void updateSettingsMap(Class JavaDoc kitClass, Map JavaDoc settingsMap) {
67
68         // editor breaks the contact, handle it somehow
69
if (kitClass == null) return;
70         
71         if (kitClass == BaseKit.class) {
72
73             new CSSTokenColoringInitializer().updateSettingsMap(kitClass, settingsMap);
74             // coloring has to be present in base kit
75

76         }
77
78         // #21053
79
if ("org.netbeans.modules.css.text.syntax.CSSEditorKit".equals(kitClass.getName())) {
80             
81             // popup menu
82

83             List JavaDoc cssActionNames = new ArrayList JavaDoc
84                 (Arrays.asList (new String JavaDoc[] {
85                     CopyStyleAction.XML.class.getName(),
86                     CopyStyleAction.HTML.class.getName(),
87                     CheckStyleAction.class.getName(),
88                     null,
89 // <comment> Wait for indent engine.
90
// BaseKit.formatAction,
91
// null,
92
// </comment>
93
TopComponent.class.getName(),
94                     null,
95                     BaseKit.cutAction,
96                     BaseKit.copyAction,
97                     BaseKit.pasteAction,
98                     null,
99                     BaseKit.removeSelectionAction,
100                     null,
101                     ToolsAction.class.getName(),
102                 }));
103             
104             settingsMap.put (ExtSettingsNames.POPUP_MENU_ACTION_NAME_LIST, cssActionNames);
105
106             // abbrevirations
107
settingsMap.put (SettingsNames.ABBREV_MAP, getCSSAbbrevMap());
108
109             SettingsUtil.updateListSetting (settingsMap, SettingsNames.TOKEN_CONTEXT_LIST,
110                     new TokenContext[] { CSSTokenContext.context });
111
112         }
113
114     }
115
116     /** @return Map of common CSS abbrevirations.
117     */

118     private Map JavaDoc getCSSAbbrevMap() {
119         Map JavaDoc map = new TreeMap JavaDoc();
120
121         map.put ("bg", "background: "); // NOI18N
122
map.put ("di", "display: "); // NOI18N
123
map.put ("fs", "font-size: "); // NOI18N
124

125         return map;
126     }
127
128     /** CSS colorings for standalone editor */
129     static class CSSTokenColoringInitializer
130     extends SettingsUtil.TokenColoringInitializer {
131
132         public CSSTokenColoringInitializer() {
133             super(CSSTokenContext.context);
134         }
135
136         public Object JavaDoc getTokenColoring(TokenContextPath tokenContextPath, TokenCategory tokenIDOrCategory, boolean printingSet) {
137             return new Coloring (null, Color.black, null);
138         }
139
140     }
141
142 }
143
Popular Tags