[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: New Platform Browser from Browser Widget

Short answer is: not supported.

If you are willing to experiment, here is a - poor - hack below. 
Program.launch is used to access an external native viewer (IE ..). It is 
inefficient - document gets loaded twice - and fragile - Program.launch 
could fail or be passed unsupported content. If you own the HTML content you 
could verify it works in your situation otherwise it's probably wise not to 
use it. To try the example below, go to a link that opens up in a new window 
or right click and select "open in a new window" if you are on Windows.

Chris


import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.program.*;

public class PRBrowser {

 public static void main(String[] args) {
  final Display display = new Display();
  Shell shell = new Shell(display);
  shell.setText("PRBrowser");
  shell.setLayout(new FillLayout());

  final Shell hiddenShell = new Shell(display);
  final Browser hiddenBrowser = new Browser(hiddenShell, SWT.NONE);
  hiddenBrowser.addVisibilityWindowListener(new VisibilityWindowListener() {
   public void hide(WindowEvent e) {
   }
   public void show(WindowEvent e) {
    /* ignore pop-ups and other windows with no all attributes */
    if (e.addressBar && e.menuBar && e.statusBar && e.toolBar) {
     hiddenBrowser.setData("EXTERNAL", "true");
    }
   }
  });
  hiddenBrowser.addLocationListener(new LocationListener() {
   public void changing(LocationEvent event) {
   }
   public void changed(LocationEvent event) {
    if (!event.top) return;
    if (hiddenBrowser.getData("EXTERNAL") != null) {
     hiddenBrowser.setData("EXTERNAL", null);
     Program.launch(event.location);
    }
   }
  });

  Browser browser = new Browser(shell, SWT.NONE);
  browser.addOpenWindowListener(new OpenWindowListener() {
   public void open(WindowEvent e) {
    e.browser = hiddenBrowser;
   }
  });
  browser.setUrl("http://www.eclipse.org";);
  shell.open();

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