Search in sources :

Example 26 with StyleRange

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

the class InformationWindow method decorateText.

/**
	 * Decorate the text
	 */
private void decorateText(Set<String> keyWords) {
    String text = infoText.getText();
    infoText.setAlignment(SWT.LEFT_TO_RIGHT);
    for (String key : keyWords) {
        int index = text.indexOf(key);
        if (index >= 0) {
            StyleRange eachStyle = new StyleRange();
            eachStyle.start = index;
            eachStyle.length = key.length();
            eachStyle.fontStyle = SWT.BOLD;
            infoText.setStyleRange(eachStyle);
        }
    }
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange) Point(org.eclipse.swt.graphics.Point)

Example 27 with StyleRange

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

the class QueryRecordListComparator method setQueryMessage.

/**
	 * Set query result message
	 *
	 * @param messageText
	 * @param queryRecord
	 */
private void setQueryMessage(StyledText messageText, QueryRecord queryRecord) {
    StringBuilder sb = new StringBuilder();
    /*Query message*/
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(3);
    double elapsedTime = (queryRecord.getStopTime() - queryRecord.getStartTime()) * 0.001;
    String elapsedTimeStr = nf.format(elapsedTime);
    if (elapsedTime < 0.001) {
        elapsedTimeStr = "0.000";
    }
    /*elapsed time*/
    sb.append(Messages.queryWithoutSeq).append("[ ").append(elapsedTimeStr).append(Messages.second);
    /*total row*/
    if (queryRecord.getQueryInfo() != null) {
        sb.append(" , ").append(Messages.totalRows).append(" : ").append(queryRecord.getQueryInfo().getTotalRs()).append(" ]").append(StringUtil.NEWLINE);
    }
    //		sb.append(QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT);
    //		sb.append("Statistics");
    //		sb.append(StringUtil.NEWLINE);
    //		sb.append(queryRecord.getStatisticsWithRawText().trim());
    //		sb.append(StringUtil.NEWLINE);
    //		String indexInfo = queryRecord.getIndexesOnQueryWithText();
    //		if (StringUtil.isNotEmpty(indexInfo)) {
    //			sb.append(QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT);
    //			sb.append("Indexes");
    //			sb.append(StringUtil.NEWLINE);
    //			sb.append(indexInfo);
    //			sb.append(StringUtil.NEWLINE);
    //		}
    sb.append(QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT);
    sb.append(StringUtil.NEWLINE);
    sb.append(queryRecord.getQuery());
    sb.append(StringUtil.NEWLINE);
    String result = sb.toString();
    messageText.setText(result);
    int splitterLen = QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT.length();
    {
        StyleRange eachStyle = new StyleRange();
        eachStyle.start = 0;
        eachStyle.length = result.indexOf(QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT);
        eachStyle.fontStyle = SWT.NORMAL;
        eachStyle.foreground = ResourceManager.getColor(SWT.COLOR_BLUE);
        messageText.setStyleRange(eachStyle);
    }
    for (int sp = 0; ; ) {
        StyleRange eachStyle = new StyleRange();
        sp = result.indexOf(QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT, sp);
        if (sp == -1) {
            break;
        }
        int ep = result.indexOf(StringUtil.NEWLINE, sp);
        if (ep != -1) {
            splitterLen = ep - sp;
        }
        eachStyle.start = sp;
        eachStyle.length = splitterLen;
        eachStyle.fontStyle = SWT.NORMAL;
        eachStyle.foreground = ResourceManager.getColor(SWT.COLOR_BLUE);
        messageText.setStyleRange(eachStyle);
        sp += splitterLen;
    }
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange) NumberFormat(java.text.NumberFormat)

Example 28 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project eclipse.platform.text by eclipse.

the class InlinedAnnotationDrawingStrategy method draw.

/**
 * Draw the line content annotation inside line in the empty area computed by
 * {@link GlyphMetrics}.
 *
 * @param annotation the annotation to be drawn
 * @param gc the graphics context, <code>null</code> when in clearing mode
 * @param textWidget the text widget to draw on
 * @param offset the offset of the line
 * @param length the length of the line
 * @param color the color of the line
 */
