508ae007345e4809d7f6db253f179611162537a2
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / editors / PHPConfiguration.java
1 package net.sourceforge.phpeclipse.editors;
2
3 import org.eclipse.jface.text.IDocument;
4 import org.eclipse.jface.text.ITextDoubleClickStrategy;
5 import org.eclipse.jface.text.TextAttribute;
6 import org.eclipse.jface.text.presentation.IPresentationReconciler;
7 import org.eclipse.jface.text.presentation.PresentationReconciler;
8 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
9 import org.eclipse.jface.text.rules.Token;
10 import org.eclipse.jface.text.source.ISourceViewer;
11 import org.eclipse.jface.text.source.SourceViewerConfiguration;
12
13 public class PHPConfiguration extends SourceViewerConfiguration {
14         private PHPDoubleClickStrategy doubleClickStrategy;
15         private PHPTagScanner tagScanner;
16         private PHPScanner scanner;
17         private ColorManager colorManager;
18
19         public PHPConfiguration(ColorManager colorManager) {
20                 this.colorManager = colorManager;
21         }
22         public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
23                 return new String[] {
24                         IDocument.DEFAULT_CONTENT_TYPE,
25                         PHPPartitionScanner.HTML_COMMENT,
26                         PHPPartitionScanner.HTML_TAG };
27         }
28         public ITextDoubleClickStrategy getDoubleClickStrategy(
29                 ISourceViewer sourceViewer,
30                 String contentType) {
31                 if (doubleClickStrategy == null)
32                         doubleClickStrategy = new PHPDoubleClickStrategy();
33                 return doubleClickStrategy;
34         }
35
36         protected PHPScanner getXMLScanner() {
37                 if (scanner == null) {
38                         scanner = new PHPScanner(colorManager);
39                         scanner.setDefaultReturnToken(
40                                 new Token(
41                                         new TextAttribute(
42                                                 colorManager.getColor(IPHPColorConstants.DEFAULT))));
43                 }
44                 return scanner;
45
46         }
47
48         protected PHPTagScanner getXMLTagScanner() {
49                 if (tagScanner == null) {
50                         tagScanner = new PHPTagScanner(colorManager);
51                         tagScanner.setDefaultReturnToken(
52                                 new Token(
53                                         new TextAttribute(
54                                                 colorManager.getColor(IPHPColorConstants.PHP_TAG))));
55                 }
56                 return tagScanner;
57         }
58
59         public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
60                 PresentationReconciler reconciler = new PresentationReconciler();
61
62                 DefaultDamagerRepairer dr =
63                         new DefaultDamagerRepairer(getXMLTagScanner());
64                 reconciler.setDamager(dr, PHPPartitionScanner.HTML_TAG);
65                 reconciler.setRepairer(dr, PHPPartitionScanner.HTML_TAG);
66
67                 dr = new DefaultDamagerRepairer(getXMLScanner());
68                 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
69                 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
70
71                 NonRuleBasedDamagerRepairer ndr =
72                         new NonRuleBasedDamagerRepairer(
73                                 new TextAttribute(
74                                         colorManager.getColor(IPHPColorConstants.XML_COMMENT)));
75                 reconciler.setDamager(ndr, PHPPartitionScanner.HTML_COMMENT);
76                 reconciler.setRepairer(ndr, PHPPartitionScanner.HTML_COMMENT);
77
78                 return reconciler;
79         }
80
81 }