Search in sources :

Example 51 with StyleRange

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

the class SpringConfigurationStyledText method updateStyledRanges.

private void updateStyledRanges(ExtendedModifyEvent event) {
    StyledText st = (StyledText) event.widget;
    int start = event.start;
    int length = event.length;
    String replacedText = event.replacedText;
    String textRange = st.getTextRange(start, length);
    /*
		 * if no real change
		 * then return
		 */
    if ("".equals(textRange.trim()) && "".equals(replacedText.trim())) {
        return;
    }
    List<StyleRange> styles = new ArrayList<StyleRange>();
    scanner.setRange(st.getText());
    int token = scanner.nextToken();
    while (token != EOF) {
        int startOffset = scanner.getStartOffset();
        int tokenLength = scanner.getLength();
        String tokenText = st.getTextRange(startOffset, tokenLength).trim();
        for (String s : fgKeywords) {
            if (s.equals(tokenText)) {
                token = KEY;
                break;
            }
        }
        Color color = getColor(token);
        StyleRange style = new StyleRange(startOffset, tokenLength, color, null);
        if (token == KEY) {
            style.fontStyle = SWT.BOLD;
        }
        styles.add(style);
        token = scanner.nextToken();
    }
    st.setStyleRanges(styles.toArray(new StyleRange[0]));
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) StyleRange(org.eclipse.swt.custom.StyleRange) Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList) 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