FileDocCategorySizeDatePackage
TorrentThumbnail.javaAPI DocAzureus 3.0.3.44172Mon Dec 04 11:59:34 GMT 2006com.aelitis.azureus.ui.swt.test

TorrentThumbnail

public class TorrentThumbnail extends Object
author
TuxPaper
created
Sep 28, 2006

Fields Summary
public static byte[]
b
public static org.gudy.azureus2.core3.torrent.TOTorrent
torrent
public static String
sFileName
Constructors Summary
Methods Summary
public static byte[]getFileContents(java.lang.String sFile)

		File f = new File(sFile);

		try {
			FileInputStream fs = new FileInputStream(f);

			byte b[] = new byte[(int) f.length()];

			fs.read(b);

			fs.close();

			return b;

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return null;
	
public static voidmain(java.lang.String[] args)

		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();
			}
		}