Search in sources :

Example 1 with Device

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);
}
Also used : Path(org.eclipse.swt.graphics.Path) Device(org.eclipse.swt.graphics.Device) Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 2 with Device

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;
}
Also used : Device(org.eclipse.swt.graphics.Device) Color(org.eclipse.swt.graphics.Color) ColorManager(de.jaret.util.swt.ColorManager)

Example 3 with Device

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;
}
Also used : Device(org.eclipse.swt.graphics.Device) Color(org.eclipse.swt.graphics.Color) RGB(org.eclipse.swt.graphics.RGB) ColorManager(de.jaret.util.swt.ColorManager)

Example 4 with Device

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);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) Device(org.eclipse.swt.graphics.Device) Color(org.eclipse.swt.graphics.Color) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) RGB(org.eclipse.swt.graphics.RGB) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) IMatchViewPart(net.heartsome.cat.ts.ui.view.IMatchViewPart)

Example 5 with Device

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);
}
Also used : Device(org.eclipse.swt.graphics.Device) Color(org.eclipse.swt.graphics.Color) RGB(org.eclipse.swt.graphics.RGB)

Aggregations

Device (org.eclipse.swt.graphics.Device)7 Color (org.eclipse.swt.graphics.Color)5 ColorManager (de.jaret.util.swt.ColorManager)3 RGB (org.eclipse.swt.graphics.RGB)3 FontManager (de.jaret.util.swt.FontManager)1 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)1 IMatchViewPart (net.heartsome.cat.ts.ui.view.IMatchViewPart)1 Font (org.eclipse.swt.graphics.Font)1 Path (org.eclipse.swt.graphics.Path)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IViewPart (org.eclipse.ui.IViewPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1