Java Code Examples for org.eclipse.swt.SWT#FOREGROUND

The following examples show how to use org.eclipse.swt.SWT#FOREGROUND . 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: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void handleEvent(Event event) {
    TableItem item = (TableItem) event.item;
    List<?> styleRanges = (List<?>) item.getData(Key.STYLE_RANGES);

    GC gc = event.gc;
    Color background = item.getBackground(event.index);
    /*
     * Paint the background if it is not the default system color. In
     * Windows, if you let the widget draw the background, it will not
     * show the item's background color if the item is selected or hot.
     * If there are no style ranges and the item background is the
     * default system color, we do not want to paint it or otherwise we
     * would override the platform theme (e.g. alternating colors).
     */
    if (styleRanges != null || !background.equals(item.getParent().getBackground())) {
        // we will paint the table item's background
        event.detail &= ~SWT.BACKGROUND;

        // paint the item's default background
        gc.setBackground(background);
        gc.fillRectangle(event.x, event.y, event.width, event.height);
    }

    /*
     * We will paint the table item's foreground. In Windows, if you
     * paint the background but let the widget draw the foreground, it
     * will override your background, unless the item is selected or
     * hot.
     */
    event.detail &= ~SWT.FOREGROUND;

    // paint the highlighted background for all style ranges
    if (styleRanges != null) {
        Rectangle textBounds = item.getTextBounds(event.index);
        String text = item.getText(event.index);
        for (Object o : styleRanges) {
            if (o instanceof StyleRange) {
                StyleRange styleRange = (StyleRange) o;
                if (styleRange.data.equals(event.index)) {
                    int startIndex = styleRange.start;
                    int endIndex = startIndex + styleRange.length;
                    int startX = gc.textExtent(text.substring(0, startIndex)).x;
                    int endX = gc.textExtent(text.substring(0, endIndex)).x;
                    gc.setBackground(styleRange.background);
                    gc.fillRectangle(textBounds.x + startX, textBounds.y, (endX - startX), textBounds.height);
                }
            }
        }
    }
}
 
Example 5
Source File: GamlAccessEntry.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param event
 */
public void erase(final Event event) {
	// We are only custom drawing the foreground.
	event.detail &= ~SWT.FOREGROUND;
}