001: /*
002: * Sun Public License Notice
003: *
004: * The contents of this file are subject to the Sun Public License
005: * Version 1.0 (the "License"). You may not use this file except in
006: * compliance with the License. A copy of the License is available at
007: * http://www.sun.com/
008: *
009: * The Original Code is NetBeans. The Initial Developer of the Original
010: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
011: * Microsystems, Inc. All Rights Reserved.
012: */
013:
014: package org.netbeans.editor.ext.html;
015:
016: import java.awt.Color;
017: import java.awt.Font;
018: import java.util.Map;
019:
020: import org.netbeans.editor.BaseKit;
021: import org.netbeans.editor.Coloring;
022: import org.netbeans.editor.Settings;
023: import org.netbeans.editor.SettingsDefaults;
024: import org.netbeans.editor.SettingsNames;
025: import org.netbeans.editor.SettingsUtil;
026: import org.netbeans.editor.TokenCategory;
027: import org.netbeans.editor.TokenContext;
028: import org.netbeans.editor.TokenContextPath;
029:
030: /**
031: * Extended settings provide the settings for the extended editor features
032: * supported by the various classes of this package.
033: *
034: * @author Miloslav Metelka
035: * @version 1.00
036: */
037:
038: public class HTMLSettingsInitializer extends
039: Settings.AbstractInitializer {
040:
041: private final Class htmlKitClass;
042:
043: /** Name assigned to initializer */
044: public static final String NAME = "html-settings-initializer";
045:
046: /**
047: * Construct HTML Settings initializer
048: *
049: * @param htmlKitClass
050: * the real kit class for which the settings are created. It's
051: * unknown here so it must be passed to this constructor.
052: */
053: public HTMLSettingsInitializer(Class htmlKitClass) {
054: super (NAME);
055: this .htmlKitClass = htmlKitClass;
056: }
057:
058: /**
059: * Update map filled with the settings.
060: *
061: * @param kitClass
062: * kit class for which the settings are being updated. It is
063: * always non-null value.
064: * @param settingsMap
065: * map holding [setting-name, setting-value] pairs. The map can
066: * be empty if this is the first initializer that updates it or
067: * if no previous initializers updated it.
068: */
069: public void updateSettingsMap(Class kitClass, Map settingsMap) {
070:
071: if (kitClass == BaseKit.class) {
072:
073: new HTMLTokenColoringInitializer().updateSettingsMap(
074: kitClass, settingsMap);
075:
076: }
077:
078: if (kitClass == htmlKitClass) {
079:
080: SettingsUtil.updateListSetting(settingsMap,
081: SettingsNames.TOKEN_CONTEXT_LIST,
082: new TokenContext[] { HTMLTokenContext.context });
083: }
084:
085: }
086:
087: static class HTMLTokenColoringInitializer extends
088: SettingsUtil.TokenColoringInitializer {
089:
090: Font boldFont = SettingsDefaults.defaultFont
091: .deriveFont(Font.BOLD);
092: Font italicFont = SettingsDefaults.defaultFont
093: .deriveFont(Font.ITALIC);
094: Settings.Evaluator boldSubst = new SettingsUtil.FontStylePrintColoringEvaluator(
095: Font.BOLD);
096: Settings.Evaluator italicSubst = new SettingsUtil.FontStylePrintColoringEvaluator(
097: Font.ITALIC);
098: Settings.Evaluator lightGraySubst = new SettingsUtil.ForeColorPrintColoringEvaluator(
099: Color.lightGray);
100:
101: public HTMLTokenColoringInitializer() {
102: super (HTMLTokenContext.context);
103: }
104:
105: public Object getTokenColoring(
106: TokenContextPath tokenContextPath,
107: TokenCategory tokenIDOrCategory, boolean printingSet) {
108: if (!printingSet) {
109: switch (tokenIDOrCategory.getNumericID()) {
110: case HTMLTokenContext.TEXT_ID:
111: case HTMLTokenContext.WS_ID:
112: return SettingsDefaults.emptyColoring;
113:
114: case HTMLTokenContext.ERROR_ID:
115: return new Coloring(null, Color.white, Color.red);
116:
117: case HTMLTokenContext.TAG_ID:
118: return new Coloring(null, Color.blue, null);
119:
120: case HTMLTokenContext.ARGUMENT_ID:
121: return new Coloring(null, Color.green.darker()
122: .darker(), null);
123:
124: case HTMLTokenContext.OPERATOR_ID:
125: return new Coloring(null, Color.green.darker()
126: .darker(), null);
127:
128: case HTMLTokenContext.VALUE_ID:
129: return new Coloring(null, new Color(153, 0, 107),
130: null);
131:
132: case HTMLTokenContext.BLOCK_COMMENT_ID:
133: return new Coloring(italicFont,
134: Coloring.FONT_MODE_APPLY_STYLE, Color.gray,
135: null);
136:
137: case HTMLTokenContext.SGML_COMMENT_ID:
138: return new Coloring(null, Color.gray, null);
139:
140: case HTMLTokenContext.DECLARATION_ID:
141: return new Coloring(null, new Color(191, 146, 33),
142: null);
143:
144: case HTMLTokenContext.CHARACTER_ID:
145: return new Coloring(null, Color.red.darker(), null);
146: }
147:
148: } else { // printing set
149: switch (tokenIDOrCategory.getNumericID()) {
150: case HTMLTokenContext.BLOCK_COMMENT_ID:
151: case HTMLTokenContext.SGML_COMMENT_ID:
152: return lightGraySubst;
153:
154: default:
155: return SettingsUtil.defaultPrintColoringEvaluator;
156: }
157:
158: }
159:
160: return null;
161:
162: }
163:
164: }
165:
166: }
|