Thread: [Texeclipse-cvs] net.sourceforge.texeclipse/src/net/sourceforge/texeclipse/editors TexConfiguration.
Status: Planning
Brought to you by:
sba
From: <sb...@us...> - 2003-09-14 22:49:56
|
Update of /cvsroot/texeclipse/net.sourceforge.texeclipse/src/net/sourceforge/texeclipse/editors In directory sc8-pr-cvs1:/tmp/cvs-serv16922/src/net/sourceforge/texeclipse/editors Added Files: TexConfiguration.java TexDocumentProvider.java ColorManager.java TexPartitionScanner.java ColorConstants.java TexEditor.java Log Message: Initial commit. Nothing more then simple syntax highlighting is supported, a new tex project wizard and a new tex file wizard. --- NEW FILE: TexConfiguration.java --- /* * Created on 12.09.2003 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package net.sourceforge.texeclipse.editors; 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.DefaultDamagerRepairer; import org.eclipse.jface.text.rules.EndOfLineRule; import org.eclipse.jface.text.rules.IRule; import org.eclipse.jface.text.rules.IToken; import org.eclipse.jface.text.rules.IWordDetector; import org.eclipse.jface.text.rules.MultiLineRule; import org.eclipse.jface.text.rules.RuleBasedScanner; import org.eclipse.jface.text.rules.Token; import org.eclipse.jface.text.rules.WordRule; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; /** * @author sba * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class TexConfiguration extends SourceViewerConfiguration { private ColorManager colorManager; private RuleBasedScanner defaultScanner; private RuleBasedScanner mathScanner; /** * @param colorManager */ public TexConfiguration(ColorManager colorManager) { this.colorManager = colorManager; } public RuleBasedScanner getDefaultScanner() { if (defaultScanner != null) return defaultScanner; defaultScanner = new RuleBasedScanner() {{ IToken comment = new Token(new TextAttribute(colorManager.getColor(ColorConstants.COMMENT))); IToken tag = new Token(new TextAttribute(colorManager.getColor(ColorConstants.TAG))); IToken command = new Token(new TextAttribute(colorManager.getColor(ColorConstants.COMMAND))); IRule rules[] = new IRule[4]; rules[0] = new EndOfLineRule("%",comment); rules[1] = new MultiLineRule("\\begin{","}",tag,'\\',true); rules[2] = new MultiLineRule("\\end{","}",tag,'\\',true); rules[3] = new WordRule(new IWordDetector() { public boolean isWordStart(char c) { return c == '\\'; } public boolean isWordPart(char c) { return Character.isLetterOrDigit(c); } },command); setRules(rules); }}; defaultScanner.setDefaultReturnToken(new Token(new TextAttribute( colorManager.getColor(ColorConstants.DEFAULT)))); return defaultScanner; } public RuleBasedScanner getMathScanner() { if (mathScanner != null) return mathScanner; mathScanner = new RuleBasedScanner() {{ IToken comment = new Token(new TextAttribute(colorManager.getColor(ColorConstants.COMMENT))); IRule rules[] = new IRule[1]; rules[0] = new EndOfLineRule("%",comment); setRules(rules); }}; mathScanner.setDefaultReturnToken(new Token(new TextAttribute( colorManager.getColor(ColorConstants.MATH)))); return mathScanner; } /* (non-Javadoc) * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(org.eclipse.jface.text.source.ISourceViewer) */ public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { PresentationReconciler reconciler = new PresentationReconciler(); DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getDefaultScanner()); reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); dr = new DefaultDamagerRepairer(getMathScanner()); reconciler.setDamager(dr, TexPartitionScanner.TEX_MATH); reconciler.setRepairer(dr, TexPartitionScanner.TEX_MATH); return reconciler; } public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { return new String[] { IDocument.DEFAULT_CONTENT_TYPE, TexPartitionScanner.TEX_MATH }; } } --- NEW FILE: TexDocumentProvider.java --- /* * Created on 12.09.2003 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package net.sourceforge.texeclipse.editors; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentPartitioner; import org.eclipse.jface.text.rules.DefaultPartitioner; import org.eclipse.ui.editors.text.FileDocumentProvider; public class TexDocumentProvider extends FileDocumentProvider { protected IDocument createDocument(Object element) throws CoreException { IDocument document = super.createDocument(element); if (document != null) { IDocumentPartitioner partitioner = new DefaultPartitioner(new TexPartitionScanner(), TexPartitionScanner.getLegalContentTypes()); partitioner.connect(document); document.setDocumentPartitioner(partitioner); } return document; } } --- NEW FILE: ColorManager.java --- /******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package net.sourceforge.texeclipse.editors; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; public class ColorManager { protected Map fColorTable = new HashMap(10); public void dispose() { Iterator e = fColorTable.values().iterator(); while (e.hasNext()) ((Color) e.next()).dispose(); } public Color getColor(RGB rgb) { Color color = (Color) fColorTable.get(rgb); if (color == null) { color = new Color(Display.getCurrent(), rgb); fColorTable.put(rgb, color); } return color; } } --- NEW FILE: TexPartitionScanner.java --- /* * Created on 12.09.2003 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package net.sourceforge.texeclipse.editors; import org.eclipse.jface.text.rules.*; public class TexPartitionScanner extends RuleBasedPartitionScanner { public final static String TEX_DEFAULT = "__tex_default"; public final static String TEX_MATH = "__tex_math"; public final static String TEX_TAG = "__tex_tag"; public final static String[] legalContentTypes = new String[] { TEX_MATH, TEX_TAG }; public TexPartitionScanner() { IToken math = new Token(TEX_MATH); IToken tag = new Token(TEX_TAG); IPredicateRule[] rules = new IPredicateRule[1]; rules[0] = new MultiLineRule("$", "$", math, '\\', true); // rules[1] = new TagRule(tag); setPredicateRules(rules); } /** * */ public static String[] getLegalContentTypes() { return legalContentTypes; } } --- NEW FILE: ColorConstants.java --- /* * Created on 12.09.2003 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package net.sourceforge.texeclipse.editors; import org.eclipse.swt.graphics.RGB; /** * @author sba * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class ColorConstants { static RGB DEFAULT = new RGB(0, 0, 0); static RGB COMMENT = new RGB(0, 128, 0); static RGB TAG = new RGB(128, 0, 128); static RGB COMMAND = new RGB(0,0,160); static RGB MATH = new RGB(0,0,255); } --- NEW FILE: TexEditor.java --- /******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package net.sourceforge.texeclipse.editors; import org.eclipse.ui.editors.text.TextEditor; public class TexEditor extends TextEditor { private ColorManager colorManager; public TexEditor() { super(); colorManager = new ColorManager(); setSourceViewerConfiguration(new TexConfiguration(colorManager)); setDocumentProvider(new TexDocumentProvider()); } public void dispose() { colorManager.dispose(); super.dispose(); } } |