skinnableManagerSWT.addSkinnableListener(MessageBoxShell.class.toString(),
new UISkinnableSWTListener() {
public void skinBeforeComponents(Composite composite,
Object skinnableObject, Object[] relatedObjects) {
MessageBoxShell shell = (MessageBoxShell) skinnableObject;
TOTorrent torrent = null;
DownloadManager dm = (DownloadManager) LogRelationUtils.queryForClass(
relatedObjects, DownloadManager.class);
if (dm != null) {
torrent = dm.getTorrent();
} else {
torrent = (TOTorrent) LogRelationUtils.queryForClass(
relatedObjects, TOTorrent.class);
}
if (torrent != null && shell.getLeftImage() == null) {
byte[] contentThumbnail = PlatformTorrentUtils.getContentThumbnail(torrent);
if (contentThumbnail != null) {
try {
ByteArrayInputStream bis = new ByteArrayInputStream(
contentThumbnail);
final Image img = new Image(Display.getDefault(), bis);
shell.setLeftImage(img);
composite.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
if (!img.isDisposed()) {
img.dispose();
}
}
});
} catch (Exception e) {
}
}
}
}
public void skinAfterComponents(Composite composite,
Object skinnableObject, Object[] relatedObjects) {
}
});
skinnableManagerSWT.addSkinnableListener(
MessageSlideShell.class.toString(), new UISkinnableSWTListener() {
public void skinBeforeComponents(Composite composite,
Object skinnableObject, Object[] relatedObjects) {
if (skinnableObject instanceof MessageSlideShell) {
final Image image = new Image(composite.getDisplay(), 250, 300);
TOTorrent torrent = null;
DownloadManager dm = (DownloadManager) LogRelationUtils.queryForClass(
relatedObjects, DownloadManager.class);
if (dm != null) {
torrent = dm.getTorrent();
} else {
torrent = (TOTorrent) LogRelationUtils.queryForClass(
relatedObjects, TOTorrent.class);
}
MessageSlideShell shell = (MessageSlideShell) skinnableObject;
byte[] contentThumbnail = PlatformTorrentUtils.getContentThumbnail(torrent);
GC gc = new GC(image);
try {
gc.setBackground(gc.getDevice().getSystemColor(
SWT.COLOR_WIDGET_BACKGROUND));
gc.fillRectangle(image.getBounds());
if (contentThumbnail != null) {
try {
ByteArrayInputStream bis = new ByteArrayInputStream(
contentThumbnail);
final Image img = new Image(Display.getDefault(), bis);
Rectangle imgBounds = img.getBounds();
double pct = 35.0 / imgBounds.height;
int w = (int) (imgBounds.width * pct);
try {
gc.setAdvanced(true);
gc.setInterpolation(SWT.HIGH);
} catch (Exception e) {
// not important if we can't set advanced
}
gc.drawImage(img, 0, 0, imgBounds.width, imgBounds.height,
0, 265, w, 35);
img.dispose();
} catch (Exception e) {
}
}
} finally {
gc.dispose();
}
shell.setImgPopup(image);
composite.addListener(SWT.Dispose, new Listener() {
public void handleEvent(Event event) {
if (!image.isDisposed()) {
image.dispose();