FileDocCategorySizeDatePackage
BrowserFlicker.javaAPI DocAzureus 3.0.3.43299Thu Mar 01 23:47:32 GMT 2007com.aelitis.azureus.ui.swt.test

BrowserFlicker

public class BrowserFlicker extends Object
Eclipse Bug 164512: seizure inducing flicker on resize in Browser w/parent having paint listener https://bugs.eclipse.org/bugs/show_bug.cgi?id=164512
author
TuxPaper
created
Nov 13, 2006

Fields Summary
static final int
INDENT
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)


	     
		final Display display = new Display();
		final Shell shell = new Shell(display, SWT.SHELL_TRIM);

		FormData fd;

		shell.setLayout(new FormLayout());

		final Composite right = new Composite(shell, SWT.NONE);
		right.setLayout(new FormLayout());

		final Browser b = new Browser(right, SWT.BORDER);
		fd = new FormData();
		fd.top = new FormAttachment(0, INDENT);
		fd.left = new FormAttachment(0, INDENT);
		fd.right = new FormAttachment(100, -INDENT);
		fd.bottom = new FormAttachment(100, -INDENT);
		b.setLayoutData(fd);
		// black so we can see the flicker better
		b.setText("<html><body BGCOLOR=black></body></html>");

		fd = new FormData();
		fd.top = new FormAttachment(0);
		fd.left = new FormAttachment(50);
		fd.bottom = new FormAttachment(100);
		fd.right = new FormAttachment(100);
		right.setLayoutData(fd);

		shell.addListener(SWT.Resize, new Listener() {
			public void handleEvent(Event event) {
				// code here to resulting in a need to re-layout

				right.getParent().layout();
			}
		});

		Listener l = new Listener() {
			public void handleEvent(Event event) {
				Point size = ((Control) event.widget).getSize();
				event.gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
				event.gc.fillOval(0, 0, INDENT, INDENT);
				event.gc.fillOval(size.x - INDENT, 0, INDENT, INDENT);
				event.gc.fillOval(size.x - INDENT, size.y - INDENT, INDENT, INDENT);
				event.gc.fillOval(0, size.y - INDENT, INDENT, INDENT);

				// mimic other work
				try {
					Thread.sleep(10);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}

		};

		right.addListener(SWT.Paint, l);
		shell.setSize(200, 200);
		shell.open();

		while (!shell.isDisposed()) {
			if (display.readAndDispatch()) {
				display.sleep();
			}
		}