browser.setUrl freeze [message #518368] |
Wed, 03 March 2010 21:59 |
Filip Messages: 16 Registered: March 2010 Location: Czech Republic |
Junior Member |
|
|
Hello,
I have swt.browser with xulrunner (swt-3.6M5-gtk-linux-x86_64, xulrunner-sdk-1.9.1.3-linux-x86_64 - my own build). I render the page and get all links from the page as String[]. Now I want to render all pages the links refer to. So I made my own ProgressListener which takes link one by one and calls browser.setUrl() in its completed method. The trouble is that the rendering freezes. The ProgressListener is not noticed again until I move with the cursor or invoke any other system event. What am I doing wrong? I am not sure if its swt-xulrunner or OS problem? I am using Ubuntu 9.10 x86_64.
Most important part of my code is attached.
Thanks a lot for any help.
My code:
public class Test {
//swt
private Shell shell;
private Display display;
private Label status;
private Browser browser;
private ExtractLocationListener extractLocListener;
private RebuildLocationListener rebuildLocListener;
private AdvancedStatusTextListener statusListener;
private Text url;
private Button backButton;
private Button refreshButton;
private Button forwardButton;
private Button stopButton;
private Button goButton;
private Button extractButton;
private Button rebuildButton;
private Label tabInfo;
private Label statusInfo;
private TabFolder tabFolder;
private Tree treeOfBlocks;
private Tree treeOfCritics;
private Tree treeOfRegularity;
private TreeViewer treeOfBlocksViewer;
private TreeViewer treeOfCriticsViewer;
private TreeViewer treeOfRegularityViewer;
//implementation
private Links links;
public Test() {
display = new Display();
shell = new Shell(display);
shell.setText("Test");
createContents(shell, "");
try {
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
} catch (SWTException ex) {
}
}
/**
* Creates the main window's contents
*
* @param shell the main window
* @param location the initial location
*/
private void createContents(Shell shell, String location) {
// Create the web browser
browser = new Browser(shell, SWT.MOZILLA);
// !!!!!!!!!!!!!!!!!!
// Here I create a button that gets all links from to rendered webpage
// and set them to the 'links'.
// Add browsers event handlers
extractLocListener = new AdvancedLocationListener(url, statusInfo);
statusListener = new AdvancedStatusTextListener(status);
browser.addLocationListener(extractLocListener);
browser.addProgressListener(new AdvancedProgressListener(links));
browser.addStatusTextListener(statusListener);
}
static class AdvancedLocationListener implements LocationListener {
private Text url;
private Label info;
public AdvancedLocationListener(Text url, Label info) {
// Store the address box for updates
this.url = url;
this.info = info;
}
public void changing(LocationEvent event) {
// Show the location that's loading
url.setText("Loading ... " + event.location);
}
public void changed(LocationEvent event) {
// Show the loaded location
url.setText(event.location);
info.setText("Loaded");
}
}
public class AdvancedProgressListener implements ProgressListener {
private Links links;
public AdvancedProgressListener(Links links) {
this.links = links;
}
public void changed(ProgressEvent event) {
}
public void completed(ProgressEvent event) {
if (links.hasLinks()) {
browser.setUrl(links.getLink());
}
}
}
static class AdvancedStatusTextListener implements StatusTextListener {
private Label status;
public AdvancedStatusTextListener(Label label) {
// Store the label on which to report status
status = label;
}
public void changed(StatusTextEvent event) {
// Report the status
status.setText(event.text);
}
}
public static void main(String[] args) {
new Test();
}
}
[Updated on: Wed, 03 March 2010 22:01] Report message to a moderator
|
|
|
Re: browser.setUrl freeze [message #518423 is a reply to message #518368] |
Thu, 04 March 2010 05:01 |
Vijay Raj Messages: 608 Registered: July 2009 |
Senior Member |
|
|
Do you want the urls to be opened in same browser or in a seperate browser....
What you are doing is opening the url's in the same browser which is providing the urls...
this may result is recursive calls....
---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
|
|
|
|
Re: browser.setUrl freeze [message #518689 is a reply to message #518545] |
Thu, 04 March 2010 18:30 |
Filip Messages: 16 Registered: March 2010 Location: Czech Republic |
Junior Member |
|
|
Hello,
I tried my code on win XP with xulrunner-sdk-1.9.1.3-win32 and swt-3.6M5-win32-x86 and it works fine, no freeze anymmore. All pages are loaded successfully. I dont know if it's OS, xulrunner or swt problem? I tried the snippet below that doesn't use xulrunner and it freezed on kubuntu too. So I guess it is OS or swt problem. What do u think?
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
// pretend the following links were parsed out from the google.com page
final String[] links = {
"http://www.google.com/intl/en/ads/",
"http://www.google.com/services/",
"http://www.google.com/intl/en/about.html",
"http://www.google.com/intl/en/privacy.html"
};
final Browser browser = new Browser(shell, SWT.NONE);
browser.setUrl("google.com");
browser.addProgressListener(new ProgressAdapter() {
public void completed(ProgressEvent event) {
if (++linkIndex > 3) return; // done
String link = links[linkIndex];
System.out.println("changing to " + link);
browser.setUrl(link);
}
});
shell.setBounds(10,10,300,300);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
|
|
|
Re: browser.setUrl freeze [message #518717 is a reply to message #518689] |
Thu, 04 March 2010 19:41 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
It's difficult to know where the problem lies without being able to
reproduce the problem and investigate. I would suggest logging a report
with swt (
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform &component=SWT )
and including the snippet that hangs. An SWT.NONE-style Browser on Linux
actually does use XULRunner, to find out which one make the snippet's first
line "Device.DEBUG=true;". Be sure to specify your XULRunner version and
linux distro, as the snippet worked for me on 32-bit Ubuntu 9.10.
Grant
"Filip" <filip.pekarek@gmail.com> wrote in message
news:hmou7l$3as$1@build.eclipse.org...
> Hello,
> I tried my code on win XP with xulrunner-sdk-1.9.1.3-win32 and
swt-3.6M5-win32-x86 and it works fine, no freeze anymmore. All pages are
loaded successfully. I dont know if it's OS, xulrunner or swt problem? I
tried the snippet below that doesn't use xulrunner and it freezed on kubuntu
too. So I guess it is OS or swt problem. What do u think?
>
> public static void main(String[] args) {
> final Display display = new Display();
> final Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
> // pretend the following links were parsed out from the google.com
page
> final String[] links = {
> "http://www.google.com/intl/en/ads/",
> "http://www.google.com/services/",
> "http://www.google.com/intl/en/about.html",
> "http://www.google.com/intl/en/privacy.html"
> };
> final Browser browser = new Browser(shell, SWT.NONE);
> browser.setUrl("google.com");
> browser.addProgressListener(new ProgressAdapter() {
> public void completed(ProgressEvent event) {
> if (++linkIndex > 3) return; // done
> String link = links[linkIndex];
> System.out.println("changing to " + link);
> browser.setUrl(link);
> }
> });
> shell.setBounds(10,10,300,300);
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) display.sleep();
> }
> display.dispose();
> }
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.09331 seconds