Search in sources :

Example 16 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 17 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 18 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)

Example 19 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project cubrid-manager by CUBRID.

the class ProductInfoDialog method getCurrentRange.

/**
	 * Find the range of the current selection.
	 * 
	 * @param text the StyledText
	 * @return the StyleRange
	 */
protected StyleRange getCurrentRange(StyledText text) {
    StyleRange[] ranges = text.getStyleRanges();
    int currentSelectionEnd = text.getSelection().y;
    int currentSelectionStart = text.getSelection().x;
    for (int i = 0; i < ranges.length; i++) {
        if ((currentSelectionStart >= ranges[i].start) && (currentSelectionEnd <= (ranges[i].start + ranges[i].length))) {
            return ranges[i];
        }
    }
    return null;
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange) Point(org.eclipse.swt.graphics.Point)

Example 20 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project cubrid-manager by CUBRID.

the class ProductInfoDialog method setLinkRanges.

/**
	 * Sets the styled text's link (blue) ranges
	 * 
	 * @param styledText the styledText
	 * @param linkRanges the range array
	 */
protected void setLinkRanges(StyledText styledText, int[][] linkRanges) {
    Color fg = JFaceColors.getHyperlinkText(styledText.getShell().getDisplay());
    for (int i = 0; i < linkRanges.length; i++) {
        StyleRange r = new StyleRange(linkRanges[i][0], linkRanges[i][1], fg, null);
        styledText.setStyleRange(r);
    }
}
Also used : Color(org.eclipse.swt.graphics.Color) StyleRange(org.eclipse.swt.custom.StyleRange) Point(org.eclipse.swt.graphics.Point)

Aggregations

StyleRange (org.eclipse.swt.custom.StyleRange)51 Point (org.eclipse.swt.graphics.Point)24 ArrayList (java.util.ArrayList)13 Color (org.eclipse.swt.graphics.Color)9 StyledText (org.eclipse.swt.custom.StyledText)7 Matcher (java.util.regex.Matcher)6 TextStyle (org.eclipse.swt.graphics.TextStyle)5 LinkedList (java.util.LinkedList)2 List (java.util.List)2 InnerTag (net.heartsome.cat.common.ui.innertag.InnerTag)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 KeyEvent (org.eclipse.swt.events.KeyEvent)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)2 GlyphMetrics (org.eclipse.swt.graphics.GlyphMetrics)2 ParamSetException (com.cubrid.common.ui.spi.util.paramSetter.ParamSetException)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1