Search in sources :

Example 76 with TextAttribute

use of org.eclipse.jface.text.TextAttribute in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonScanner method init.

protected void init() {
    TextAttribute keyAttr = tokenAttribute(PreferenceConstants.COLOR_KEY, PreferenceConstants.BOLD_KEY, PreferenceConstants.ITALIC_KEY, PreferenceConstants.UNDERLINE_KEY);
    IToken keyToken = new YAMLToken(keyAttr, YAMLToken.KEY);
    TextAttribute scalarAttr = tokenAttribute(PreferenceConstants.COLOR_SCALAR, PreferenceConstants.BOLD_SCALAR, PreferenceConstants.ITALIC_SCALAR, PreferenceConstants.UNDERLINE_SCALAR);
    IToken scalarToken = new YAMLToken(scalarAttr, YAMLToken.SCALAR);
    TextAttribute commentAttr = tokenAttribute(PreferenceConstants.COLOR_COMMENT, PreferenceConstants.BOLD_COMMENT, PreferenceConstants.ITALIC_COMMENT, PreferenceConstants.UNDERLINE_COMMENT);
    IToken commentToken = new YAMLToken(commentAttr, YAMLToken.COMMENT);
    TextAttribute documentAttr = tokenAttribute(PreferenceConstants.COLOR_DOCUMENT, PreferenceConstants.BOLD_DOCUMENT, PreferenceConstants.ITALIC_DOCUMENT, PreferenceConstants.UNDERLINE_DOCUMENT);
    IToken documentStartToken = new YAMLToken(documentAttr, YAMLToken.DOCUMENT_START);
    IToken documentEndToken = new YAMLToken(documentAttr, YAMLToken.DOCUMENT_END);
    TextAttribute anchorAttr = tokenAttribute(PreferenceConstants.COLOR_ANCHOR, PreferenceConstants.BOLD_ANCHOR, PreferenceConstants.ITALIC_ANCHOR, PreferenceConstants.UNDERLINE_ANCHOR);
    IToken anchorToken = new YAMLToken(anchorAttr, YAMLToken.ANCHOR);
    TextAttribute aliasAttr = tokenAttribute(PreferenceConstants.COLOR_ALIAS, PreferenceConstants.BOLD_ALIAS, PreferenceConstants.ITALIC_ALIAS, PreferenceConstants.UNDERLINE_ALIAS);
    IToken aliasToken = new YAMLToken(aliasAttr, YAMLToken.ALIAS);
    IToken indicatorCharToken = new YAMLToken(new TextAttribute(null), YAMLToken.INDICATOR_CHARACTER);
    TextAttribute tagAttr = tokenAttribute(PreferenceConstants.COLOR_TAG_PROPERTY, PreferenceConstants.BOLD_TAG_PROPERTY, PreferenceConstants.ITALIC_TAG_PROPERTY, PreferenceConstants.UNDERLINE_TAG_PROPERTY);
    IToken tagPropToken = new YAMLToken(tagAttr, YAMLToken.TAG_PROPERTY);
    TextAttribute constantAttr = tokenAttribute(PreferenceConstants.COLOR_CONSTANT, PreferenceConstants.BOLD_CONSTANT, PreferenceConstants.ITALIC_CONSTANT, PreferenceConstants.UNDERLINE_CONSTANT);
    IToken predefinedValToken = new YAMLToken(constantAttr, YAMLToken.CONSTANT);
    IToken whitespaceToken = new YAMLToken(new TextAttribute(null), YAMLToken.WHITESPACE);
    IToken directiveToken = new YAMLToken(new TextAttribute(null), YAMLToken.DIRECTIVE);
    ArrayList<IRule> rules = new ArrayList<IRule>();
    rules.add(new KeyRule(keyToken));
    rules.add(new SingleQuotedKeyRule(keyToken));
    rules.add(new DoubleQuotedKeyRule(keyToken));
    rules.add(new MultiLineRule("\"", "\"", scalarToken, '\\'));
    rules.add(new MultiLineRule("'", "'", scalarToken));
    rules.add(new EndOfLineRule("#", commentToken));
    rules.add(new EndOfLineRule("%TAG", directiveToken));
    rules.add(new EndOfLineRule("%YAML", directiveToken));
    rules.add(new DocumentStartAndEndRule("---", documentStartToken));
    rules.add(new DocumentStartAndEndRule("...", documentEndToken));
    rules.add(new IndicatorCharacterRule(indicatorCharToken));
    rules.add(new WhitespaceRule(whitespaceToken));
    rules.add(new WordPatternRule(new AnchorWordDetector(), "&", "", anchorToken));
    rules.add(new WordPatternRule(new AnchorWordDetector(), "*", "", aliasToken));
    rules.add(new WordPatternRule(new TagWordDetector(), "!", "", tagPropToken));
    rules.add(new PredefinedValueRule(predefinedValToken));
    rules.add(new ScalarRule(scalarToken));
    IRule[] rulesArray = new IRule[rules.size()];
    rules.toArray(rulesArray);
    setRules(rulesArray);
    setDefaultReturnToken(scalarToken);
}
Also used : WordPatternRule(org.eclipse.jface.text.rules.WordPatternRule) AnchorWordDetector(org.dadacoalition.yedit.editor.scanner.AnchorWordDetector) ScalarRule(org.dadacoalition.yedit.editor.scanner.ScalarRule) TextAttribute(org.eclipse.jface.text.TextAttribute) KeyRule(org.dadacoalition.yedit.editor.scanner.KeyRule) DoubleQuotedKeyRule(org.dadacoalition.yedit.editor.scanner.DoubleQuotedKeyRule) SingleQuotedKeyRule(org.dadacoalition.yedit.editor.scanner.SingleQuotedKeyRule) TagWordDetector(org.dadacoalition.yedit.editor.scanner.TagWordDetector) YAMLToken(org.dadacoalition.yedit.editor.scanner.YAMLToken) ArrayList(java.util.ArrayList) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) PredefinedValueRule(org.dadacoalition.yedit.editor.scanner.PredefinedValueRule) WhitespaceRule(org.dadacoalition.yedit.editor.scanner.WhitespaceRule) IRule(org.eclipse.jface.text.rules.IRule) DocumentStartAndEndRule(org.dadacoalition.yedit.editor.scanner.DocumentStartAndEndRule) SingleQuotedKeyRule(org.dadacoalition.yedit.editor.scanner.SingleQuotedKeyRule) DoubleQuotedKeyRule(org.dadacoalition.yedit.editor.scanner.DoubleQuotedKeyRule) IToken(org.eclipse.jface.text.rules.IToken) IndicatorCharacterRule(org.dadacoalition.yedit.editor.scanner.IndicatorCharacterRule) EndOfLineRule(org.eclipse.jface.text.rules.EndOfLineRule)

