Search in sources :

Example 6 with GC

use of org.eclipse.swt.graphics.GC in project translationstudio8 by heartsome.

the class HSDropDownButton method getSpaceByWidth.

public String getSpaceByWidth(int width) {
    GC gc = new GC(Display.getDefault());
    int spaceWidth = gc.getAdvanceWidth(' ');
    gc.dispose();
    int spacecount = width / spaceWidth;
    StringBuilder b = new StringBuilder();
    while (spacecount-- > 0) {
        b.append(" ");
    }
    return b.toString();
}
Also used : GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Example 7 with GC

use of org.eclipse.swt.graphics.GC in project translationstudio8 by heartsome.

the class TableCombo method computeSize.

/**
	 * {@inheritDoc}
	 */
public Point computeSize(int wHint, int hHint, boolean changed) {
    checkWidget();
    int overallWidth = 0;
    int overallHeight = 0;
    int borderWidth = getBorderWidth();
    // use user defined values if they are specified.
    if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {
        overallWidth = wHint;
        overallHeight = hHint;
    } else {
        TableItem[] tableItems = table.getItems();
        GC gc = new GC(text);
        //$NON-NLS-1$
        int spacer = gc.stringExtent(" ").x;
        int maxTextWidth = gc.stringExtent(text.getText()).x;
        int colIndex = getDisplayColumnIndex();
        int maxImageHeight = 0;
        int currTextWidth = 0;
        // calculate the maximum text width and image height.
        for (int i = 0; i < tableItems.length; i++) {
            currTextWidth = gc.stringExtent(tableItems[i].getText(colIndex)).x;
            // take image into account if there is one for the tableitem.
            if (tableItems[i].getImage() != null) {
                currTextWidth += tableItems[i].getImage().getBounds().width;
                maxImageHeight = Math.max(tableItems[i].getImage().getBounds().height, maxImageHeight);
            }
            maxTextWidth = Math.max(currTextWidth, maxTextWidth);
        }
        gc.dispose();
        Point textSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
        Point arrowSize = arrow.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
        Point tableSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
        overallHeight = Math.max(textSize.y, arrowSize.y);
        overallHeight = Math.max(maxImageHeight, overallHeight);
        overallWidth = Math.max(maxTextWidth + 2 * spacer + arrowSize.x + 2 * borderWidth, tableSize.x);
        // use user specified if they were entered.
        if (wHint != SWT.DEFAULT)
            overallWidth = wHint;
        if (hHint != SWT.DEFAULT)
            overallHeight = hHint;
    }
    return new Point(overallWidth + 2 * borderWidth, overallHeight + 2 * borderWidth);
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Example 8 with GC

use of org.eclipse.swt.graphics.GC in project translationstudio8 by heartsome.

the class GridDragSourceEffect method getDragSourceImage.

Image getDragSourceImage(DragSourceEvent event) {
    if (dragSourceImage != null)
        dragSourceImage.dispose();
    dragSourceImage = null;
    Grid grid = (Grid) getControl();
    Display display = grid.getDisplay();
    Rectangle empty = new Rectangle(0, 0, 0, 0);
    // Collect the currently selected items. 
    Point[] selection;
    if (grid.getCellSelectionEnabled()) {
        selection = grid.getCellSelection();
    } else {
        List l = new ArrayList();
        GridItem[] selItems = grid.getSelection();
        for (int i = 0; i < selItems.length; i++) {
            for (int j = 0; j < grid.getColumnCount(); j++) {
                if (grid.getColumn(j).isVisible()) {
                    l.add(new Point(j, grid.indexOf(selItems[i])));
                }
            }
        }
        selection = (Point[]) l.toArray(new Point[l.size()]);
    }
    if (selection.length == 0)
        return null;
    Rectangle bounds = null;
    for (int i = 0; i < selection.length; i++) {
        GridItem item = grid.getItem(selection[i].y);
        Rectangle currBounds = item.getBounds(selection[i].x);
        if (empty.equals(currBounds)) {
            selection[i] = null;
        } else {
            if (bounds == null) {
                bounds = currBounds;
            } else {
                bounds = bounds.union(currBounds);
            }
        }
    }
    if (bounds == null)
        return null;
    if (bounds.width <= 0 || bounds.height <= 0)
        return null;
    dragSourceImage = new Image(display, bounds.width, bounds.height);
    GC gc = new GC(dragSourceImage);
    for (int i = 0; i < selection.length; i++) {
        if (selection[i] == null)
            continue;
        GridItem item = grid.getItem(selection[i].y);
        GridColumn column = grid.getColumn(selection[i].x);
        Rectangle currBounds = item.getBounds(selection[i].x);
        GridCellRenderer r = column.getCellRenderer();
        r.setBounds(currBounds.x - bounds.x, currBounds.y - bounds.y, currBounds.width, currBounds.height);
        gc.setClipping(currBounds.x - bounds.x - 1, currBounds.y - bounds.y - 1, currBounds.width + 2, currBounds.height + 2);
        r.setColumn(selection[i].x);
        r.setSelected(false);
        r.setFocus(false);
        r.setRowFocus(false);
        r.setCellFocus(false);
        r.setRowHover(false);
        r.setColumnHover(false);
        r.setCellSelected(false);
        r.setHoverDetail("");
        r.setDragging(true);
        r.paint(gc, item);
        gc.setClipping((Rectangle) null);
    }
    gc.dispose();
    return dragSourceImage;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ArrayList(java.util.ArrayList) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) List(java.util.List) ArrayList(java.util.ArrayList) GC(org.eclipse.swt.graphics.GC) Display(org.eclipse.swt.widgets.Display)

Example 9 with GC

use of org.eclipse.swt.graphics.GC in project translationstudio8 by heartsome.

the class GridItem method pack.

/**
	 * Sets this <code>GridItem</code> to its preferred height.
	 *
	 * @throws org.eclipse.swt.SWTException
	 *             <ul>
	 *             <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
	 *             </li>
	 *             <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
	 *             thread that created the receiver</li>
	 *             </ul>
	 */
public void pack() {
    checkWidget();
    int maxPrefHeight = 2;
    GridColumn[] columns = parent.getColumns();
    GC gc = new GC(parent);
    for (int cnt = 0; cnt < columns.length; cnt++) {
        if (!columns[cnt].isVisible())
            // invisible columns do not affect item/row height
            continue;
        GridCellRenderer renderer = columns[cnt].getCellRenderer();
        renderer.setAlignment(columns[cnt].getAlignment());
        renderer.setCheck(columns[cnt].isCheck());
        renderer.setColumn(cnt);
        renderer.setTree(columns[cnt].isTree());
        renderer.setWordWrap(columns[cnt].getWordWrap());
        Point size = renderer.computeSize(gc, columns[cnt].getWidth(), SWT.DEFAULT, this);
        if (size != null)
            maxPrefHeight = Math.max(maxPrefHeight, size.y);
    }
    gc.dispose();
    setHeight(maxPrefHeight);
}
Also used : Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Example 10 with GC

use of org.eclipse.swt.graphics.GC in project translationstudio8 by heartsome.

the class GridItem method setHeaderImage.

/**
	 * Sets the receiver's row header image. If the image is <code>null</code>
	 * none is shown in the header
	 *
	 * @param image
	 *            the new image
	 * @throws org.eclipse.swt.SWTException
	 *             <ul>
	 *             <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
	 *             </li>
	 *             <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
	 *             thread that created the receiver</li>
	 *             </ul>
	 */
public void setHeaderImage(Image image) {
    checkWidget();
    // if (text == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    if (image != headerImage) {
        GC gc = new GC(parent);
        int oldWidth = parent.getRowHeaderRenderer().computeSize(gc, SWT.DEFAULT, SWT.DEFAULT, this).x;
        int oldHeight = parent.getRowHeaderRenderer().computeSize(gc, SWT.DEFAULT, SWT.DEFAULT, this).y;
        this.headerImage = image;
        int newWidth = parent.getRowHeaderRenderer().computeSize(gc, SWT.DEFAULT, SWT.DEFAULT, this).x;
        int newHeight = parent.getRowHeaderRenderer().computeSize(gc, SWT.DEFAULT, SWT.DEFAULT, this).y;
        gc.dispose();
        parent.recalculateRowHeaderWidth(this, oldWidth, newWidth);
        parent.recalculateRowHeaderHeight(this, oldHeight, newHeight);
    }
    parent.redraw();
}
Also used : GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Aggregations

GC (org.eclipse.swt.graphics.GC)122 Point (org.eclipse.swt.graphics.Point)90 FormAttachment (org.eclipse.swt.layout.FormAttachment)46 FormData (org.eclipse.swt.layout.FormData)46 CLabel (org.eclipse.swt.custom.CLabel)42 Node (org.talend.designer.core.ui.editor.nodes.Node)39 Control (org.eclipse.swt.widgets.Control)31 Rectangle (org.eclipse.swt.graphics.Rectangle)29 DecoratedField (org.eclipse.jface.fieldassist.DecoratedField)28 FieldDecoration (org.eclipse.jface.fieldassist.FieldDecoration)27 Image (org.eclipse.swt.graphics.Image)27 Button (org.eclipse.swt.widgets.Button)24 Composite (org.eclipse.swt.widgets.Composite)18 CCombo (org.eclipse.swt.custom.CCombo)16 Text (org.eclipse.swt.widgets.Text)12 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 GridData (org.eclipse.swt.layout.GridData)11 SelectAllTextControlCreator (org.talend.designer.core.ui.editor.properties.controllers.creator.SelectAllTextControlCreator)11 INode (org.talend.core.model.process.INode)10 Label (org.eclipse.swt.widgets.Label)9