Java Code Examples for org.eclipse.swt.widgets.TableItem#getImage()

The following examples show how to use org.eclipse.swt.widgets.TableItem#getImage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CenteredContentCellPaint.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
@Override
public void handleEvent(final Event event) {
    if (event.index == colIndex) {
        if (event.type == SWT.EraseItem) {
            event.detail &= (Integer.MAX_VALUE ^ SWT.FOREGROUND);

        } else if (event.type == SWT.PaintItem) {
            final TableItem item = (TableItem) event.item;
            final Image img = item.getImage(colIndex);
            if (img != null) {
                final Rectangle size = img.getBounds();
                final Table tbl = (Table) event.widget;
                event.gc.drawImage(img, event.x + (tbl.getColumn(colIndex).getWidth() - size.width) / 2, event.y + (tbl.getItemHeight() - size.height) / 2);
            }
        }
    }
}
 
Example 2
Source File: CenteredContentCellPaint.java    From erflute with Apache License 2.0 6 votes vote down vote up
@Override
public void handleEvent(Event event) {
    if (event.index == colIndex) {
        if (event.type == SWT.EraseItem) {
            event.detail &= (Integer.MAX_VALUE ^ SWT.FOREGROUND);

        } else if (event.type == SWT.PaintItem) {
            final TableItem item = (TableItem) event.item;
            final Image img = item.getImage(colIndex);
            if (img != null) {
                final Rectangle size = img.getBounds();
                final Table tbl = (Table) event.widget;
                event.gc.drawImage(img, event.x + (tbl.getColumn(colIndex).getWidth() - size.width) / 2,
                        event.y + (tbl.getItemHeight() - size.height) / 2);
            }
        }
    }
}
 
Example 3
Source File: CenteredContentCellPaint.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
public void handleEvent(Event event) {
	if (event.index == colIndex) {
		if (event.type == SWT.EraseItem) {
			event.detail &= (Integer.MAX_VALUE ^ SWT.FOREGROUND);
			
		} else if (event.type == SWT.PaintItem) {
			TableItem item = (TableItem) event.item;
			Image img = item.getImage(colIndex);
			if (img != null) {
				Rectangle size = img.getBounds();
				Table tbl = (Table) event.widget;
				event.gc.drawImage(img, event.x
						+ (tbl.getColumn(colIndex).getWidth() - size.width)
						/ 2, event.y + (tbl.getItemHeight() - size.height)
						/ 2);
			}
		}
	}
}
 
Example 4
Source File: TableComboViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected void doResetItem(Item item) {
	if (isWidgetDisposed()) {
		return;
	}
	TableItem tableItem = (TableItem) item;
	int columnCount = Math.max(1, tableCombo.getTable().getColumnCount());
	for (int i = 0; i < columnCount; i++) {
		tableItem.setText(i, ""); //$NON-NLS-1$
		if (tableItem.getImage(i) != null) {
			tableItem.setImage(i, null);
		}
	}
}
 
Example 5
Source File: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void handleEvent(Event event) {
    TableItem item = (TableItem) event.item;

    // we promised to paint the table item's foreground
    GC gc = event.gc;
    Image image = item.getImage(event.index);
    if (image != null) {
        Rectangle imageBounds = item.getImageBounds(event.index);
        /*
         * The image bounds don't match the default image position.
         */
        if (IS_LINUX) {
            gc.drawImage(image, imageBounds.x + 1, imageBounds.y + 3);
        } else {
            gc.drawImage(image, imageBounds.x, imageBounds.y + 1);
        }
    }
    Object o = item.getData(Key.IS_DEFAULT_FG_COLOR);
    if (!(o instanceof Boolean) || !(Boolean) o) {
        gc.setForeground(item.getForeground(event.index));
    }
    gc.setFont(item.getFont(event.index));
    String text = item.getText(event.index);
    Rectangle textBounds = item.getTextBounds(event.index);
    /*
     * The text bounds don't match the default text position.
     */
    if (IS_LINUX) {
        gc.drawText(text, textBounds.x + 1, textBounds.y + 3, true);
    } else {
        gc.drawText(text, textBounds.x - 1, textBounds.y + 2, true);
    }
}
 
Example 6
Source File: TableComboViewer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected void doResetItem(Item item) {
	TableItem tableItem = (TableItem) item;
	int columnCount = Math.max(1, tableCombo.getTable().getColumnCount());
	for (int i = 0; i < columnCount; i++) {
		tableItem.setText(i, ""); //$NON-NLS-1$
		if (tableItem.getImage(i) != null) {
			tableItem.setImage(i, null);
		}
	}
}
 
Example 7
Source File: TableComboViewer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected void doResetItem(Item item) {
	TableItem tableItem = (TableItem) item;
	int columnCount = Math.max(1, tableCombo.getTable().getColumnCount());
	for (int i = 0; i < columnCount; i++) {
		tableItem.setText(i, ""); //$NON-NLS-1$
		if (tableItem.getImage(i) != null) {
			tableItem.setImage(i, null);
		}
	}
}
 
Example 8
Source File: TableComboViewer.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void doResetItem(Item item) {
    TableItem tableItem = (TableItem) item;
    int columnCount = Math.max(1, tableCombo.getTable().getColumnCount());
    for (int i = 0; i < columnCount; i++) {
        tableItem.setText(i, ""); //$NON-NLS-1$
        if (tableItem.getImage(i) != null) {
            tableItem.setImage(i, null);
        }
    }
}
 
Example 9
Source File: TableCombo.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Point computeSize(final int wHint, final int hHint, final boolean changed) {
	checkWidget();

	int overallWidth = 0;
	int overallHeight = 0;
	final int borderWidth = hasBorder ? 2 : 0;

	// use user defined values if they are specified.
	if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {
		overallWidth = wHint;
		overallHeight = hHint;
	} else {
		final TableItem[] tableItems = table.getItems();

		final GC gc = new GC(text);
		final int spacer = gc.stringExtent(" ").x; //$NON-NLS-1$
		int maxTextWidth = gc.stringExtent(text.getText()).x;
		final int colIndex = getDisplayColumnIndex();
		int maxImageHeight = 0;
		int currTextWidth = 0;

		// calculate the maximum text width and image height.
		for (final TableItem tableItem : tableItems) {
			currTextWidth = gc.stringExtent(tableItem.getText(colIndex)).x;

			// take image into account if there is one for the tableitem.
			if (tableItem.getImage() != null) {
				currTextWidth += tableItem.getImage().getBounds().width;
				maxImageHeight = Math.max(tableItem.getImage().getBounds().height, maxImageHeight);
			}

			maxTextWidth = Math.max(currTextWidth, maxTextWidth);
		}

		gc.dispose();
		final Point textSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
		final Point arrowSize = arrow.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);

		overallHeight = Math.max(textSize.y, arrowSize.y);
		overallHeight = Math.max(maxImageHeight, overallHeight);
		overallWidth = maxTextWidth + 2 * spacer + arrowSize.x + 2 * borderWidth;

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