public void handleEvent(Event event) { if (event.type == SWT.PaintItem) { performPaint(event); } else if (event.type == SWT.EraseItem) { performErase(event); } else if (event.type == SWT.Dispose) { dispose(); } }
GC gc= event.gc; ColoredString coloredLabel= getColoredLabel(item); boolean isSelected= (event.detail & SWT.SELECTED) != 0 && fControl.isFocusControl(); if (item instanceof TreeItem) { Image image = treeItem.getImage(event.index); if (image != null) { processImage(image, gc, treeItem.getImageBounds(event.index)); processColoredLabel(coloredLabel, gc, textBounds, isSelected, font); Image image = tableItem.getImage(event.index); if (image != null) { processImage(image, gc, tableItem.getImageBounds(event.index)); processColoredLabel(coloredLabel, gc, textBounds, isSelected, font);
protected void uninstallOwnerDraw() { if (fOwnerDrawSupport == null) return; // not installed fOwnerDrawSupport.dispose(); // removes itself as listener fOwnerDrawSupport= null; refreshViewer(); }
private void processColoredLabel(ColoredString richLabel, GC gc, Rectangle textBounds, boolean isSelected, Font font) { String text= richLabel.getString(); fTextLayout.setText(text); fTextLayout.setFont(font); if (!isSelected) { // apply the styled ranges only when element is not selected Display display= (Display) gc.getDevice(); Iterator ranges= richLabel.getRanges(); while (ranges.hasNext()) { ColoredString.StyleRange curr= (ColoredString.StyleRange) ranges.next(); ColoredString.Style style= curr.style; if (style != null) { Color foreground= getColor(style.getForegroundColorName(), display); TextStyle textStyle= new TextStyle(null, foreground, null); fTextLayout.setStyle(textStyle, curr.offset, curr.offset + curr.length - 1); } } } Rectangle bounds= fTextLayout.getBounds(); int x= textBounds.x; int y = textBounds.y + Math.max(0, (textBounds.height - bounds.height) / 2); fTextLayout.draw(gc, x, y); fTextLayout.setText(""); // clear all ranges //$NON-NLS-1$ }