Search in sources :

Example 16 with TextLayout

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

the class TextCellRenderer method draw.

/**
     * {@inheritDoc}
     */
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row, IColumn column, boolean drawFocus, boolean selected, boolean printing) {
    drawBackground(gc, drawingArea, cellStyle, selected, printing);
    Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
    Rectangle rect = applyInsets(drect);
    // convert the value to a string
    String s = convertValue(row, column);
    Color fg = gc.getForeground();
    Color bg = gc.getBackground();
    Font font = gc.getFont();
    // draw comment marker if comment is present and not printing
    if (!printing && getComment(row, column) != null) {
        drawCommentMarker(gc, drawingArea, _commentColor, COMMENTMARKER_SIZE);
    }
    if (drawFocus) {
        drawFocus(gc, drect);
    }
    drawSelection(gc, drawingArea, cellStyle, selected, printing);
    gc.setForeground(fg);
    gc.setBackground(bg);
    gc.setFont(font);
    if (s != null) {
        if (selected && !printing) {
            gc.setBackground(SELECTIONCOLOR);
        } else {
            gc.setBackground(getBackgroundColor(cellStyle, printing));
        }
        gc.setForeground(getForegroundColor(cellStyle, printing));
        gc.setFont(getFont(cellStyle, printing, gc.getFont()));
        drawCellString(gc, rect, s, cellStyle);
        if (s.indexOf("we") != -1) {
            TextLayout textLayout = new TextLayout(gc.getDevice());
            textLayout.setText(s);
            textLayout.setFont(gc.getFont());
            textLayout.setWidth(rect.width);
            Color color = new Color(gc.getDevice(), 150, 100, 100);
            Font font2 = new Font(gc.getDevice(), gc.getFont().getFontData()[0].getName(), gc.getFont().getFontData()[0].getHeight(), SWT.ITALIC);
            TextStyle style = new TextStyle(font2, color, null);
            for (int i = 1; i < s.length(); i++) {
                int j = indexOf(s, "we", i, false);
                if (j != -1) {
                    textLayout.setStyle(style, j, j + 3);
                } else {
                    break;
                }
            }
            gc.fillRectangle(rect);
            textLayout.draw(gc, rect.x, rect.y);
            gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
        }
    }
}
Also used : TextStyle(org.eclipse.swt.graphics.TextStyle) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) Font(org.eclipse.swt.graphics.Font) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 17 with TextLayout

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

the class DefaultCellRenderer method computeSize.

/**
     * {@inheritDoc}
     */
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
    GridItem item = (GridItem) value;
    gc.setFont(item.getFont(getColumn()));
    int x = 0;
    x += leftMargin;
    if (isTree()) {
        x += getToggleIndent(item);
        x += toggleRenderer.getBounds().width + insideMargin;
    }
    if (isCheck()) {
        x += checkRenderer.getBounds().width + insideMargin;
    }
    int y = 0;
    Image image = item.getImage(getColumn());
    if (image != null) {
        y = topMargin + image.getBounds().height + bottomMargin;
        x += image.getBounds().width + insideMargin;
    }
    // MOPR-DND
    // MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
    //
    //       x += gc.stringExtent(item.getText(column)).x + rightMargin;
    //
    //        y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
    //
    // with this code:
    int textHeight = 0;
    if (!isWordWrap()) {
        x += gc.textExtent(item.getText(getColumn())).x + rightMargin;
        textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
    } else {
        int plainTextWidth;
        if (wHint == SWT.DEFAULT)
            plainTextWidth = getBounds().width - x - rightMargin;
        else
            plainTextWidth = wHint - x - rightMargin;
        TextLayout currTextLayout = new TextLayout(gc.getDevice());
        currTextLayout.setFont(gc.getFont());
        currTextLayout.setText(item.getText(getColumn()));
        currTextLayout.setAlignment(getAlignment());
        currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);
        x += plainTextWidth + rightMargin;
        textHeight += topMargin + textTopMargin;
        for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++) textHeight += currTextLayout.getLineBounds(cnt).height;
        textHeight += textBottomMargin + bottomMargin;
        currTextLayout.dispose();
    }
    y = Math.max(y, textHeight);
    return new Point(x, y);
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 18 with TextLayout

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

the class DefaultColumnGroupHeaderRenderer method getTextLayout.

private void getTextLayout(GC gc, GridColumnGroup group) {
    if (textLayout == null) {
        textLayout = new TextLayout(gc.getDevice());
        textLayout.setFont(gc.getFont());
        group.getParent().addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                textLayout.dispose();
            }
        });
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 19 with TextLayout

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

the class DefaultColumnHeaderRenderer method getTextLayout.

private void getTextLayout(GC gc, GridColumn column) {
    if (textLayout == null) {
        textLayout = new TextLayout(gc.getDevice());
        textLayout.setFont(gc.getFont());
        column.getParent().addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                textLayout.dispose();
            }
        });
    }
    textLayout.setAlignment(column.getAlignment());
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 20 with TextLayout

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

the class DefaultRowHeaderRenderer method getTextLayout.

private void getTextLayout(GC gc, GridItem gridItem) {
    if (textLayout == null) {
        textLayout = new TextLayout(gc.getDevice());
        textLayout.setFont(gc.getFont());
        gridItem.getParent().addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                textLayout.dispose();
            }
        });
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) 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