Example 77 with TextAttribute

use of org.eclipse.jface.text.TextAttribute in project dbeaver by dbeaver.

the class MySQLDialect method extendRules.

@Override
public void extendRules(@NotNull List<IRule> rules, @NotNull RulePosition position) {
    if (position == RulePosition.CONTROL) {
        final SQLControlToken sourceToken = new SQLControlToken(new TextAttribute(UIUtils.getGlobalColor(SQLConstants.CONFIG_COLOR_COMMAND), null, SWT.BOLD), "mysql.source");
        // $NON-NLS-1$
        SQLFullLineRule sourceRule2 = new SQLFullLineRule("SOURCE", sourceToken);
        rules.add(sourceRule2);
    }
}
Also used : SQLFullLineRule(org.jkiss.dbeaver.ui.editors.sql.syntax.rules.SQLFullLineRule) TextAttribute(org.eclipse.jface.text.TextAttribute) SQLControlToken(org.jkiss.dbeaver.ui.editors.sql.syntax.tokens.SQLControlToken)

Example 78 with TextAttribute

use of org.eclipse.jface.text.TextAttribute in project dbeaver by dbeaver.

the class HTMLSQLConverter method convertText.

@NotNull
@Override
public String convertText(@NotNull SQLDialect dialect, @NotNull SQLSyntaxManager syntaxManager, @NotNull SQLRuleManager ruleManager, @NotNull IDocument document, int startPos, int length, @NotNull Map<String, Object> options) {
    StringBuilder result = new StringBuilder();
    ruleManager.setRange(document, startPos, length);
    try {
        result.append("<pre>");
        for (; ; ) {
            IToken token = ruleManager.nextToken();
            if (token.isEOF()) {
                break;
            }
            int tokenOffset = ruleManager.getTokenOffset();
            final int tokenLength = ruleManager.getTokenLength();
            boolean hasSpan = false;
            Object data = token.getData();
            if (data instanceof TextAttribute) {
                result.append("<span style='");
                TextAttribute ta = (TextAttribute) data;
                if (ta.getBackground() != null) {
                    result.append("background-color:").append(toHex(ta.getBackground())).append(";");
                }
                if (ta.getForeground() != null) {
                    result.append("color:").append(toHex(ta.getForeground())).append(";");
                }
                if ((ta.getStyle() & SWT.BOLD) == SWT.BOLD) {
                    result.append("font-weight:bold;");
                }
                if ((ta.getStyle() & SWT.ITALIC) == SWT.ITALIC) {
                    result.append("font-style: italic;");
                }
                // ta.getStyle()
                result.append("'>");
                hasSpan = true;
            }
            result.append(document.get(tokenOffset, tokenLength));
            if (hasSpan) {
                result.append("</span>");
            }
        }
        result.append("</pre>");
    } catch (BadLocationException e) {
        log.error("Error converting SQL to HTML", e);
    }
    return result.toString().trim();
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) TextAttribute(org.eclipse.jface.text.TextAttribute) BadLocationException(org.eclipse.jface.text.BadLocationException) NotNull(org.jkiss.code.NotNull)

