// @see org.gudy.azureus2.ui.swt.views.table.TableCellSWTPaintListener#cellPaint(org.eclipse.swt.graphics.GC, org.gudy.azureus2.ui.swt.views.table.TableCellSWT)
public void cellPaint(GC gc, final TableCellSWT cell) {
Object ds = cell.getDataSource();
Rectangle cellBounds = cell.getBounds();
Image[] imgThumbnail = TorrentUIUtilsV3.getContentImage(ds,
cellBounds.width >= 20 && cellBounds.height >= 20,
new ContentImageLoadedListener() {
public void contentImageLoaded(Image image, boolean wasReturned) {
if (!wasReturned) {
// this may be triggered many times, so only invalidate and don't
// force a refresh()
cell.invalidate();
}
}
});
if (imgThumbnail == null) {
// don't need to release a null image
return;
}
if (cellBounds.height > 30) {
cellBounds.y += 2;
cellBounds.height -= 4;
}
Rectangle imgBounds = imgThumbnail[0].getBounds();
int dstWidth;
int dstHeight;
if (imgBounds.height > cellBounds.height) {
dstHeight = cellBounds.height;
dstWidth = imgBounds.width * cellBounds.height / imgBounds.height;
} else if (imgBounds.width > cellBounds.width) {
dstWidth = cellBounds.width - 4;
dstHeight = imgBounds.height * cellBounds.width / imgBounds.width;
} else {
dstWidth = imgBounds.width;
dstHeight = imgBounds.height;
}
try {
gc.setAdvanced(true);
gc.setInterpolation(SWT.HIGH);
} catch (Exception e) {
}
int x = cellBounds.x + ((cellBounds.width - dstWidth + 1) / 2);
int y = cellBounds.y + ((cellBounds.height - dstHeight + 1) / 2);
if (dstWidth > 0 && dstHeight > 0 && !imgBounds.isEmpty()) {
Rectangle dst = new Rectangle(x, y, dstWidth, dstHeight);
Rectangle lastClipping = gc.getClipping();
try {
gc.setClipping(cellBounds);
for (int i = 0; i < imgThumbnail.length; i++) {
Image image = imgThumbnail[i];
Rectangle srcBounds = image.getBounds();
if (i == 0) {
int w = dstWidth;
int h = dstHeight;
if (imgThumbnail.length > 1) {
w = w * 9 / 10;