Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] swt.browser trouble

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.

Filip

package test;

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


Back to the top