Search in sources :

Example 11 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project tdi-studio-se by Talend.

the class ReportMessageManager method setStartMessage.

public synchronized void setStartMessage(String content, Color foreground, Color background) {
    messages.clear();
    StyleRange styleRange = new StyleRange(0, content.length(), foreground, background);
    messages.add(new ReportMessage(styleRange, content));
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange)

Example 12 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project tdi-studio-se by Talend.

the class ProcessComposite method processMessage.

private boolean processMessage(StringBuffer consoleText, IProcessMessage message, int startLength, List<StyleRange> styles) {
    String content = message.getContent();
    int lengthBeforeAdd = consoleText.length();
    //$NON-NLS-1$
    String[] contents = content.split("\n");
    for (String content2 : contents) {
        if (isPattern(content2) || isPatternFor(content2)) {
            //$NON-NLS-1$
            consoleText.append("");
            //$NON-NLS-1$
            content = "";
        } else {
            consoleText.append(content2);
            //$NON-NLS-1$
            consoleText.append("\n");
        }
    }
    boolean newStyle = false;
    if (message.getType() != MsgType.STD_OUT) {
        StyleRange style = new StyleRange();
        style.start = startLength + lengthBeforeAdd;
        style.length = content.length();
        if (message.getType() == MsgType.CORE_OUT || message.getType() == MsgType.CORE_ERR) {
            style.fontStyle = SWT.ITALIC;
        }
        Color color = getColor((MsgType) message.getType());
        style.foreground = color;
        if ((style.start + style.length) > (startLength + consoleText.length())) {
            style.length = startLength + consoleText.length() - style.start;
        }
        styles.add(style);
        newStyle = true;
    }
    return newStyle;
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange) Color(org.eclipse.swt.graphics.Color) Point(org.eclipse.swt.graphics.Point)

Example 13 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project tesb-studio-se by Talend.

the class AnsiConsoleStyleListener method lineGetStyle.

@Override
public void lineGetStyle(LineStyleEvent event) {
    if (event == null || event.lineText == null || event.lineText.length() == 0)
        return;
    StyleRange defStyle;
    if (event.styles != null && event.styles.length > 0) {
        defStyle = (StyleRange) event.styles[0].clone();
        if (defStyle.background == null)
            defStyle.background = AnsiConsoleUtils.getDebugConsoleBgColor();
    } else {
        defStyle = new StyleRange(1, lastRangeEnd, new Color(null, AnsiConsoleColorPalette.getColor(0)), new Color(null, AnsiConsoleColorPalette.getColor(15)), SWT.NORMAL);
    }
    lastRangeEnd = 0;
    List<StyleRange> ranges = new ArrayList<StyleRange>();
    String currentText = event.lineText;
    Matcher matcher = pattern.matcher(currentText);
    while (matcher.find()) {
        int start = matcher.start();
        int end = matcher.end();
        String theEscape = currentText.substring(matcher.start() + 2, matcher.end() - 1);
        char code = currentText.charAt(matcher.end() - 1);
        if (code == ESCAPE_SGR) {
            // Select Graphic Rendition (SGR) escape sequence
            List<Integer> nCommands = new ArrayList<Integer>();
            for (String cmd : theEscape.split(";")) {
                int nCmd = AnsiConsoleUtils.tryParseInteger(cmd);
                if (nCmd != -1)
                    nCommands.add(nCmd);
            }
            if (nCommands.isEmpty())
                nCommands.add(0);
            interpretCommand(nCommands);
        }
        if (lastRangeEnd != start)
            addRange(ranges, event.lineOffset + lastRangeEnd, start - lastRangeEnd, defStyle.foreground, false);
        lastAttributes = currentAttributes.clone();
        addRange(ranges, event.lineOffset + start, end - start, defStyle.foreground, true);
    }
    if (lastRangeEnd != currentText.length())
        addRange(ranges, event.lineOffset + lastRangeEnd, currentText.length() - lastRangeEnd, defStyle.foreground, false);
    lastAttributes = currentAttributes.clone();
    if (!ranges.isEmpty())
        event.styles = ranges.toArray(new StyleRange[ranges.size()]);
}
Also used : Matcher(java.util.regex.Matcher) StyleRange(org.eclipse.swt.custom.StyleRange) Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList)

Example 14 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project tesb-studio-se by Talend.

the class AnsiConsoleStyleListener method addRange.

private void addRange(List<StyleRange> ranges, int start, int length, Color foreground, boolean isCode) {
    StyleRange range = new StyleRange(start, length, foreground, null);
    AnsiConsoleAttributes.updateRangeStyle(range, lastAttributes);
    if (isCode) {
        range.metrics = new GlyphMetrics(0, 0, 0);
    }
    ranges.add(range);
    lastRangeEnd = lastRangeEnd + range.length;
}
Also used : GlyphMetrics(org.eclipse.swt.graphics.GlyphMetrics) StyleRange(org.eclipse.swt.custom.StyleRange)

Example 15 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project tesb-studio-se by Talend.

the class SearchCellLabelProvider method update.

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    final String text = getText(element);
    cell.setText(text);
    cell.setImage(getImage(element));
    cell.setFont(getFont(element));
    if (filterString != null && !filterString.isEmpty()) {
        int filterIndex = text.indexOf(filterString);
        StyleRange styleRange = new StyleRange(filterIndex, filterString.length(), null, hightLight);
        cell.setStyleRanges(new StyleRange[] { styleRange });
    } else {
        cell.setStyleRanges(null);
    }
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange)

Aggregations

StyleRange (org.eclipse.swt.custom.StyleRange)145 Point (org.eclipse.swt.graphics.Point)52 Test (org.junit.Test)39 ArrayList (java.util.ArrayList)25 Color (org.eclipse.swt.graphics.Color)22 StyledText (org.eclipse.swt.custom.StyledText)13 Font (org.eclipse.swt.graphics.Font)10 GlyphMetrics (org.eclipse.swt.graphics.GlyphMetrics)10 Matcher (java.util.regex.Matcher)9 FontData (org.eclipse.swt.graphics.FontData)8 RGB (org.eclipse.swt.graphics.RGB)8 Rectangle (org.eclipse.swt.graphics.Rectangle)7 IOException (java.io.IOException)5 TextPresentation (org.eclipse.jface.text.TextPresentation)5 Image (org.eclipse.swt.graphics.Image)5 Control (org.eclipse.swt.widgets.Control)5 Position (org.eclipse.jface.text.Position)4 TextStyle (org.eclipse.swt.graphics.TextStyle)4 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3