Package com.rescripter

Source Code of com.rescripter.RSConfiguration

package com.rescripter;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextDoubleClickStrategy;
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.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;

public class RSConfiguration extends SourceViewerConfiguration {
  private RSDoubleClickStrategy doubleClickStrategy;
  private RSScanner scanner;
  private ColorManager colorManager;

  public RSConfiguration(ColorManager colorManager) {
    this.colorManager = colorManager;
  }
  @Override
  public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
    return new String[] {
      IDocument.DEFAULT_CONTENT_TYPE,
      RSPartitionScanner.COMMENT};
  }
  @Override
  public ITextDoubleClickStrategy getDoubleClickStrategy(
    ISourceViewer sourceViewer,
    String contentType) {
    if (doubleClickStrategy == null)
      doubleClickStrategy = new RSDoubleClickStrategy();
    return doubleClickStrategy;
  }

  protected RSScanner getVSScanner() {
    if (scanner == null) {
      scanner = new RSScanner(colorManager);
      scanner.setDefaultReturnToken(
        new Token(
          new TextAttribute(
            colorManager.getColor(IRSColorConstants.DEFAULT))));
    }
    return scanner;
  }

  @Override
  public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
    PresentationReconciler reconciler = new PresentationReconciler();

    DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getVSScanner());
    reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
    reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);

    NonRuleBasedDamagerRepairer ndr =
      new NonRuleBasedDamagerRepairer(
        new TextAttribute(
          colorManager.getColor(IRSColorConstants.VS_COMMENT)));
    reconciler.setDamager(ndr, RSPartitionScanner.COMMENT);
    reconciler.setRepairer(ndr, RSPartitionScanner.COMMENT);

    return reconciler;
  }

}
TOP

Related Classes of com.rescripter.RSConfiguration

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.