Example 79 with TextAttribute

use of org.eclipse.jface.text.TextAttribute in project eclipse.platform.text by eclipse.

the class JavaSourceViewerConfiguration method getPresentationReconciler.

@Override
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
    JavaColorProvider provider = JavaEditorExamplePlugin.getDefault().getJavaColorProvider();
    PresentationReconciler reconciler = new PresentationReconciler();
    reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
    DefaultDamagerRepairer dr = new DefaultDamagerRepairer(JavaEditorExamplePlugin.getDefault().getJavaCodeScanner());
    reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
    reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
    dr = new DefaultDamagerRepairer(JavaEditorExamplePlugin.getDefault().getJavaDocScanner());
    reconciler.setDamager(dr, JavaPartitionScanner.JAVA_DOC);
    reconciler.setRepairer(dr, JavaPartitionScanner.JAVA_DOC);
    dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(JavaColorProvider.MULTI_LINE_COMMENT))));
    reconciler.setDamager(dr, JavaPartitionScanner.JAVA_MULTILINE_COMMENT);
    reconciler.setRepairer(dr, JavaPartitionScanner.JAVA_MULTILINE_COMMENT);
    return reconciler;
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) JavaColorProvider(org.eclipse.ui.examples.javaeditor.util.JavaColorProvider) DefaultDamagerRepairer(org.eclipse.jface.text.rules.DefaultDamagerRepairer) IPresentationReconciler(org.eclipse.jface.text.presentation.IPresentationReconciler) PresentationReconciler(org.eclipse.jface.text.presentation.PresentationReconciler)

Example 80 with TextAttribute

use of org.eclipse.jface.text.TextAttribute in project eclipse.platform.text by eclipse.

the class XMLConfiguration method getPresentationReconciler.

@Override
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
    PresentationReconciler reconciler = new PresentationReconciler();
    DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getXMLTagScanner());
    reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG);
    reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG);
    dr = new DefaultDamagerRepairer(getXMLScanner());
    reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
    reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
    NonRuleBasedDamagerRepairer ndr = new NonRuleBasedDamagerRepairer(new TextAttribute(colorManager.getColor(IXMLColorConstants.XML_COMMENT)));
    reconciler.setDamager(ndr, XMLPartitionScanner.XML_COMMENT);
    reconciler.setRepairer(ndr, XMLPartitionScanner.XML_COMMENT);
    return reconciler;
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) DefaultDamagerRepairer(org.eclipse.jface.text.rules.DefaultDamagerRepairer) IPresentationReconciler(org.eclipse.jface.text.presentation.IPresentationReconciler) PresentationReconciler(org.eclipse.jface.text.presentation.PresentationReconciler)

Aggregations

TextAttribute (org.eclipse.jface.text.TextAttribute)142 Token (org.eclipse.jface.text.rules.Token)45 RGB (org.eclipse.swt.graphics.RGB)37 Color (org.eclipse.swt.graphics.Color)36 IToken (org.eclipse.jface.text.rules.IToken)23 StyleRange (org.eclipse.swt.custom.StyleRange)20 IPresentationReconciler (org.eclipse.jface.text.presentation.IPresentationReconciler)16 PresentationReconciler (org.eclipse.jface.text.presentation.PresentationReconciler)16 DefaultDamagerRepairer (org.eclipse.jface.text.rules.DefaultDamagerRepairer)14 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)12 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)12 IRule (org.eclipse.jface.text.rules.IRule)10 RuleBasedScanner (org.eclipse.jface.text.rules.RuleBasedScanner)9 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)8 ArrayList (java.util.ArrayList)7 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)6 ColorRegistry (org.eclipse.jface.resource.ColorRegistry)5 Document (org.eclipse.jface.text.Document)4 IDocument (org.eclipse.jface.text.IDocument)4 MultiLineRule (org.eclipse.jface.text.rules.MultiLineRule)4