package CDBuilder.couplingSyntaxEditor; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.TextAttribute; import org.eclipse.jface.text.presentation.IPresentationReconciler; import org.eclipse.jface.text.presentation.PresentationReconciler; import org.eclipse.jface.text.rules.BufferedRuleBasedScanner; import org.eclipse.jface.text.rules.DefaultDamagerRepairer; import org.eclipse.jface.text.rules.Token; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; /** * @author Sherwin Sim and Lucie Zhao * * @version 1 May - August 2003 * * This class specifies the configuration of our * coupling syntax editor. It extends * SourceViewerConfiguration which is a default * configuration for an editor. Our class uses a * ColorManager class to speciy the coloring * scheme for our editor and a CDScanner class to * specify what words will be scanned * */ public class cseConfiguration extends SourceViewerConfiguration { // A ColorManager which provides different colors that we can use private ColorManager colorManager; // A CDScanner, which scans documents to locate keywords private cseScanner syntaxScanner; /** * Extending SourceViewerConfiguration requires us to have this * nested class. We write the nested class but extended it to * the type of Scanner we want out sytax to be scanned. In this * case we want a buffered rule based scanner, this means we can * set rules or use provided rules in Eclipse to check/color our * sytax */ static class SingleTokenScanner extends BufferedRuleBasedScanner { public SingleTokenScanner(TextAttribute attribute) { setDefaultReturnToken(new Token(attribute)); } } /** * The constructor for this class, it is passed a ColorManager * object which we set to our local ColorManager object. * * @param colorManager - a coloring scheme for our syntax editor */ public cseConfiguration(ColorManager colorManager) { this.colorManager = colorManager; } /** * Returns the information control creator. The creator is a * factory creating information controls for the given source * viewer. This implementation always returns a creator for * DefaultInformationControl instances. * * @param sourceViewer - the source viewer to be configured by this configuration * @return the configured content types for the given viewer */ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { return new String[] { IDocument.DEFAULT_CONTENT_TYPE, csePartitionScanner.CD_COMMENT, csePartitionScanner.CD_DEFAULT }; } /** * Accessor method for getting the syntax scanner * @return the syntax scanner used * */ protected cseScanner getCDScanner() { if (syntaxScanner == null) { syntaxScanner = new cseScanner(colorManager); syntaxScanner.setDefaultReturnToken( new Token( new TextAttribute( colorManager.getColor(ICDColorConstants.DEFAULT)))); } return syntaxScanner; } /** * Returns the presentation reconciler ready to * be used with the given source viewer. This * implementation always returns null. * also sets the damager repairer for the editor * * @param sourceViewer the source viewer used * @return the presentation reconciler or null if presentation reconciling should not be supported */ public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { PresentationReconciler reconciler = new PresentationReconciler(); DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getCDScanner()); reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); dr= new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(colorManager.getColor(ICDColorConstants.COMMENT)))); reconciler.setDamager(dr, csePartitionScanner.CD_COMMENT); reconciler.setRepairer(dr, csePartitionScanner.CD_COMMENT); return reconciler; } }