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