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));
}
}
}
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);
}
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();
}
});
}
}
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());
}
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();
}
});
}
}
Aggregations