final Display display = new Display();
final Shell shell = new Shell(display, SWT.DIALOG_TRIM);
shell.setLayout(new FillLayout());
final Label image = new Label(shell, SWT.NONE);
Button btnGetTorrent = new Button(shell, SWT.PUSH);
btnGetTorrent.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
FileDialog fd = new FileDialog(shell);
sFileName = fd.open();
try {
torrent = TorrentUtils.readFromFile(new File(sFileName), false);
} catch (TOTorrentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
b = PlatformTorrentUtils.getContentThumbnail(torrent);
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
btnGetTorrent.setText("Get Torrent");
Button btnShowImage = new Button(shell, SWT.PUSH);
btnShowImage.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
if (b == null) {
System.out.println("null");
return;
}
ByteArrayInputStream bis = new ByteArrayInputStream(b);
Image img = new Image(display, bis);
image.setImage(img);
shell.layout(true, true);
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
btnShowImage.setText("Show Image");
Button btnGetFile = new Button(shell, SWT.PUSH);
btnGetFile.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
FileDialog fd = new FileDialog(shell);
String sTFileName = fd.open();
b = getFileContents(sTFileName);
PlatformTorrentUtils.setContentThumbnail(torrent, b);
System.out.println("yay");
try {
TorrentUtils.writeToFile(torrent, new File(sFileName));
} catch (TOTorrentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
btnGetFile.setText("Add thumb to torrent");
shell.open();
while (!shell.isDisposed()) {
if (display.readAndDispatch()) {
display.sleep();
}
}