Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Wait for Browser thread to return
Wait for Browser thread to return [message #757204] Thu, 17 November 2011 05:55 Go to next message
andzsinszan is currently offline andzsinszanFriend
Messages: 32
Registered: August 2011
Member
Hi,

Is there a way to wait for the Browser rendering thread to return after dispatching with a setText(String s)? I am changing the Browser's contents programmatically with Browser#setText, so there isn't any delay that would require a separate thread.
I would prefer to wait for the Browser thread to return after rendering the html, in order to update the widget's preferred size.

While I can update the the size from Browser#addProgressListener it results in a flickering:
paint#1 "normal" paint
paint#2 paint after browser is finished, size are calculated

In this particular example there is flickering - because there is no resize.
The resize event would take place where STDOUT says "Browser ready".


A working example:
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class SwtBrowserThread extends Composite{
	
	final Browser browser ;
	int i = 0;
	public SwtBrowserThread (Composite parent){
		super(parent, SWT.NONE);
		setLayout(new FillLayout(SWT.VERTICAL));
		
		browser = new Browser(this, SWT.NONE);
		browser.addProgressListener(new ProgressListener() {
			@Override
			public void completed(ProgressEvent arg0){
				System.out.println("Browser ready!");
			}
			@Override
			public void changed(ProgressEvent arg0) {
			}
		});
		
		Button btn = new Button(this, SWT.PUSH);
		btn.setText("Change");
		btn.addListener(SWT.Selection, new Listener() {
			@Override
			public void handleEvent(Event arg0) {
				System.out.println("\nBefore setText()");
				browser.setText("Changed " +  i++ );
				System.out.println("After setText()");
			}
		});
	}
	
	
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell =  new Shell(display);
		shell.setLayout(new FillLayout());


		Composite panel = new SwtBrowserThread(shell);
		shell.setSize(200,120);
		shell.open();
		while(!shell.isDisposed()){
	        if (!display.readAndDispatch())
	            display.sleep();
		}
		display.dispose();
		
	}
}



Re: Wait for Browser thread to return [message #757205 is a reply to message #757204] Thu, 17 November 2011 05:57 Go to previous messageGo to next message
andzsinszan is currently offline andzsinszanFriend
Messages: 32
Registered: August 2011
Member
Actually there is something similar in the forum topic below, but in that case the focus is on the onsets of the repaints.

http://www.eclipse.org/forums/index.php/mv/tree/148384/
Re: Wait for Browser thread to return [message #757932 is a reply to message #757204] Thu, 17 November 2011 15:27 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi,

Listening to ProgressListener.completed() is the correct place to
receive notification of this.

Something you can try is to add "browser.setRedraw(false);" when
invoking setText(), and then when ProgressListener.completed() is
received you can resize it if needed and then invoke
"browser.setRedraw(true);" to display its content.

HTH,
Grant


On 11/17/2011 12:55 AM, andzsinszan wrote:
> Hi,
>
> Is there a way to wait for the Browser rendering thread to return after
> dispatching with a setText(String s)? I am changing the Browser's
> contents programmatically with Browser#setText, so there isn't any delay
> that would require a separate thread.
> I would prefer to wait for the Browser thread to return after rendering
> the html, in order to update the widget's preferred size.
>
> While I can update the the size from Browser#addProgressListener it
> results in a flickering: paint#1 "normal" paint
> paint#2 paint after browser is finished, size are calculated
>
> In this particular example there is flickering - because there is no
> resize.
> The resize event would take place where STDOUT says "Browser ready".
>
>
> A working example:
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.browser.Browser;
> import org.eclipse.swt.browser.ProgressEvent;
> import org.eclipse.swt.browser.ProgressListener;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Event;
> import org.eclipse.swt.widgets.Listener;
> import org.eclipse.swt.widgets.Shell;
>
> public class SwtBrowserThread extends Composite{
>
> final Browser browser ;
> int i = 0;
> public SwtBrowserThread (Composite parent){
> super(parent, SWT.NONE);
> setLayout(new FillLayout(SWT.VERTICAL));
>
> browser = new Browser(this, SWT.NONE);
> browser.addProgressListener(new ProgressListener() {
> @Override
> public void completed(ProgressEvent arg0){
> System.out.println("Browser ready!");
> }
> @Override
> public void changed(ProgressEvent arg0) {
> }
> });
>
> Button btn = new Button(this, SWT.PUSH);
> btn.setText("Change");
> btn.addListener(SWT.Selection, new Listener() {
> @Override
> public void handleEvent(Event arg0) {
> System.out.println("\nBefore setText()");
> browser.setText("Changed " + i++ );
> System.out.println("After setText()");
> }
> });
> }
>
>
> public static void main(String[] args) {
> Display display = new Display();
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
>
>
> Composite panel = new SwtBrowserThread(shell);
> shell.setSize(200,120);
> shell.open();
> while(!shell.isDisposed()){
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
>
> }
> }
>
>
>
>
Re: Wait for Browser thread to return [message #758529 is a reply to message #757932] Wed, 23 November 2011 15:22 Go to previous message
andzsinszan is currently offline andzsinszanFriend
Messages: 32
Registered: August 2011
Member
Hi Grant,

Thank you for the help.
I am coming to accept the fact that I have to do something with the ProgressListener..

I tried browser.setRedraw(false) but it does nothing. The doc says:
"Note: This operation is a hint and may not be supported on some platforms or for some widgets. "
I guess probably I am out of luck with my gtk-linux implementation. I will check on Windows as well (my clients don't use linux, after all).

Thanks.






Previous Topic:Push Button with drop down behaviour
Next Topic:Section in Form Page is Collapsed
Goto Forum:
  


Current Time: Tue Mar 19 05:28:41 GMT 2024

Powered by FUDForum. Page generated in 0.02378 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top