Search in sources :

Example 26 with TextLayout

use of org.eclipse.swt.graphics.TextLayout in project translationstudio8 by heartsome.

the class StyleTextCellRenderer method draw.

public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row, IColumn column, boolean drawFocus, boolean selected, boolean printing) {
    super.draw(gc, jaretTable, cellStyle, drawingArea, row, column, drawFocus, selected, printing);
    // Color bg = gc.getBackground();
    // Color fg = gc.getForeground();
    Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
    Rectangle rect = applyInsets(drect);
    String s = convertValue(row, column);
    if (s != null && strStyleText != null && !strStyleText.equals("")) {
        if (selected && !printing) {
            Color color = ColorManager.getColorManager(Display.getCurrent()).getColor(new RGB(218, 218, 218));
            gc.setBackground(color);
        } else {
            gc.setBackground(getBackgroundColor(cellStyle, printing));
        }
        if (textLayout == null) {
            textLayout = new TextLayout(gc.getDevice());
            jaretTable.getParent().addDisposeListener(new DisposeListener() {

                public void widgetDisposed(DisposeEvent e) {
                    textLayout.dispose();
                }
            });
        }
        textLayout.setOrientation(jaretTable.getOrientation());
        textLayout.setText(s);
        textLayout.setFont(gc.getFont());
        textLayout.setWidth(rect.width);
        if (blnIsApplyRegular) {
            Pattern pattern = null;
            if (blnIsCaseSensitive) {
                pattern = Pattern.compile(strStyleText);
            } else {
                pattern = Pattern.compile(strStyleText, Pattern.CASE_INSENSITIVE);
            }
            Matcher matcher = pattern.matcher(s);
            while (matcher.find()) {
                textLayout.setStyle(style, matcher.start(), matcher.end() - 1);
            }
            gc.fillRectangle(rect);
            textLayout.draw(gc, rect.x, rect.y);
            gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
        } else {
            int index = -1;
            if (!blnIsCaseSensitive) {
                index = s.toUpperCase().indexOf(strStyleText.toUpperCase());
            } else {
                index = s.indexOf(strStyleText);
            }
            if (index != -1) {
                for (int i = 1; i < s.length(); i++) {
                    int j = TextUtil.indexOf(s, strStyleText, i, blnIsCaseSensitive);
                    if (j != -1) {
                        textLayout.setStyle(style, j, j + strStyleText.length() - 1);
                    } else {
                        break;
                    }
                }
                gc.fillRectangle(rect);
                textLayout.draw(gc, rect.x, rect.y);
                gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
            }
        }
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) RGB(org.eclipse.swt.graphics.RGB) DisposeEvent(org.eclipse.swt.events.DisposeEvent) TextLayout(org.eclipse.swt.graphics.TextLayout)

Aggregations

TextLayout (org.eclipse.swt.graphics.TextLayout)26 Point (org.eclipse.swt.graphics.Point)19 GridItem (org.eclipse.nebula.widgets.grid.GridItem)13 Color (org.eclipse.swt.graphics.Color)10 Image (org.eclipse.swt.graphics.Image)10 Rectangle (org.eclipse.swt.graphics.Rectangle)10 DisposeEvent (org.eclipse.swt.events.DisposeEvent)9 DisposeListener (org.eclipse.swt.events.DisposeListener)9 TextStyle (org.eclipse.swt.graphics.TextStyle)7 Font (org.eclipse.swt.graphics.Font)4 Matcher (java.util.regex.Matcher)3 ArrayList (java.util.ArrayList)2 Pattern (java.util.regex.Pattern)2 InnerTagBean (net.heartsome.cat.common.innertag.InnerTagBean)2 XliffInnerTagFactory (net.heartsome.cat.common.innertag.factory.XliffInnerTagFactory)2 GridColumn (org.eclipse.nebula.widgets.grid.GridColumn)2 StyleRange (org.eclipse.swt.custom.StyleRange)2 RGB (org.eclipse.swt.graphics.RGB)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1