Search in sources :

Example 26 with DisposeEvent

use of org.eclipse.swt.events.DisposeEvent in project translationstudio8 by heartsome.

the class DefaultCellRenderer method paint.

/**
     * {@inheritDoc}
     */
public void paint(GC gc, Object value) {
    GridItem item = (GridItem) value;
    gc.setFont(item.getFont(getColumn()));
    boolean drawAsSelected = isSelected();
    boolean drawBackground = true;
    if (isCellSelected()) {
        //(!isCellFocus());
        drawAsSelected = true;
    }
    if (drawAsSelected) {
        gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
        gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
    } else {
        if (item.getParent().isEnabled()) {
            Color back = item.getBackground(getColumn());
            if (back != null) {
                gc.setBackground(back);
            } else {
                drawBackground = false;
            }
        } else {
            gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
        }
        gc.setForeground(item.getForeground(getColumn()));
    }
    if (drawBackground)
        gc.fillRectangle(getBounds().x, getBounds().y, getBounds().width, getBounds().height);
    int x = leftMargin;
    if (isTree()) {
        boolean renderBranches = item.getParent().getTreeLinesVisible();
        if (renderBranches) {
            branchRenderer.setBranches(getBranches(item));
            branchRenderer.setIndent(treeIndent);
            branchRenderer.setBounds(getBounds().x + x, getBounds().y, getToggleIndent(item), // Take into account border
            getBounds().height + 1);
        }
        x += getToggleIndent(item);
        toggleRenderer.setExpanded(item.isExpanded());
        toggleRenderer.setHover(getHoverDetail().equals("toggle"));
        toggleRenderer.setLocation(getBounds().x + x, (getBounds().height - toggleRenderer.getBounds().height) / 2 + getBounds().y);
        if (item.hasChildren())
            toggleRenderer.paint(gc, null);
        if (renderBranches) {
            branchRenderer.setToggleBounds(toggleRenderer.getBounds());
            branchRenderer.paint(gc, null);
        }
        x += toggleRenderer.getBounds().width + insideMargin;
    }
    if (isCheck()) {
        checkRenderer.setChecked(item.getChecked(getColumn()));
        checkRenderer.setGrayed(item.getGrayed(getColumn()));
        if (!item.getParent().isEnabled()) {
            checkRenderer.setGrayed(true);
        }
        checkRenderer.setHover(getHoverDetail().equals("check"));
        if (isCenteredCheckBoxOnly(item)) {
            //Special logic if this column only has a checkbox and is centered
            checkRenderer.setBounds(getBounds().x + ((getBounds().width - checkRenderer.getBounds().width) / 2), (getBounds().height - checkRenderer.getBounds().height) / 2 + getBounds().y, checkRenderer.getBounds().width, checkRenderer.getBounds().height);
        } else {
            checkRenderer.setBounds(getBounds().x + x, (getBounds().height - checkRenderer.getBounds().height) / 2 + getBounds().y, checkRenderer.getBounds().width, checkRenderer.getBounds().height);
            x += checkRenderer.getBounds().width + insideMargin;
        }
        checkRenderer.paint(gc, null);
    }
    Image image = item.getImage(getColumn());
    if (image != null) {
        int y = getBounds().y;
        y += (getBounds().height - image.getBounds().height) / 2;
        gc.drawImage(image, getBounds().x + x, y);
        x += image.getBounds().width + insideMargin;
    }
    int width = getBounds().width - x - rightMargin;
    if (drawAsSelected) {
        gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
    } else {
        gc.setForeground(item.getForeground(getColumn()));
    }
    if (!isWordWrap()) {
        String text = TextUtils.getShortString(gc, item.getText(getColumn()), width);
        if (getAlignment() == SWT.RIGHT) {
            int len = gc.stringExtent(text).x;
            if (len < width) {
                x += width - len;
            }
        } else if (getAlignment() == SWT.CENTER) {
            int len = gc.stringExtent(text).x;
            if (len < width) {
                x += (width - len) / 2;
            }
        }
        gc.drawString(text, getBounds().x + x, getBounds().y + textTopMargin + topMargin, true);
    } else {
        if (textLayout == null) {
            textLayout = new TextLayout(gc.getDevice());
            item.getParent().addDisposeListener(new DisposeListener() {

                public void widgetDisposed(DisposeEvent e) {
                    textLayout.dispose();
                }
            });
        }
        textLayout.setFont(gc.getFont());
        textLayout.setText(item.getText(getColumn()));
        textLayout.setAlignment(getAlignment());
        textLayout.setWidth(width < 1 ? 1 : width);
        if (item.getParent().isAutoHeight()) {
            // Look through all columns (except this one) to get the max height needed for this item
            int columnCount = item.getParent().getColumnCount();
            int maxHeight = textLayout.getBounds().height + textTopMargin + textBottomMargin;
            for (int i = 0; i < columnCount; i++) {
                GridColumn column = item.getParent().getColumn(i);
                if (i != getColumn() && column.getWordWrap()) {
                    int height = column.getCellRenderer().computeSize(gc, column.getWidth(), SWT.DEFAULT, item).y;
                    maxHeight = Math.max(maxHeight, height);
                }
            }
            // Also look at the row header if necessary
            if (item.getParent().isWordWrapHeader()) {
                int height = item.getParent().getRowHeaderRenderer().computeSize(gc, SWT.DEFAULT, SWT.DEFAULT, item).y;
                maxHeight = Math.max(maxHeight, height);
            }
            if (maxHeight != item.getHeight()) {
                item.setHeight(maxHeight);
            }
        }
        textLayout.draw(gc, getBounds().x + x, getBounds().y + textTopMargin + topMargin);
    }
    if (item.getParent().getLinesVisible()) {
        if (isCellSelected()) {
            //XXX: should be user definable?
            gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
        } else {
            gc.setForeground(item.getParent().getLineColor());
        }
        gc.drawLine(getBounds().x, getBounds().y + getBounds().height, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height);
        gc.drawLine(getBounds().x + getBounds().width - 1, getBounds().y, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height);
    }
    if (isCellFocus()) {
        Rectangle focusRect = new Rectangle(getBounds().x, getBounds().y, getBounds().width - 1, getBounds().height);
        gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
        gc.drawRectangle(focusRect);
        if (isFocus()) {
            focusRect.x++;
            focusRect.width -= 2;
            focusRect.y++;
            focusRect.height -= 2;
            gc.drawRectangle(focusRect);
        }
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) GridItem(org.eclipse.nebula.widgets.grid.GridItem) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) Image(org.eclipse.swt.graphics.Image) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Point(org.eclipse.swt.graphics.Point) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 27 with DisposeEvent

