1 package net.sourceforge.phpdt.sql.editors;
3 import java.util.HashMap;
5 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
7 import org.eclipse.jface.preference.IPreferenceStore;
8 import org.eclipse.jface.preference.PreferenceConverter;
9 import org.eclipse.jface.text.IDocument;
10 import org.eclipse.jface.text.TextAttribute;
11 import org.eclipse.jface.text.presentation.IPresentationReconciler;
12 import org.eclipse.jface.text.presentation.PresentationReconciler;
13 import org.eclipse.jface.text.source.ISourceViewer;
14 import org.eclipse.jface.text.source.SourceViewerConfiguration;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.graphics.Color;
17 import org.eclipse.swt.graphics.RGB;
19 public class SQLConfiguration extends SourceViewerConfiguration {
20 private PresentationReconciler reconciler = new PresentationReconciler();
21 private ColorManager colorManager;
22 private HashMap cache = new HashMap();
23 private boolean textBold = false;
24 private boolean keywordBold = true;
25 private boolean stringBold = false;
26 private boolean commentBold = false;
27 private boolean numericBold = false;
28 public SQLConfiguration(ColorManager colorManager) {
29 this.colorManager = colorManager;
31 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
33 IDocument.DEFAULT_CONTENT_TYPE,
34 SQLPartitionScanner.SQL_COMMENT,
35 SQLPartitionScanner.SQL_KEYWORD,
36 SQLPartitionScanner.SQL_IDENTIFIER};
39 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
43 public void loadPrefs() {
44 IPreferenceStore store = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
45 textBold = store.getBoolean("phpeclipse.sql.text.bold");
46 keywordBold = store.getBoolean("phpeclipse.sql.keyword.bold");
47 stringBold = store.getBoolean("phpeclipse.sql.string.bold");
48 commentBold = store.getBoolean("phpeclipse.sql.comment.bold");
49 numericBold = store.getBoolean("phpeclipse.sql.numeric.bold");
50 SQLColorConstants.BACKGROUND = PreferenceConverter.getColor(store, "phpeclipse.sql.background.color");
51 SQLColorConstants.DEFAULT = PreferenceConverter.getColor(store, "phpeclipse.sql.text.color");
52 SQLColorConstants.IDENTIFIER = PreferenceConverter.getColor(store, "phpeclipse.sql.text.color");
53 SQLColorConstants.KEYWORD = PreferenceConverter.getColor(store, "phpeclipse.sql.keyword.color");
54 SQLColorConstants.STRING = PreferenceConverter.getColor(store, "phpeclipse.sql.string.color");
55 SQLColorConstants.COMMENT = PreferenceConverter.getColor(store, "phpeclipse.sql.comment.color");
56 SQLColorConstants.NUMERIC = PreferenceConverter.getColor(store, "phpeclipse.sql.numeric.color");
58 public void initializeColors() {
59 setDamageRepairer(getAttr(SQLColorConstants.KEYWORD, keywordBold), SQLPartitionScanner.SQL_KEYWORD);
60 setDamageRepairer(getAttr(SQLColorConstants.COMMENT, commentBold), SQLPartitionScanner.SQL_COMMENT);
61 setDamageRepairer(getAttr(SQLColorConstants.STRING, stringBold), SQLPartitionScanner.SQL_STRING);
62 setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), IDocument.DEFAULT_CONTENT_TYPE);
63 setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), SQLPartitionScanner.SQL_SYMBOL);
64 setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), SQLPartitionScanner.SQL_IDENTIFIER);
65 setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), SQLPartitionScanner.SQL_SEPARATOR);
66 setDamageRepairer(getAttr(SQLColorConstants.NUMERIC, numericBold), SQLPartitionScanner.SQL_NUMERIC);
68 public TextAttribute getAttr(RGB color, boolean bold) {
69 Color background = colorManager.getColor(SQLColorConstants.BACKGROUND);
70 Color foreground = colorManager.getColor(color);
71 TextAttribute attr = new TextAttribute(foreground);
73 return new TextAttribute(foreground, attr.getBackground(), SWT.BOLD);
77 public void setDamageRepairer(TextAttribute attr, String token) {
78 NonRuleBasedDamagerRepairer ndr = (NonRuleBasedDamagerRepairer) cache.get(token);
81 new NonRuleBasedDamagerRepairer(attr);
82 reconciler.setDamager(ndr, token);
83 reconciler.setRepairer(ndr, token);
84 cache.put(token, ndr);
86 ndr.setTextAttribute(attr);