private static void draw(LineContentAnnotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) {
    StyleRange style = null;
    try {
        style = textWidget.getStyleRangeAtOffset(offset);
    } catch (Exception e) {
        return;
    }
    if (annotation.isMarkedDeleted()) {
        // When annotation is deleted, update metrics to null to remove extra spaces of the line content annotation.
        if (style != null) {
            style.metrics = null;
            textWidget.setStyleRange(style);
        }
        return;
    }
    if (gc != null) {
        // Compute the location of the annotation
        Rectangle bounds = textWidget.getTextBounds(offset, offset);
        int x = bounds.x;
        int y = bounds.y;
        // Get size of the character where GlyphMetrics width is added
        String s = textWidget.getText(offset, offset);
        Point charBounds = gc.stringExtent(s);
        int charWidth = charBounds.x;
        int charHeight = charBounds.y;
        // When line text has line header annotation, there is a space on the top, adjust the y by using char height
        y += bounds.height - charHeight;
        // Draw the line content annotation
        annotation.draw(gc, textWidget, offset, length, color, x, y);
        int width = annotation.getWidth();
        if (width != 0) {
            // FIXME: remove this code when we need not redraw the character (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=531769)
            // START TO REMOVE
            annotation.setRedrawnCharacterWidth(charWidth);
            // END TO REMOVE
            // Annotation takes place, add GlyphMetrics width to the style
            StyleRange newStyle = updateStyle(annotation, style);
            if (newStyle != null) {
                textWidget.setStyleRange(newStyle);
                return;
            }
            // FIXME: remove this code when we need not redraw the character (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=531769)
            // START TO REMOVE
            // The inline annotation replaces one character by taking a place width
            // GlyphMetrics
            // Here we need to redraw this first character because GlyphMetrics clip this
            // character.
            int charX = x + bounds.width - charWidth;
            int charY = y;
            if (style != null) {
                if (style.background != null) {
                    gc.setBackground(style.background);
                    gc.fillRectangle(charX, charY, charWidth + 1, bounds.height);
                }
                if (style.foreground != null) {
                    gc.setForeground(style.foreground);
                } else {
                    gc.setForeground(textWidget.getForeground());
                }
                gc.setFont(annotation.getFont(style.fontStyle));
            }
            gc.drawString(s, charX, charY, true);
        // END TO REMOVE
        } else if (style != null && style.metrics != null && style.metrics.width != 0) {
            // line content annotation had an , reset it
            style.metrics = null;
            textWidget.setStyleRange(style);
        }
    } else {
        textWidget.redrawRange(offset, length, true);
    }
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 29 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project eclipse.platform.text by eclipse.

the class InlinedAnnotationDrawingStrategy method updateStyle.

/**
 * Returns the style to apply with GlyphMetrics ascent only if needed.
 *
 * @param annotation the line header annotation
 * @param style the current style and null otherwise.
 * @return the style to apply with GlyphMetrics ascent only if needed.
 */
static StyleRange updateStyle(LineHeaderAnnotation annotation, StyleRange style) {
    int width = annotation.getRedrawnCharacterWidth();
    if (width == 0) {
        // Update GlyphMetrics only when mining was already drawn
        return null;
    }
    int height = annotation.getHeight();
    if (height == 0) {
        return null;
    }
    int fullHeight = height + annotation.getRedrawnCharacterHeight();
    if (style == null) {
        style = new StyleRange();
        Position position = annotation.getPosition();
        style.start = position.getOffset();
        style.length = 1;
    }
    GlyphMetrics metrics = style.metrics;
    if (!annotation.isMarkedDeleted()) {
        if (metrics == null) {
            metrics = new GlyphMetrics(fullHeight, 0, width);
        } else {
            if (metrics.ascent == fullHeight) {
                return null;
            }
            /**
             * We must create a new GlyphMetrics instance because comparison with similarTo used
             * later in StyledText#setStyleRange will compare the same (modified) and won't
             * realize an update happened.
             */
            metrics = new GlyphMetrics(fullHeight, 0, width);
        }
    } else {
        metrics = null;
    }
    style.metrics = metrics;
    return style;
}
Also used : Position(org.eclipse.jface.text.Position) GlyphMetrics(org.eclipse.swt.graphics.GlyphMetrics) StyleRange(org.eclipse.swt.custom.StyleRange) Point(org.eclipse.swt.graphics.Point)

Example 30 with StyleRange

use of org.eclipse.swt.custom.StyleRange in project eclipse.platform.text by eclipse.

the class TextViewer method modelStyleRange2WidgetStyleRange.

/**
 * Translates a style range given relative to the viewer's document into style
 * ranges relative to the viewer's widget or <code>null</code>.
 *
 * @param range the style range in the coordinates of the viewer's document
 * @return the style range in the coordinates of the viewer's widget or <code>null</code>
 * @since 2.1
 */
protected StyleRange modelStyleRange2WidgetStyleRange(StyleRange range) {
    IRegion region = modelRange2WidgetRange(new Region(range.start, range.length));
    if (region != null) {
        StyleRange result = (StyleRange) range.clone();
        result.start = region.getOffset();
        result.length = region.getLength();
        return result;
    }
    return 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