1 19 20 package org.netbeans.editor.ext.html; 21 22 import java.awt.Color ; 23 import java.awt.Font ; 24 import java.util.Map ; 25 import java.util.HashMap ; 26 import org.netbeans.editor.Acceptor; 27 import org.netbeans.editor.AcceptorFactory; 28 import org.netbeans.editor.Coloring; 29 import org.netbeans.editor.Settings; 30 import org.netbeans.editor.SettingsNames; 31 import org.netbeans.editor.SettingsDefaults; 32 import org.netbeans.editor.SettingsUtil; 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 38 45 46 public class HTMLSettingsInitializer extends Settings.AbstractInitializer { 47 48 private final Class htmlKitClass; 49 50 51 public static final String NAME = "html-settings-initializer"; 53 public static final Acceptor HTML_IDENTIFIER_ACCEPTOR = 54 new Acceptor() { 55 public final boolean accept(char ch) { 56 return (ch == ':') || AcceptorFactory.JAVA_IDENTIFIER.accept(ch); 57 } 58 }; 59 60 61 65 public HTMLSettingsInitializer(Class htmlKitClass) { 66 super(NAME); 67 this.htmlKitClass = htmlKitClass; 68 } 69 70 77 public void updateSettingsMap(Class kitClass, Map settingsMap) { 78 79 if (kitClass == BaseKit.class) { 80 81 new HTMLTokenColoringInitializer().updateSettingsMap(kitClass, settingsMap); 82 83 } 84 85 if (kitClass == htmlKitClass) { 86 87 SettingsUtil.updateListSetting(settingsMap, SettingsNames.TOKEN_CONTEXT_LIST, 88 new TokenContext[] { 89 HTMLTokenContext.context 90 } 91 ); 92 93 settingsMap.put(SettingsNames.IDENTIFIER_ACCEPTOR, 94 HTML_IDENTIFIER_ACCEPTOR); 95 96 settingsMap.put(HTMLSettingsNames.COMPLETION_LOWER_CASE, 97 HTMLSettingsDefaults.defaultCompletionLowerCase); 98 99 } 100 101 } 102 103 static class HTMLTokenColoringInitializer 104 extends SettingsUtil.TokenColoringInitializer { 105 106 Font boldFont = SettingsDefaults.defaultFont.deriveFont(Font.BOLD); 107 Font italicFont = SettingsDefaults.defaultFont.deriveFont(Font.ITALIC); 108 Settings.Evaluator boldSubst = new SettingsUtil.FontStylePrintColoringEvaluator(Font.BOLD); 109 Settings.Evaluator italicSubst = new SettingsUtil.FontStylePrintColoringEvaluator(Font.ITALIC); 110 Settings.Evaluator lightGraySubst = new SettingsUtil.ForeColorPrintColoringEvaluator(Color.lightGray); 111 112 public HTMLTokenColoringInitializer() { 113 super(HTMLTokenContext.context); 114 } 115 116 public Object getTokenColoring(TokenContextPath tokenContextPath, 117 TokenCategory tokenIDOrCategory, boolean printingSet) { 118 if (!printingSet) { 119 switch (tokenIDOrCategory.getNumericID()) { 120 case HTMLTokenContext.TEXT_ID: 121 case HTMLTokenContext.WS_ID: 122 return SettingsDefaults.emptyColoring; 123 124 case HTMLTokenContext.ERROR_ID: 125 return new Coloring(null, Color.white, Color.red); 126 127 case HTMLTokenContext.TAG_CATEGORY_ID: 128 return new Coloring(null, Color.blue, null); 129 130 case HTMLTokenContext.ARGUMENT_ID: 131 return new Coloring(null, Color.green.darker().darker(), null); 132 133 case HTMLTokenContext.OPERATOR_ID: 134 return new Coloring(null, Color.green.darker().darker(), null); 135 136 case HTMLTokenContext.VALUE_ID: 137 return new Coloring(null, new Color (153, 0, 107), null); 138 139 case HTMLTokenContext.BLOCK_COMMENT_ID: 140 return new Coloring(null, Color.gray, null); 142 143 case HTMLTokenContext.SGML_COMMENT_ID: 144 return new Coloring( null, Color.gray, null ); 145 146 case HTMLTokenContext.DECLARATION_ID: 147 return new Coloring(null, new Color (191, 146, 33), null); 148 149 case HTMLTokenContext.CHARACTER_ID: 150 return new Coloring(null, Color.red.darker(), null); 151 152 } 153 154 } else { switch (tokenIDOrCategory.getNumericID()) { 156 case HTMLTokenContext.BLOCK_COMMENT_ID: 157 case HTMLTokenContext.SGML_COMMENT_ID: 158 return lightGraySubst; 159 160 default: 161 return SettingsUtil.defaultPrintColoringEvaluator; 162 } 163 164 } 165 166 return null; 167 168 } 169 170 } 171 172 } 173 | Popular Tags |