2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.editor.example;
45
import java.awt.Color;
46
import java.awt.SystemColor;
49
import org.netbeans.editor.Settings;
50
import org.netbeans.editor.SettingsNames;
51
import org.netbeans.editor.SettingsUtil;
52
import org.netbeans.editor.Coloring;
53
import org.netbeans.editor.SettingsDefaults;
54
import org.netbeans.editor.Syntax;
55
import org.netbeans.editor.BaseKit;
56
import org.netbeans.editor.TokenContext;
57
import org.netbeans.editor.TokenContextPath;
58
import org.netbeans.editor.TokenCategory;
59
import org.netbeans.modules.properties.syntax.*;
62
public class PropertiesSettingsInitializer extends Settings.AbstractInitializer {
64
/** Name assigned to initializer */
65
public static final String NAME = "properties-settings-initializer"; // NOI18N
66
private Class propertiesClass;
68
public PropertiesSettingsInitializer( Class propertiesClass ) {
70
this.propertiesClass = propertiesClass;
73
public void updateSettingsMap (Class kitClass, Map settingsMap) {
75
// Properties colorings
76
if (kitClass == BaseKit.class) {
77
new PropertiesTokenColoringInitializer().updateSettingsMap(kitClass, settingsMap);
81
if (kitClass == propertiesClass) {
82
settingsMap.put (org.netbeans.editor.SettingsNames.ABBREV_MAP, getPropertiesAbbrevMap());
84
SettingsUtil.updateListSetting(settingsMap, SettingsNames.TOKEN_CONTEXT_LIST,
86
PropertiesTokenContext.context
95
Map getPropertiesAbbrevMap() {
96
Map propertiesAbbrevMap = new TreeMap ();
97
return propertiesAbbrevMap;
100
static class PropertiesTokenColoringInitializer
101
extends SettingsUtil.TokenColoringInitializer {
103
Font boldFont = SettingsDefaults.defaultFont.deriveFont(Font.BOLD);
104
Font italicFont = SettingsDefaults.defaultFont.deriveFont(Font.ITALIC);
106
Coloring emptyColoring = new Coloring(null, null, null);
107
Coloring commentColoring = new Coloring(italicFont, Coloring.FONT_MODE_APPLY_STYLE,
110
Coloring numbersColoring = new Coloring(null, Color.red, null);
112
public PropertiesTokenColoringInitializer() {
113
super(PropertiesTokenContext.context);
116
public Object getTokenColoring(TokenContextPath tokenContextPath,
117
TokenCategory tokenIDOrCategory, boolean printingSet) {
120
switch (tokenIDOrCategory.getNumericID()) {
121
case PropertiesTokenContext.KEY_ID:
122
return new Coloring(boldFont, Coloring.FONT_MODE_APPLY_STYLE,
125
case PropertiesTokenContext.EQ_ID:
126
case PropertiesTokenContext.TEXT_ID:
127
return emptyColoring;
129
case PropertiesTokenContext.LINE_COMMENT_ID:
130
return new Coloring(italicFont, Coloring.FONT_MODE_APPLY_STYLE,
133
case PropertiesTokenContext.VALUE_ID:
134
return new Coloring(null, Color.magenta, null);
139
} else { // printing set
140
switch (tokenIDOrCategory.getNumericID()) {
143
return SettingsUtil.defaultPrintColoringEvaluator;