X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FcomponentTypeEditor%2FPGraphSourceViewerConfigurationNew.java;fp=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FcomponentTypeEditor%2FPGraphSourceViewerConfigurationNew.java;h=bad6703b0971c6abdefdb62ae059d6301fa49df7;hp=5b02cec79cc35dea165ceff522955d7ccc8e5cce;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/PGraphSourceViewerConfigurationNew.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/PGraphSourceViewerConfigurationNew.java index 5b02cec79..bad6703b0 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/PGraphSourceViewerConfigurationNew.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/PGraphSourceViewerConfigurationNew.java @@ -1,134 +1,134 @@ -package org.simantics.modeling.ui.componentTypeEditor; - -import org.eclipse.jface.text.DefaultTextHover; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextHover; -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.IRule; -import org.eclipse.jface.text.rules.ITokenScanner; -import org.eclipse.jface.text.rules.IWordDetector; -import org.eclipse.jface.text.rules.MultiLineRule; -import org.eclipse.jface.text.rules.PatternRule; -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.DefaultAnnotationHover; -import org.eclipse.jface.text.source.IAnnotationHover; -import org.eclipse.jface.text.source.ISharedTextColors; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Device; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.RGB; - -public class PGraphSourceViewerConfigurationNew extends SourceViewerConfiguration { - - public static final char[] CONTENT_ASSIST_AUTO_CHARS = new char[] { '.' }; - Device device; - - ISharedTextColors sharedTextColors; - - public PGraphSourceViewerConfigurationNew(Device device, - ISharedTextColors sharedTextColors) { - this.device = device; - this.sharedTextColors = sharedTextColors; - } - - public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { - return new String[] { - IDocument.DEFAULT_CONTENT_TYPE - }; - } - - public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { - PresentationReconciler reconciler = new PresentationReconciler(); - - DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getSclTokenScanner()); - - reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); - reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); - - return reconciler; - } - - ITokenScanner getSclTokenScanner() { - RuleBasedScanner scanner = new RuleBasedScanner(); - - Font font = new Font(device, "Courier New", 10, SWT.NORMAL); - Font boldFont = new Font(device, "Courier New", 10, SWT.BOLD); - - Token defaultToken = new Token( - new TextAttribute( - sharedTextColors.getColor(new RGB(0, 0, 0)), - null, - 0, - font - )); - Token string = new Token(new TextAttribute( - sharedTextColors.getColor(new RGB(42, 0, 255)), - null, - 0, - font - )); - Token reserved = new Token( - new TextAttribute( - sharedTextColors.getColor(new RGB(127, 0, 85)), - null, - SWT.BOLD, - boldFont - )); - Token comment = new Token(new TextAttribute( - sharedTextColors.getColor(new RGB(63, 127, 95)), - null, - 0, - font - )); - - WordRule reservedWord = new WordRule(new IWordDetector() { - @Override - public boolean isWordStart(char c) { - return Character.isJavaIdentifierStart(c); - } - - @Override - public boolean isWordPart(char c) { - return Character.isJavaIdentifierPart(c) || c=='.'; - } - }); - - reservedWord.addWord("if", reserved); - reservedWord.addWord("then", reserved); - reservedWord.addWord("else", reserved); - reservedWord.addWord("match", reserved); - reservedWord.addWord("with", reserved); - reservedWord.addWord("data", reserved); - reservedWord.addWord("type", reserved); - reservedWord.addWord("class", reserved); - - IRule[] rules = new IRule[] { - //new MultiLineRule("\"\"\"", "\"\"\"", string), - new PatternRule("\"", "\"", string, '\\', true), - new MultiLineRule("/*", "*/", comment), - new PatternRule("//", null, comment, '\0', true), - reservedWord - }; - scanner.setRules(rules); - scanner.setDefaultReturnToken(defaultToken); - - return scanner; - } - - @Override - public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) { - return new DefaultTextHover(sourceViewer); - } - - @Override - public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { - return new DefaultAnnotationHover(); - } -} +package org.simantics.modeling.ui.componentTypeEditor; + +import org.eclipse.jface.text.DefaultTextHover; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextHover; +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.IRule; +import org.eclipse.jface.text.rules.ITokenScanner; +import org.eclipse.jface.text.rules.IWordDetector; +import org.eclipse.jface.text.rules.MultiLineRule; +import org.eclipse.jface.text.rules.PatternRule; +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.DefaultAnnotationHover; +import org.eclipse.jface.text.source.IAnnotationHover; +import org.eclipse.jface.text.source.ISharedTextColors; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Device; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.RGB; + +public class PGraphSourceViewerConfigurationNew extends SourceViewerConfiguration { + + public static final char[] CONTENT_ASSIST_AUTO_CHARS = new char[] { '.' }; + Device device; + + ISharedTextColors sharedTextColors; + + public PGraphSourceViewerConfigurationNew(Device device, + ISharedTextColors sharedTextColors) { + this.device = device; + this.sharedTextColors = sharedTextColors; + } + + public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { + return new String[] { + IDocument.DEFAULT_CONTENT_TYPE + }; + } + + public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { + PresentationReconciler reconciler = new PresentationReconciler(); + + DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getSclTokenScanner()); + + reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); + reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); + + return reconciler; + } + + ITokenScanner getSclTokenScanner() { + RuleBasedScanner scanner = new RuleBasedScanner(); + + Font font = new Font(device, "Courier New", 10, SWT.NORMAL); + Font boldFont = new Font(device, "Courier New", 10, SWT.BOLD); + + Token defaultToken = new Token( + new TextAttribute( + sharedTextColors.getColor(new RGB(0, 0, 0)), + null, + 0, + font + )); + Token string = new Token(new TextAttribute( + sharedTextColors.getColor(new RGB(42, 0, 255)), + null, + 0, + font + )); + Token reserved = new Token( + new TextAttribute( + sharedTextColors.getColor(new RGB(127, 0, 85)), + null, + SWT.BOLD, + boldFont + )); + Token comment = new Token(new TextAttribute( + sharedTextColors.getColor(new RGB(63, 127, 95)), + null, + 0, + font + )); + + WordRule reservedWord = new WordRule(new IWordDetector() { + @Override + public boolean isWordStart(char c) { + return Character.isJavaIdentifierStart(c); + } + + @Override + public boolean isWordPart(char c) { + return Character.isJavaIdentifierPart(c) || c=='.'; + } + }); + + reservedWord.addWord("if", reserved); + reservedWord.addWord("then", reserved); + reservedWord.addWord("else", reserved); + reservedWord.addWord("match", reserved); + reservedWord.addWord("with", reserved); + reservedWord.addWord("data", reserved); + reservedWord.addWord("type", reserved); + reservedWord.addWord("class", reserved); + + IRule[] rules = new IRule[] { + //new MultiLineRule("\"\"\"", "\"\"\"", string), + new PatternRule("\"", "\"", string, '\\', true), + new MultiLineRule("/*", "*/", comment), + new PatternRule("//", null, comment, '\0', true), + reservedWord + }; + scanner.setRules(rules); + scanner.setDefaultReturnToken(defaultToken); + + return scanner; + } + + @Override + public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) { + return new DefaultTextHover(sourceViewer); + } + + @Override + public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { + return new DefaultAnnotationHover(); + } +}