1 19 20 package org.netbeans.modules.db.sql.editor; 21 22 import java.awt.Color ; 23 import java.awt.Font ; 24 import java.util.Map ; 25 import javax.swing.JEditorPane ; 26 import javax.swing.JFrame ; 27 import javax.swing.JScrollPane ; 28 import org.netbeans.editor.Acceptor; 29 import org.netbeans.editor.AcceptorFactory; 30 import org.netbeans.editor.BaseKit; 31 import org.netbeans.editor.Coloring; 32 import org.netbeans.editor.Settings; 33 import org.netbeans.editor.SettingsDefaults; 34 import org.netbeans.editor.SettingsNames; 35 import org.netbeans.editor.SettingsUtil; 36 import org.netbeans.editor.TokenCategory; 37 import org.netbeans.editor.TokenContext; 38 import org.netbeans.editor.TokenContextPath; 39 import org.openide.util.NbBundle; 40 41 46 public class SQLSettingsInitializer extends Settings.AbstractInitializer { 47 48 public static final String NAME = "sql-settings-initializer"; 50 53 public SQLSettingsInitializer() { 54 super(NAME); 55 } 56 57 65 public void updateSettingsMap(Class kitClass, Map settingsMap) { 66 if (kitClass == BaseKit.class) { 67 new SQLTokenColoringInitializer().updateSettingsMap(kitClass, settingsMap); 68 } 69 70 if (kitClass == SQLEditorKit.class) { 71 SettingsUtil.updateListSetting( 72 settingsMap, 73 SettingsNames.TOKEN_CONTEXT_LIST, 74 new TokenContext[] { SQLTokenContext.context } 75 ); 76 } 77 } 78 79 82 static class SQLTokenColoringInitializer extends SettingsUtil.TokenColoringInitializer { 83 84 Font boldFont = SettingsDefaults.defaultFont.deriveFont(Font.BOLD); 85 Settings.Evaluator lightGraySubst = 86 new SettingsUtil.ForeColorPrintColoringEvaluator(Color.lightGray); 87 88 91 public SQLTokenColoringInitializer() { 92 super(SQLTokenContext.context); 93 } 94 95 98 public Object getTokenColoring( 99 TokenContextPath tokenContextPath, 100 TokenCategory tokenIDOrCategory, 101 boolean printingSet) { 102 if (!printingSet) { 104 int id = tokenIDOrCategory.getNumericID(); 105 switch (id) { 106 case SQLTokenContext.WHITESPACE_ID: 107 return SettingsDefaults.emptyColoring; 108 case SQLTokenContext.LINE_COMMENT_ID: 109 return new Coloring( 110 null, 111 Color.gray, 112 null); 113 case SQLTokenContext.BLOCK_COMMENT_ID: 114 return new Coloring( 115 null, 116 Color.gray, 117 null); 118 case SQLTokenContext.STRING_ID: 119 return new Coloring( 120 null, 121 new Color (153, 0, 107), 122 null); 123 case SQLTokenContext.IDENTIFIER_ID: 124 return new Coloring( 125 null, 126 Color.blue, 127 null); 128 case SQLTokenContext.OPERATOR_ID: 129 return new Coloring( 130 null, 131 Color.black, 132 null); 133 case SQLTokenContext.DOT_ID: 134 return new Coloring( 135 null, 136 Color.black, 137 null); 138 case SQLTokenContext.INT_LITERAL_ID: 139 case SQLTokenContext.DOUBLE_LITERAL_ID: 140 return new Coloring( 141 null, 142 new Color (120, 0, 0), 143 null); 144 case SQLTokenContext.KEYWORD_ID: 145 return new Coloring( 146 boldFont, 147 Coloring.FONT_MODE_APPLY_STYLE, 148 Color.blue.darker().darker(), 149 null); 150 case SQLTokenContext.ERRORS_ID: 151 return new Coloring( 152 null, 153 Color.black, 154 Color.pink); 155 } 156 157 } else { 158 switch (tokenIDOrCategory.getNumericID()) { 160 case SQLTokenContext.BLOCK_COMMENT_ID: 161 case SQLTokenContext.LINE_COMMENT_ID: 162 return lightGraySubst; 163 164 default: 165 return SettingsUtil.defaultPrintColoringEvaluator; 166 } 167 } 168 169 return null; 170 } 171 } 172 } 173 | Popular Tags |