use of org.eclipse.swt.events.DisposeEvent in project translationstudio8 by heartsome.

the class AttributeTextCellRenderer 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 && mapStyle != null && mapStyle.containsKey(row)) {
        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);
        ArrayList<int[]> lstIndex = mapStyle.get(row);
        if (lstIndex != null) {
            for (int[] arrIndex : lstIndex) {
                if (arrIndex != null && arrIndex.length == 2) {
                    textLayout.setStyle(style, arrIndex[0], arrIndex[1] - 1);
                }
            }
            gc.fillRectangle(rect);
            textLayout.draw(gc, rect.x, rect.y);
            gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
        }
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) RGB(org.eclipse.swt.graphics.RGB) DisposeEvent(org.eclipse.swt.events.DisposeEvent) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 28 with DisposeEvent

use of org.eclipse.swt.events.DisposeEvent in project translationstudio8 by heartsome.

the class TmDbManagerDialog method createHelpControl.

/**
	 * 添加帮助按钮 robert 2012-09-06
	 */
@Override
protected Control createHelpControl(Composite parent) {
    // ROBERTHELP 记忆库管理
    String language = CommonFunction.getSystemLanguage();
    final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch06s02.html#tm-management", language);
    Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
    ((GridLayout) parent.getLayout()).numColumns++;
    toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
    toolBar.setCursor(cursor);
    toolBar.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            cursor.dispose();
        }
    });
    ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
    helpItem.setImage(helpImage);
    //$NON-NLS-1$
    helpItem.setToolTipText(JFaceResources.getString("helpToolTip"));
    helpItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
        }
    });
    return toolBar;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 29 with DisposeEvent

use of org.eclipse.swt.events.DisposeEvent in project translationstudio8 by heartsome.

the class ExportTmxDialog method createHelpControl.

/**
	 * 添加帮助按钮 robert 2012-09-06
	 */
@Override
protected Control createHelpControl(Composite parent) {
    // ROBERTHELP 导出tmx
    String language = CommonFunction.getSystemLanguage();
    final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch06s03.html#export-tmx", language);
    Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
    ((GridLayout) parent.getLayout()).numColumns++;
    toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
    toolBar.setCursor(cursor);
    toolBar.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            cursor.dispose();
        }
    });
    ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
    helpItem.setImage(helpImage);
    //$NON-NLS-1$
    helpItem.setToolTipText(JFaceResources.getString("helpToolTip"));
    helpItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
        }
    });
    return toolBar;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 30 with DisposeEvent

use of org.eclipse.swt.events.DisposeEvent in project translationstudio8 by heartsome.

the class UpdateTMWizardDialog method createHelpControl.

/**
	 * 添加帮助按钮
	 * robert	2012-09-06
	 */
@Override
protected Control createHelpControl(Composite parent) {
    // ROBERTHELP 更新记忆库
    String language = CommonFunction.getSystemLanguage();
    final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch06.html#update-tm", language);
    Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
    ((GridLayout) parent.getLayout()).numColumns++;
    toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
    toolBar.setCursor(cursor);
    toolBar.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            cursor.dispose();
        }
    });
    ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
    helpItem.setImage(helpImage);
    //$NON-NLS-1$
    helpItem.setToolTipText(JFaceResources.getString("helpToolTip"));
    helpItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
        }
    });
    return toolBar;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ToolItem(org.eclipse.swt.widgets.ToolItem)

Aggregations

DisposeEvent (org.eclipse.swt.events.DisposeEvent)365 DisposeListener (org.eclipse.swt.events.DisposeListener)362 GridData (org.eclipse.swt.layout.GridData)103 Composite (org.eclipse.swt.widgets.Composite)91 SelectionEvent (org.eclipse.swt.events.SelectionEvent)88 GridLayout (org.eclipse.swt.layout.GridLayout)76 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)71 Image (org.eclipse.swt.graphics.Image)53 Cursor (org.eclipse.swt.graphics.Cursor)49 Label (org.eclipse.swt.widgets.Label)42 ToolBar (org.eclipse.swt.widgets.ToolBar)42 Point (org.eclipse.swt.graphics.Point)38 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)37 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)36 Control (org.eclipse.swt.widgets.Control)36 Color (org.eclipse.swt.graphics.Color)35 FillLayout (org.eclipse.swt.layout.FillLayout)35 Event (org.eclipse.swt.widgets.Event)35 MouseEvent (org.eclipse.swt.events.MouseEvent)32 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)31