use of org.eclipse.swt.graphics.Device in project translationstudio8 by heartsome.
the class SmileyCellRenderer 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);
Object value = column.getValue(row);
if (value != null) {
saveGCAttributes(gc);
int val = ((Integer) value).intValue();
_brModel.setValue(val);
calcSmileFactor();
if (_forceCircle) {
int a = Math.min(rect.width, rect.height);
Rectangle nrect = new Rectangle(0, 0, a, a);
nrect.x = rect.x + (rect.width - a) / 2;
nrect.y = rect.y + (rect.height - a) / 2;
rect = nrect;
}
int width = rect.width;
int height = rect.height;
int offx = rect.x;
int offy = rect.y;
float foffx = (float) offx;
float foffy = (float) offy;
int lineWidth = height / 40;
if (!_colorChange) {
gc.setBackground(_neutral);
} else {
if (_currentValue >= 0) {
// positive
gc.setBackground(calcColor(_positive, printing));
} else {
// negative
gc.setBackground(calcColor(_negative, printing));
}
}
Device device = printing ? _printer : Display.getCurrent();
Path p = new Path(device);
p.addArc(foffx + 0 + lineWidth / 2, foffy + 0 + lineWidth / 2, width - 1 - lineWidth, height - 1 - lineWidth, 0, 360);
gc.fillPath(p);
gc.setForeground(_black);
gc.setLineWidth(lineWidth);
gc.drawPath(p);
p.dispose();
// eyes
int y = height / 3;
int x1 = width / 3;
int x2 = width - width / 3;
int r = width / 30;
// eyes have a minimal size
if (r == 0) {
r = 1;
}
gc.setBackground(_black);
gc.fillOval(offx + x1 - r, offy + y - r, 2 * r, 2 * r);
gc.fillOval(offx + x2 - r, offy + y - r, 2 * r, 2 * r);
// eye brows
if (_eyeBrows) {
gc.setLineWidth(lineWidth / 2);
int ebWidth = width / 10;
int yDist = height / 13;
int yOff = (int) (_currentValue * (double) height / 30);
int xShift = (int) (_currentValue * (double) width / 90);
p = new Path(device);
p.moveTo(foffx + x1 - ebWidth / 2 + xShift, foffy + y - yDist + yOff);
p.lineTo(foffx + x1 + ebWidth / 2 - xShift, foffy + y - yDist - yOff);
gc.drawPath(p);
p.dispose();
p = new Path(device);
p.moveTo(foffx + x2 - ebWidth / 2 + xShift, foffy + y - yDist - yOff);
p.lineTo(foffx + x2 + ebWidth / 2 - xShift, foffy + y - yDist + yOff);
gc.drawPath(p);
p.dispose();
}
// mouth
gc.setLineWidth(lineWidth);
x1 = (int) (width / 4.5);
x2 = width - x1;
y = height - height / 3;
int midX = width / 2;
int offset = (int) (_currentValue * (double) height / 3);
p = new Path(Display.getCurrent());
p.moveTo(foffx + x1, foffy + y);
p.quadTo(foffx + midX, foffy + y + offset, foffx + x2, foffy + y);
gc.drawPath(p);
p.dispose();
restoreGCAttributes(gc);
}
if (drawFocus) {
drawFocus(gc, drect);
}
drawSelection(gc, drawingArea, cellStyle, selected, printing);
}
use of org.eclipse.swt.graphics.Device in project translationstudio8 by heartsome.
the class CellRendererBase method getBackgroundColor.
/**
* Get the background color according to a cell style.
*
* @param style cell style
* @param printing true for printing
* @return the color
*/
protected Color getBackgroundColor(ICellStyle style, boolean printing) {
Device device = printing ? _printer : Display.getCurrent();
ColorManager cm = ColorManager.getColorManager(device);
Color bg = cm.getColor(style.getBackgroundColor() != null ? style.getBackgroundColor() : WHITERGB);
return bg;
}
use of org.eclipse.swt.graphics.Device in project translationstudio8 by heartsome.
the class CellRendererBase method getBorderColor.
/**
* Get the border color according to the cell style.
*
* @param style cell style
* @param printing true for printing
* @return the border color
*/
protected Color getBorderColor(ICellStyle style, boolean printing) {
Device device = printing ? _printer : Display.getCurrent();
ColorManager cm = ColorManager.getColorManager(device);
Color bg = cm.getColor(style.getBorderColor() != null ? style.getBorderColor() : new RGB(0, 0, 0));
return bg;
}
use of org.eclipse.swt.graphics.Device in project translationstudio8 by heartsome.
the class ColorConfigLoader method loadColor.
private void loadColor() {
Device device = Activator.getDefault().getWorkbench().getDisplay();
if (pfStore == null) {
pfStore = Activator.getDefault().getPreferenceStore();
pfStore.addPropertyChangeListener(this);
}
colorConfigBean.release();
colorConfigBean.setPtColor(getColor(device, IColorPreferenceConstant.PT_COLOR));
colorConfigBean.setQtColor(getColor(device, IColorPreferenceConstant.QT_COLOR));
colorConfigBean.setMtColor(getColor(device, IColorPreferenceConstant.MT_COLOR));
colorConfigBean.setTm101Color(getColor(device, IColorPreferenceConstant.TM_MATCH101_COLOR));
colorConfigBean.setTm100Color(getColor(device, IColorPreferenceConstant.TM_MATCH100_COLOR));
colorConfigBean.setTm90Color(getColor(device, IColorPreferenceConstant.TM_MATCH90_COLOR));
colorConfigBean.setTm80Color(getColor(device, IColorPreferenceConstant.TM_MATCH80_COLOR));
colorConfigBean.setTm70Color(getColor(device, IColorPreferenceConstant.TM_MATCH70_COLOR));
colorConfigBean.setTm0Color(getColor(device, IColorPreferenceConstant.TM_MATCH0_COLOR));
colorConfigBean.setSrcDiffFgColor(getColor(device, IColorPreferenceConstant.DIFFERENCE_FG_COLOR));
colorConfigBean.setSrcDiffBgColor(getColor(device, IColorPreferenceConstant.DIFFERENCE_BG_COLOR));
colorConfigBean.setTagFgColor(getColor(device, IColorPreferenceConstant.TAG_FG_COLOR));
colorConfigBean.setTagBgColor(getColor(device, IColorPreferenceConstant.TAG_BG_COLOR));
colorConfigBean.setWrongTagColor(getColor(device, IColorPreferenceConstant.WRONG_TAG_COLOR));
colorConfigBean.setErrorWordColor(getColor(device, IColorPreferenceConstant.WRONG_TAG_COLOR));
String strColor = colorConfigBean.toString();
IXliffEditor xliffEditor = null;
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IEditorPart editor = page.getActiveEditor();
if (editor != null && editor instanceof IXliffEditor) {
xliffEditor = (IXliffEditor) editor;
}
}
}
if (strCurColor != null && !strCurColor.equals(strColor)) {
// 更改颜色设置后刷新界面
if (xliffEditor != null) {
xliffEditor.autoResize();
xliffEditor.refresh();
}
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IViewPart viewPart = page.findView("net.heartsome.cat.ts.ui.translation.view.matchview");
if (viewPart != null) {
IMatchViewPart part = (IMatchViewPart) viewPart;
part.refreshTable();
}
}
}
strCurColor = strColor;
}
Color highlightedTermColor = colorConfigBean.getHighlightedTermColor();
RGB newRgb = StringConverter.asRGB(pfStore.getString(IColorPreferenceConstant.HIGHLIGHTED_TERM_COLOR));
if (highlightedTermColor == null || highlightedTermColor.isDisposed()) {
highlightedTermColor = new Color(device, newRgb);
} else if (!highlightedTermColor.getRGB().equals(newRgb)) {
highlightedTermColor.dispose();
highlightedTermColor = new Color(device, newRgb);
// had changed
if (xliffEditor != null) {
// 刷新
xliffEditor.highlightedTerms(0, null);
}
}
colorConfigBean.setHighlightedTermColor(highlightedTermColor);
}
use of org.eclipse.swt.graphics.Device in project translationstudio8 by heartsome.
the class ColorConfigLoader method initColor.
private void initColor() {
Device device = Display.getDefault();
if (pfStore == null) {
pfStore = Activator.getDefault().getPreferenceStore();
pfStore.addPropertyChangeListener(this);
}
colorConfigBean.release();
colorConfigBean.setPtColor(getColor(device, IColorPreferenceConstant.PT_COLOR));
colorConfigBean.setQtColor(getColor(device, IColorPreferenceConstant.QT_COLOR));
colorConfigBean.setMtColor(getColor(device, IColorPreferenceConstant.MT_COLOR));
colorConfigBean.setTm101Color(getColor(device, IColorPreferenceConstant.TM_MATCH101_COLOR));
colorConfigBean.setTm100Color(getColor(device, IColorPreferenceConstant.TM_MATCH100_COLOR));
colorConfigBean.setTm90Color(getColor(device, IColorPreferenceConstant.TM_MATCH90_COLOR));
colorConfigBean.setTm80Color(getColor(device, IColorPreferenceConstant.TM_MATCH80_COLOR));
colorConfigBean.setTm70Color(getColor(device, IColorPreferenceConstant.TM_MATCH70_COLOR));
colorConfigBean.setTm0Color(getColor(device, IColorPreferenceConstant.TM_MATCH0_COLOR));
colorConfigBean.setSrcDiffFgColor(getColor(device, IColorPreferenceConstant.DIFFERENCE_FG_COLOR));
colorConfigBean.setSrcDiffBgColor(getColor(device, IColorPreferenceConstant.DIFFERENCE_BG_COLOR));
colorConfigBean.setTagFgColor(getColor(device, IColorPreferenceConstant.TAG_FG_COLOR));
colorConfigBean.setTagBgColor(getColor(device, IColorPreferenceConstant.TAG_BG_COLOR));
colorConfigBean.setWrongTagColor(getColor(device, IColorPreferenceConstant.WRONG_TAG_COLOR));
colorConfigBean.setErrorWordColor(getColor(device, IColorPreferenceConstant.WRONG_TAG_COLOR));
Color highlightedTermColor = colorConfigBean.getHighlightedTermColor();
RGB newRgb = StringConverter.asRGB(pfStore.getString(IColorPreferenceConstant.HIGHLIGHTED_TERM_COLOR));
if (highlightedTermColor == null || highlightedTermColor.isDisposed()) {
highlightedTermColor = new Color(device, newRgb);
} else if (!highlightedTermColor.getRGB().equals(newRgb)) {
highlightedTermColor.dispose();
highlightedTermColor = new Color(device, newRgb);
// had changed
}
colorConfigBean.setHighlightedTermColor(highlightedTermColor);
}
Aggregations